DLP控制中的字節解析過程詳解(解析0x78指令發送過程)

  計算過程:



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;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章