计算过程:
0 trigType
0 patNum
8 bitDepth
7 ledSelect
0 invertPat
0 insertBlack
1 bufSwap
0 trigOutPrev
unsigned long int lutWord = 0;
1 lutWord = TrigType & 3;
解析:
4字节: 0000 0000 ; 0000 0000 ; 0000 0000; 0000 0000;
TeigType & 3 =>0001 & 0011 => 0001 => LutWord = 1;
2 if(PatNum > 24)
return -1;
lutWord |= ((PatNum & 0x3F) << 2);
解析:
0x3F: 0011 1111;
patNum:有三个数值:0 1 2=>0000 ;0001 ; 0010
假设patNum = 1
patNum & 0x3F => 0000 0001 & 0011 1111 => 0000 0001;
(patNum & 0x3F)<<2 => 0000 0100 => 4;
lutWord | ((patNum & 0x3F)<<2) => 0001 | 0100 => 0101?
3 if( (BitDepth > 8) || (BitDepth <= 0))
return -1;
lutWord |= ((BitDepth & 0xF) << 8);
解析:
0xF: 0000 1111;
bitDepth拥有:0 1 2 3 4 5 6 7 8; 假设其为8
bitDepth & 0xF => 1000 & 1111 => 1000;
((BitDepth & 0xF) << 8) => 1000 0000 0000 : 800
lutWord | ((BitDepth & 0xF) << 8) =>
0000 0000 0000 0101 | 0000 1000 0000 0000 => 0000 1000 0000 0101
4 if(LEDSelect > 7)
return -1;
lutWord |= ((LEDSelect & 0x7) << 12);
解析:
0x7:0111
LEDSelect:0-8选择.假设当前选择7,Red?
7:0111;
LEDSelect & 0x7 =>0111 & 0111 =>0111;
(LEDSelect & 0x7) << 12 => 0111 0000 0000 0000
lutWord | ((LEDSelect & 0x7) << 12) => 0000 1000 0000 0101 | 0111 0000 0000 0000
=> 0111 1000 0000 0101
if(InvertPat)
lutWord |= BIT16;
BIT16: 0x00010000 : 0001 0000 0000 0000 0000
BIT17: 0x00020000 : 0010 0000 0000 0000 0000
BIT18: 0x00040000 : 0100 0000 0000 0000 0000
BIT19: 0x00080000 : 1000 0000 0000 0000 0000
以上:LutWord | BiT16 =>0000 0111 1000 0000 0101 | 0001 0000 0000 0000 0000
=>0001 0111 1000 0000 0101
|BIT17 =>0011 0111 1000 0000 0101
|BIT18 =>0101 0111 1000 0000 0101
|BIT19 =>1111 0111 1000 0000 0101
5 if(InsertBlack)
lutWord |= BIT17;
6 if(BufSwap)
lutWord |= BIT18;
7 if(trigOutPrev)
lutWord |= BIT19;
g_PatLut[g_PatLutIndex++] = lutWord;
*/
// unsigned long int : 4 byte;