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>
30 #include "connect_scan.h"
36 // Macro for adding to each uart Tx ring buffer
37 #define uart_addTxBuffer( uartNum ) \
39 /* Delay UART copy until there's some space left */ \
40 while ( uart##uartNum##_buffer_items + count > uart_buffer_size ) \
42 warn_msg("Too much data to send on UART0, waiting..."); \
45 /* Append data to ring buffer */ \
46 for ( uint8_t c = 0; c < count; c++ ) \
48 if ( Connect_debug ) \
50 printHex( buffer[ c ] ); \
51 print( " +" #uartNum NL ); \
53 uart##uartNum##_buffer[ uart##uartNum##_buffer_tail++ ] = buffer[ c ]; \
54 uart##uartNum##_buffer_items++; \
55 if ( uart##uartNum##_buffer_tail >= uart_buffer_size ) \
56 uart##uartNum##_buffer_tail = 0; \
57 if ( uart##uartNum##_buffer_head == uart##uartNum##_buffer_tail ) \
58 uart##uartNum##_buffer_head++; \
59 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \
60 uart##uartNum##_buffer_head = 0; \
64 // Macro for popping from Tx ring buffer
65 #define uart_fillTxFifo( uartNum ) \
67 uint8_t fifoSize = ( ( UART##uartNum##_PFIFO & UART_PFIFO_TXFIFOSIZE ) >> 2 ); \
68 if ( fifoSize == 0 ) \
70 while ( UART##uartNum##_TCFIFO < fifoSize ) \
72 if ( uart##uartNum##_buffer_items == 0 ) \
74 UART##uartNum##_D = uart##uartNum##_buffer[ uart##uartNum##_buffer_head++ ]; \
75 uart##uartNum##_buffer_items--; \
76 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \
77 uart##uartNum##_buffer_head = 0; \
81 // Macro for processing UART Rx
82 #define uart_processRx( uartNum ) \
84 if ( !( UART##uartNum##_S1 & UART_S1_RDRF ) ) \
86 uint8_t available = UART##uartNum##_RCFIFO; \
87 if ( available == 0 ) \
89 available = UART##uartNum##_D; \
90 UART##uartNum##_CFIFO = UART_CFIFO_RXFLUSH; \
93 /* Process each byte in the UART buffer */ \
94 while ( available-- > 0 ) \
96 uint8_t byteRead = UART##uartNum##_D; \
97 if ( Connect_debug ) \
99 printHex( byteRead ); \
101 printInt8( available ); \
104 switch ( uart##uartNum##_rx_status ) \
106 case UARTStatus_Wait: \
107 if ( Connect_debug ) \
111 uart##uartNum##_rx_status = byteRead == 0x16 ? UARTStatus_SYN : UARTStatus_Wait; \
113 case UARTStatus_SYN: \
114 if ( Connect_debug ) \
118 uart##uartNum##_rx_status = byteRead == 0x01 ? UARTStatus_SOH : UARTStatus_Wait; \
120 case UARTStatus_SOH: \
122 if ( Connect_debug ) \
126 uint8_t byte = byteRead; \
127 if ( byte <= Animation ) \
129 uart##uartNum##_rx_status = UARTStatus_Command; \
130 uart##uartNum##_rx_command = byte; \
131 uart##uartNum##_rx_bytes_waiting = 0xFFFF; \
135 uart##uartNum##_rx_status = UARTStatus_Wait; \
137 switch ( uart##uartNum##_rx_command ) \
140 Connect_receive_IdRequest( 0, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ); \
141 uart##uartNum##_rx_status = UARTStatus_Wait; \
144 if ( Connect_debug ) \
152 case UARTStatus_Command: \
154 if ( Connect_debug ) \
158 /* Call specific UARTConnect command receive function */ \
159 uint8_t (*rcvFunc)(uint8_t, uint16_t(*), uint8_t) = (uint8_t(*)(uint8_t, uint16_t(*), uint8_t))(Connect_receiveFunctions[ uart##uartNum##_rx_command ]); \
160 if ( rcvFunc( byteRead, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ) ) \
161 uart##uartNum##_rx_status = UARTStatus_Wait; \
165 erro_msg("Invalid UARTStatus..."); \
166 uart##uartNum##_rx_status = UARTStatus_Wait; \
170 if ( Connect_debug ) \
177 // Macros for locking/unlock Tx buffers
178 #define uart_lockTx( uartNum ) \
180 while ( uart##uartNum##_tx_status == UARTStatus_Wait ); \
181 uart##uartNum##_tx_status = UARTStatus_Wait; \
184 #define uart_unlockTx( uartNum ) \
186 uart##uartNum##_tx_status = UARTStatus_Ready; \
191 // ----- Function Declarations -----
194 void cliFunc_connectCmd ( char *args );
195 void cliFunc_connectIdl ( char *args );
196 void cliFunc_connectLst ( char *args );
197 void cliFunc_connectMst ( char *args );
198 void cliFunc_connectRst ( char *args );
199 void cliFunc_connectSts ( char *args );
203 // ----- Variables -----
205 // Connect Module command dictionary
206 CLIDict_Entry( connectCmd, "Sends a command via UART Connect, first arg is which uart, next arg is the command, rest are the arguments." );
207 CLIDict_Entry( connectIdl, "Sends N number of Idle commands, 2 is the default value, and should be sufficient in most cases." );
208 CLIDict_Entry( connectLst, "Lists available UARTConnect commands and index id" );
209 CLIDict_Entry( connectMst, "Sets the device as master. Use argument of s to set as slave." );
210 CLIDict_Entry( connectRst, "Resets both Rx and Tx connect buffers and state variables." );
211 CLIDict_Entry( connectSts, "UARTConnect status." );
212 CLIDict_Def( uartConnectCLIDict, "UARTConnect Module Commands" ) = {
213 CLIDict_Item( connectCmd ),
214 CLIDict_Item( connectIdl ),
215 CLIDict_Item( connectLst ),
216 CLIDict_Item( connectMst ),
217 CLIDict_Item( connectRst ),
218 CLIDict_Item( connectSts ),
219 { 0, 0, 0 } // Null entry for dictionary end
223 // -- Connect Device Id Variables --
224 uint8_t Connect_id = 255; // Invalid, unset
225 uint8_t Connect_master = 0;
228 // -- Control Variables --
229 uint32_t Connect_lastCheck = 0; // Cable Check scheduler
230 uint8_t Connect_debug = 0; // Set 1 for debug
233 // -- Rx Status Variables --
235 volatile UARTStatus uart0_rx_status;
236 volatile UARTStatus uart1_rx_status;
237 volatile uint16_t uart0_rx_bytes_waiting;
238 volatile uint16_t uart1_rx_bytes_waiting;
239 volatile Command uart0_rx_command;
240 volatile Command uart1_rx_command;
243 // -- Tx Status Variables --
245 volatile UARTStatus uart0_tx_status;
246 volatile UARTStatus uart1_tx_status;
249 // -- Ring Buffer Variables --
251 #define uart_buffer_size UARTConnectBufSize_define
252 volatile uint8_t uart0_buffer_head;
253 volatile uint8_t uart0_buffer_tail;
254 volatile uint8_t uart0_buffer_items;
255 volatile uint8_t uart0_buffer[uart_buffer_size];
256 volatile uint8_t uart1_buffer_head;
257 volatile uint8_t uart1_buffer_tail;
258 volatile uint8_t uart1_buffer_items;
259 volatile uint8_t uart1_buffer[uart_buffer_size];
261 volatile uint8_t uarts_configured = 0;
264 // -- Ring Buffer Convenience Functions --
266 void Connect_addBytes( uint8_t *buffer, uint8_t count, uint8_t uart )
268 // Too big to fit into buffer
269 if ( count > uart_buffer_size )
271 erro_msg("Too big of a command to fit into the buffer...");
278 uart_addTxBuffer( 0 );
279 uart_addTxBuffer( 1 );
281 erro_msg("Invalid UART to send from...");
287 // -- Connect send functions --
289 // patternLen defines how many bytes should the incrementing pattern have
290 void Connect_send_CableCheck( uint8_t patternLen )
292 // Wait until the Tx buffers are ready, then lock them
297 uint8_t header[] = { 0x16, 0x01, CableCheck, patternLen };
300 Connect_addBytes( header, sizeof( header ), 1 ); // Master
301 Connect_addBytes( header, sizeof( header ), 0 ); // Slave
303 // Send 0xD2 (11010010) for each argument
304 uint8_t value = 0xD2;
305 for ( uint8_t c = 0; c < patternLen; c++ )
307 Connect_addBytes( &value, 1, 1 ); // Master
308 Connect_addBytes( &value, 1, 0 ); // Slave
311 // Release Tx buffers
316 void Connect_send_IdRequest()
318 // Lock master bound Tx
322 uint8_t header[] = { 0x16, 0x01, IdRequest };
325 Connect_addBytes( header, sizeof( header ), 1 ); // Master
331 // id is the value the next slave should enumerate as
332 void Connect_send_IdEnumeration( uint8_t id )
334 // Lock slave bound Tx
338 uint8_t header[] = { 0x16, 0x01, IdEnumeration, id };
341 Connect_addBytes( header, sizeof( header ), 0 ); // Slave
347 // id is the currently assigned id to the slave
348 void Connect_send_IdReport( uint8_t id )
350 // Lock master bound Tx
354 uint8_t header[] = { 0x16, 0x01, IdReport, id };
357 Connect_addBytes( header, sizeof( header ), 1 ); // Master
363 // id is the currently assigned id to the slave
364 // scanCodeStateList is an array of [scancode, state]'s (8 bit values)
365 // numScanCodes is the number of scan codes to parse from array
366 void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes )
368 // Lock master bound Tx
372 uint8_t header[] = { 0x16, 0x01, ScanCode, id, numScanCodes };
375 Connect_addBytes( header, sizeof( header ), 1 ); // Master
377 // Send each of the scan codes
378 Connect_addBytes( (uint8_t*)scanCodeStateList, numScanCodes * TriggerGuideSize, 1 ); // Master
384 // id is the currently assigned id to the slave
385 // paramList is an array of [param, value]'s (8 bit values)
386 // numParams is the number of params to parse from the array
387 void Connect_send_Animation( uint8_t id, uint8_t *paramList, uint8_t numParams )
389 // Lock slave bound Tx
393 uint8_t header[] = { 0x16, 0x01, Animation, id, numParams };
396 Connect_addBytes( header, sizeof( header ), 0 ); // Slave
398 // Send each of the scan codes
399 Connect_addBytes( paramList, numParams, 0 ); // Slave
405 void Connect_send_Idle( uint8_t num )
407 // Wait until the Tx buffers are ready, then lock them
411 // Send n number of idles to reset link status (if in a bad state)
412 uint8_t value = 0x16;
413 for ( uint8_t c = 0; c < num; c++ )
415 Connect_addBytes( &value, 1, 1 ); // Master
416 Connect_addBytes( &value, 1, 0 ); // Slave
419 // Release Tx buffers
425 // -- Connect receive functions --
427 // - Cable Check variables -
428 uint32_t Connect_cableFaultsMaster = 0;
429 uint32_t Connect_cableFaultsSlave = 0;
430 uint8_t Connect_cableOkMaster = 0;
431 uint8_t Connect_cableOkSlave = 0;
433 uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
435 // Check if this is the first byte
436 if ( *pending_bytes == 0xFFFF )
438 *pending_bytes = byte;
442 dbug_msg("PENDING SET -> ");
445 printHex( *pending_bytes );
454 // The argument bytes are always 0xD2 (11010010)
457 warn_print("Cable Fault!");
459 // Check which side of the chain
462 Connect_cableFaultsMaster++;
463 Connect_cableOkMaster = 0;
468 Connect_cableFaultsSlave++;
469 Connect_cableOkSlave = 0;
475 // Signal that the command should wait for a SYN again
480 // If cable check was successful, set cable ok
481 if ( *pending_bytes == 0 )
485 Connect_cableOkMaster = 1;
489 Connect_cableOkSlave = 1;
495 dbug_msg("CABLECHECK RECEIVE - ");
498 printHex( *pending_bytes );
502 // Check whether the cable check has finished
503 return *pending_bytes == 0 ? 1 : 0;
506 uint8_t Connect_receive_IdRequest( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
508 dbug_print("IdRequest");
509 // Check the directionality
512 erro_print("Invalid IdRequest direction...");
515 // Check if master, begin IdEnumeration
516 if ( Connect_master )
518 // The first device is always id 1
519 // Id 0 is reserved for the master
520 Connect_send_IdEnumeration( 1 );
522 // Propagate IdRequest
525 Connect_send_IdRequest();
531 uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint8_t to_slave )
533 dbug_print("IdEnumeration");
534 // Check the directionality
537 erro_print("Invalid IdEnumeration direction...");
543 // Send reponse back to master
544 Connect_send_IdReport( id );
546 // Propogate next Id if the connection is ok
547 if ( Connect_cableOkSlave )
549 Connect_send_IdEnumeration( id + 1 );
555 uint8_t Connect_receive_IdReport( uint8_t id, uint16_t *pending_bytes, uint8_t to_slave )
557 dbug_print("IdReport");
558 // Check the directionality
561 erro_print("Invalid IdRequest direction...");
564 // Track Id response if master
565 if ( Connect_master )
568 info_msg("Id Reported: ");
573 // Propagate id if yet another slave
576 Connect_send_IdReport( id );
582 // - Scan Code Variables -
583 TriggerGuide Connect_receive_ScanCodeBuffer;
584 uint8_t Connect_receive_ScanCodeBufferPos;
585 uint8_t Connect_receive_ScanCodeDeviceId;
587 uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
589 dbug_print("ScanCode");
590 // Check the directionality
593 erro_print("Invalid ScanCode direction...");
596 // Master node, trigger scan codes
597 if ( Connect_master ) switch ( (*pending_bytes)-- )
599 // Byte count always starts at 0xFFFF
600 case 0xFFFF: // Device Id
601 Connect_receive_ScanCodeDeviceId = byte;
604 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3)
605 *pending_bytes = byte * sizeof( TriggerGuide );
606 Connect_receive_ScanCodeBufferPos = 0;
610 // Set the specific TriggerGuide entry
611 ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte;
613 // Reset the BufferPos if higher than sizeof TriggerGuide
614 // And send the TriggerGuide to the Macro Module
615 if ( Connect_receive_ScanCodeBufferPos > sizeof( TriggerGuide ) )
617 Connect_receive_ScanCodeBufferPos = 0;
619 // Adjust ScanCode offset
620 if ( Connect_receive_ScanCodeDeviceId > 0 )
622 // This variable is in generatedKeymaps.h
623 extern uint8_t InterconnectOffsetList[];
624 Connect_receive_ScanCodeBuffer.scanCode = Connect_receive_ScanCodeBuffer.scanCode + InterconnectOffsetList[ Connect_receive_ScanCodeDeviceId - 1 ];
627 // ScanCode receive debug
629 printHex( Connect_receive_ScanCodeBuffer.type );
631 printHex( Connect_receive_ScanCodeBuffer.state );
633 printHex( Connect_receive_ScanCodeBuffer.scanCode );
636 // Send ScanCode to macro module
638 //Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 );
643 // Propagate ScanCode packet
644 else switch ( (*pending_bytes)-- )
646 // Byte count always starts at 0xFFFF
647 case 0xFFFF: // Device Id
649 Connect_receive_ScanCodeDeviceId = byte;
651 // Lock the master Tx buffer
654 // Send header + Id byte
655 uint8_t header[] = { 0x16, 0x01, ScanCode, byte };
656 Connect_addBytes( header, sizeof( header ), 1 ); // Master
659 case 0xFFFE: // Number of TriggerGuides in bytes
660 *pending_bytes = byte * sizeof( TriggerGuide );
661 Connect_receive_ScanCodeBufferPos = 0;
664 Connect_addBytes( &byte, 1, 1 ); // Master
669 Connect_addBytes( &byte, 1, 1 ); // Master
671 // Unlock Tx Buffer after sending last byte
672 if ( *pending_bytes == 0 )
677 // Check whether the scan codes have finished sending
678 return *pending_bytes == 0 ? 1 : 0;
681 uint8_t Connect_receive_Animation( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
683 dbug_print("Animation");
689 // NOTE: If finer baud adjustment is needed see UARTx_C4 -> BRFA in the datasheet
690 uint16_t Connect_baud = UARTConnectBaud_define; // Max setting of 8191
691 uint16_t Connect_baudFine = UARTConnectBaudFine_define;
693 // Connect receive function lookup
694 void *Connect_receiveFunctions[] = {
695 Connect_receive_CableCheck,
696 Connect_receive_IdRequest,
697 Connect_receive_IdEnumeration,
698 Connect_receive_IdReport,
699 Connect_receive_ScanCode,
700 Connect_receive_Animation,
705 // ----- Interrupt Functions -----
707 // Master / UART0 ISR
708 void uart0_status_isr()
715 void uart1_status_isr()
723 // ----- Functions -----
725 // Resets the state of the UART buffers and state variables
728 // Rx Status Variables
729 uart0_rx_status = UARTStatus_Wait;
730 uart1_rx_status = UARTStatus_Wait;
731 uart0_rx_bytes_waiting = 0;
732 uart1_rx_bytes_waiting = 0;
734 // Tx Status Variables
735 uart0_tx_status = UARTStatus_Ready;
736 uart1_tx_status = UARTStatus_Ready;
738 // Ring Buffer Variables
739 uart0_buffer_head = 0;
740 uart0_buffer_tail = 0;
741 uart0_buffer_items = 0;
742 uart1_buffer_head = 0;
743 uart1_buffer_tail = 0;
744 uart1_buffer_items = 0;
748 // Setup connection to other side
749 // - Only supports a single slave and master
750 // - If USB has been initiallized at this point, this side is the master
751 // - If both sides assert master, flash error leds
752 void Connect_setup( uint8_t master )
754 // Indication that UARTs are not ready
755 uarts_configured = 0;
757 // Register Connect CLI dictionary
758 CLI_registerDictionary( uartConnectCLIDict, uartConnectCLIDictName );
761 Connect_master = master;
762 if ( Connect_master )
763 Connect_id = 0; // 0x00 is always the master Id
765 // Master / UART0 setup
766 // Slave / UART1 setup
767 // Setup the the UART interface for keyboard data input
768 SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating
769 SIM_SCGC4 |= SIM_SCGC4_UART1; // Disable clock gating
771 // Pin Setup for UART0 / UART1
772 PORTA_PCR1 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(2); // RX Pin
773 PORTA_PCR2 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(2); // TX Pin
774 PORTE_PCR0 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin
775 PORTE_PCR1 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin
778 UART0_BDH = (uint8_t)(Connect_baud >> 8);
779 UART0_BDL = (uint8_t)Connect_baud;
780 UART0_C4 = Connect_baudFine;
781 UART1_BDH = (uint8_t)(Connect_baud >> 8);
782 UART1_BDL = (uint8_t)Connect_baud;
783 UART1_C4 = Connect_baudFine;
785 // 8 bit, Even Parity, Idle Character bit after stop
786 // NOTE: For 8 bit with Parity you must enable 9 bit transmission (pg. 1065)
787 // You only need to use UART0_D for 8 bit reading/writing though
788 // UART_C1_M UART_C1_PE UART_C1_PT UART_C1_ILT
789 UART0_C1 = UART_C1_M | UART_C1_PE | UART_C1_ILT;
790 UART1_C1 = UART_C1_M | UART_C1_PE | UART_C1_ILT;
792 // Number of bytes in FIFO before TX Interrupt
797 // Number of bytes in FIFO before RX Interrupt
801 // Enable TX and RX FIFOs
802 UART0_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE;
803 UART1_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE;
805 // Reciever Inversion Disabled, LSBF
806 // UART_S2_RXINV UART_S2_MSBF
810 // Transmit Inversion Disabled
815 // TX Enabled, RX Enabled, RX Interrupt Enabled
816 // UART_C2_TE UART_C2_RE UART_C2_RIE
817 UART0_C2 = UART_C2_TE | UART_C2_RE | UART_C2_RIE;
818 UART1_C2 = UART_C2_TE | UART_C2_RE | UART_C2_RIE;
820 // Add interrupts to the vector table
821 NVIC_ENABLE_IRQ( IRQ_UART0_STATUS );
822 NVIC_ENABLE_IRQ( IRQ_UART1_STATUS );
824 // UARTs are now ready to go
825 uarts_configured = 1;
827 // Reset the state of the UART variables
832 // Scan for updates in the master/slave
833 // - Interrupts will deal with most input functions
834 // - Used to send queries
835 // - SyncEvent is sent immediately once the current command is sent
836 // - SyncEvent is also blocking until sent
839 // Check if initially configured as a slave and usb comes up
840 // Then reconfigure as a master
841 if ( !Connect_master && Output_Available )
843 Connect_setup( Output_Available );
846 // Limit how often we do cable checks
847 uint32_t time_compare = 0x7FF; // Must be all 1's, 0x3FF is valid, 0x4FF is not
848 uint32_t current_time = systick_millis_count;
849 if ( Connect_lastCheck != current_time
850 && ( current_time & time_compare ) == time_compare
853 // Make sure we don't double check if the clock speed is too high
854 Connect_lastCheck = current_time;
856 // Send a cable check command of 2 bytes
857 Connect_send_CableCheck( UARTConnectCableCheckLength_define );
859 // If this is a slave, and we don't have an id yeth
860 // Don't bother sending if there are cable issues
861 if ( !Connect_master && Connect_id == 0xFF && Connect_cableOkMaster )
863 Connect_send_IdRequest();
867 // Only process commands if uarts have been configured
868 if ( uarts_configured )
870 // Check if Tx Buffers are empty and the Tx Ring buffers have data to send
871 // This happens if there was previously nothing to send
872 if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 )
873 uart_fillTxFifo( 0 );
874 if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 )
875 uart_fillTxFifo( 1 );
881 // ----- CLI Command Functions -----
883 void cliFunc_connectCmd( char* args )
885 // Parse number from argument
886 // NOTE: Only first argument is used
889 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
893 switch ( numToInt( &arg1Ptr[0] ) )
896 Connect_send_CableCheck( UARTConnectCableCheckLength_define );
900 Connect_send_IdRequest();
904 Connect_send_IdEnumeration( 5 );
908 Connect_send_IdReport( 8 );
913 TriggerGuide scanCodes[] = { { 0x00, 0x01, 0x05 }, { 0x00, 0x03, 0x16 } };
914 Connect_send_ScanCode( 10, scanCodes, 2 );
920 case RemoteCapability:
937 void cliFunc_connectIdl( char* args )
939 // Parse number from argument
940 // NOTE: Only first argument is used
943 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
946 info_msg("Sending Sync Idles...");
948 uint8_t count = numToInt( &arg1Ptr[0] );
949 // Default to 2 idles
953 Connect_send_Idle( count );
956 void cliFunc_connectLst( char* args )
958 const char *Command_strs[] = {
971 info_msg("List of UARTConnect commands");
972 for ( uint8_t cmd = 0; cmd < Command_TOP; cmd++ )
977 dPrint( (char*)Command_strs[ cmd ] );
981 void cliFunc_connectMst( char* args )
983 // Parse number from argument
984 // NOTE: Only first argument is used
987 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
991 switch ( arg1Ptr[0] )
995 info_msg("Setting device as slave.");
1003 info_msg("Setting device as master.");
1010 void cliFunc_connectRst( char* args )
1013 info_msg("Resetting UARTConnect state...");
1020 void cliFunc_connectSts( char* args )
1023 info_msg("UARTConnect Status");
1024 print( NL "Device Type:\t" );
1025 print( Connect_master ? "Master" : "Slave" );
1026 print( NL "Device Id:\t" );
1027 printHex( Connect_id );
1028 print( NL "Master <=" NL "\tStatus:\t");
1029 printHex( Connect_cableOkMaster );
1030 print( NL "\tFaults:\t");
1031 printHex( Connect_cableFaultsMaster );
1032 print( NL "\tRx:\t");
1033 printHex( uart1_rx_status );
1034 print( NL "\tTx:\t");
1035 printHex( uart1_tx_status );
1036 print( NL "Slave <=" NL "\tStatus:\t");
1037 printHex( Connect_cableOkSlave );
1038 print( NL "\tFaults:\t");
1039 printHex( Connect_cableFaultsSlave );
1040 print( NL "\tRx:\t");
1041 printHex( uart0_rx_status );
1042 print( NL "\tTx:\t");
1043 printHex( uart0_tx_status );