1 /* Copyright (C) 2014-2015 by Jacob Alexander
3 * This file is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This file is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this file. If not, see <http://www.gnu.org/licenses/>.
17 // ----- Includes -----
20 #include <Lib/ScanLib.h>
28 // Interconnect module if compiled in
29 #if defined(ConnectEnabled_define)
30 #include <connect_scan.h>
38 // ----- Defines -----
40 #define I2C_TxBufferLength 300
41 #define I2C_RxBufferLength 8
43 #define LED_BufferLength 144
45 // TODO Needs to be defined per keyboard
46 #define LED_TotalChannels 144
50 // ----- Structs -----
52 typedef struct I2C_Buffer {
60 typedef struct LED_Buffer {
63 uint8_t buffer[LED_BufferLength];
68 // ----- Function Declarations -----
71 void cliFunc_i2cRecv ( char* args );
72 void cliFunc_i2cSend ( char* args );
73 void cliFunc_ledCtrl ( char* args );
74 void cliFunc_ledRPage( char* args );
75 void cliFunc_ledStart( char* args );
76 void cliFunc_ledTest ( char* args );
77 void cliFunc_ledWPage( char* args );
78 void cliFunc_ledZero ( char* args );
80 uint8_t I2C_TxBufferPop();
81 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer );
82 uint16_t I2C_BufferLen( I2C_Buffer *buffer );
83 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen );
87 // ----- Variables -----
89 // Scan Module command dictionary
90 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." );
91 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
92 CLIDict_Entry( ledCtrl, "Basic LED control. Args: <mode> <amount> [<index>]" );
93 CLIDict_Entry( ledRPage, "Read the given register page." );
94 CLIDict_Entry( ledStart, "Disable software shutdown." );
95 CLIDict_Entry( ledTest, "Test out the led pages." );
96 CLIDict_Entry( ledWPage, "Write to given register page starting at address. i.e. 0x2 0x24 0xF0 0x12" );
97 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
99 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
100 CLIDict_Item( i2cRecv ),
101 CLIDict_Item( i2cSend ),
102 CLIDict_Item( ledCtrl ),
103 CLIDict_Item( ledRPage ),
104 CLIDict_Item( ledStart ),
105 CLIDict_Item( ledTest ),
106 CLIDict_Item( ledWPage ),
107 CLIDict_Item( ledZero ),
108 { 0, 0, 0 } // Null entry for dictionary end
113 // Before sending the sequence, I2C_TxBuffer_CurLen is assigned and as each byte is sent, it is decremented
114 // Once I2C_TxBuffer_CurLen reaches zero, a STOP on the I2C bus is sent
115 volatile uint8_t I2C_TxBufferPtr[ I2C_TxBufferLength ];
116 volatile uint8_t I2C_RxBufferPtr[ I2C_TxBufferLength ];
118 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr };
119 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr };
121 LED_Buffer LED_pageBuffer;
123 // A bit mask determining which LEDs are enabled in the ISSI chip
124 const uint8_t LED_ledEnableMask1[] = {
126 0x00, // Starting register address
130 // Default LED brightness
131 const uint8_t LED_defaultBrightness1[] = {
133 0x24, // Starting register address
134 ISSILedBrightness1_define
139 // ----- Interrupt Functions -----
143 cli(); // Disable Interrupts
145 uint8_t status = I2C0_S; // Read I2C Bus status
147 // Master Mode Transmit
148 if ( I2C0_C1 & I2C_C1_TX )
150 // Check current use of the I2C bus
151 // Currently sending data
152 if ( I2C_TxBuffer.sequencePos > 0 )
154 // Make sure slave sent an ACK
155 if ( status & I2C_S_RXAK )
157 // NACK Detected, disable interrupt
158 erro_print("I2C NAK detected...");
159 I2C0_C1 = I2C_C1_IICEN;
162 I2C_TxBuffer.head = 0;
163 I2C_TxBuffer.tail = 0;
164 I2C_TxBuffer.sequencePos = 0;
169 I2C0_D = I2C_TxBufferPop();
173 else if ( I2C_RxBuffer.sequencePos > 0 )
175 // Master Receive, addr sent
176 if ( status & I2C_S_ARBL )
179 erro_print("Arbitration lost...");
182 I2C0_C1 = I2C_C1_IICEN;
183 I2C0_S = I2C_S_ARBL | I2C_S_IICIF; // Clear ARBL flag and interrupt
185 if ( status & I2C_S_RXAK )
187 // Slave Address NACK Detected, disable interrupt
188 erro_print("Slave Address I2C NAK detected...");
191 I2C0_C1 = I2C_C1_IICEN;
195 dbug_msg("Attempting to read byte - ");
196 printHex( I2C_RxBuffer.sequencePos );
198 I2C0_C1 = I2C_RxBuffer.sequencePos == 1
199 ? I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK // Single byte read
200 : I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST; // Multi-byte read
207 printHex( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) );
211 // Delay around STOP to make sure it actually happens...
212 delayMicroseconds( 1 );
213 I2C0_C1 = I2C_C1_IICEN; // Send STOP
214 delayMicroseconds( 7 );
216 // If there is another sequence, start sending
217 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) < I2C_TxBuffer.size )
219 // Clear status flags
220 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
222 // Wait...till the master dies
223 while ( I2C0_S & I2C_S_BUSY );
225 // Enable I2C interrupt
226 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
229 I2C0_D = I2C_TxBufferPop();
233 // Master Mode Receive
236 // XXX Do we need to handle 2nd last byte?
237 //I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK; // No STOP, Rx, NAK on recv
240 if ( I2C_TxBuffer.sequencePos <= 1 )
243 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
246 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
248 delayMicroseconds( 1 ); // Should be enough time before issuing the stop
249 I2C0_C1 = I2C_C1_IICEN; // Send STOP
254 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
258 I2C0_S = I2C_S_IICIF; // Clear interrupt
260 sei(); // Re-enable Interrupts
265 // ----- Functions -----
267 inline void I2C_setup()
269 // Enable I2C internal clock
270 SIM_SCGC4 |= SIM_SCGC4_I2C0; // Bus 0
272 // External pull-up resistor
273 PORTB_PCR0 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
274 PORTB_PCR1 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
276 // SCL Frequency Divider
277 // 400kHz -> 120 (0x85) @ 48 MHz F_BUS
280 I2C0_C1 = I2C_C1_IICEN;
281 I2C0_C2 = I2C_C2_HDRS; // High drive select
283 // Enable I2C Interrupt
284 NVIC_ENABLE_IRQ( IRQ_I2C0 );
287 void LED_zeroPages( uint8_t startPage, uint8_t numPages, uint8_t startReg, uint8_t endReg )
290 uint8_t pageSetup[] = { 0xE8, 0xFD, 0x00 };
292 // Max length of a page + chip id + reg start
293 uint8_t fullPage[ 0xB4 + 2 ] = { 0 }; // Max size of page
294 fullPage[0] = 0xE8; // Set chip id
295 fullPage[1] = startReg; // Set start reg
297 // Iterate through given pages, zero'ing out the given register regions
298 for ( uint8_t page = startPage; page < startPage + numPages; page++ )
304 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
308 while ( I2C_Send( fullPage, endReg - startReg + 2, 0 ) == 0 )
313 void LED_sendPage( uint8_t *buffer, uint8_t len, uint8_t page )
316 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
319 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
322 // Write page to I2C Tx Buffer
323 while ( I2C_Send( buffer, len, 0 ) == 0 )
328 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
331 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
334 uint8_t writeData[] = { 0xE8, reg, val };
337 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
340 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 )
344 void LED_readPage( uint8_t len, uint8_t page )
346 // Software shutdown must be enabled to read registers
347 LED_writeReg( 0x0A, 0x00, 0x0B );
350 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
353 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
357 uint8_t regSetup[] = { 0xE8, 0x00 };
359 // Read each register in the page
360 for ( uint8_t reg = 0; reg < len; reg++ )
362 // Update register to read
365 // Configure register
366 while ( I2C_Send( regSetup, sizeof( regSetup ), 0 ) == 0 )
369 // Register Read Command
370 uint8_t regReadCmd[] = { 0xE9 };
372 // Request single register byte
373 while ( I2C_Send( regReadCmd, sizeof( regReadCmd ), 1 ) == 0 )
378 // Disable software shutdown
379 LED_writeReg( 0x0A, 0x01, 0x0B );
383 inline void LED_setup()
385 // Register Scan CLI dictionary
386 CLI_registerDictionary( ledCLIDict, ledCLIDictName );
391 // Zero out Frame Registers
392 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
393 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
395 // Disable Hardware shutdown of ISSI chip (pull high)
396 GPIOB_PDDR |= (1<<16);
397 PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
398 GPIOB_PSOR |= (1<<16);
401 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
403 // Enable LEDs based upon mask
404 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
406 // Set default brightness
407 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
409 // Disable Software shutdown of ISSI chip
410 LED_writeReg( 0x0A, 0x01, 0x0B );
414 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer )
418 // If sendLen is greater than buffer fail right away
419 if ( sendLen > buffer->size )
422 // Calculate new tail to determine if buffer has enough space
423 // The first element specifies the expected number of bytes from the slave (+1)
424 // The second element in the new buffer is the length of the buffer sequence (+1)
425 uint16_t newTail = buffer->tail + sendLen + 2;
426 if ( newTail >= buffer->size )
427 newTail -= buffer->size;
429 if ( I2C_BufferLen( buffer ) < sendLen + 2 )
434 printHex( sendLen + 2 );
442 // If buffer is clean, return 1, otherwise 2
443 reTurn = buffer->head == buffer->tail ? 1 : 2;
445 // Add to buffer, already know there is enough room (simplifies adding logic)
446 uint8_t bufferHeaderPos = 0;
447 for ( uint16_t c = 0; c < sendLen; c++ )
449 // Add data to buffer
450 switch ( bufferHeaderPos )
453 buffer->buffer[ buffer->tail ] = recvLen;
459 buffer->buffer[ buffer->tail ] = sendLen;
465 buffer->buffer[ buffer->tail ] = data[ c ];
469 // Check for wrap-around case
470 if ( buffer->tail + 1 >= buffer->size )
485 inline uint16_t I2C_BufferLen( I2C_Buffer *buffer )
488 if ( buffer->tail >= buffer->head )
489 return buffer->head + buffer->size - buffer->tail;
492 return buffer->head - buffer->tail;
496 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
501 // Make sure buffer isn't full
502 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
504 warn_msg("I2C_BufferPush failed, buffer full: ");
510 // Check for wrap-around case
511 if ( buffer->tail + 1 >= buffer->size )
521 // Add byte to buffer
522 buffer->buffer[ buffer->tail ] = byte;
526 uint8_t I2C_TxBufferPop()
528 // Return 0xFF if no buffer left (do not rely on this)
529 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) >= I2C_TxBuffer.size )
531 erro_msg("No buffer to pop an entry from... ");
532 printHex( I2C_TxBuffer.head );
534 printHex( I2C_TxBuffer.tail );
536 printHex( I2C_TxBuffer.sequencePos );
541 // If there is currently no sequence being sent, the first entry in the RingBuffer is the length
542 if ( I2C_TxBuffer.sequencePos == 0 )
544 I2C_TxBuffer.sequencePos = 0xFF; // So this doesn't become an infinite loop
545 I2C_RxBuffer.sequencePos = I2C_TxBufferPop();
546 I2C_TxBuffer.sequencePos = I2C_TxBufferPop();
549 uint8_t data = I2C_TxBuffer.buffer[ I2C_TxBuffer.head ];
555 if ( I2C_TxBuffer.head >= I2C_TxBuffer.size )
556 I2C_TxBuffer.head = 0;
558 // Decrement buffer sequence (until next stop will be sent)
559 I2C_TxBuffer.sequencePos--;
562 dbug_msg("Popping: ");
565 printHex( I2C_TxBuffer.head );
567 printHex( I2C_TxBuffer.tail );
569 printHex( I2C_TxBuffer.sequencePos );
576 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen )
578 // Check head and tail pointers
580 // If empty, start up I2C Master Tx
581 // If buffer is non-empty and non-full, just append to the buffer
582 switch ( I2C_BufferCopy( data, sendLen, recvLen, (I2C_Buffer*)&I2C_TxBuffer ) )
584 // Not enough buffer space...
587 erro_msg("Not enough Tx buffer space... ");
588 printHex( I2C_TxBuffer.head );
590 printHex( I2C_TxBuffer.tail );
594 printHex( I2C_TxBuffer.size );
599 // Empty buffer, initialize I2C
601 // Clear status flags
602 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
604 // Check to see if we already have control of the bus
605 if ( I2C0_C1 & I2C_C1_MST )
607 // Already the master (ah yeah), send a repeated start
608 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_RSTA | I2C_C1_TX;
610 // Otherwise, seize control
613 // Wait...till the master dies
614 while ( I2C0_S & I2C_S_BUSY );
616 // Now we're the master (ah yisss), get ready to send stuffs
617 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
620 // Enable I2C interrupt
621 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
623 // Depending on what type of transfer, the first byte is configured for R or W
624 I2C0_D = I2C_TxBufferPop();
629 // Dirty buffer, I2C already initialized
635 // LED State processing loop
636 inline uint8_t LED_scan()
648 // ----- Capabilities -----
650 // Basic LED Control Capability
651 typedef enum LedControlMode {
653 LedControlMode_brightness_decrease,
654 LedControlMode_brightness_increase,
655 LedControlMode_brightness_set,
656 // Set all LEDs (index argument not required)
657 LedControlMode_brightness_decrease_all,
658 LedControlMode_brightness_increase_all,
659 LedControlMode_brightness_set_all,
662 typedef struct LedControl {
663 LedControlMode mode; // XXX Make sure to adjust the .kll capability if this variable is larger than 8 bits
668 void LED_control( LedControl *control )
670 // Only send if we've completed all other transactions
672 if ( I2C_TxBuffer.sequencePos > 0 )
676 // Configure based upon the given mode
677 // TODO Perhaps do gamma adjustment?
678 switch ( control->mode )
680 case LedControlMode_brightness_decrease:
681 // Don't worry about rolling over, the cycle is quick
682 LED_pageBuffer.buffer[ control->index ] -= control->amount;
685 case LedControlMode_brightness_increase:
686 // Don't worry about rolling over, the cycle is quick
687 LED_pageBuffer.buffer[ control->index ] += control->amount;
690 case LedControlMode_brightness_set:
691 LED_pageBuffer.buffer[ control->index ] = control->amount;
694 case LedControlMode_brightness_decrease_all:
695 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
697 // Don't worry about rolling over, the cycle is quick
698 LED_pageBuffer.buffer[ channel ] -= control->amount;
702 case LedControlMode_brightness_increase_all:
703 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
705 // Don't worry about rolling over, the cycle is quick
706 LED_pageBuffer.buffer[ channel ] += control->amount;
710 case LedControlMode_brightness_set_all:
711 for ( uint8_t channel = 0; channel < LED_TotalChannels; channel++ )
713 LED_pageBuffer.buffer[ channel ] = control->amount;
718 // Sync LED buffer with ISSI chip buffer
719 // TODO Support multiple frames
720 LED_pageBuffer.i2c_addr = 0xE8; // Chip 1
721 LED_pageBuffer.reg_addr = 0x24; // Brightness section
722 LED_sendPage( (uint8_t*)&LED_pageBuffer, sizeof( LED_Buffer ), 0 );
725 uint8_t LED_control_timer = 0;
726 void LED_control_capability( uint8_t state, uint8_t stateType, uint8_t *args )
728 // Display capability name
729 if ( stateType == 0xFF && state == 0xFF )
731 print("LED_control_capability(mode,amount,index)");
735 // Only use capability on press
737 if ( stateType == 0x00 && state == 0x03 ) // Not on release
741 // ISSI Chip locks up if we spam updates too quickly (might be an I2C bug on this side too -HaaTa)
742 // Make sure we only send an update every 30 milliseconds at most
743 // It may be possible to optimize speed even further, but will likely require serious time with a logic analyzer
745 uint8_t currentTime = (uint8_t)systick_millis_count;
746 int8_t compare = (int8_t)(currentTime - LED_control_timer) & 0x7F;
751 LED_control_timer = currentTime;
753 // Set the input structure
754 LedControl *control = (LedControl*)args;
756 // Interconnect broadcasting
757 #if defined(ConnectEnabled_define)
758 uint8_t send_packet = 0;
759 uint8_t ignore_node = 0;
761 // By default send to the *next* node, which will determine where to go next
762 extern uint8_t Connect_id; // connect_scan.c
763 uint8_t addr = Connect_id + 1;
765 switch ( control->mode )
767 // Calculate the led address to send
768 // If greater than the Total hannels
769 // Set address - Total channels
771 case LedControlMode_brightness_decrease:
772 case LedControlMode_brightness_increase:
773 case LedControlMode_brightness_set:
774 // Ignore if led is on this node
775 if ( control->index < LED_TotalChannels )
778 // Calculate new led index
779 control->index -= LED_TotalChannels;
785 // Broadcast to all nodes
786 // XXX Do not set broadcasting address
787 // Will send command twice
788 case LedControlMode_brightness_decrease_all:
789 case LedControlMode_brightness_increase_all:
790 case LedControlMode_brightness_set_all:
795 // Only send interconnect remote capability packet if necessary
799 extern const Capability CapabilitiesList[];
801 // Broadcast layerStackExact remote capability (0xFF is the broadcast id)
802 Connect_send_RemoteCapability(
804 LED_control_capability_index,
807 CapabilitiesList[ LED_control_capability_index ].argCount,
812 // If there is nothing to do on this node, ignore
817 // Modify led state of this node
818 LED_control( control );
823 // ----- CLI Command Functions -----
825 // TODO Currently not working correctly
826 void cliFunc_i2cSend( char* args )
830 char* arg2Ptr = args;
832 // Buffer used after interpretting the args, will be sent to I2C functions
833 // NOTE: Limited to 8 bytes currently (can be increased if necessary
834 #define i2cSend_BuffLenMax 8
835 uint8_t buffer[ i2cSend_BuffLenMax ];
836 uint8_t bufferLen = 0;
838 // No \r\n by default after the command is entered
840 info_msg("Sending: ");
842 // Parse args until a \0 is found
843 while ( bufferLen < i2cSend_BuffLenMax )
845 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
846 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
848 // Stop processing args if no more are found
849 if ( *arg1Ptr == '\0' )
852 // If | is found, end sequence and start new one
853 if ( *arg1Ptr == '|' )
856 I2C_Send( buffer, bufferLen, 0 );
861 // Interpret the argument
862 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
871 I2C_Send( buffer, bufferLen, 0 );
874 void cliFunc_i2cRecv( char* args )
878 char* arg2Ptr = args;
880 // Buffer used after interpretting the args, will be sent to I2C functions
881 // NOTE: Limited to 8 bytes currently (can be increased if necessary
882 #define i2cSend_BuffLenMax 8
883 uint8_t buffer[ i2cSend_BuffLenMax ];
884 uint8_t bufferLen = 0;
886 // No \r\n by default after the command is entered
888 info_msg("Sending: ");
890 // Parse args until a \0 is found
891 while ( bufferLen < i2cSend_BuffLenMax )
893 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
894 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
896 // Stop processing args if no more are found
897 if ( *arg1Ptr == '\0' )
900 // If | is found, end sequence and start new one
901 if ( *arg1Ptr == '|' )
904 I2C_Send( buffer, bufferLen, 0 );
909 // Interpret the argument
910 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
919 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
922 // TODO Currently not working correctly
923 void cliFunc_ledRPage( char* args )
925 // Parse number from argument
926 // NOTE: Only first argument is used
929 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
931 // Default to 0 if no argument is given
934 if ( arg1Ptr[0] != '\0' )
936 page = (uint8_t)numToInt( arg1Ptr );
939 // No \r\n by default after the command is entered
942 LED_readPage( 0x1, page );
943 //LED_readPage( 0xB4, page );
946 void cliFunc_ledWPage( char* args )
950 char* arg2Ptr = args;
952 // First process page and starting address
954 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
956 // Stop processing args if no more are found
957 if ( *arg1Ptr == '\0' )
959 uint8_t page[] = { 0xE8, 0xFD, numToInt( arg1Ptr ) };
962 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
964 // Stop processing args if no more are found
965 if ( *arg1Ptr == '\0' )
967 uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 };
969 // Set the register page
970 while ( I2C_Send( page, sizeof( page ), 0 ) == 0 )
977 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
979 // Stop processing args if no more are found
980 if ( *arg1Ptr == '\0' )
983 data[2] = numToInt( arg1Ptr );
985 // Write register location and data to I2C
986 while ( I2C_Send( data, sizeof( data ), 0 ) == 0 )
994 void cliFunc_ledStart( char* args )
996 print( NL ); // No \r\n by default after the command is entered
997 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
998 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
999 LED_writeReg( 0x0A, 0x01, 0x0B );
1000 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
1004 void cliFunc_ledTest( char* args )
1006 print( NL ); // No \r\n by default after the command is entered
1007 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
1010 void cliFunc_ledZero( char* args )
1012 print( NL ); // No \r\n by default after the command is entered
1013 LED_zeroPages( 0x00, 8, 0x24, 0xB4 ); // Only PWMs
1016 void cliFunc_ledCtrl( char* args )
1020 char* arg2Ptr = args;
1023 // First process mode
1025 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
1027 // Stop processing args if no more are found
1028 if ( *arg1Ptr == '\0' )
1030 control.mode = numToInt( arg1Ptr );
1033 // Next process amount
1035 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
1037 // Stop processing args if no more are found
1038 if ( *arg1Ptr == '\0' )
1040 control.amount = numToInt( arg1Ptr );
1043 // Finally process led index, if it exists
1046 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
1047 control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr );
1050 LED_control( &control );