annotate Scan/UARTConnect/connect_scan.c @ 360:dbefb68411e1

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