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