Mercurial > louis > kiibohd-controller
comparison Scan/ISSILed/led_scan.c @ 356:58d2c5bf95eb
Adding ISSILed API calls and default brightness
- Adds override functionality in main module
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 02 Aug 2015 16:28:21 -0700 |
parents | 66eccdd9ced5 |
children | 86b937945313 |
comparison
equal
deleted
inserted
replaced
355:0597f6c0d194 | 356:58d2c5bf95eb |
---|---|
19 // Compiler Includes | 19 // Compiler Includes |
20 #include <Lib/ScanLib.h> | 20 #include <Lib/ScanLib.h> |
21 | 21 |
22 // Project Includes | 22 // Project Includes |
23 #include <cli.h> | 23 #include <cli.h> |
24 #include <kll.h> | |
24 #include <led.h> | 25 #include <led.h> |
25 #include <print.h> | 26 #include <print.h> |
26 #include <led_conf.h> // Located with scan_loop.c | |
27 | 27 |
28 // Local Includes | 28 // Local Includes |
29 #include "led_scan.h" | 29 #include "led_scan.h" |
30 | 30 |
31 | 31 |
55 | 55 |
56 | 56 |
57 // ----- Function Declarations ----- | 57 // ----- Function Declarations ----- |
58 | 58 |
59 // CLI Functions | 59 // CLI Functions |
60 void cliFunc_i2cRecv( char* args ); | 60 void cliFunc_i2cRecv ( char* args ); |
61 void cliFunc_i2cSend( char* args ); | 61 void cliFunc_i2cSend ( char* args ); |
62 void cliFunc_ledPage( char* args ); | 62 void cliFunc_ledRPage( char* args ); |
63 void cliFunc_ledStart( char* args ); | 63 void cliFunc_ledStart( char* args ); |
64 void cliFunc_ledTest( char* args ); | 64 void cliFunc_ledTest ( char* args ); |
65 void cliFunc_ledZero( char* args ); | 65 void cliFunc_ledWPage( char* args ); |
66 void cliFunc_ledZero ( char* args ); | |
66 | 67 |
67 uint8_t I2C_TxBufferPop(); | 68 uint8_t I2C_TxBufferPop(); |
68 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ); | 69 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer ); |
69 uint16_t I2C_BufferLen( I2C_Buffer *buffer ); | 70 uint16_t I2C_BufferLen( I2C_Buffer *buffer ); |
70 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen ); | 71 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen ); |
74 // ----- Variables ----- | 75 // ----- Variables ----- |
75 | 76 |
76 // Scan Module command dictionary | 77 // Scan Module command dictionary |
77 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." ); | 78 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." ); |
78 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." ); | 79 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." ); |
79 CLIDict_Entry( ledPage, "Read the given register page." ); | 80 CLIDict_Entry( ledRPage, "Read the given register page." ); |
80 CLIDict_Entry( ledStart, "Disable software shutdown." ); | 81 CLIDict_Entry( ledStart, "Disable software shutdown." ); |
81 CLIDict_Entry( ledTest, "Test out the led pages." ); | 82 CLIDict_Entry( ledTest, "Test out the led pages." ); |
83 CLIDict_Entry( ledWPage, "Write to given register page starting at address. i.e. 0x2 0x24 0xF0 0x12" ); | |
82 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." ); | 84 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." ); |
83 | 85 |
84 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = { | 86 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = { |
85 CLIDict_Item( i2cRecv ), | 87 CLIDict_Item( i2cRecv ), |
86 CLIDict_Item( i2cSend ), | 88 CLIDict_Item( i2cSend ), |
87 CLIDict_Item( ledPage ), | 89 CLIDict_Item( ledRPage ), |
88 CLIDict_Item( ledStart ), | 90 CLIDict_Item( ledStart ), |
89 CLIDict_Item( ledTest ), | 91 CLIDict_Item( ledTest ), |
92 CLIDict_Item( ledWPage ), | |
90 CLIDict_Item( ledZero ), | 93 CLIDict_Item( ledZero ), |
91 { 0, 0, 0 } // Null entry for dictionary end | 94 { 0, 0, 0 } // Null entry for dictionary end |
92 }; | 95 }; |
93 | 96 |
94 | 97 |
101 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr }; | 104 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr }; |
102 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr }; | 105 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr }; |
103 | 106 |
104 LED_Buffer LED_pageBuffer; | 107 LED_Buffer LED_pageBuffer; |
105 | 108 |
106 /* | |
107 // A bit mask determining which LEDs are enabled in the ISSI chip | 109 // A bit mask determining which LEDs are enabled in the ISSI chip |
108 // All channel mask example | 110 const uint8_t LED_ledEnableMask1[] = { |
109 // 0x00 -> 0x11 | 111 0xE8, // I2C address |
110 const uint8_t LED_ledEnableMask[] = { | 112 0x00, // Starting register address |
111 0xE8, // I2C address | 113 ISSILedMask1_define |
112 0x00, // Starting register address | |
113 0xFF, 0xFF, // C1-1 -> C1-16 | |
114 0xFF, 0xFF, // C2-1 -> C2-16 | |
115 0xFF, 0xFF, // C3-1 -> C3-16 | |
116 0xFF, 0xFF, // C4-1 -> C4-16 | |
117 0xFF, 0xFF, // C5-1 -> C5-16 | |
118 0xFF, 0xFF, // C6-1 -> C6-16 | |
119 0xFF, 0xFF, // C7-1 -> C7-16 | |
120 0xFF, 0xFF, // C8-1 -> C8-16 | |
121 0xFF, 0xFF, // C9-1 -> C9-16 | |
122 }; | 114 }; |
123 */ | 115 |
124 | 116 // Default LED brightness |
125 /* | 117 const uint8_t LED_defaultBrightness1[] = { |
126 // A bit mask determining which LEDs are enabled in the ISSI chip | 118 0xE8, // I2C address |
127 // Infinity ErgoDox full mask | 119 0x24, // Starting register address |
128 // 0x00 -> 0x11 | 120 ISSILedBrightness1_define |
129 const uint8_t LED_ledEnableMask[] = { | |
130 0xE8, // I2C address | |
131 0x00, // Starting register address | |
132 0xFC, 0xFC, // C1-1 -> C1-16 | |
133 0xFB, 0xFB, // C2-1 -> C2-16 | |
134 0xFF, 0xFF, // C3-1 -> C3-16 | |
135 0xFE, 0xFE, // C4-1 -> C4-16 | |
136 0x7F, 0x7F, // C5-1 -> C5-16 | |
137 0xFF, 0xFF, // C6-1 -> C6-16 | |
138 0xCF, 0xCF, // C7-1 -> C7-16 | |
139 0xC7, 0xC7, // C8-1 -> C8-16 | |
140 0x43, 0x43, // C9-1 -> C9-16 | |
141 }; | |
142 */ | |
143 | |
144 /* | |
145 const uint8_t LED_ledEnableMask[] = { | |
146 0xE8, // I2C address | |
147 0x00, // Starting register address | |
148 0x00, 0x00, // C1-1 -> C1-16 | |
149 //0xEC, 0xEC, // C1-1 -> C1-16 | |
150 0x00, 0x00, // C2-1 -> C2-16 | |
151 0x00, 0x00, // C3-1 -> C3-16 | |
152 0x00, 0x00, // C4-1 -> C4-16 | |
153 0x00, 0x00, // C5-1 -> C5-16 | |
154 0x00, 0x00, // C6-1 -> C6-16 | |
155 0x08, 0x08, // C7-1 -> C7-16 | |
156 0x00, 0x00, // C8-1 -> C8-16 | |
157 0x00, 0x00, // C9-1 -> C9-16 | |
158 }; | |
159 */ | |
160 | |
161 | |
162 /* | |
163 // XXX Pre-fill example of buffers | |
164 const uint8_t examplePage[] = { | |
165 0xE8, // I2C address | |
166 0x24, // Starting register address | |
167 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C1-1 -> C1-16 | |
168 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C2-1 -> C2-16 | |
169 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C3-1 -> C3-16 | |
170 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C4-1 -> C4-16 | |
171 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C5-1 -> C5-16 | |
172 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C6-1 -> C6-16 | |
173 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C7-1 -> C7-16 | |
174 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C8-1 -> C8-16 | |
175 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // C9-1 -> C9-16 | |
176 }; | |
177 */ | |
178 | |
179 // XXX Pre-fill example of buffers | |
180 const uint8_t examplePage[] = { | |
181 0xE8, // I2C address | |
182 0x24, // Starting register address | |
183 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, // C1-1 -> C1-16 | |
184 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, // C2-1 -> C2-16 | |
185 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, // C3-1 -> C3-16 | |
186 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, // C4-1 -> C4-16 | |
187 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, // C5-1 -> C5-16 | |
188 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, // C6-1 -> C6-16 | |
189 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, // C7-1 -> C7-16 | |
190 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, // C8-1 -> C8-16 | |
191 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, // C9-1 -> C9-16 | |
192 }; | 121 }; |
193 | 122 |
194 | 123 |
195 | 124 |
196 // ----- Interrupt Functions ----- | 125 // ----- Interrupt Functions ----- |
444 | 373 |
445 // Clear LED Pages | 374 // Clear LED Pages |
446 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers | 375 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers |
447 | 376 |
448 // Enable LEDs based upon mask | 377 // Enable LEDs based upon mask |
449 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 ); | 378 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 ); |
379 | |
380 // Set default brightness | |
381 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 ); | |
450 | 382 |
451 // Disable Software shutdown of ISSI chip | 383 // Disable Software shutdown of ISSI chip |
452 LED_writeReg( 0x0A, 0x01, 0x0B ); | 384 LED_writeReg( 0x0A, 0x01, 0x0B ); |
453 } | 385 } |
454 | 386 |
783 print( NL ); | 715 print( NL ); |
784 | 716 |
785 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip | 717 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip |
786 } | 718 } |
787 | 719 |
788 void cliFunc_ledPage( char* args ) | 720 void cliFunc_ledRPage( char* args ) |
789 { | 721 { |
790 // Parse number from argument | 722 // Parse number from argument |
791 // NOTE: Only first argument is used | 723 // NOTE: Only first argument is used |
792 char* arg1Ptr; | 724 char* arg1Ptr; |
793 char* arg2Ptr; | 725 char* arg2Ptr; |
805 print( NL ); | 737 print( NL ); |
806 | 738 |
807 LED_readPage( 0xB4, page ); | 739 LED_readPage( 0xB4, page ); |
808 } | 740 } |
809 | 741 |
742 void cliFunc_ledWPage( char* args ) | |
743 { | |
744 char* curArgs; | |
745 char* arg1Ptr; | |
746 char* arg2Ptr = args; | |
747 | |
748 // First process page and starting address | |
749 curArgs = arg2Ptr; | |
750 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
751 | |
752 // Stop processing args if no more are found | |
753 if ( *arg1Ptr == '\0' ) | |
754 return; | |
755 uint8_t page[] = { 0xE8, 0xFD, numToInt( arg1Ptr ) }; | |
756 | |
757 curArgs = arg2Ptr; | |
758 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
759 | |
760 // Stop processing args if no more are found | |
761 if ( *arg1Ptr == '\0' ) | |
762 return; | |
763 uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 }; | |
764 | |
765 // Set the register page | |
766 while ( I2C_Send( page, sizeof( page ), 0 ) == 0 ) | |
767 delay(1); | |
768 | |
769 // Process all args | |
770 for ( ;; ) | |
771 { | |
772 curArgs = arg2Ptr; | |
773 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
774 | |
775 // Stop processing args if no more are found | |
776 if ( *arg1Ptr == '\0' ) | |
777 break; | |
778 | |
779 data[2] = numToInt( arg1Ptr ); | |
780 | |
781 // Write register location and data to I2C | |
782 while ( I2C_Send( data, sizeof( data ), 0 ) == 0 ) | |
783 delay(1); | |
784 | |
785 // Increment address | |
786 data[1]++; | |
787 } | |
788 } | |
789 | |
810 void cliFunc_ledStart( char* args ) | 790 void cliFunc_ledStart( char* args ) |
811 { | 791 { |
812 print( NL ); // No \r\n by default after the command is entered | 792 print( NL ); // No \r\n by default after the command is entered |
813 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers | 793 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers |
814 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers | 794 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers |
815 LED_writeReg( 0x0A, 0x01, 0x0B ); | 795 LED_writeReg( 0x0A, 0x01, 0x0B ); |
816 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 ); | 796 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 ); |
817 | 797 |
818 } | 798 } |
819 | 799 |
820 void cliFunc_ledTest( char* args ) | 800 void cliFunc_ledTest( char* args ) |
821 { | 801 { |
822 print( NL ); // No \r\n by default after the command is entered | 802 print( NL ); // No \r\n by default after the command is entered |
823 LED_sendPage( (uint8_t*)examplePage, sizeof( examplePage ), 0 ); | 803 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 ); |
824 } | 804 } |
825 | 805 |
826 void cliFunc_ledZero( char* args ) | 806 void cliFunc_ledZero( char* args ) |
827 { | 807 { |
828 print( NL ); // No \r\n by default after the command is entered | 808 print( NL ); // No \r\n by default after the command is entered |