Mercurial > louis > kiibohd-controller
annotate Scan/UARTConnect/connect_scan.c @ 348:06225a619152
Adding connection type list
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 25 Jul 2015 14:54:36 -0700 |
parents | 136e47478441 |
children | 86b937945313 |
rev | line source |
---|---|
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 /* Copyright (C) 2014-2015 by Jacob Alexander |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * This file is free software: you can redistribute it and/or modify |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * it under the terms of the GNU General Public License as published by |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * the Free Software Foundation, either version 3 of the License, or |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * (at your option) any later version. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * This file is distributed in the hope that it will be useful, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * You should have received a copy of the GNU General Public License |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * along with this file. If not, see <http://www.gnu.org/licenses/>. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 */ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 // ----- Includes ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 // Compiler Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 #include <Lib/ScanLib.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 // Project Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 #include <cli.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 #include <led.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 #include <print.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 #include <macro.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 // Local Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 #include "connect_scan.h" |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 // ----- Macros ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 // Macro for adding to each uart Tx ring buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 #define uart_addTxBuffer( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 case uartNum: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 while ( uart##uartNum##_buffer_items + count > uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 warn_msg("Too much data to send on UART0, waiting..."); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 delay( 1 ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 for ( uint8_t c = 0; c < count; c++ ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 { \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
45 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
46 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
47 printHex( buffer[ c ] ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
48 print( " +" #uartNum NL ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
49 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 uart##uartNum##_buffer[ uart##uartNum##_buffer_tail++ ] = buffer[ c ]; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 uart##uartNum##_buffer_items++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 if ( uart##uartNum##_buffer_tail >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 uart##uartNum##_buffer_tail = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 if ( uart##uartNum##_buffer_head == uart##uartNum##_buffer_tail ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 uart##uartNum##_buffer_head++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 uart##uartNum##_buffer_head = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 break |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 // Macro for popping from Tx ring buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 #define uart_fillTxFifo( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 uint8_t fifoSize = ( ( UART##uartNum##_PFIFO & UART_PFIFO_TXFIFOSIZE ) >> 2 ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 if ( fifoSize == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 fifoSize = 1; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 while ( UART##uartNum##_TCFIFO < fifoSize ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 if ( uart##uartNum##_buffer_items == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 UART##uartNum##_D = uart##uartNum##_buffer[ uart##uartNum##_buffer_head++ ]; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
72 uart##uartNum##_buffer_items--; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 uart##uartNum##_buffer_head = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 // Macro for processing UART Rx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 #define uart_processRx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
81 if ( !( UART##uartNum##_S1 & UART_S1_RDRF ) ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
82 return; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
83 uint8_t available = UART##uartNum##_RCFIFO; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
84 if ( available == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
85 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
86 available = UART##uartNum##_D; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
87 UART##uartNum##_CFIFO = UART_CFIFO_RXFLUSH; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
88 return; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
89 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 while ( available-- > 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 uint8_t byteRead = UART##uartNum##_D; \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
93 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
94 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
95 printHex( byteRead ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
96 print( "(" ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
97 printInt8( available ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
98 print( ") <-" ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
99 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 switch ( uart##uartNum##_rx_status ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 case UARTStatus_Wait: \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
103 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
104 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
105 print(" SYN "); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
106 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
107 uart##uartNum##_rx_status = byteRead == 0x16 ? UARTStatus_SYN : UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 case UARTStatus_SYN: \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
110 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
111 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
112 print(" SOH "); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
113 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 uart##uartNum##_rx_status = byteRead == 0x01 ? UARTStatus_SOH : UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
115 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 case UARTStatus_SOH: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 { \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
118 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
119 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
120 print(" CMD "); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
121 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
122 uint8_t byte = byteRead; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
123 if ( byte <= Animation ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
124 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
125 uart##uartNum##_rx_status = UARTStatus_Command; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
126 uart##uartNum##_rx_command = byte; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
127 uart##uartNum##_rx_bytes_waiting = 0xFFFF; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
128 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
129 else \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
130 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
131 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
132 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
133 switch ( uart##uartNum##_rx_command ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
134 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
135 case IdRequest: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
136 Connect_receive_IdRequest( 0, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
137 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
138 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
139 default: \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
140 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
141 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
142 print("###"); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
143 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
144 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
145 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
146 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
147 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
148 case UARTStatus_Command: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
149 { \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
150 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
151 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
152 print(" CMD "); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
153 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
154 uint8_t (*rcvFunc)(uint8_t, uint16_t(*), uint8_t) = (uint8_t(*)(uint8_t, uint16_t(*), uint8_t))(Connect_receiveFunctions[ uart##uartNum##_rx_command ]); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
155 if ( rcvFunc( byteRead, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ) ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
156 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
157 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
158 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
159 default: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
160 erro_msg("Invalid UARTStatus..."); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
161 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
162 available++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
163 continue; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
164 } \ |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
165 if ( Connect_debug ) \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
166 { \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
167 print( NL ); \ |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
168 } \ |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
169 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
170 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
171 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
172 // Macros for locking/unlock Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
173 #define uart_lockTx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
174 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
175 while ( uart##uartNum##_tx_status == UARTStatus_Wait ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
176 uart##uartNum##_tx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
177 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
178 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
179 #define uart_unlockTx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
180 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
181 uart##uartNum##_tx_status = UARTStatus_Ready; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
182 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
183 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
184 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
185 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
186 // ----- Function Declarations ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
187 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
188 // CLI Functions |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
189 void cliFunc_connectCmd ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
190 void cliFunc_connectIdl ( char *args ); |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
191 void cliFunc_connectLst ( char *args ); |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 void cliFunc_connectMst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 void cliFunc_connectRst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 void cliFunc_connectSts ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
195 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
196 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
197 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
198 // ----- Variables ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
199 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 // Connect Module command dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 CLIDict_Entry( connectCmd, "Sends a command via UART Connect, first arg is which uart, next arg is the command, rest are the arguments." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 CLIDict_Entry( connectIdl, "Sends N number of Idle commands, 2 is the default value, and should be sufficient in most cases." ); |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
203 CLIDict_Entry( connectLst, "Lists available UARTConnect commands and index id" ); |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
204 CLIDict_Entry( connectMst, "Sets the device as master. Use argument of s to set as slave." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
205 CLIDict_Entry( connectRst, "Resets both Rx and Tx connect buffers and state variables." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
206 CLIDict_Entry( connectSts, "UARTConnect status." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
207 CLIDict_Def( uartConnectCLIDict, "UARTConnect Module Commands" ) = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
208 CLIDict_Item( connectCmd ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
209 CLIDict_Item( connectIdl ), |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
210 CLIDict_Item( connectLst ), |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
211 CLIDict_Item( connectMst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
212 CLIDict_Item( connectRst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 CLIDict_Item( connectSts ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 { 0, 0, 0 } // Null entry for dictionary end |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
215 }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
217 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 // -- Connect Device Id Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 uint8_t Connect_id = 255; // Invalid, unset |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
220 uint8_t Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
221 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
222 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
223 // -- Control Variables -- |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
224 uint32_t Connect_lastCheck = 0; // Cable Check scheduler |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
225 uint8_t Connect_debug = 0; // Set 1 for debug |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
226 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
227 |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
228 // -- Rx Status Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
229 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
230 volatile UARTStatus uart0_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
231 volatile UARTStatus uart1_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 volatile uint16_t uart0_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
233 volatile uint16_t uart1_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
234 volatile Command uart0_rx_command; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
235 volatile Command uart1_rx_command; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
236 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
237 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 // -- Tx Status Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
239 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
240 volatile UARTStatus uart0_tx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
241 volatile UARTStatus uart1_tx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
242 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
243 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
244 // -- Ring Buffer Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
245 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 #define uart_buffer_size UARTConnectBufSize_define |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 volatile uint8_t uart0_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
248 volatile uint8_t uart0_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
249 volatile uint8_t uart0_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 volatile uint8_t uart0_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 volatile uint8_t uart1_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 volatile uint8_t uart1_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 volatile uint8_t uart1_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 volatile uint8_t uart1_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
255 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 volatile uint8_t uarts_configured = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
258 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
259 // -- Ring Buffer Convenience Functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 void Connect_addBytes( uint8_t *buffer, uint8_t count, uint8_t uart ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
262 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
263 // Too big to fit into buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
264 if ( count > uart_buffer_size ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
265 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
266 erro_msg("Too big of a command to fit into the buffer..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 return; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
268 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
269 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
270 // Choose the uart |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
271 switch ( uart ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 uart_addTxBuffer( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 uart_addTxBuffer( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 erro_msg("Invalid UART to send from..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
277 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
278 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
279 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
280 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
281 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
282 // -- Connect send functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
283 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
284 // patternLen defines how many bytes should the incrementing pattern have |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 void Connect_send_CableCheck( uint8_t patternLen ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
286 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
287 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
288 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
290 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
291 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
292 uint8_t header[] = { 0x16, 0x01, CableCheck, patternLen }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
293 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
294 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
295 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
296 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
297 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
298 // Send 0xD2 (11010010) for each argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
299 uint8_t value = 0xD2; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
300 for ( uint8_t c = 0; c < patternLen; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
301 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
302 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
303 Connect_addBytes( &value, 1, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
304 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
305 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
307 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
308 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
309 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
310 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
311 void Connect_send_IdRequest() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
312 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
313 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
314 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
315 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
316 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
317 uint8_t header[] = { 0x16, 0x01, IdRequest }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
318 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
319 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
320 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
321 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
322 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
323 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
324 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
325 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
326 // id is the value the next slave should enumerate as |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
327 void Connect_send_IdEnumeration( uint8_t id ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
328 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
329 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
330 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
331 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
332 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
333 uint8_t header[] = { 0x16, 0x01, IdEnumeration, id }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
334 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
335 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
336 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
337 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
338 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
339 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
340 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
341 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
342 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
343 void Connect_send_IdReport( uint8_t id ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
344 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
345 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
346 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
347 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
348 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
349 uint8_t header[] = { 0x16, 0x01, IdReport, id }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
350 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
351 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
352 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
353 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
354 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
355 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
356 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
357 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
358 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
359 // scanCodeStateList is an array of [scancode, state]'s (8 bit values) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
360 // numScanCodes is the number of scan codes to parse from array |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
361 void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
362 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
363 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
364 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
365 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
366 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
367 uint8_t header[] = { 0x16, 0x01, ScanCode, id, numScanCodes }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
368 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
369 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
370 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
371 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
372 // Send each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
373 Connect_addBytes( (uint8_t*)scanCodeStateList, numScanCodes * TriggerGuideSize, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
374 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
375 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
376 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
377 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
378 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
379 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
380 // paramList is an array of [param, value]'s (8 bit values) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
381 // numParams is the number of params to parse from the array |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
382 void Connect_send_Animation( uint8_t id, uint8_t *paramList, uint8_t numParams ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
383 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
384 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
385 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
386 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
387 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
388 uint8_t header[] = { 0x16, 0x01, Animation, id, numParams }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
389 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
390 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
391 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
392 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
393 // Send each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
394 Connect_addBytes( paramList, numParams, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
395 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
396 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
397 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
398 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
399 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
400 void Connect_send_Idle( uint8_t num ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
401 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
402 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
403 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
404 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
405 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
406 // Send n number of idles to reset link status (if in a bad state) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
407 uint8_t value = 0x16; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
408 for ( uint8_t c = 0; c < num; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
409 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
410 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
411 Connect_addBytes( &value, 1, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
412 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
413 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
414 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
415 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
416 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
417 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
418 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
419 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 // -- Connect receive functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
421 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
422 // - Cable Check variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 uint32_t Connect_cableFaultsMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
424 uint32_t Connect_cableFaultsSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
425 uint8_t Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
426 uint8_t Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
427 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
428 uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
429 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
430 // Check if this is the first byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
431 if ( *pending_bytes == 0xFFFF ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
432 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
433 *pending_bytes = byte; |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
434 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
435 if ( Connect_debug ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
436 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
437 dbug_msg("PENDING SET -> "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
438 printHex( byte ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
439 print(" "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
440 printHex( *pending_bytes ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
441 print( NL ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
442 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
443 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
444 // Verify byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
445 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 (*pending_bytes)--; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
448 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
449 // The argument bytes are always 0xD2 (11010010) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 if ( byte != 0xD2 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
452 warn_print("Cable Fault!"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
453 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
454 // Check which side of the chain |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
455 if ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
456 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
457 Connect_cableFaultsMaster++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
458 Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 print(" Master "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
460 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
461 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
462 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
463 Connect_cableFaultsSlave++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
464 Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
465 print(" Slave "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
466 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
467 printHex( byte ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
469 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 // Signal that the command should wait for a SYN again |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
473 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
474 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
475 // If cable check was successful, set cable ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
476 if ( *pending_bytes == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
478 if ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
479 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
480 Connect_cableOkMaster = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
481 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
482 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
483 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
484 Connect_cableOkSlave = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
485 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
486 } |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
487 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
488 if ( Connect_debug ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
489 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
490 dbug_msg("CABLECHECK RECEIVE - "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
491 printHex( byte ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
492 print(" "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
493 printHex( *pending_bytes ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
494 print( NL ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
495 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
496 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
497 // Check whether the cable check has finished |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 return *pending_bytes == 0 ? 1 : 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
499 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
500 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 uint8_t Connect_receive_IdRequest( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
502 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 dbug_print("IdRequest"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
504 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
505 if ( to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
506 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
507 erro_print("Invalid IdRequest direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
509 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
510 // Check if master, begin IdEnumeration |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 if ( Connect_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 // The first device is always id 1 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
514 // Id 0 is reserved for the master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
515 Connect_send_IdEnumeration( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
516 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
517 // Propagate IdRequest |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
518 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
519 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
520 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
521 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
522 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
523 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
524 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
525 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
526 uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
527 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
528 dbug_print("IdEnumeration"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
530 if ( !to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
531 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
532 erro_print("Invalid IdEnumeration direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
533 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
534 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
535 // Set the device id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 Connect_id = id; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 // Send reponse back to master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 Connect_send_IdReport( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
540 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
541 // Propogate next Id if the connection is ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 if ( Connect_cableOkSlave ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
544 Connect_send_IdEnumeration( id + 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
545 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
546 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
547 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
548 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
549 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
550 uint8_t Connect_receive_IdReport( uint8_t id, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
551 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
552 dbug_print("IdReport"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
553 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
554 if ( to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
555 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
556 erro_print("Invalid IdRequest direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
557 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
558 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
559 // Track Id response if master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 if ( Connect_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
562 // TODO, setup id's |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
563 info_msg("Id Reported: "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
564 printHex( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
565 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
566 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
567 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
568 // Propagate id if yet another slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
570 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
571 Connect_send_IdReport( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
572 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
573 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
574 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
575 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
576 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
577 // - Scan Code Variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
578 TriggerGuide Connect_receive_ScanCodeBuffer; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
579 uint8_t Connect_receive_ScanCodeBufferPos; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
580 uint8_t Connect_receive_ScanCodeDeviceId; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
581 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
582 uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
583 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
584 dbug_print("ScanCode"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
585 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 if ( !to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
587 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
588 erro_print("Invalid ScanCode direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
589 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
590 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
591 // Master node, trigger scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
592 if ( Connect_master ) switch ( (*pending_bytes)-- ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
594 case 0xFFFF: // Device Id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
595 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
596 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
598 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
599 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
600 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
602 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
603 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
604 // Set the specific TriggerGuide entry |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
605 ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
606 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
607 // Reset the BufferPos if higher than 3 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
608 // And send the TriggerGuide to the Macro Module |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
609 if ( Connect_receive_ScanCodeBufferPos > 3 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
610 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
611 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
612 Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
613 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
614 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
615 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
616 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
617 // Propagate ScanCode packet |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
618 else switch ( (*pending_bytes)-- ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
619 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 case 0xFFFF: // Device Id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
623 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
624 // Lock the master Tx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
626 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 // Send header + Id byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
628 uint8_t header[] = { 0x16, 0x01, ScanCode, byte }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
630 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
631 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
632 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
633 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
634 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
635 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
636 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
637 Connect_addBytes( &byte, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
638 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
639 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
640 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
641 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
642 Connect_addBytes( &byte, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
643 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
644 // Unlock Tx Buffer after sending last byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
645 if ( *pending_bytes == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
646 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
647 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
649 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
650 // Check whether the scan codes have finished sending |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 return *pending_bytes == 0 ? 1 : 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
652 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
653 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
654 uint8_t Connect_receive_Animation( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
655 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
656 dbug_print("Animation"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
657 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
658 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
659 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
660 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
661 // Baud Rate |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
662 // NOTE: If finer baud adjustment is needed see UARTx_C4 -> BRFA in the datasheet |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
663 uint16_t Connect_baud = UARTConnectBaud_define; // Max setting of 8191 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
664 uint16_t Connect_baudFine = UARTConnectBaudFine_define; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
665 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
666 // Connect receive function lookup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
667 void *Connect_receiveFunctions[] = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
668 Connect_receive_CableCheck, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
669 Connect_receive_IdRequest, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
670 Connect_receive_IdEnumeration, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
671 Connect_receive_IdReport, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
672 Connect_receive_ScanCode, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
673 Connect_receive_Animation, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
674 }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
675 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
676 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
677 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
678 // ----- Interrupt Functions ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
679 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
680 // Master / UART0 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
681 void uart0_status_isr() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
682 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
683 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
684 uart_processRx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
685 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
686 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
687 // Slave / UART1 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
688 void uart1_status_isr() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
689 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
690 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
691 uart_processRx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
692 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
693 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
694 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
695 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
696 // ----- Functions ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
697 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
698 // Resets the state of the UART buffers and state variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
699 void Connect_reset() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
700 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
701 // Rx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
702 uart0_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
703 uart1_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
704 uart0_rx_bytes_waiting = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
705 uart1_rx_bytes_waiting = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
707 // Tx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
708 uart0_tx_status = UARTStatus_Ready; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
709 uart1_tx_status = UARTStatus_Ready; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
710 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
711 // Ring Buffer Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 uart0_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
713 uart0_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
714 uart0_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
715 uart1_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
716 uart1_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
717 uart1_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
718 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
719 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
720 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
721 // Setup connection to other side |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
722 // - Only supports a single slave and master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
723 // - If USB has been initiallized at this point, this side is the master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
724 // - If both sides assert master, flash error leds |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
725 void Connect_setup( uint8_t master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
726 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
727 // Indication that UARTs are not ready |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
728 uarts_configured = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
729 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
730 // Register Connect CLI dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
731 CLI_registerDictionary( uartConnectCLIDict, uartConnectCLIDictName ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
732 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
733 // Check if master |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
734 Connect_master = master; |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
735 if ( Connect_master ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
736 Connect_id = 0; // 0x00 is always the master Id |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
737 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
738 // Master / UART0 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
739 // Slave / UART1 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
740 // Setup the the UART interface for keyboard data input |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
741 SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
742 SIM_SCGC4 |= SIM_SCGC4_UART1; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
743 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
744 // Pin Setup for UART0 / UART1 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
745 PORTA_PCR1 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(2); // RX Pin |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
746 PORTA_PCR2 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(2); // TX Pin |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
747 PORTE_PCR0 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
748 PORTE_PCR1 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
749 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
750 // Baud Rate setting |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
751 UART0_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
752 UART0_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
753 UART0_C4 = Connect_baudFine; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
754 UART1_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
755 UART1_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
756 UART1_C4 = Connect_baudFine; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
757 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
758 // 8 bit, Even Parity, Idle Character bit after stop |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
759 // NOTE: For 8 bit with Parity you must enable 9 bit transmission (pg. 1065) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
760 // You only need to use UART0_D for 8 bit reading/writing though |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
761 // UART_C1_M UART_C1_PE UART_C1_PT UART_C1_ILT |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
762 UART0_C1 = UART_C1_M | UART_C1_PE | UART_C1_ILT; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
763 UART1_C1 = UART_C1_M | UART_C1_PE | UART_C1_ILT; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
764 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
765 // Number of bytes in FIFO before TX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 // TODO Set 0 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
767 UART0_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
768 UART1_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
769 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
770 // Number of bytes in FIFO before RX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
771 UART0_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
772 UART1_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
773 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
774 // Enable TX and RX FIFOs |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
775 UART0_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
776 UART1_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
777 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
778 // Reciever Inversion Disabled, LSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
779 // UART_S2_RXINV UART_S2_MSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
780 UART0_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
781 UART1_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
782 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
783 // Transmit Inversion Disabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
784 // UART_C3_TXINV |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
785 UART0_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
786 UART1_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
787 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
788 // TX Enabled, RX Enabled, RX Interrupt Enabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
789 // UART_C2_TE UART_C2_RE UART_C2_RIE |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
790 UART0_C2 = UART_C2_TE | UART_C2_RE | UART_C2_RIE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
791 UART1_C2 = UART_C2_TE | UART_C2_RE | UART_C2_RIE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
792 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
793 // Add interrupts to the vector table |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
794 NVIC_ENABLE_IRQ( IRQ_UART0_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
795 NVIC_ENABLE_IRQ( IRQ_UART1_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
796 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
797 // UARTs are now ready to go |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
798 uarts_configured = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
799 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
800 // Reset the state of the UART variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
801 Connect_reset(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
802 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
803 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
804 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
805 // Scan for updates in the master/slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
806 // - Interrupts will deal with most input functions |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
807 // - Used to send queries |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
808 // - SyncEvent is sent immediately once the current command is sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
809 // - SyncEvent is also blocking until sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
810 void Connect_scan() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
811 { |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
812 // Check if initially configured as a slave and usb comes up |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
813 // Then reconfigure as a master |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
814 if ( !Connect_master && Output_Available ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
815 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
816 Connect_setup( Output_Available ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
817 } |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
818 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
819 // Limit how often we do cable checks |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
820 uint32_t time_compare = 0x7FF; // Must be all 1's, 0x3FF is valid, 0x4FF is not |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
821 uint32_t current_time = systick_millis_count; |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
822 if ( Connect_lastCheck != current_time |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
823 && ( current_time & time_compare ) == time_compare |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
824 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
825 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
826 // Make sure we don't double check if the clock speed is too high |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
827 Connect_lastCheck = current_time; |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
828 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
829 // Send a cable check command of 2 bytes |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
830 Connect_send_CableCheck( UARTConnectCableCheckLength_define ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
831 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
832 // If this is a slave, and we don't have an id yeth |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
833 // Don't bother sending if there are cable issues |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
834 if ( !Connect_master && Connect_id == 0xFF && Connect_cableOkMaster ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
835 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
836 Connect_send_IdRequest(); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
837 } |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
838 } |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
839 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
840 // Only process commands if uarts have been configured |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
841 if ( uarts_configured ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
842 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
843 // Check if Tx Buffers are empty and the Tx Ring buffers have data to send |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
844 // This happens if there was previously nothing to send |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
845 if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
846 uart_fillTxFifo( 0 ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
847 if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
848 uart_fillTxFifo( 1 ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
849 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
850 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
851 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
852 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
853 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
854 // ----- CLI Command Functions ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
855 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
856 void cliFunc_connectCmd( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
857 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
858 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
859 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
860 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
861 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
862 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
863 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
864 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
865 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
866 switch ( numToInt( &arg1Ptr[0] ) ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
867 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
868 case CableCheck: |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
869 Connect_send_CableCheck( UARTConnectCableCheckLength_define ); |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
870 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
871 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
872 case IdRequest: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
873 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
874 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
875 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
876 case IdEnumeration: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
877 Connect_send_IdEnumeration( 5 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
878 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
879 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
880 case IdReport: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
881 Connect_send_IdReport( 8 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
882 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
883 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
884 case ScanCode: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
885 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
886 TriggerGuide scanCodes[] = { { 0x00, 0x01, 0x05 }, { 0x00, 0x03, 0x16 } }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
887 Connect_send_ScanCode( 10, scanCodes, 2 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
888 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
890 case Animation: |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
891 break; |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
892 |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
893 case RemoteCapability: |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
894 // TODO |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
895 break; |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
896 |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
897 case RemoteOutput: |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
898 // TODO |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
899 break; |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
900 |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
901 case RemoteInput: |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
902 // TODO |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
903 break; |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
904 |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
905 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
906 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
907 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
908 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
909 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
910 void cliFunc_connectIdl( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
911 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
912 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
913 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
914 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
915 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
916 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
917 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
918 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
919 info_msg("Sending Sync Idles..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
920 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
921 uint8_t count = numToInt( &arg1Ptr[0] ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
922 // Default to 2 idles |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
923 if ( count == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
924 count = 2; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
925 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
926 Connect_send_Idle( count ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
927 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
928 |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
929 void cliFunc_connectLst( char* args ) |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
930 { |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
931 const char *Command_strs[] = { |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
932 "CableCheck", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
933 "IdRequest", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
934 "IdEnumeration", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
935 "IdReport", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
936 "ScanCode", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
937 "Animation", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
938 "RemoteCapability", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
939 "RemoteOutput", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
940 "RemoteInput", |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
941 }; |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
942 |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
943 print( NL ); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
944 info_msg("List of UARTConnect commands"); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
945 for ( uint8_t cmd = 0; cmd < Command_TOP; cmd++ ) |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
946 { |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
947 print( NL ); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
948 printInt8( cmd ); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
949 print(" - "); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
950 dPrint( (char*)Command_strs[ cmd ] ); |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
951 } |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
952 } |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
953 |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
954 void cliFunc_connectMst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
955 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
956 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
957 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
958 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
959 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
960 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
961 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
962 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
963 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
964 switch ( arg1Ptr[0] ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
965 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
966 case 's': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
967 case 'S': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
968 info_msg("Setting device as slave."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
969 Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
970 Connect_id = 0xFF; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
971 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
972 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
973 case 'm': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
974 case 'M': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
975 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
976 info_msg("Setting device as master."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
977 Connect_master = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
978 Connect_id = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
979 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
980 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
981 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
982 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
983 void cliFunc_connectRst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
984 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
985 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
986 info_msg("Resetting UARTConnect state..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
987 Connect_reset(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
988 |
348
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
989 // Reset node id |
06225a619152
Adding connection type list
Jacob Alexander <haata@kiibohd.com>
parents:
347
diff
changeset
|
990 Connect_id = 0xFF; |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
991 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
992 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
993 void cliFunc_connectSts( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
994 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
995 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
996 info_msg("UARTConnect Status"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
997 print( NL "Device Type:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
998 print( Connect_master ? "Master" : "Slave" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
999 print( NL "Device Id:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1000 printHex( Connect_id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1001 print( NL "Master <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1002 printHex( Connect_cableOkMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1003 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1004 printHex( Connect_cableFaultsMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1005 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1006 printHex( uart1_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1007 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1008 printHex( uart1_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1009 print( NL "Slave <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1010 printHex( Connect_cableOkSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1011 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1012 printHex( Connect_cableFaultsSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1013 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1014 printHex( uart0_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1015 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1016 printHex( uart0_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1017 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1018 |