Created
August 18, 2017 07:22
-
-
Save electronut/382ce40be1d138bbd1ba5ee689e83344 to your computer and use it in GitHub Desktop.
caclChannelValue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint32_t caclChannelValue(uint8_t level) | |
{ | |
uint32_t val = 0; | |
// 0 | |
if(level == 0) { | |
val = 0x88888888; | |
} | |
// 255 | |
else if (level == 255) { | |
val = 0xeeeeeeee; | |
} | |
else { | |
// apply 4-bit 0xe HIGH pattern wherever level bits are 1. | |
val = 0x88888888; | |
for (uint8_t i = 0; i < 8; i++) { | |
if((1 << i) & level) { | |
uint32_t mask = ~(0x0f << 4*i); | |
uint32_t patt = (0x0e << 4*i); | |
val = (val & mask) | patt; | |
} | |
} | |
// swap 16 bits | |
val = (val >> 16) | (val << 16); | |
} | |
return val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment