Mercurial > louis > kiibohd-controller
annotate Scan/UARTConnect/connect_scan.c @ 347:136e47478441
UARTConnect enumeration working!
- Fixed cli reflash mode set
- Cleaned up debugging code
- 4 500 000 baud seems to be reliable
- Fixed master selection (assumes slave node unless USB enumerates)
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sat, 18 Jul 2015 18:53:21 -0700 |
parents | ecd2ae35d25c |
children | 06225a619152 |
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 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
191 void cliFunc_connectMst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 void cliFunc_connectRst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 void cliFunc_connectSts ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 |
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 // ----- Variables ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
198 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
199 // Connect Module command dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 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
|
201 CLIDict_Entry( connectIdl, "Sends N number of Idle commands, 2 is the default value, and should be sufficient in most cases." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 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
|
203 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
|
204 CLIDict_Entry( connectSts, "UARTConnect status." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
205 CLIDict_Def( uartConnectCLIDict, "UARTConnect Module Commands" ) = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
206 CLIDict_Item( connectCmd ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
207 CLIDict_Item( connectIdl ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
208 CLIDict_Item( connectMst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
209 CLIDict_Item( connectRst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
210 CLIDict_Item( connectSts ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
211 { 0, 0, 0 } // Null entry for dictionary end |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
212 }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
215 // -- Connect Device Id Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 uint8_t Connect_id = 255; // Invalid, unset |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
217 uint8_t Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
220 // -- Control Variables -- |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
221 uint32_t Connect_lastCheck = 0; // Cable Check scheduler |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
222 uint8_t Connect_debug = 0; // Set 1 for debug |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
223 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
224 |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
225 // -- Rx Status Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
226 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
227 volatile UARTStatus uart0_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
228 volatile UARTStatus uart1_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
229 volatile uint16_t uart0_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
230 volatile uint16_t uart1_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
231 volatile Command uart0_rx_command; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 volatile Command uart1_rx_command; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
233 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
234 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
235 // -- Tx Status Variables -- |
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 volatile UARTStatus uart0_tx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 volatile UARTStatus uart1_tx_status; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
241 // -- Ring Buffer Variables -- |
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 #define uart_buffer_size UARTConnectBufSize_define |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
244 volatile uint8_t uart0_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
245 volatile uint8_t uart0_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 volatile uint8_t uart0_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 volatile uint8_t uart0_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
248 volatile uint8_t uart1_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
249 volatile uint8_t uart1_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 volatile uint8_t uart1_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 volatile uint8_t uart1_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 volatile uint8_t uarts_configured = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 |
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 // -- Ring Buffer Convenience Functions -- |
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 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
|
259 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 // Too big to fit into buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 if ( count > uart_buffer_size ) |
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 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
|
264 return; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 // Choose the uart |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
268 switch ( uart ) |
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 uart_addTxBuffer( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
271 uart_addTxBuffer( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 erro_msg("Invalid UART to send from..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
277 |
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 // -- Connect send functions -- |
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 // patternLen defines how many bytes should the incrementing pattern have |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
282 void Connect_send_CableCheck( uint8_t patternLen ) |
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 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
286 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
287 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
288 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 uint8_t header[] = { 0x16, 0x01, CableCheck, patternLen }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
292 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
293 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
294 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
295 // Send 0xD2 (11010010) for each argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
296 uint8_t value = 0xD2; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
297 for ( uint8_t c = 0; c < patternLen; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
298 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
299 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
300 Connect_addBytes( &value, 1, 0 ); // Slave |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
303 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
304 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
305 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
307 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
308 void Connect_send_IdRequest() |
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 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
311 uart_lockTx( 1 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
314 uint8_t header[] = { 0x16, 0x01, IdRequest }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
317 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
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 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
320 uart_unlockTx( 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
323 // id is the value the next slave should enumerate as |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
324 void Connect_send_IdEnumeration( uint8_t id ) |
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 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
327 uart_lockTx( 0 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
330 uint8_t header[] = { 0x16, 0x01, IdEnumeration, id }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
333 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
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 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
336 uart_unlockTx( 0 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
339 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
340 void Connect_send_IdReport( uint8_t id ) |
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 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
343 uart_lockTx( 1 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
346 uint8_t header[] = { 0x16, 0x01, IdReport, id }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
349 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
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 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
352 uart_unlockTx( 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
355 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
356 // 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
|
357 // 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
|
358 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
|
359 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
360 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
361 uart_lockTx( 1 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
364 uint8_t header[] = { 0x16, 0x01, ScanCode, id, numScanCodes }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
367 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
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 each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
370 Connect_addBytes( (uint8_t*)scanCodeStateList, numScanCodes * TriggerGuideSize, 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 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
373 uart_unlockTx( 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
376 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
377 // 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
|
378 // 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
|
379 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
|
380 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
381 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
382 uart_lockTx( 0 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
385 uint8_t header[] = { 0x16, 0x01, Animation, id, numParams }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
388 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
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 each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
391 Connect_addBytes( paramList, numParams, 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 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
394 uart_unlockTx( 0 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
397 void Connect_send_Idle( uint8_t num ) |
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 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
400 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
401 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
402 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
403 // 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
|
404 uint8_t value = 0x16; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
405 for ( uint8_t c = 0; c < num; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
406 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
407 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
408 Connect_addBytes( &value, 1, 0 ); // Slave |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
411 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
412 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
413 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
414 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
415 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
416 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
417 // -- Connect receive functions -- |
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 // - Cable Check variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 uint32_t Connect_cableFaultsMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
421 uint32_t Connect_cableFaultsSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
422 uint8_t Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 uint8_t Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
424 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
425 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
|
426 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
427 // Check if this is the first byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
428 if ( *pending_bytes == 0xFFFF ) |
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 *pending_bytes = byte; |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
431 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
432 if ( Connect_debug ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
433 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
434 dbug_msg("PENDING SET -> "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
435 printHex( byte ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
436 print(" "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
437 printHex( *pending_bytes ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
438 print( NL ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
439 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
440 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
441 // Verify byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
442 else |
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 (*pending_bytes)--; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
445 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 // The argument bytes are always 0xD2 (11010010) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 if ( byte != 0xD2 ) |
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 warn_print("Cable Fault!"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 // Check which side of the chain |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
452 if ( to_master ) |
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 Connect_cableFaultsMaster++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
455 Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
456 print(" Master "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
457 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
458 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
460 Connect_cableFaultsSlave++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
461 Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
462 print(" Slave "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
463 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
464 printHex( byte ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
465 print( NL ); |
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 // Signal that the command should wait for a SYN again |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 return 1; |
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 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 // If cable check was successful, set cable ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
473 if ( *pending_bytes == 0 ) |
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 ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
476 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 Connect_cableOkMaster = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
478 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
479 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
480 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
481 Connect_cableOkSlave = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
482 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
483 } |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
484 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
485 if ( Connect_debug ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
486 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
487 dbug_msg("CABLECHECK RECEIVE - "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
488 printHex( byte ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
489 print(" "); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
490 printHex( *pending_bytes ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
491 print( NL ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
492 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
493 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
494 // Check whether the cable check has finished |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
495 return *pending_bytes == 0 ? 1 : 0; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 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
|
499 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
500 dbug_print("IdRequest"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
502 if ( to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
504 erro_print("Invalid IdRequest direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
505 } |
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 // Check if master, begin IdEnumeration |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 if ( Connect_master ) |
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 // The first device is always id 1 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 // Id 0 is reserved for the master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 Connect_send_IdEnumeration( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
514 // Propagate IdRequest |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
515 else |
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 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
518 } |
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 return 1; |
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 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
|
524 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
525 dbug_print("IdEnumeration"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
526 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
527 if ( !to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
528 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 erro_print("Invalid IdEnumeration direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
530 } |
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 // Set the device id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
533 Connect_id = id; |
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 // Send reponse back to master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 Connect_send_IdReport( 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 // Propogate next Id if the connection is ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 if ( Connect_cableOkSlave ) |
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 Connect_send_IdEnumeration( id + 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 } |
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 return 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 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
|
548 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
549 dbug_print("IdReport"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
550 // Check the directionality |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
551 if ( to_master ) |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
552 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
553 erro_print("Invalid IdRequest direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
554 } |
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 // Track Id response if master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
557 if ( Connect_master ) |
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 // TODO, setup id's |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 info_msg("Id Reported: "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 printHex( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
562 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
563 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
564 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
565 // Propagate id if yet another slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
566 else |
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 Connect_send_IdReport( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 } |
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 return 1; |
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 // - Scan Code Variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
575 TriggerGuide Connect_receive_ScanCodeBuffer; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
576 uint8_t Connect_receive_ScanCodeBufferPos; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
577 uint8_t Connect_receive_ScanCodeDeviceId; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
578 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
579 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
|
580 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
581 dbug_print("ScanCode"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
582 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
583 if ( !to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
584 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
585 erro_print("Invalid ScanCode direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 } |
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 // Master node, trigger scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
589 if ( Connect_master ) switch ( (*pending_bytes)-- ) |
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 case 0xFFFF: // Device Id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
592 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
594 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
595 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
596 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
598 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
599 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
600 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 // Set the specific TriggerGuide entry |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
602 ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
603 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
604 // Reset the BufferPos if higher than 3 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
605 // And send the TriggerGuide to the Macro Module |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
606 if ( Connect_receive_ScanCodeBufferPos > 3 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
607 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
608 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
609 Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
612 break; |
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 // Propagate ScanCode packet |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
615 else switch ( (*pending_bytes)-- ) |
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 case 0xFFFF: // Device Id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
618 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
619 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 // Lock the master Tx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 uart_lockTx( 1 ); |
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 // Send header + Id byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 uint8_t header[] = { 0x16, 0x01, ScanCode, byte }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
626 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
628 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
630 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
631 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
632 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
633 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
634 Connect_addBytes( &byte, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
635 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
636 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
637 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
638 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
639 Connect_addBytes( &byte, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
640 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
641 // Unlock Tx Buffer after sending last byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
642 if ( *pending_bytes == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
643 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
644 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
645 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
646 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
647 // Check whether the scan codes have finished sending |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 return *pending_bytes == 0 ? 1 : 0; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 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
|
652 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
653 dbug_print("Animation"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
654 return 1; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
657 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
658 // Baud Rate |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
659 // 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
|
660 uint16_t Connect_baud = UARTConnectBaud_define; // Max setting of 8191 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
661 uint16_t Connect_baudFine = UARTConnectBaudFine_define; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
662 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
663 // Connect receive function lookup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
664 void *Connect_receiveFunctions[] = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
665 Connect_receive_CableCheck, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
666 Connect_receive_IdRequest, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
667 Connect_receive_IdEnumeration, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
668 Connect_receive_IdReport, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
669 Connect_receive_ScanCode, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
670 Connect_receive_Animation, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
671 }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
672 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
673 |
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 // ----- Interrupt Functions ----- |
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 // Master / UART0 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
678 void uart0_status_isr() |
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 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
681 uart_processRx( 0 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
684 // Slave / UART1 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
685 void uart1_status_isr() |
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 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
688 uart_processRx( 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
691 |
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 // ----- Functions ----- |
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 // Resets the state of the UART buffers and state variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
696 void Connect_reset() |
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 // Rx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
699 uart0_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
700 uart1_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
701 uart0_rx_bytes_waiting = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
702 uart1_rx_bytes_waiting = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
703 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
704 // Tx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
705 uart0_tx_status = UARTStatus_Ready; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 uart1_tx_status = UARTStatus_Ready; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
707 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
708 // Ring Buffer Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
709 uart0_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
710 uart0_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
711 uart0_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 uart1_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
713 uart1_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
714 uart1_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
715 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
716 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
717 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
718 // Setup connection to other side |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
719 // - Only supports a single slave and master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
720 // - 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
|
721 // - If both sides assert master, flash error leds |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
722 void Connect_setup( uint8_t master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
723 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
724 // Indication that UARTs are not ready |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
725 uarts_configured = 0; |
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 // Register Connect CLI dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
728 CLI_registerDictionary( uartConnectCLIDict, uartConnectCLIDictName ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
729 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
730 // Check if master |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
731 Connect_master = master; |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
732 if ( Connect_master ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
733 Connect_id = 0; // 0x00 is always the master Id |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
734 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
735 // Master / UART0 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
736 // Slave / UART1 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
737 // Setup the the UART interface for keyboard data input |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
738 SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
739 SIM_SCGC4 |= SIM_SCGC4_UART1; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
740 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
741 // Pin Setup for UART0 / UART1 |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
742 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
|
743 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
|
744 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
|
745 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
|
746 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
747 // Baud Rate setting |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
748 UART0_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
749 UART0_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
750 UART0_C4 = Connect_baudFine; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
751 UART1_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
752 UART1_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
753 UART1_C4 = Connect_baudFine; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
754 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
755 // 8 bit, Even Parity, Idle Character bit after stop |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
756 // 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
|
757 // 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
|
758 // 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
|
759 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
|
760 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
|
761 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
762 // Number of bytes in FIFO before TX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
763 // TODO Set 0 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
764 UART0_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
765 UART1_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
767 // Number of bytes in FIFO before RX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
768 UART0_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
769 UART1_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
770 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
771 // Enable TX and RX FIFOs |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
772 UART0_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
773 UART1_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
774 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
775 // Reciever Inversion Disabled, LSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
776 // UART_S2_RXINV UART_S2_MSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
777 UART0_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
778 UART1_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
779 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
780 // Transmit Inversion Disabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
781 // UART_C3_TXINV |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
782 UART0_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
783 UART1_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
784 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
785 // TX Enabled, RX Enabled, RX Interrupt Enabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
786 // UART_C2_TE UART_C2_RE UART_C2_RIE |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
787 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
|
788 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
|
789 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
790 // Add interrupts to the vector table |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
791 NVIC_ENABLE_IRQ( IRQ_UART0_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
792 NVIC_ENABLE_IRQ( IRQ_UART1_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
793 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
794 // UARTs are now ready to go |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
795 uarts_configured = 1; |
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 // Reset the state of the UART variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
798 Connect_reset(); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
801 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
802 // Scan for updates in the master/slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
803 // - Interrupts will deal with most input functions |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
804 // - Used to send queries |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
805 // - SyncEvent is sent immediately once the current command is sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
806 // - SyncEvent is also blocking until sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
807 void Connect_scan() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
808 { |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
809 // Check if initially configured as a slave and usb comes up |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
810 // Then reconfigure as a master |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
811 if ( !Connect_master && Output_Available ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
812 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
813 Connect_setup( Output_Available ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
814 } |
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 // Limit how often we do cable checks |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
817 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
|
818 uint32_t current_time = systick_millis_count; |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
819 if ( Connect_lastCheck != current_time |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
820 && ( current_time & time_compare ) == time_compare |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
821 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
822 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
823 // 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
|
824 Connect_lastCheck = current_time; |
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 // Send a cable check command of 2 bytes |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
827 Connect_send_CableCheck( UARTConnectCableCheckLength_define ); |
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 // 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
|
830 // Don't bother sending if there are cable issues |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
831 if ( !Connect_master && Connect_id == 0xFF && Connect_cableOkMaster ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
832 { |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
833 Connect_send_IdRequest(); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
834 } |
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 |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
837 // Only process commands if uarts have been configured |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
838 if ( uarts_configured ) |
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 // 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
|
841 // This happens if there was previously nothing to send |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
842 if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
843 uart_fillTxFifo( 0 ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
844 if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 ) |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
845 uart_fillTxFifo( 1 ); |
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
846 } |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
847 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
848 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
849 |
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 // ----- CLI Command Functions ----- |
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 void cliFunc_connectCmd( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
854 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
855 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
856 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
857 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
858 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
859 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
860 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
861 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
862 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
863 switch ( numToInt( &arg1Ptr[0] ) ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
864 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
865 case CableCheck: |
347
136e47478441
UARTConnect enumeration working!
Jacob Alexander <haata@kiibohd.com>
parents:
307
diff
changeset
|
866 Connect_send_CableCheck( UARTConnectCableCheckLength_define ); |
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
867 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
868 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
869 case IdRequest: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
870 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
871 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
872 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
873 case IdEnumeration: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
874 Connect_send_IdEnumeration( 5 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
875 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
876 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
877 case IdReport: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
878 Connect_send_IdReport( 8 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
879 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
880 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
881 case ScanCode: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
882 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
883 TriggerGuide scanCodes[] = { { 0x00, 0x01, 0x05 }, { 0x00, 0x03, 0x16 } }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
884 Connect_send_ScanCode( 10, scanCodes, 2 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
885 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
886 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
887 case Animation: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
888 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
890 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
891 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
892 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
893 void cliFunc_connectIdl( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
894 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
895 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
896 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
897 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
898 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
899 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
900 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
901 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
902 info_msg("Sending Sync Idles..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
903 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
904 uint8_t count = numToInt( &arg1Ptr[0] ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
905 // Default to 2 idles |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
906 if ( count == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
907 count = 2; |
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 Connect_send_Idle( count ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
910 } |
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 void cliFunc_connectMst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
913 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
914 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
915 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
916 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
917 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
918 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
919 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
920 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
921 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
922 switch ( arg1Ptr[0] ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
923 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
924 case 's': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
925 case 'S': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
926 info_msg("Setting device as slave."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
927 Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
928 Connect_id = 0xFF; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
929 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
930 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
931 case 'm': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
932 case 'M': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
933 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
934 info_msg("Setting device as master."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
935 Connect_master = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
936 Connect_id = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
937 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
938 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
939 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
940 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
941 void cliFunc_connectRst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
942 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
943 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
944 info_msg("Resetting UARTConnect state..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
945 Connect_reset(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
946 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
947 // TODO - Argument for re-sync |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
948 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
949 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
950 void cliFunc_connectSts( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
951 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
952 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
953 info_msg("UARTConnect Status"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
954 print( NL "Device Type:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
955 print( Connect_master ? "Master" : "Slave" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
956 print( NL "Device Id:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
957 printHex( Connect_id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
958 print( NL "Master <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
959 printHex( Connect_cableOkMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
960 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
961 printHex( Connect_cableFaultsMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
962 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
963 printHex( uart1_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
964 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
965 printHex( uart1_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
966 print( NL "Slave <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
967 printHex( Connect_cableOkSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
968 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
969 printHex( Connect_cableFaultsSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
970 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
971 printHex( uart0_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
972 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
973 printHex( uart0_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
974 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
975 |