Mercurial > louis > kiibohd-controller
annotate Scan/UARTConnect/connect_scan.c @ 307:ecd2ae35d25c
Initial commit for UARTConnect module
* Keyboard interconnect using two uarts
* Supports daisy chain addressing using a master/slave direction communication scheme
- Still needs more testing
- Functions have been tested alone to be generally working
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 15 Mar 2015 16:58:01 -0700 |
parents | |
children | 136e47478441 |
rev | line source |
---|---|
307
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
1 /* Copyright (C) 2014-2015 by Jacob Alexander |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 * This file is free software: you can redistribute it and/or modify |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 * it under the terms of the GNU General Public License as published by |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 * the Free Software Foundation, either version 3 of the License, or |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 * (at your option) any later version. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 * This file is distributed in the hope that it will be useful, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 * |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 * You should have received a copy of the GNU General Public License |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 * along with this file. If not, see <http://www.gnu.org/licenses/>. |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 */ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 // ----- Includes ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 // Compiler Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 #include <Lib/ScanLib.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 // Project Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 #include <cli.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 #include <led.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 #include <print.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 #include <macro.h> |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 // Local Includes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 #include "connect_scan.h" |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 // ----- Macros ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 // Macro for adding to each uart Tx ring buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 #define uart_addTxBuffer( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 case uartNum: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 while ( uart##uartNum##_buffer_items + count > uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 warn_msg("Too much data to send on UART0, waiting..."); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 delay( 1 ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 for ( uint8_t c = 0; c < count; c++ ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 printHex( buffer[ c ] ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 print( " +" #uartNum NL ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
47 uart##uartNum##_buffer[ uart##uartNum##_buffer_tail++ ] = buffer[ c ]; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 uart##uartNum##_buffer_items++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
49 if ( uart##uartNum##_buffer_tail >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 uart##uartNum##_buffer_tail = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 if ( uart##uartNum##_buffer_head == uart##uartNum##_buffer_tail ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 uart##uartNum##_buffer_head++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 uart##uartNum##_buffer_head = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 break |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 // Macro for popping from Tx ring buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 #define uart_fillTxFifo( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 uint8_t fifoSize = ( ( UART##uartNum##_PFIFO & UART_PFIFO_TXFIFOSIZE ) >> 2 ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 if ( fifoSize == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 fifoSize = 1; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 while ( UART##uartNum##_TCFIFO < fifoSize ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 if ( uart##uartNum##_buffer_items == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 UART##uartNum##_D = uart##uartNum##_buffer[ uart##uartNum##_buffer_head++ ]; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 uart##uartNum##_buffer_items--; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 if ( uart##uartNum##_buffer_head >= uart_buffer_size ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 uart##uartNum##_buffer_head = 0; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
72 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 // Macro for processing UART Rx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 #define uart_processRx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 if ( !( UART##uartNum##_S1 & UART_S1_RDRF ) ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 return; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 uint8_t available = UART##uartNum##_RCFIFO; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
81 if ( available == 0 ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
82 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
83 available = UART##uartNum##_D; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
84 UART##uartNum##_CFIFO = UART_CFIFO_RXFLUSH; \ |
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 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
87 while ( 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 uint8_t byteRead = UART##uartNum##_D; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
90 printHex( byteRead ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 print( "(" ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
92 printInt8( available ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
93 print( ") <-" ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
94 switch ( uart##uartNum##_rx_status ) \ |
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 case UARTStatus_Wait: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 print(" SYN "); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
98 uart##uartNum##_rx_status = byteRead == 0x16 ? UARTStatus_SYN : UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
99 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 case UARTStatus_SYN: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
101 print(" SOH "); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
102 uart##uartNum##_rx_status = byteRead == 0x01 ? UARTStatus_SOH : UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
103 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
104 case UARTStatus_SOH: \ |
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 print(" CMD "); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
107 uint8_t byte = byteRead; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
108 if ( byte <= Animation ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
109 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
110 uart##uartNum##_rx_status = UARTStatus_Command; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
111 uart##uartNum##_rx_command = byte; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
112 uart##uartNum##_rx_bytes_waiting = 0xFFFF; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
113 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
114 else \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
115 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
116 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
117 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
118 switch ( uart##uartNum##_rx_command ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
119 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
120 case IdRequest: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
121 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
|
122 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
123 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
124 default: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
125 print("###"); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
126 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
127 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
128 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
129 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
130 case UARTStatus_Command: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
131 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
132 print(" CMD "); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
133 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
|
134 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
|
135 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
136 break; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
137 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
138 default: \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
139 erro_msg("Invalid UARTStatus..."); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
140 uart##uartNum##_rx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
141 available++; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
142 continue; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
143 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
144 print( NL ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
145 } \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
146 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
147 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
148 // Macros for locking/unlock Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
149 #define uart_lockTx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
150 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
151 while ( uart##uartNum##_tx_status == UARTStatus_Wait ); \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
152 uart##uartNum##_tx_status = UARTStatus_Wait; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
153 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
154 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
155 #define uart_unlockTx( uartNum ) \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
156 { \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
157 uart##uartNum##_tx_status = UARTStatus_Ready; \ |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
158 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
159 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
160 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
161 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
162 // ----- Function Declarations ----- |
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 // CLI Functions |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
165 void cliFunc_connectCmd ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
166 void cliFunc_connectIdl ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
167 void cliFunc_connectMst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
168 void cliFunc_connectRst ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
169 void cliFunc_connectSts ( char *args ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
170 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
171 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
172 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
173 // ----- Variables ----- |
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 // Connect Module command dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
176 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
|
177 CLIDict_Entry( connectIdl, "Sends N number of Idle commands, 2 is the default value, and should be sufficient in most cases." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
178 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
|
179 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
|
180 CLIDict_Entry( connectSts, "UARTConnect status." ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
181 CLIDict_Def( uartConnectCLIDict, "UARTConnect Module Commands" ) = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
182 CLIDict_Item( connectCmd ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
183 CLIDict_Item( connectIdl ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
184 CLIDict_Item( connectMst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
185 CLIDict_Item( connectRst ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
186 CLIDict_Item( connectSts ), |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
187 { 0, 0, 0 } // Null entry for dictionary end |
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 // -- Connect Device Id Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
192 uint8_t Connect_id = 255; // Invalid, unset |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
193 uint8_t Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
194 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
195 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
196 // -- Rx Status Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
197 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
198 volatile UARTStatus uart0_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
199 volatile UARTStatus uart1_rx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
200 volatile uint16_t uart0_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
201 volatile uint16_t uart1_rx_bytes_waiting; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
202 volatile Command uart0_rx_command; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
203 volatile Command uart1_rx_command; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
206 // -- Tx Status Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
207 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
208 volatile UARTStatus uart0_tx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
209 volatile UARTStatus uart1_tx_status; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
210 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
211 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
212 // -- Ring Buffer Variables -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
213 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
214 #define uart_buffer_size UARTConnectBufSize_define |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
215 volatile uint8_t uart0_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
216 volatile uint8_t uart0_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
217 volatile uint8_t uart0_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
218 volatile uint8_t uart0_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
219 volatile uint8_t uart1_buffer_head; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
220 volatile uint8_t uart1_buffer_tail; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
221 volatile uint8_t uart1_buffer_items; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
222 volatile uint8_t uart1_buffer[uart_buffer_size]; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
223 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
224 volatile uint8_t uarts_configured = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
225 |
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 // -- Ring Buffer Convenience Functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
228 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
229 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
|
230 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
231 // Too big to fit into buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
232 if ( count > uart_buffer_size ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
233 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
234 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
|
235 return; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
236 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
237 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
238 // Choose the uart |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
239 switch ( uart ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
240 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
241 uart_addTxBuffer( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
242 uart_addTxBuffer( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
243 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
244 erro_msg("Invalid UART to send from..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
245 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
246 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
247 } |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
250 // -- Connect send functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
251 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
252 // patternLen defines how many bytes should the incrementing pattern have |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
253 void Connect_send_CableCheck( uint8_t patternLen ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
254 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
255 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
256 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
257 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
258 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
259 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
260 uint8_t header[] = { 0x16, 0x01, CableCheck, patternLen }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
261 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
262 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
263 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
264 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
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 // Send 0xD2 (11010010) for each argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
267 uint8_t value = 0xD2; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
268 for ( uint8_t c = 0; c < patternLen; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
269 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
270 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
271 Connect_addBytes( &value, 1, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
272 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
273 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
274 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
275 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
276 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
277 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
278 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
279 void Connect_send_IdRequest() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
280 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
281 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
282 uart_lockTx( 1 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
285 uint8_t header[] = { 0x16, 0x01, IdRequest }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
288 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
289 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
290 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
291 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
292 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
293 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
294 // id is the value the next slave should enumerate as |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
295 void Connect_send_IdEnumeration( uint8_t id ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
296 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
297 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
298 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
299 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
300 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
301 uint8_t header[] = { 0x16, 0x01, IdEnumeration, id }; |
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 header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
304 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
305 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
306 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
307 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
308 } |
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 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
311 void Connect_send_IdReport( uint8_t id ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
312 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
313 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
314 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
315 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
316 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
317 uint8_t header[] = { 0x16, 0x01, IdReport, id }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
318 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
319 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
320 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
321 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
322 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
323 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
324 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
325 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
326 // id is the currently assigned id to the slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
327 // 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
|
328 // 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
|
329 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
|
330 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
331 // Lock master bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
332 uart_lockTx( 1 ); |
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 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
335 uint8_t header[] = { 0x16, 0x01, ScanCode, id, numScanCodes }; |
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 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
338 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
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 each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
341 Connect_addBytes( (uint8_t*)scanCodeStateList, numScanCodes * TriggerGuideSize, 1 ); // Master |
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( 1 ); |
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 // 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
|
349 // 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
|
350 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
|
351 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
352 // Lock slave bound Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
353 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
354 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
355 // Prepare header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
356 uint8_t header[] = { 0x16, 0x01, Animation, id, numParams }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
357 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
358 // Send header |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
359 Connect_addBytes( header, sizeof( header ), 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
360 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
361 // Send each of the scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
362 Connect_addBytes( paramList, numParams, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
363 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
364 // Unlock Tx |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
365 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
366 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
367 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
368 void Connect_send_Idle( uint8_t num ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
369 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
370 // Wait until the Tx buffers are ready, then lock them |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
371 uart_lockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
372 uart_lockTx( 1 ); |
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 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
|
375 uint8_t value = 0x16; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
376 for ( uint8_t c = 0; c < num; c++ ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
377 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
378 Connect_addBytes( &value, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
379 Connect_addBytes( &value, 1, 0 ); // Slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
380 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
381 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
382 // Release Tx buffers |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
383 uart_unlockTx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
384 uart_unlockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
385 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
386 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
387 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
388 // -- Connect receive functions -- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
389 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
390 // - Cable Check variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
391 uint32_t Connect_cableFaultsMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
392 uint32_t Connect_cableFaultsSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
393 uint8_t Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
394 uint8_t Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
395 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
396 uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
397 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
398 // Check if this is the first byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
399 if ( *pending_bytes == 0xFFFF ) |
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 dbug_msg("PENDING SET -> "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
402 printHex( byte ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
403 print(" "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
404 *pending_bytes = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
405 printHex( *pending_bytes ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
406 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
407 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
408 // Verify byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
409 else |
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 (*pending_bytes)--; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
412 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
413 // The argument bytes are always 0xD2 (11010010) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
414 if ( byte != 0xD2 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
415 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
416 warn_print("Cable Fault!"); |
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 // Check which side of the chain |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
419 if ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
420 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
421 Connect_cableFaultsMaster++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
422 Connect_cableOkMaster = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
423 print(" Master "); |
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 else |
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 Connect_cableFaultsSlave++; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
428 Connect_cableOkSlave = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
429 print(" Slave "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
430 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
431 printHex( byte ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
432 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
433 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
434 // Signal that the command should wait for a SYN again |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
435 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
436 } |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
439 // If cable check was successful, set cable ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
440 if ( *pending_bytes == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
441 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
442 if ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
443 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
444 Connect_cableOkMaster = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
445 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
446 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
447 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
448 Connect_cableOkSlave = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
449 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
450 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
451 dbug_msg("CABLECHECK RECEIVE - "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
452 printHex( byte ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
453 print(" "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
454 printHex( *pending_bytes ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
455 print(NL); |
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 // Check whether the cable check has finished |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
458 return *pending_bytes == 0 ? 1 : 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
459 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
460 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
461 uint8_t Connect_receive_IdRequest( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
462 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
463 dbug_print("IdRequest"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
464 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
465 if ( !to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
466 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
467 erro_print("Invalid IdRequest direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
468 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
469 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
470 // Check if master, begin IdEnumeration |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
471 if ( Connect_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
472 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
473 // The first device is always id 1 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
474 // Id 0 is reserved for the master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
475 Connect_send_IdEnumeration( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
476 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
477 // Propagate IdRequest |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
478 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
479 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
480 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
481 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
482 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
483 return 1; |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
486 uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
487 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
488 dbug_print("IdEnumeration"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
489 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
490 if ( to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
491 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
492 erro_print("Invalid IdEnumeration direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
493 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
494 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
495 // Set the device id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
496 Connect_id = id; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
497 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
498 // Send reponse back to master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
499 Connect_send_IdReport( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
500 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
501 // Propogate next Id if the connection is ok |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
502 if ( Connect_cableOkSlave ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
503 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
504 Connect_send_IdEnumeration( id + 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
505 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
506 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
507 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
508 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
509 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
510 uint8_t Connect_receive_IdReport( uint8_t id, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
511 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
512 dbug_print("IdReport"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
513 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
514 if ( !to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
515 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
516 erro_print("Invalid IdRequest direction..."); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
519 // Track Id response if master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
520 if ( Connect_master ) |
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 // TODO, setup id's |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
523 info_msg("Id Reported: "); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
524 printHex( id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
525 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
526 return 1; |
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 // Propagate id if yet another slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
529 else |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
530 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
531 Connect_send_IdReport( id ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
534 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
535 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
536 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
537 // - Scan Code Variables - |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
538 TriggerGuide Connect_receive_ScanCodeBuffer; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
539 uint8_t Connect_receive_ScanCodeBufferPos; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
540 uint8_t Connect_receive_ScanCodeDeviceId; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
541 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
542 uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
543 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
544 dbug_print("ScanCode"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
545 // Check the directionality |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
546 if ( !to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
547 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
548 erro_print("Invalid ScanCode direction..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
549 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
550 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
551 // Master node, trigger scan codes |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
552 if ( Connect_master ) switch ( (*pending_bytes)-- ) |
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 case 0xFFFF: // Device Id |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
555 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
556 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
557 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
558 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
559 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
560 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
561 break; |
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 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
564 // Set the specific TriggerGuide entry |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
565 ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte; |
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 // Reset the BufferPos if higher than 3 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
568 // And send the TriggerGuide to the Macro Module |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
569 if ( Connect_receive_ScanCodeBufferPos > 3 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
570 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
571 Connect_receive_ScanCodeBufferPos = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
572 Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
573 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
574 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
575 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
576 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
577 // Propagate ScanCode packet |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
578 else switch ( (*pending_bytes)-- ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
579 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
580 case 0xFFFF: // Device Id |
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 Connect_receive_ScanCodeDeviceId = byte; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
583 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
584 // Lock the master Tx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
585 uart_lockTx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
586 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
587 // Send header + Id byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
588 uint8_t header[] = { 0x16, 0x01, ScanCode, byte }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
589 Connect_addBytes( header, sizeof( header ), 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
590 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
591 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
592 case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
593 *pending_bytes = byte * 3; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
594 Connect_receive_ScanCodeBufferPos = 0; |
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 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
597 Connect_addBytes( &byte, 1, 1 ); // Master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
598 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
599 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
600 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
601 // Pass through byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
602 Connect_addBytes( &byte, 1, 1 ); // Master |
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 // Unlock Tx Buffer after sending last byte |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
605 if ( *pending_bytes == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
606 uart_unlockTx( 1 ); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
610 // Check whether the scan codes have finished sending |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
611 return *pending_bytes == 0 ? 1 : 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
612 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
613 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
614 uint8_t Connect_receive_Animation( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
615 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
616 dbug_print("Animation"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
617 return 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
618 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
619 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
620 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
621 // Baud Rate |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
622 // 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
|
623 uint16_t Connect_baud = UARTConnectBaud_define; // Max setting of 8191 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
624 uint16_t Connect_baudFine = UARTConnectBaudFine_define; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
625 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
626 // Connect receive function lookup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
627 void *Connect_receiveFunctions[] = { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
628 Connect_receive_CableCheck, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
629 Connect_receive_IdRequest, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
630 Connect_receive_IdEnumeration, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
631 Connect_receive_IdReport, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
632 Connect_receive_ScanCode, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
633 Connect_receive_Animation, |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
634 }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
635 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
636 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
637 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
638 // ----- Interrupt Functions ----- |
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 // Master / UART0 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
641 void uart0_status_isr() |
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 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
644 uart_processRx( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
645 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
646 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
647 // Slave / UART1 ISR |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
648 void uart1_status_isr() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
649 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
650 // Process Rx buffer |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
651 uart_processRx( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
652 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
653 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
654 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
655 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
656 // ----- Functions ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
657 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
658 // Resets the state of the UART buffers and state variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
659 void Connect_reset() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
660 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
661 // Rx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
662 uart0_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
663 uart1_rx_status = UARTStatus_Wait; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
664 uart0_rx_bytes_waiting = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
665 uart1_rx_bytes_waiting = 0; |
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 // Tx Status Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
668 uart0_tx_status = UARTStatus_Ready; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
669 uart1_tx_status = UARTStatus_Ready; |
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 // Ring Buffer Variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
672 uart0_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
673 uart0_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
674 uart0_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
675 uart1_buffer_head = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
676 uart1_buffer_tail = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
677 uart1_buffer_items = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
678 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
679 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
680 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
681 // Setup connection to other side |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
682 // - Only supports a single slave and master |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
683 // - 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
|
684 // - If both sides assert master, flash error leds |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
685 void Connect_setup( uint8_t master ) |
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 // Indication that UARTs are not ready |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
688 uarts_configured = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
689 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
690 // Register Connect CLI dictionary |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
691 CLI_registerDictionary( uartConnectCLIDict, uartConnectCLIDictName ); |
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_master = master; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
694 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
695 // Master / UART0 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
696 // Slave / UART1 setup |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
697 // Setup the the UART interface for keyboard data input |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
698 SIM_SCGC4 |= SIM_SCGC4_UART0; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
699 SIM_SCGC4 |= SIM_SCGC4_UART1; // Disable clock gating |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
700 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
701 // Pin Setup for UART0 / UART1 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
702 // XXX TODO Set to actual (Teensy 3.1s don't have the correct pins available) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
703 PORTB_PCR16 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
704 PORTB_PCR17 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
705 PORTC_PCR3 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
706 PORTC_PCR4 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
707 //PORTA_PCR1 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(2); // RX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
708 //PORTA_PCR2 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(2); // TX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
709 //PORTE_PCR0 = PORT_PCR_PE | PORT_PCR_PS | PORT_PCR_PFE | PORT_PCR_MUX(3); // RX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
710 //PORTE_PCR1 = PORT_PCR_DSE | PORT_PCR_SRE | PORT_PCR_MUX(3); // TX Pin |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
711 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
712 // Baud Rate setting |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
713 UART0_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
714 UART0_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
715 UART0_C4 = Connect_baudFine; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
716 UART1_BDH = (uint8_t)(Connect_baud >> 8); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
717 UART1_BDL = (uint8_t)Connect_baud; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
718 UART1_C4 = Connect_baudFine; |
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 // 8 bit, Even Parity, Idle Character bit after stop |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
721 // 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
|
722 // 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
|
723 // 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
|
724 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
|
725 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
|
726 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
727 // Number of bytes in FIFO before TX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
728 // TODO Set 0 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
729 UART0_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
730 UART1_TWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
731 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
732 // Number of bytes in FIFO before RX Interrupt |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
733 UART0_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
734 UART1_RWFIFO = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
735 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
736 // Enable TX and RX FIFOs |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
737 UART0_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
738 UART1_PFIFO = UART_PFIFO_TXFE | UART_PFIFO_RXFE; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
739 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
740 // Reciever Inversion Disabled, LSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
741 // UART_S2_RXINV UART_S2_MSBF |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
742 UART0_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
743 UART1_S2 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
744 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
745 // Transmit Inversion Disabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
746 // UART_C3_TXINV |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
747 UART0_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
748 UART1_C3 |= 0x00; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
749 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
750 // TX Enabled, RX Enabled, RX Interrupt Enabled |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
751 // UART_C2_TE UART_C2_RE UART_C2_RIE |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
752 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
|
753 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
|
754 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
755 // Add interrupts to the vector table |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
756 NVIC_ENABLE_IRQ( IRQ_UART0_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
757 NVIC_ENABLE_IRQ( IRQ_UART1_STATUS ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
758 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
759 // UARTs are now ready to go |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
760 uarts_configured = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
761 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
762 // Reset the state of the UART variables |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
763 Connect_reset(); |
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 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
766 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
767 // Scan for updates in the master/slave |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
768 // - Interrupts will deal with most input functions |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
769 // - Used to send queries |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
770 // - SyncEvent is sent immediately once the current command is sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
771 // - SyncEvent is also blocking until sent |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
772 void Connect_scan() |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
773 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
774 // Check if Tx Buffers are empty and the Tx Ring buffers have data to send |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
775 // This happens if there was previously nothing to send |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
776 if ( uart0_buffer_items > 0 && UART0_TCFIFO == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
777 uart_fillTxFifo( 0 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
778 if ( uart1_buffer_items > 0 && UART1_TCFIFO == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
779 uart_fillTxFifo( 1 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
780 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
781 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
782 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
783 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
784 // ----- CLI Command Functions ----- |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
785 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
786 void cliFunc_connectCmd( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
787 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
788 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
789 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
790 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
791 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
792 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
793 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
794 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
795 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
796 switch ( numToInt( &arg1Ptr[0] ) ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
797 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
798 case CableCheck: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
799 Connect_send_CableCheck( 2 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
800 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
801 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
802 case IdRequest: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
803 Connect_send_IdRequest(); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
804 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
805 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
806 case IdEnumeration: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
807 Connect_send_IdEnumeration( 5 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
808 break; |
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 case IdReport: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
811 Connect_send_IdReport( 8 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
812 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
813 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
814 case ScanCode: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
815 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
816 TriggerGuide scanCodes[] = { { 0x00, 0x01, 0x05 }, { 0x00, 0x03, 0x16 } }; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
817 Connect_send_ScanCode( 10, scanCodes, 2 ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
818 break; |
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 case Animation: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
821 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
822 break; |
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 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
825 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
826 void cliFunc_connectIdl( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
827 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
828 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
829 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
830 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
831 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
832 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
833 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
834 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
835 info_msg("Sending Sync Idles..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
836 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
837 uint8_t count = numToInt( &arg1Ptr[0] ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
838 // Default to 2 idles |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
839 if ( count == 0 ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
840 count = 2; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
841 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
842 Connect_send_Idle( count ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
843 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
844 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
845 void cliFunc_connectMst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
846 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
847 // Parse number from argument |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
848 // NOTE: Only first argument is used |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
849 char* arg1Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
850 char* arg2Ptr; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
851 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
852 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
853 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
854 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
855 switch ( arg1Ptr[0] ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
856 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
857 case 's': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
858 case 'S': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
859 info_msg("Setting device as slave."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
860 Connect_master = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
861 Connect_id = 0xFF; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
862 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
863 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
864 case 'm': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
865 case 'M': |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
866 default: |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
867 info_msg("Setting device as master."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
868 Connect_master = 1; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
869 Connect_id = 0; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
870 break; |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
871 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
872 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
873 |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
874 void cliFunc_connectRst( char* args ) |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
875 { |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
876 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
877 info_msg("Resetting UARTConnect state..."); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
878 Connect_reset(); |
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 // TODO - Argument for re-sync |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
881 } |
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_connectSts( 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 print( NL ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
886 info_msg("UARTConnect Status"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
887 print( NL "Device Type:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
888 print( Connect_master ? "Master" : "Slave" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
889 print( NL "Device Id:\t" ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
890 printHex( Connect_id ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
891 print( NL "Master <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
892 printHex( Connect_cableOkMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
893 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
894 printHex( Connect_cableFaultsMaster ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
895 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
896 printHex( uart1_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
897 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
898 printHex( uart1_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
899 print( NL "Slave <=" NL "\tStatus:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
900 printHex( Connect_cableOkSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
901 print( NL "\tFaults:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
902 printHex( Connect_cableFaultsSlave ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
903 print( NL "\tRx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
904 printHex( uart0_rx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
905 print( NL "\tTx:\t"); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
906 printHex( uart0_tx_status ); |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
907 } |
ecd2ae35d25c
Initial commit for UARTConnect module
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
908 |