Mercurial > louis > kiibohd-controller
comparison Scan/UARTConnect/connect_scan.c @ 390:a3825c7fc651
Adding remote capability LED control
- Works for all nodes in chain
- Synchronized to 30 ms update rate (required for ISSI chip)
* Interconnect cannot handle full update speed from Scan module
* Though it should be able to handle quite a bit more than 30 ms updates
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 16 Oct 2015 10:02:01 -0700 |
parents | fc2c2a1e9615 |
children | e7a3be42ae1e |
comparison
equal
deleted
inserted
replaced
389:fc2c2a1e9615 | 390:a3825c7fc651 |
---|---|
39 #define UART_Buffer_Size UARTConnectBufSize_define | 39 #define UART_Buffer_Size UARTConnectBufSize_define |
40 | 40 |
41 | 41 |
42 | 42 |
43 // ----- Macros ----- | 43 // ----- Macros ----- |
44 | |
45 // Macro for adding to each uart Tx ring buffer | |
46 #define uart_addTxBuffer( uartNum ) \ | |
47 case uartNum: \ | |
48 /* Delay UART copy until there's some space left */ \ | |
49 while ( uart_tx_buf[ uartNum ].items + count > UART_Buffer_Size ) \ | |
50 { \ | |
51 warn_msg("Too much data to send on UART0, waiting..."); \ | |
52 delay( 1 ); \ | |
53 } \ | |
54 /* Append data to ring buffer */ \ | |
55 for ( uint8_t c = 0; c < count; c++ ) \ | |
56 { \ | |
57 if ( Connect_debug ) \ | |
58 { \ | |
59 printHex( buffer[ c ] ); \ | |
60 print( " +" #uartNum NL ); \ | |
61 } \ | |
62 uart_tx_buf[ uartNum ].buffer[ uart_tx_buf[ uartNum ].tail++ ] = buffer[ c ]; \ | |
63 uart_tx_buf[ uartNum ].items++; \ | |
64 if ( uart_tx_buf[ uartNum ].tail >= UART_Buffer_Size ) \ | |
65 uart_tx_buf[ uartNum ].tail = 0; \ | |
66 if ( uart_tx_buf[ uartNum ].head == uart_tx_buf[ uartNum ].tail ) \ | |
67 uart_tx_buf[ uartNum ].head++; \ | |
68 if ( uart_tx_buf[ uartNum ].head >= UART_Buffer_Size ) \ | |
69 uart_tx_buf[ uartNum ].head = 0; \ | |
70 } \ | |
71 break | |
72 | 44 |
73 // Macro for popping from Tx ring buffer | 45 // Macro for popping from Tx ring buffer |
74 #define uart_fillTxFifo( uartNum ) \ | 46 #define uart_fillTxFifo( uartNum ) \ |
75 { \ | 47 { \ |
76 uint8_t fifoSize = ( ( UART##uartNum##_PFIFO & UART_PFIFO_TXFIFOSIZE ) >> 2 ); \ | 48 uint8_t fifoSize = ( ( UART##uartNum##_PFIFO & UART_PFIFO_TXFIFOSIZE ) >> 2 ); \ |
231 { | 203 { |
232 erro_msg("Too big of a command to fit into the buffer..."); | 204 erro_msg("Too big of a command to fit into the buffer..."); |
233 return; | 205 return; |
234 } | 206 } |
235 | 207 |
236 // Choose the uart | 208 // Invalid UART |
237 switch ( uart ) | 209 if ( uart >= UART_Num_Interfaces ) |
238 { | 210 { |
239 uart_addTxBuffer( UART_Master ); | 211 erro_print("Invalid UART to send from..."); |
240 uart_addTxBuffer( UART_Slave ); | 212 return; |
241 default: | 213 } |
242 erro_msg("Invalid UART to send from..."); | 214 |
243 break; | 215 // Delay UART copy until there's some space left |
216 while ( uart_tx_buf[ uart ].items + count > UART_Buffer_Size ) | |
217 { | |
218 warn_msg("Too much data to send on UART"); | |
219 printInt8( uart ); | |
220 print( ", waiting..." NL ); | |
221 delay( 1 ); | |
222 } | |
223 | |
224 // Append data to ring buffer | |
225 for ( uint8_t c = 0; c < count; c++ ) | |
226 { | |
227 if ( Connect_debug ) | |
228 { | |
229 printHex( buffer[ c ] ); | |
230 print(" +"); | |
231 printInt8( uart ); | |
232 print( NL ); | |
233 } | |
234 | |
235 uart_tx_buf[ uart ].buffer[ uart_tx_buf[ uart ].tail++ ] = buffer[ c ]; | |
236 uart_tx_buf[ uart ].items++; | |
237 if ( uart_tx_buf[ uart ].tail >= UART_Buffer_Size ) | |
238 uart_tx_buf[ uart ].tail = 0; | |
239 if ( uart_tx_buf[ uart ].head == uart_tx_buf[ uart ].tail ) | |
240 uart_tx_buf[ uart ].head++; | |
241 if ( uart_tx_buf[ uart ].head >= UART_Buffer_Size ) | |
242 uart_tx_buf[ uart ].head = 0; | |
244 } | 243 } |
245 } | 244 } |
246 | 245 |
247 | 246 |
248 // -- Connect send functions -- | 247 // -- Connect send functions -- |
716 dbug_print("Animation"); | 715 dbug_print("Animation"); |
717 return 1; | 716 return 1; |
718 } | 717 } |
719 | 718 |
720 // - Remote Capability Variables - | 719 // - Remote Capability Variables - |
721 #define Connect_receive_RemoteCapabilityMaxArgs 5 // XXX Calculate the max using kll | 720 #define Connect_receive_RemoteCapabilityMaxArgs 25 // XXX Calculate the max using kll |
722 RemoteCapabilityCommand Connect_receive_RemoteCapabilityBuffer; | 721 RemoteCapabilityCommand Connect_receive_RemoteCapabilityBuffer; |
723 uint8_t Connect_receive_RemoteCapabilityArgs[Connect_receive_RemoteCapabilityMaxArgs]; | 722 uint8_t Connect_receive_RemoteCapabilityArgs[Connect_receive_RemoteCapabilityMaxArgs]; |
724 | 723 |
725 uint8_t Connect_receive_RemoteCapability( uint8_t byte, uint16_t *pending_bytes, uint8_t uart_num ) | 724 uint8_t Connect_receive_RemoteCapability( uint8_t byte, uint16_t *pending_bytes, uint8_t uart_num ) |
726 { | 725 { |