Mercurial > louis > kiibohd-controller
comparison Scan/ISSILed/led_scan.c @ 331:9e31d92caf12
Initial STLcd code.
- Basic screen initialization and clear is working
- Currently SPI is set to a low speed for easy logic analyzer debugging
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Tue, 14 Apr 2015 00:40:48 -0700 |
parents | f4d4cad283c6 |
children | 66eccdd9ced5 |
comparison
equal
deleted
inserted
replaced
330:f4d4cad283c6 | 331:9e31d92caf12 |
---|---|
54 | 54 |
55 | 55 |
56 // ----- Function Declarations ----- | 56 // ----- Function Declarations ----- |
57 | 57 |
58 // CLI Functions | 58 // CLI Functions |
59 void cliFunc_echo( char* args ); | |
60 void cliFunc_i2cRecv( char* args ); | 59 void cliFunc_i2cRecv( char* args ); |
61 void cliFunc_i2cSend( char* args ); | 60 void cliFunc_i2cSend( char* args ); |
61 void cliFunc_ledPage( char* args ); | |
62 void cliFunc_ledStart( char* args ); | |
62 void cliFunc_ledTest( char* args ); | 63 void cliFunc_ledTest( char* args ); |
63 void cliFunc_ledZero( char* args ); | 64 void cliFunc_ledZero( char* args ); |
64 | 65 |
65 uint8_t I2C_TxBufferPop(); | 66 uint8_t I2C_TxBufferPop(); |
66 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ); | 67 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ); |
72 // ----- Variables ----- | 73 // ----- Variables ----- |
73 | 74 |
74 // Scan Module command dictionary | 75 // Scan Module command dictionary |
75 CLIDict_Entry( i2cRecv, "Send I2C sequence of bytes and expect a reply of 1 byte on the last sequence." NL "\t\tUse |'s to split sequences with a stop." ); | 76 CLIDict_Entry( i2cRecv, "Send I2C sequence of bytes and expect a reply of 1 byte on the last sequence." NL "\t\tUse |'s to split sequences with a stop." ); |
76 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." ); | 77 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." ); |
78 CLIDict_Entry( ledPage, "Read the given register page." ); | |
79 CLIDict_Entry( ledStart, "Disable software shutdown." ); | |
77 CLIDict_Entry( ledTest, "Test out the led pages." ); | 80 CLIDict_Entry( ledTest, "Test out the led pages." ); |
78 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." ); | 81 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." ); |
79 | 82 |
80 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = { | 83 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = { |
81 CLIDict_Item( i2cRecv ), | 84 CLIDict_Item( i2cRecv ), |
82 CLIDict_Item( i2cSend ), | 85 CLIDict_Item( i2cSend ), |
86 CLIDict_Item( ledPage ), | |
87 CLIDict_Item( ledStart ), | |
83 CLIDict_Item( ledTest ), | 88 CLIDict_Item( ledTest ), |
84 CLIDict_Item( ledZero ), | 89 CLIDict_Item( ledZero ), |
85 { 0, 0, 0 } // Null entry for dictionary end | 90 { 0, 0, 0 } // Null entry for dictionary end |
86 }; | 91 }; |
87 | 92 |
95 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr }; | 100 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr }; |
96 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr }; | 101 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr }; |
97 | 102 |
98 LED_Buffer LED_pageBuffer; | 103 LED_Buffer LED_pageBuffer; |
99 | 104 |
105 /* | |
100 // A bit mask determining which LEDs are enabled in the ISSI chip | 106 // A bit mask determining which LEDs are enabled in the ISSI chip |
107 // All channel mask example | |
101 // 0x00 -> 0x11 | 108 // 0x00 -> 0x11 |
102 const uint8_t LED_ledEnableMask[] = { | 109 const uint8_t LED_ledEnableMask[] = { |
103 0xE8, // I2C address | 110 0xE8, // I2C address |
104 0x00, // Starting register address | 111 0x00, // Starting register address |
105 0xFF, 0xFF, // C1-1 -> C1-16 | 112 0xFF, 0xFF, // C1-1 -> C1-16 |
110 0xFF, 0xFF, // C6-1 -> C6-16 | 117 0xFF, 0xFF, // C6-1 -> C6-16 |
111 0xFF, 0xFF, // C7-1 -> C7-16 | 118 0xFF, 0xFF, // C7-1 -> C7-16 |
112 0xFF, 0xFF, // C8-1 -> C8-16 | 119 0xFF, 0xFF, // C8-1 -> C8-16 |
113 0xFF, 0xFF, // C9-1 -> C9-16 | 120 0xFF, 0xFF, // C9-1 -> C9-16 |
114 }; | 121 }; |
115 | 122 */ |
123 | |
124 /* | |
125 // A bit mask determining which LEDs are enabled in the ISSI chip | |
126 // Infinity ErgoDox full mask | |
127 // 0x00 -> 0x11 | |
128 const uint8_t LED_ledEnableMask[] = { | |
129 0xE8, // I2C address | |
130 0x00, // Starting register address | |
131 0xFC, 0xFC, // C1-1 -> C1-16 | |
132 0xFB, 0xFB, // C2-1 -> C2-16 | |
133 0xFF, 0xFF, // C3-1 -> C3-16 | |
134 0xFE, 0xFE, // C4-1 -> C4-16 | |
135 0x7F, 0x7F, // C5-1 -> C5-16 | |
136 0xFF, 0xFF, // C6-1 -> C6-16 | |
137 0xCF, 0xCF, // C7-1 -> C7-16 | |
138 0xC7, 0xC7, // C8-1 -> C8-16 | |
139 0x43, 0x43, // C9-1 -> C9-16 | |
140 }; | |
141 */ | |
142 const uint8_t LED_ledEnableMask[] = { | |
143 0xE8, // I2C address | |
144 0x00, // Starting register address | |
145 0x00, 0x00, // C1-1 -> C1-16 | |
146 //0xEC, 0xEC, // C1-1 -> C1-16 | |
147 0x00, 0x00, // C2-1 -> C2-16 | |
148 0x00, 0x00, // C3-1 -> C3-16 | |
149 0x00, 0x00, // C4-1 -> C4-16 | |
150 0x00, 0x00, // C5-1 -> C5-16 | |
151 0x00, 0x00, // C6-1 -> C6-16 | |
152 0x08, 0x08, // C7-1 -> C7-16 | |
153 0x00, 0x00, // C8-1 -> C8-16 | |
154 0x00, 0x00, // C9-1 -> C9-16 | |
155 }; | |
156 | |
157 | |
158 // XXX Pre-fill example of buffers | |
159 const uint8_t examplePage[] = { | |
160 0xE8, // I2C address | |
161 0x24, // Starting register address | |
162 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C1-1 -> C1-16 | |
163 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C2-1 -> C2-16 | |
164 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C3-1 -> C3-16 | |
165 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C4-1 -> C4-16 | |
166 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C5-1 -> C5-16 | |
167 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C6-1 -> C6-16 | |
168 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C7-1 -> C7-16 | |
169 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C8-1 -> C8-16 | |
170 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C9-1 -> C9-16 | |
171 }; | |
172 | |
173 /* | |
116 // XXX Pre-fill example of buffers | 174 // XXX Pre-fill example of buffers |
117 const uint8_t examplePage[] = { | 175 const uint8_t examplePage[] = { |
118 0xE8, // I2C address | 176 0xE8, // I2C address |
119 0x24, // Starting register address | 177 0x24, // Starting register address |
120 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, // C1-1 -> C1-16 | 178 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, // C1-1 -> C1-16 |
125 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, // C6-1 -> C6-16 | 183 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, // C6-1 -> C6-16 |
126 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, // C7-1 -> C7-16 | 184 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, // C7-1 -> C7-16 |
127 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, // C8-1 -> C8-16 | 185 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, // C8-1 -> C8-16 |
128 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, // C9-1 -> C9-16 | 186 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, // C9-1 -> C9-16 |
129 }; | 187 }; |
188 */ | |
130 | 189 |
131 | 190 |
132 | 191 |
133 // ----- Interrupt Functions ----- | 192 // ----- Interrupt Functions ----- |
134 | 193 |
315 while ( I2C_Send( buffer, len, 0 ) == 0 ) | 374 while ( I2C_Send( buffer, len, 0 ) == 0 ) |
316 delay(1); | 375 delay(1); |
317 | 376 |
318 } | 377 } |
319 | 378 |
320 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page ) | 379 void LED_readPage( uint8_t len, uint8_t page ) |
321 { | 380 { |
322 // Page Setup | 381 // Page Setup |
323 uint8_t pageSetup[] = { 0xE8, 0xFD, page }; | 382 uint8_t pageSetup[] = { 0xE8, 0xFD, page }; |
324 | |
325 // Reg Write Setup | |
326 uint8_t writeData[] = { 0xE8, reg, val }; | |
327 | 383 |
328 // Setup page | 384 // Setup page |
329 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 ) | 385 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 ) |
330 delay(1); | 386 delay(1); |
331 | 387 |
388 // Register Setup | |
389 uint8_t regSetup[] = { 0xE8, 0x00 }; | |
390 | |
391 // Setup starting register | |
392 while ( I2C_Send( regSetup, sizeof( regSetup ), 0 ) == 0 ) | |
393 delay(1); | |
394 | |
395 // Register Read Command | |
396 uint8_t regReadCmd[] = { 0xE9 }; | |
397 | |
398 // Read each register in the page | |
399 for ( uint8_t reg = 0; reg < len; reg++ ) | |
400 { | |
401 // Request register data | |
402 while ( I2C_Send( regReadCmd, sizeof( regReadCmd ), 0 ) == 0 ) | |
403 delay(1); | |
404 } | |
405 } | |
406 | |
407 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page ) | |
408 { | |
409 // Page Setup | |
410 uint8_t pageSetup[] = { 0xE8, 0xFD, page }; | |
411 | |
412 // Reg Write Setup | |
413 uint8_t writeData[] = { 0xE8, reg, val }; | |
414 | |
415 // Setup page | |
416 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 ) | |
417 delay(1); | |
418 | |
332 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 ) | 419 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 ) |
333 delay(1); | 420 delay(1); |
334 } | 421 } |
335 | 422 |
336 // Setup | 423 // Setup |
340 CLI_registerDictionary( ledCLIDict, ledCLIDictName ); | 427 CLI_registerDictionary( ledCLIDict, ledCLIDictName ); |
341 | 428 |
342 // Initialize I2C | 429 // Initialize I2C |
343 I2C_setup(); | 430 I2C_setup(); |
344 | 431 |
432 /* TODO Make work | |
345 // Zero out Frame Registers | 433 // Zero out Frame Registers |
346 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things) | 434 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things) |
347 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers | 435 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers |
348 | 436 |
349 // Disable Hardware shutdown of ISSI chip (pull high) | 437 // Disable Hardware shutdown of ISSI chip (pull high) |
357 // Enable LEDs based upon mask | 445 // Enable LEDs based upon mask |
358 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 ); | 446 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 ); |
359 | 447 |
360 // Disable Software shutdown of ISSI chip | 448 // Disable Software shutdown of ISSI chip |
361 LED_writeReg( 0x0A, 0x01, 0x0B ); | 449 LED_writeReg( 0x0A, 0x01, 0x0B ); |
450 */ | |
362 } | 451 } |
363 | 452 |
364 | 453 |
365 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer ) | 454 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer ) |
366 { | 455 { |
444 } | 533 } |
445 | 534 |
446 | 535 |
447 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ) | 536 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ) |
448 { | 537 { |
538 dbug_msg("DATA: "); | |
539 printHex( byte ); | |
540 | |
449 // Make sure buffer isn't full | 541 // Make sure buffer isn't full |
450 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) ) | 542 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) ) |
451 { | 543 { |
452 warn_msg("I2C_BufferPush failed, buffer full: "); | 544 warn_msg("I2C_BufferPush failed, buffer full: "); |
453 printHex( byte ); | 545 printHex( byte ); |
689 print( NL ); | 781 print( NL ); |
690 | 782 |
691 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip | 783 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip |
692 } | 784 } |
693 | 785 |
786 void cliFunc_ledPage( char* args ) | |
787 { | |
788 // Parse number from argument | |
789 // NOTE: Only first argument is used | |
790 char* arg1Ptr; | |
791 char* arg2Ptr; | |
792 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | |
793 | |
794 // Default to 0 if no argument is given | |
795 uint8_t page = 0; | |
796 | |
797 if ( arg1Ptr[0] != '\0' ) | |
798 { | |
799 page = (uint8_t)numToInt( arg1Ptr ); | |
800 } | |
801 | |
802 // No \r\n by default after the command is entered | |
803 print( NL ); | |
804 | |
805 LED_readPage( 0xB4, page ); | |
806 } | |
807 | |
808 void cliFunc_ledStart( char* args ) | |
809 { | |
810 print( NL ); // No \r\n by default after the command is entered | |
811 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers | |
812 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers | |
813 LED_writeReg( 0x0A, 0x01, 0x0B ); | |
814 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 ); | |
815 | |
816 } | |
817 | |
694 void cliFunc_ledTest( char* args ) | 818 void cliFunc_ledTest( char* args ) |
695 { | 819 { |
696 print( NL ); // No \r\n by default after the command is entered | 820 print( NL ); // No \r\n by default after the command is entered |
697 LED_sendPage( (uint8_t*)examplePage, sizeof( examplePage ), 0 ); | 821 LED_sendPage( (uint8_t*)examplePage, sizeof( examplePage ), 0 ); |
698 } | 822 } |