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>
33 // ----- Defines -----
35 #define I2C_TxBufferLength 300
36 #define I2C_RxBufferLength 8
38 #define LED_BufferLength 144
41 // ----- Structs -----
43 typedef struct I2C_Buffer {
51 typedef struct LED_Buffer {
54 uint8_t buffer[LED_BufferLength];
59 // ----- Function Declarations -----
62 void cliFunc_i2cRecv ( char* args );
63 void cliFunc_i2cSend ( char* args );
64 void cliFunc_ledCtrl ( char* args );
65 void cliFunc_ledRPage( char* args );
66 void cliFunc_ledStart( char* args );
67 void cliFunc_ledTest ( char* args );
68 void cliFunc_ledWPage( char* args );
69 void cliFunc_ledZero ( char* args );
71 uint8_t I2C_TxBufferPop();
72 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer );
73 uint16_t I2C_BufferLen( I2C_Buffer *buffer );
74 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen );
78 // ----- Variables -----
80 // Scan Module command dictionary
81 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." );
82 CLIDict_Entry( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
83 CLIDict_Entry( ledCtrl, "Basic LED control. Args: <mode> <amount> [<index>]" );
84 CLIDict_Entry( ledRPage, "Read the given register page." );
85 CLIDict_Entry( ledStart, "Disable software shutdown." );
86 CLIDict_Entry( ledTest, "Test out the led pages." );
87 CLIDict_Entry( ledWPage, "Write to given register page starting at address. i.e. 0x2 0x24 0xF0 0x12" );
88 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
90 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
91 CLIDict_Item( i2cRecv ),
92 CLIDict_Item( i2cSend ),
93 CLIDict_Item( ledCtrl ),
94 CLIDict_Item( ledRPage ),
95 CLIDict_Item( ledStart ),
96 CLIDict_Item( ledTest ),
97 CLIDict_Item( ledWPage ),
98 CLIDict_Item( ledZero ),
99 { 0, 0, 0 } // Null entry for dictionary end
104 // Before sending the sequence, I2C_TxBuffer_CurLen is assigned and as each byte is sent, it is decremented
105 // Once I2C_TxBuffer_CurLen reaches zero, a STOP on the I2C bus is sent
106 volatile uint8_t I2C_TxBufferPtr[ I2C_TxBufferLength ];
107 volatile uint8_t I2C_RxBufferPtr[ I2C_TxBufferLength ];
109 volatile I2C_Buffer I2C_TxBuffer = { 0, 0, 0, I2C_TxBufferLength, (uint8_t*)I2C_TxBufferPtr };
110 volatile I2C_Buffer I2C_RxBuffer = { 0, 0, 0, I2C_RxBufferLength, (uint8_t*)I2C_RxBufferPtr };
112 LED_Buffer LED_pageBuffer;
114 // A bit mask determining which LEDs are enabled in the ISSI chip
115 const uint8_t LED_ledEnableMask1[] = {
117 0x00, // Starting register address
121 // Default LED brightness
122 const uint8_t LED_defaultBrightness1[] = {
124 0x24, // Starting register address
125 ISSILedBrightness1_define
130 // ----- Interrupt Functions -----
134 cli(); // Disable Interrupts
136 uint8_t status = I2C0_S; // Read I2C Bus status
138 // Master Mode Transmit
139 if ( I2C0_C1 & I2C_C1_TX )
141 // Check current use of the I2C bus
142 // Currently sending data
143 if ( I2C_TxBuffer.sequencePos > 0 )
145 // Make sure slave sent an ACK
146 if ( status & I2C_S_RXAK )
148 // NACK Detected, disable interrupt
149 erro_print("I2C NAK detected...");
150 I2C0_C1 = I2C_C1_IICEN;
153 I2C_TxBuffer.head = 0;
154 I2C_TxBuffer.tail = 0;
155 I2C_TxBuffer.sequencePos = 0;
160 I2C0_D = I2C_TxBufferPop();
164 else if ( I2C_RxBuffer.sequencePos > 0 )
166 // Master Receive, addr sent
167 if ( status & I2C_S_ARBL )
170 erro_print("Arbitration lost...");
173 I2C0_C1 = I2C_C1_IICEN;
174 I2C0_S = I2C_S_ARBL | I2C_S_IICIF; // Clear ARBL flag and interrupt
176 if ( status & I2C_S_RXAK )
178 // Slave Address NACK Detected, disable interrupt
179 erro_print("Slave Address I2C NAK detected...");
182 I2C0_C1 = I2C_C1_IICEN;
186 dbug_msg("Attempting to read byte - ");
187 printHex( I2C_RxBuffer.sequencePos );
189 I2C0_C1 = I2C_RxBuffer.sequencePos == 1
190 ? I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK // Single byte read
191 : I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST; // Multi-byte read
198 printHex( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) );
202 // Delay around STOP to make sure it actually happens...
203 delayMicroseconds( 1 );
204 I2C0_C1 = I2C_C1_IICEN; // Send STOP
205 delayMicroseconds( 7 );
207 // If there is another sequence, start sending
208 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) < I2C_TxBuffer.size )
210 // Clear status flags
211 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
213 // Wait...till the master dies
214 while ( I2C0_S & I2C_S_BUSY );
216 // Enable I2C interrupt
217 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
220 I2C0_D = I2C_TxBufferPop();
224 // Master Mode Receive
227 // XXX Do we need to handle 2nd last byte?
228 //I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK; // No STOP, Rx, NAK on recv
231 if ( I2C_TxBuffer.sequencePos <= 1 )
234 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
237 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
239 delayMicroseconds( 1 ); // Should be enough time before issuing the stop
240 I2C0_C1 = I2C_C1_IICEN; // Send STOP
245 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
249 I2C0_S = I2C_S_IICIF; // Clear interrupt
251 sei(); // Re-enable Interrupts
256 // ----- Functions -----
258 inline void I2C_setup()
260 // Enable I2C internal clock
261 SIM_SCGC4 |= SIM_SCGC4_I2C0; // Bus 0
263 // External pull-up resistor
264 PORTB_PCR0 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
265 PORTB_PCR1 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
267 // SCL Frequency Divider
268 // 400kHz -> 120 (0x85) @ 48 MHz F_BUS
271 I2C0_C1 = I2C_C1_IICEN;
272 I2C0_C2 = I2C_C2_HDRS; // High drive select
274 // Enable I2C Interrupt
275 NVIC_ENABLE_IRQ( IRQ_I2C0 );
278 void LED_zeroPages( uint8_t startPage, uint8_t numPages, uint8_t startReg, uint8_t endReg )
281 uint8_t pageSetup[] = { 0xE8, 0xFD, 0x00 };
283 // Max length of a page + chip id + reg start
284 uint8_t fullPage[ 0xB4 + 2 ] = { 0 }; // Max size of page
285 fullPage[0] = 0xE8; // Set chip id
286 fullPage[1] = startReg; // Set start reg
288 // Iterate through given pages, zero'ing out the given register regions
289 for ( uint8_t page = startPage; page < startPage + numPages; page++ )
295 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
299 while ( I2C_Send( fullPage, endReg - startReg + 2, 0 ) == 0 )
304 void LED_sendPage( uint8_t *buffer, uint8_t len, uint8_t page )
307 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
310 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
313 // Write page to I2C Tx Buffer
314 while ( I2C_Send( buffer, len, 0 ) == 0 )
319 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
322 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
325 uint8_t writeData[] = { 0xE8, reg, val };
328 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
331 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 )
335 void LED_readPage( uint8_t len, uint8_t page )
337 // Software shutdown must be enabled to read registers
338 LED_writeReg( 0x0A, 0x00, 0x0B );
341 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
344 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
348 uint8_t regSetup[] = { 0xE8, 0x00 };
350 // Read each register in the page
351 for ( uint8_t reg = 0; reg < len; reg++ )
353 // Update register to read
356 // Configure register
357 while ( I2C_Send( regSetup, sizeof( regSetup ), 0 ) == 0 )
360 // Register Read Command
361 uint8_t regReadCmd[] = { 0xE9 };
363 // Request single register byte
364 while ( I2C_Send( regReadCmd, sizeof( regReadCmd ), 1 ) == 0 )
369 // Disable software shutdown
370 LED_writeReg( 0x0A, 0x01, 0x0B );
374 inline void LED_setup()
376 // Register Scan CLI dictionary
377 CLI_registerDictionary( ledCLIDict, ledCLIDictName );
382 // Zero out Frame Registers
383 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
384 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
386 // Disable Hardware shutdown of ISSI chip (pull high)
387 GPIOB_PDDR |= (1<<16);
388 PORTB_PCR16 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
389 GPIOB_PSOR |= (1<<16);
392 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
394 // Enable LEDs based upon mask
395 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
397 // Set default brightness
398 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
400 // Disable Software shutdown of ISSI chip
401 LED_writeReg( 0x0A, 0x01, 0x0B );
405 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer )
409 // If sendLen is greater than buffer fail right away
410 if ( sendLen > buffer->size )
413 // Calculate new tail to determine if buffer has enough space
414 // The first element specifies the expected number of bytes from the slave (+1)
415 // The second element in the new buffer is the length of the buffer sequence (+1)
416 uint16_t newTail = buffer->tail + sendLen + 2;
417 if ( newTail >= buffer->size )
418 newTail -= buffer->size;
420 if ( I2C_BufferLen( buffer ) < sendLen + 2 )
425 printHex( sendLen + 2 );
433 // If buffer is clean, return 1, otherwise 2
434 reTurn = buffer->head == buffer->tail ? 1 : 2;
436 // Add to buffer, already know there is enough room (simplifies adding logic)
437 uint8_t bufferHeaderPos = 0;
438 for ( uint16_t c = 0; c < sendLen; c++ )
440 // Add data to buffer
441 switch ( bufferHeaderPos )
444 buffer->buffer[ buffer->tail ] = recvLen;
450 buffer->buffer[ buffer->tail ] = sendLen;
456 buffer->buffer[ buffer->tail ] = data[ c ];
460 // Check for wrap-around case
461 if ( buffer->tail + 1 >= buffer->size )
476 inline uint16_t I2C_BufferLen( I2C_Buffer *buffer )
479 if ( buffer->tail >= buffer->head )
480 return buffer->head + buffer->size - buffer->tail;
483 return buffer->head - buffer->tail;
487 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
492 // Make sure buffer isn't full
493 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
495 warn_msg("I2C_BufferPush failed, buffer full: ");
501 // Check for wrap-around case
502 if ( buffer->tail + 1 >= buffer->size )
512 // Add byte to buffer
513 buffer->buffer[ buffer->tail ] = byte;
517 uint8_t I2C_TxBufferPop()
519 // Return 0xFF if no buffer left (do not rely on this)
520 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) >= I2C_TxBuffer.size )
522 erro_msg("No buffer to pop an entry from... ");
523 printHex( I2C_TxBuffer.head );
525 printHex( I2C_TxBuffer.tail );
527 printHex( I2C_TxBuffer.sequencePos );
532 // If there is currently no sequence being sent, the first entry in the RingBuffer is the length
533 if ( I2C_TxBuffer.sequencePos == 0 )
535 I2C_TxBuffer.sequencePos = 0xFF; // So this doesn't become an infinite loop
536 I2C_RxBuffer.sequencePos = I2C_TxBufferPop();
537 I2C_TxBuffer.sequencePos = I2C_TxBufferPop();
540 uint8_t data = I2C_TxBuffer.buffer[ I2C_TxBuffer.head ];
546 if ( I2C_TxBuffer.head >= I2C_TxBuffer.size )
547 I2C_TxBuffer.head = 0;
549 // Decrement buffer sequence (until next stop will be sent)
550 I2C_TxBuffer.sequencePos--;
553 dbug_msg("Popping: ");
556 printHex( I2C_TxBuffer.head );
558 printHex( I2C_TxBuffer.tail );
560 printHex( I2C_TxBuffer.sequencePos );
567 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen )
569 // Check head and tail pointers
571 // If empty, start up I2C Master Tx
572 // If buffer is non-empty and non-full, just append to the buffer
573 switch ( I2C_BufferCopy( data, sendLen, recvLen, (I2C_Buffer*)&I2C_TxBuffer ) )
575 // Not enough buffer space...
578 erro_msg("Not enough Tx buffer space... ");
579 printHex( I2C_TxBuffer.head );
581 printHex( I2C_TxBuffer.tail );
585 printHex( I2C_TxBuffer.size );
590 // Empty buffer, initialize I2C
592 // Clear status flags
593 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
595 // Check to see if we already have control of the bus
596 if ( I2C0_C1 & I2C_C1_MST )
598 // Already the master (ah yeah), send a repeated start
599 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_RSTA | I2C_C1_TX;
601 // Otherwise, seize control
604 // Wait...till the master dies
605 while ( I2C0_S & I2C_S_BUSY );
607 // Now we're the master (ah yisss), get ready to send stuffs
608 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
611 // Enable I2C interrupt
612 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
614 // Depending on what type of transfer, the first byte is configured for R or W
615 I2C0_D = I2C_TxBufferPop();
620 // Dirty buffer, I2C already initialized
626 // LED State processing loop
627 inline uint8_t LED_scan()
639 // ----- Capabilities -----
641 // Basic LED Control Capability
642 typedef enum LedControlMode {
644 LedControlMode_brightness_decrease,
645 LedControlMode_brightness_increase,
646 LedControlMode_brightness_set,
647 // Set all LEDs (index argument not required)
648 LedControlMode_brightness_decrease_all,
649 LedControlMode_brightness_increase_all,
650 LedControlMode_brightness_set_all,
653 typedef struct LedControl {
654 LedControlMode mode; // XXX Make sure to adjust the .kll capability if this variable is larger than 8 bits
659 uint8_t LED_control_timer = 0;
660 void LED_control( LedControl *control )
662 // Only send if we've completed all other transactions
663 if ( I2C_TxBuffer.sequencePos > 0 )
667 // ISSI Chip locks up if we spam updates too quickly (might be an I2C bug on this side too -HaaTa)
668 // Make sure we only send an update every 30 milliseconds at most
669 // It may be possible to optimize speed even further, but will likely require serious time with a logic analyzer
671 uint8_t currentTime = (uint8_t)systick_millis_count;
672 int8_t compare = (int8_t)(currentTime - LED_control_timer) & 0x7F;
677 LED_control_timer = currentTime;
679 // Configure based upon the given mode
680 // TODO Handle multiple issi chips per node
681 // TODO Perhaps do gamma adjustment?
682 switch ( control->mode )
684 case LedControlMode_brightness_decrease:
685 // Don't worry about rolling over, the cycle is quick
686 LED_pageBuffer.buffer[ control->index ] -= control->amount;
689 case LedControlMode_brightness_increase:
690 // Don't worry about rolling over, the cycle is quick
691 LED_pageBuffer.buffer[ control->index ] += control->amount;
694 case LedControlMode_brightness_set:
695 LED_pageBuffer.buffer[ control->index ] = control->amount;
698 case LedControlMode_brightness_decrease_all:
699 for ( uint8_t channel = 0; channel < LED_BufferLength; channel++ )
701 // Don't worry about rolling over, the cycle is quick
702 LED_pageBuffer.buffer[ channel ] -= control->amount;
706 case LedControlMode_brightness_increase_all:
707 for ( uint8_t channel = 0; channel < LED_BufferLength; channel++ )
709 // Don't worry about rolling over, the cycle is quick
710 LED_pageBuffer.buffer[ channel ] += control->amount;
714 case LedControlMode_brightness_set_all:
715 for ( uint8_t channel = 0; channel < LED_BufferLength; channel++ )
717 LED_pageBuffer.buffer[ channel ] = control->amount;
722 // Sync LED buffer with ISSI chip buffer
723 // TODO Support multiple frames
724 LED_pageBuffer.i2c_addr = 0xE8; // Chip 1
725 LED_pageBuffer.reg_addr = 0x24; // Brightness section
726 LED_sendPage( (uint8_t*)&LED_pageBuffer, sizeof( LED_Buffer ), 0 );
729 void LED_control_capability( uint8_t state, uint8_t stateType, uint8_t *args )
731 // Display capability name
732 if ( stateType == 0xFF && state == 0xFF )
734 print("LED_control_capability(mode,amount,index)");
738 // Only use capability on press
740 if ( stateType == 0x00 && state == 0x03 ) // Not on release
743 // Set the input structure
744 LedControl *control = (LedControl*)args;
746 // TODO broadcast to rest of interconnect nodes if necessary
747 LED_control( control );
752 // ----- CLI Command Functions -----
754 // TODO Currently not working correctly
755 void cliFunc_i2cSend( char* args )
759 char* arg2Ptr = args;
761 // Buffer used after interpretting the args, will be sent to I2C functions
762 // NOTE: Limited to 8 bytes currently (can be increased if necessary
763 #define i2cSend_BuffLenMax 8
764 uint8_t buffer[ i2cSend_BuffLenMax ];
765 uint8_t bufferLen = 0;
767 // No \r\n by default after the command is entered
769 info_msg("Sending: ");
771 // Parse args until a \0 is found
772 while ( bufferLen < i2cSend_BuffLenMax )
774 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
775 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
777 // Stop processing args if no more are found
778 if ( *arg1Ptr == '\0' )
781 // If | is found, end sequence and start new one
782 if ( *arg1Ptr == '|' )
785 I2C_Send( buffer, bufferLen, 0 );
790 // Interpret the argument
791 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
800 I2C_Send( buffer, bufferLen, 0 );
803 void cliFunc_i2cRecv( char* args )
807 char* arg2Ptr = args;
809 // Buffer used after interpretting the args, will be sent to I2C functions
810 // NOTE: Limited to 8 bytes currently (can be increased if necessary
811 #define i2cSend_BuffLenMax 8
812 uint8_t buffer[ i2cSend_BuffLenMax ];
813 uint8_t bufferLen = 0;
815 // No \r\n by default after the command is entered
817 info_msg("Sending: ");
819 // Parse args until a \0 is found
820 while ( bufferLen < i2cSend_BuffLenMax )
822 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
823 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
825 // Stop processing args if no more are found
826 if ( *arg1Ptr == '\0' )
829 // If | is found, end sequence and start new one
830 if ( *arg1Ptr == '|' )
833 I2C_Send( buffer, bufferLen, 0 );
838 // Interpret the argument
839 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
848 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
851 // TODO Currently not working correctly
852 void cliFunc_ledRPage( char* args )
854 // Parse number from argument
855 // NOTE: Only first argument is used
858 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
860 // Default to 0 if no argument is given
863 if ( arg1Ptr[0] != '\0' )
865 page = (uint8_t)numToInt( arg1Ptr );
868 // No \r\n by default after the command is entered
871 LED_readPage( 0x1, page );
872 //LED_readPage( 0xB4, page );
875 void cliFunc_ledWPage( char* args )
879 char* arg2Ptr = args;
881 // First process page and starting address
883 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
885 // Stop processing args if no more are found
886 if ( *arg1Ptr == '\0' )
888 uint8_t page[] = { 0xE8, 0xFD, numToInt( arg1Ptr ) };
891 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
893 // Stop processing args if no more are found
894 if ( *arg1Ptr == '\0' )
896 uint8_t data[] = { 0xE8, numToInt( arg1Ptr ), 0 };
898 // Set the register page
899 while ( I2C_Send( page, sizeof( page ), 0 ) == 0 )
906 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
908 // Stop processing args if no more are found
909 if ( *arg1Ptr == '\0' )
912 data[2] = numToInt( arg1Ptr );
914 // Write register location and data to I2C
915 while ( I2C_Send( data, sizeof( data ), 0 ) == 0 )
923 void cliFunc_ledStart( char* args )
925 print( NL ); // No \r\n by default after the command is entered
926 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
927 //LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
928 LED_writeReg( 0x0A, 0x01, 0x0B );
929 LED_sendPage( (uint8_t*)LED_ledEnableMask1, sizeof( LED_ledEnableMask1 ), 0 );
933 void cliFunc_ledTest( char* args )
935 print( NL ); // No \r\n by default after the command is entered
936 LED_sendPage( (uint8_t*)LED_defaultBrightness1, sizeof( LED_defaultBrightness1 ), 0 );
939 void cliFunc_ledZero( char* args )
941 print( NL ); // No \r\n by default after the command is entered
942 LED_zeroPages( 0x00, 8, 0x24, 0xB4 ); // Only PWMs
945 void cliFunc_ledCtrl( char* args )
949 char* arg2Ptr = args;
952 // First process mode
954 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
956 // Stop processing args if no more are found
957 if ( *arg1Ptr == '\0' )
959 control.mode = numToInt( arg1Ptr );
962 // Next process amount
964 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
966 // Stop processing args if no more are found
967 if ( *arg1Ptr == '\0' )
969 control.amount = numToInt( arg1Ptr );
972 // Finally process led index, if it exists
975 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
976 control.index = *arg1Ptr == '\0' ? 0 : numToInt( arg1Ptr );
979 LED_control( &control );