comparison Scan/ISSILed/led_scan.c @ 315:bcdc04cb8e2e

Initial LED support for ISSI IS31FL3731C - Not ready for advanced support yet - Basic register and page writing support complete
author Jacob Alexander <haata@kiibohd.com>
date Sat, 21 Mar 2015 17:12:41 -0700
parents
children f4d4cad283c6
comparison
equal deleted inserted replaced
314:8325f8c91663 315:bcdc04cb8e2e
1 /* Copyright (C) 2014-2015 by Jacob Alexander
2 *
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.
7 *
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.
12 *
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/>.
15 */
16
17 // ----- Includes -----
18
19 // Compiler Includes
20 #include <Lib/ScanLib.h>
21
22 // Project Includes
23 #include <cli.h>
24 #include <led.h>
25 #include <print.h>
26
27 // Local Includes
28 #include "led_scan.h"
29
30
31
32 // ----- Defines -----
33
34 #define I2C_TxBufferLength 300
35 #define I2C_RxBufferLength 8
36
37 #define LED_BufferLength 144
38
39
40 // ----- Structs -----
41
42 typedef struct I2C_Buffer {
43 uint16_t head;
44 uint16_t tail;
45 uint8_t sequencePos;
46 uint16_t size;
47 uint8_t *buffer;
48 } I2C_Buffer;
49
50 typedef struct LED_Buffer {
51 uint8_t buffer[LED_BufferLength];
52 } LED_Buffer;
53
54
55
56 // ----- Function Declarations -----
57
58 // CLI Functions
59 void cliFunc_echo( char* args );
60 void cliFunc_i2cRecv( char* args );
61 void cliFunc_i2cSend( char* args );
62 void cliFunc_ledTest( char* args );
63 void cliFunc_ledZero( char* args );
64
65 uint8_t I2C_TxBufferPop();
66 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer );
67 uint16_t I2C_BufferLen( I2C_Buffer *buffer );
68 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen );
69
70
71
72 // ----- Variables -----
73
74 // 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( i2cSend, "Send I2C sequence of bytes. Use |'s to split sequences with a stop." );
77 CLIDict_Entry( ledTest, "Test out the led pages." );
78 CLIDict_Entry( ledZero, "Zero out LED register pages (non-configuration)." );
79
80 CLIDict_Def( ledCLIDict, "ISSI LED Module Commands" ) = {
81 CLIDict_Item( i2cRecv ),
82 CLIDict_Item( i2cSend ),
83 CLIDict_Item( ledTest ),
84 CLIDict_Item( ledZero ),
85 { 0, 0, 0 } // Null entry for dictionary end
86 };
87
88
89
90 // Before sending the sequence, I2C_TxBuffer_CurLen is assigned and as each byte is sent, it is decremented
91 // Once I2C_TxBuffer_CurLen reaches zero, a STOP on the I2C bus is sent
92 volatile uint8_t I2C_TxBufferPtr[ I2C_TxBufferLength ];
93 volatile uint8_t I2C_RxBufferPtr[ I2C_TxBufferLength ];
94
95 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 };
97
98 LED_Buffer LED_pageBuffer;
99
100 // A bit mask determining which LEDs are enabled in the ISSI chip
101 // 0x00 -> 0x11
102 const uint8_t LED_ledEnableMask[] = {
103 0xE8, // I2C address
104 0x00, // Starting register address
105 0xFF, 0xFF, // C1-1 -> C1-16
106 0xFF, 0xFF, // C2-1 -> C2-16
107 0xFF, 0xFF, // C3-1 -> C3-16
108 0xFF, 0xFF, // C4-1 -> C4-16
109 0xFF, 0xFF, // C5-1 -> C5-16
110 0xFF, 0xFF, // C6-1 -> C6-16
111 0xFF, 0xFF, // C7-1 -> C7-16
112 0xFF, 0xFF, // C8-1 -> C8-16
113 0xFF, 0xFF, // C9-1 -> C9-16
114 };
115
116 // XXX Pre-fill example of buffers
117 const uint8_t examplePage[] = {
118 0xE8, // I2C address
119 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
121 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, // C2-1 -> C2-16
122 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, // C3-1 -> C3-16
123 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, // C4-1 -> C4-16
124 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, // C5-1 -> C5-16
125 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
127 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
129 };
130
131
132
133 // ----- Interrupt Functions -----
134
135 void i2c0_isr()
136 {
137 cli(); // Disable Interrupts
138
139 uint8_t status = I2C0_S; // Read I2C Bus status
140
141 // Master Mode Transmit
142 if ( I2C0_C1 & I2C_C1_TX )
143 {
144 // Check current use of the I2C bus
145 // Currently sending data
146 if ( I2C_TxBuffer.sequencePos > 0 )
147 {
148 // Make sure slave sent an ACK
149 if ( status & I2C_S_RXAK )
150 {
151 // NACK Detected, disable interrupt
152 erro_print("I2C NAK detected...");
153 I2C0_C1 = I2C_C1_IICEN;
154
155 // Abort Tx Buffer
156 I2C_TxBuffer.head = 0;
157 I2C_TxBuffer.tail = 0;
158 I2C_TxBuffer.sequencePos = 0;
159 }
160 else
161 {
162 // Transmit byte
163 I2C0_D = I2C_TxBufferPop();
164 }
165 }
166 // Receiving data
167 else if ( I2C_RxBuffer.sequencePos > 0 )
168 {
169 // Master Receive, addr sent
170 if ( status & I2C_S_ARBL )
171 {
172 // Arbitration Lost
173 erro_print("Arbitration lost...");
174 // TODO Abort Rx
175
176 I2C0_C1 = I2C_C1_IICEN;
177 I2C0_S = I2C_S_ARBL | I2C_S_IICIF; // Clear ARBL flag and interrupt
178 }
179 if ( status & I2C_S_RXAK )
180 {
181 // Slave Address NACK Detected, disable interrupt
182 erro_print("Slave Address I2C NAK detected...");
183 // TODO Abort Rx
184
185 I2C0_C1 = I2C_C1_IICEN;
186 }
187 else
188 {
189 dbug_print("Attempting to read byte");
190 I2C0_C1 = I2C_RxBuffer.sequencePos == 1
191 ? I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK // Single byte read
192 : I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST; // Multi-byte read
193 }
194 }
195 else
196 {
197 /*
198 dbug_msg("STOP - ");
199 printHex( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) );
200 print(NL);
201 */
202
203 // Delay around STOP to make sure it actually happens...
204 delayMicroseconds( 1 );
205 I2C0_C1 = I2C_C1_IICEN; // Send STOP
206 delayMicroseconds( 7 );
207
208 // If there is another sequence, start sending
209 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) < I2C_TxBuffer.size )
210 {
211 // Clear status flags
212 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
213
214 // Wait...till the master dies
215 while ( I2C0_S & I2C_S_BUSY );
216
217 // Enable I2C interrupt
218 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
219
220 // Transmit byte
221 I2C0_D = I2C_TxBufferPop();
222 }
223 }
224 }
225 // Master Mode Receive
226 else
227 {
228 // XXX Do we need to handle 2nd last byte?
229 //I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TXAK; // No STOP, Rx, NAK on recv
230
231 // Last byte
232 if ( I2C_TxBuffer.sequencePos <= 1 )
233 {
234 // Change to Tx mode
235 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
236
237 // Grab last byte
238 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
239
240 delayMicroseconds( 1 ); // Should be enough time before issuing the stop
241 I2C0_C1 = I2C_C1_IICEN; // Send STOP
242 }
243 else
244 {
245 // Retrieve data
246 I2C_BufferPush( I2C0_D, (I2C_Buffer*)&I2C_RxBuffer );
247 }
248 }
249
250 I2C0_S = I2C_S_IICIF; // Clear interrupt
251
252 sei(); // Re-enable Interrupts
253 }
254
255
256
257 // ----- Functions -----
258
259 inline void I2C_setup()
260 {
261 // Enable I2C internal clock
262 SIM_SCGC4 |= SIM_SCGC4_I2C0; // Bus 0
263
264 // External pull-up resistor
265 PORTB_PCR0 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
266 PORTB_PCR1 = PORT_PCR_ODE | PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(2);
267
268 // SCL Frequency Divider
269 // 400kHz -> 120 (0x85) @ 48 MHz F_BUS
270 I2C0_F = 0x85;
271 I2C0_FLT = 4;
272 I2C0_C1 = I2C_C1_IICEN;
273 I2C0_C2 = I2C_C2_HDRS; // High drive select
274 //},
275
276 // Enable I2C Interrupt
277 NVIC_ENABLE_IRQ( IRQ_I2C0 );
278 }
279
280 void LED_zeroPages( uint8_t startPage, uint8_t numPages, uint8_t startReg, uint8_t endReg )
281 {
282 // Page Setup
283 uint8_t pageSetup[] = { 0xE8, 0xFD, 0x00 };
284
285 // Max length of a page + chip id + reg start
286 uint8_t fullPage[ 0xB4 + 2 ] = { 0 }; // Max size of page
287 fullPage[0] = 0xE8; // Set chip id
288 fullPage[1] = startReg; // Set start reg
289
290 // Iterate through given pages, zero'ing out the given register regions
291 for ( uint8_t page = startPage; page < startPage + numPages; page++ )
292 {
293 // Set page
294 pageSetup[2] = page;
295
296 // Setup page
297 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
298 delay(1);
299
300 // Zero out page
301 while ( I2C_Send( fullPage, endReg - startReg + 2, 0 ) == 0 )
302 delay(1);
303 }
304 }
305
306 void LED_sendPage( uint8_t *buffer, uint8_t len, uint8_t page )
307 {
308 // Page Setup
309 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
310
311 // Setup page
312 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
313 delay(1);
314
315 // Write page to I2C Tx Buffer
316 while ( I2C_Send( buffer, len, 0 ) == 0 )
317 delay(1);
318
319 }
320
321 void LED_writeReg( uint8_t reg, uint8_t val, uint8_t page )
322 {
323 // Page Setup
324 uint8_t pageSetup[] = { 0xE8, 0xFD, page };
325
326 // Reg Write Setup
327 uint8_t writeData[] = { 0xE8, reg, val };
328
329 // Setup page
330 while ( I2C_Send( pageSetup, sizeof( pageSetup ), 0 ) == 0 )
331 delay(1);
332
333 while ( I2C_Send( writeData, sizeof( writeData ), 0 ) == 0 )
334 delay(1);
335 }
336
337 // Setup
338 inline void LED_setup()
339 {
340 // Register Scan CLI dictionary
341 CLI_registerDictionary( ledCLIDict, ledCLIDictName );
342
343 // Initialize I2C
344 I2C_setup();
345
346 // Zero out Frame Registers
347 // This needs to be done before disabling the hardware shutdown (or the leds will do undefined things)
348 LED_zeroPages( 0x0B, 1, 0x00, 0x0C ); // Control Registers
349
350 // Disable Hardware shutdown of ISSI chip (pull high)
351 GPIOD_PDDR |= (1<<1);
352 PORTD_PCR1 = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1);
353 GPIOD_PSOR |= (1<<1);
354
355 // Clear LED Pages
356 LED_zeroPages( 0x00, 8, 0x00, 0xB4 ); // LED Registers
357
358 // Enable LEDs based upon mask
359 LED_sendPage( (uint8_t*)LED_ledEnableMask, sizeof( LED_ledEnableMask ), 0 );
360
361 // Disable Software shutdown of ISSI chip
362 LED_writeReg( 0x0A, 0x01, 0x0B );
363 }
364
365
366 inline uint8_t I2C_BufferCopy( uint8_t *data, uint8_t sendLen, uint8_t recvLen, I2C_Buffer *buffer )
367 {
368 uint8_t reTurn = 0;
369
370 // If sendLen is greater than buffer fail right away
371 if ( sendLen > buffer->size )
372 return 0;
373
374 // Calculate new tail to determine if buffer has enough space
375 // The first element specifies the expected number of bytes from the slave (+1)
376 // The second element in the new buffer is the length of the buffer sequence (+1)
377 uint16_t newTail = buffer->tail + sendLen + 2;
378 if ( newTail >= buffer->size )
379 newTail -= buffer->size;
380
381 if ( I2C_BufferLen( buffer ) < sendLen + 2 )
382 return 0;
383
384 /*
385 print("|");
386 printHex( sendLen + 2 );
387 print("|");
388 printHex( *tail );
389 print("@");
390 printHex( newTail );
391 print("@");
392 */
393
394 // If buffer is clean, return 1, otherwise 2
395 reTurn = buffer->head == buffer->tail ? 1 : 2;
396
397 // Add to buffer, already know there is enough room (simplifies adding logic)
398 uint8_t bufferHeaderPos = 0;
399 for ( uint16_t c = 0; c < sendLen; c++ )
400 {
401 // Add data to buffer
402 switch ( bufferHeaderPos )
403 {
404 case 0:
405 buffer->buffer[ buffer->tail ] = recvLen;
406 bufferHeaderPos++;
407 c--;
408 break;
409
410 case 1:
411 buffer->buffer[ buffer->tail ] = sendLen;
412 bufferHeaderPos++;
413 c--;
414 break;
415
416 default:
417 buffer->buffer[ buffer->tail ] = data[ c ];
418 break;
419 }
420
421 // Check for wrap-around case
422 if ( buffer->tail + 1 >= buffer->size )
423 {
424 buffer->tail = 0;
425 }
426 // Normal case
427 else
428 {
429 buffer->tail++;
430 }
431 }
432
433 return reTurn;
434 }
435
436
437 inline uint16_t I2C_BufferLen( I2C_Buffer *buffer )
438 {
439 // Tail >= Head
440 if ( buffer->tail >= buffer->head )
441 return buffer->head + buffer->size - buffer->tail;
442
443 // Head > Tail
444 return buffer->head - buffer->tail;
445 }
446
447
448 void I2C_BufferPush( uint8_t byte, I2C_Buffer *buffer )
449 {
450 // Make sure buffer isn't full
451 if ( buffer->tail + 1 == buffer->head || ( buffer->head > buffer->tail && buffer->tail + 1 - buffer->size == buffer->head ) )
452 {
453 warn_msg("I2C_BufferPush failed, buffer full: ");
454 printHex( byte );
455 print( NL );
456 return;
457 }
458
459 // Check for wrap-around case
460 if ( buffer->tail + 1 >= buffer->size )
461 {
462 buffer->tail = 0;
463 }
464 // Normal case
465 else
466 {
467 buffer->tail++;
468 }
469
470 // Add byte to buffer
471 buffer->buffer[ buffer->tail ] = byte;
472 }
473
474
475 uint8_t I2C_TxBufferPop()
476 {
477 // Return 0xFF if no buffer left (do not rely on this)
478 if ( I2C_BufferLen( (I2C_Buffer*)&I2C_TxBuffer ) >= I2C_TxBuffer.size )
479 {
480 erro_msg("No buffer to pop an entry from... ");
481 printHex( I2C_TxBuffer.head );
482 print(" ");
483 printHex( I2C_TxBuffer.tail );
484 print(" ");
485 printHex( I2C_TxBuffer.sequencePos );
486 print(NL);
487 return 0xFF;
488 }
489
490 // If there is currently no sequence being sent, the first entry in the RingBuffer is the length
491 if ( I2C_TxBuffer.sequencePos == 0 )
492 {
493 I2C_TxBuffer.sequencePos = 0xFF; // So this doesn't become an infinite loop
494 I2C_RxBuffer.sequencePos = I2C_TxBufferPop();
495 I2C_TxBuffer.sequencePos = I2C_TxBufferPop();
496 }
497
498 uint8_t data = I2C_TxBuffer.buffer[ I2C_TxBuffer.head ];
499
500 // Prune head
501 I2C_TxBuffer.head++;
502
503 // Wrap-around case
504 if ( I2C_TxBuffer.head >= I2C_TxBuffer.size )
505 I2C_TxBuffer.head = 0;
506
507 // Decrement buffer sequence (until next stop will be sent)
508 I2C_TxBuffer.sequencePos--;
509
510 /*
511 dbug_msg("Popping: ");
512 printHex( data );
513 print(" ");
514 printHex( I2C_TxBuffer.head );
515 print(" ");
516 printHex( I2C_TxBuffer.tail );
517 print(" ");
518 printHex( I2C_TxBuffer.sequencePos );
519 print(NL);
520 */
521 return data;
522 }
523
524
525 uint8_t I2C_Send( uint8_t *data, uint8_t sendLen, uint8_t recvLen )
526 {
527 // Check head and tail pointers
528 // If full, return 0
529 // If empty, start up I2C Master Tx
530 // If buffer is non-empty and non-full, just append to the buffer
531 switch ( I2C_BufferCopy( data, sendLen, recvLen, (I2C_Buffer*)&I2C_TxBuffer ) )
532 {
533 // Not enough buffer space...
534 case 0:
535 /*
536 erro_msg("Not enough Tx buffer space... ");
537 printHex( I2C_TxBuffer.head );
538 print(":");
539 printHex( I2C_TxBuffer.tail );
540 print("+");
541 printHex( sendLen );
542 print("|");
543 printHex( I2C_TxBuffer.size );
544 print( NL );
545 */
546 return 0;
547
548 // Empty buffer, initialize I2C
549 case 1:
550 // Clear status flags
551 I2C0_S = I2C_S_IICIF | I2C_S_ARBL;
552
553 // Check to see if we already have control of the bus
554 if ( I2C0_C1 & I2C_C1_MST )
555 {
556 // Already the master (ah yeah), send a repeated start
557 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_RSTA | I2C_C1_TX;
558 }
559 // Otherwise, seize control
560 else
561 {
562 // Wait...till the master dies
563 while ( I2C0_S & I2C_S_BUSY );
564
565 // Now we're the master (ah yisss), get ready to send stuffs
566 I2C0_C1 = I2C_C1_IICEN | I2C_C1_MST | I2C_C1_TX;
567 }
568
569 // Enable I2C interrupt
570 I2C0_C1 = I2C_C1_IICEN | I2C_C1_IICIE | I2C_C1_MST | I2C_C1_TX;
571
572 // Depending on what type of transfer, the first byte is configured for R or W
573 I2C0_D = I2C_TxBufferPop();
574
575 return 1;
576 }
577
578 // Dirty buffer, I2C already initialized
579 return 2;
580 }
581
582
583
584 // LED State processing loop
585 inline uint8_t LED_scan()
586 {
587
588 // I2C Busy
589 // S & I2C_S_BUSY
590 //I2C_S_BUSY
591
592 return 0;
593 }
594
595
596
597 // ----- CLI Command Functions -----
598
599 void cliFunc_i2cSend( char* args )
600 {
601 char* curArgs;
602 char* arg1Ptr;
603 char* arg2Ptr = args;
604
605 // Buffer used after interpretting the args, will be sent to I2C functions
606 // NOTE: Limited to 8 bytes currently (can be increased if necessary
607 #define i2cSend_BuffLenMax 8
608 uint8_t buffer[ i2cSend_BuffLenMax ];
609 uint8_t bufferLen = 0;
610
611 // No \r\n by default after the command is entered
612 print( NL );
613 info_msg("Sending: ");
614
615 // Parse args until a \0 is found
616 while ( bufferLen < i2cSend_BuffLenMax )
617 {
618 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
619 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
620
621 // Stop processing args if no more are found
622 if ( *arg1Ptr == '\0' )
623 break;
624
625 // If | is found, end sequence and start new one
626 if ( *arg1Ptr == '|' )
627 {
628 print("| ");
629 I2C_Send( buffer, bufferLen, 0 );
630 bufferLen = 0;
631 continue;
632 }
633
634 // Interpret the argument
635 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
636
637 // Print out the arg
638 dPrint( arg1Ptr );
639 print(" ");
640 }
641
642 print( NL );
643
644 I2C_Send( buffer, bufferLen, 0 );
645 }
646
647 void cliFunc_i2cRecv( char* args )
648 {
649 char* curArgs;
650 char* arg1Ptr;
651 char* arg2Ptr = args;
652
653 // Buffer used after interpretting the args, will be sent to I2C functions
654 // NOTE: Limited to 8 bytes currently (can be increased if necessary
655 #define i2cSend_BuffLenMax 8
656 uint8_t buffer[ i2cSend_BuffLenMax ];
657 uint8_t bufferLen = 0;
658
659 // No \r\n by default after the command is entered
660 print( NL );
661 info_msg("Sending: ");
662
663 // Parse args until a \0 is found
664 while ( bufferLen < i2cSend_BuffLenMax )
665 {
666 curArgs = arg2Ptr; // Use the previous 2nd arg pointer to separate the next arg from the list
667 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
668
669 // Stop processing args if no more are found
670 if ( *arg1Ptr == '\0' )
671 break;
672
673 // If | is found, end sequence and start new one
674 if ( *arg1Ptr == '|' )
675 {
676 print("| ");
677 I2C_Send( buffer, bufferLen, 0 );
678 bufferLen = 0;
679 continue;
680 }
681
682 // Interpret the argument
683 buffer[ bufferLen++ ] = (uint8_t)numToInt( arg1Ptr );
684
685 // Print out the arg
686 dPrint( arg1Ptr );
687 print(" ");
688 }
689
690 print( NL );
691
692 I2C_Send( buffer, bufferLen, 1 ); // Only 1 byte is ever read at a time with the ISSI chip
693 }
694
695 void cliFunc_ledTest( char* args )
696 {
697 print( NL ); // No \r\n by default after the command is entered
698 LED_sendPage( (uint8_t*)examplePage, sizeof( examplePage ), 0 );
699 }
700
701 void cliFunc_ledZero( char* args )
702 {
703 print( NL ); // No \r\n by default after the command is entered
704 LED_zeroPages( 0x00, 8, 0x24, 0xB4 ); // Only PWMs
705 }
706