Browse Source

Initial UARTConnect scancode support

- Still some issues
- Will require some changes to MatrixARM and PartialMap
  * Currently state information is passed around too frequently
  * Needs to be reduced to state changes only
connect
Jacob Alexander 8 years ago
parent
commit
ecd9923926

+ 22
- 0
Macro/PartialMap/macro.c View File

#include "usb_hid.h" #include "usb_hid.h"
#include <generatedKeymap.h> // Generated using kll at compile time, in build directory #include <generatedKeymap.h> // Generated using kll at compile time, in build directory


// Connect Includes
#if defined(ConnectEnabled_define)
#include <connect_scan.h>
#endif

// Local Includes // Local Includes
#include "macro.h" #include "macro.h"


// Called once per USB buffer send // Called once per USB buffer send
inline void Macro_process() inline void Macro_process()
{ {
#if defined(ConnectEnabled_define)
// Only compile in if a Connect node module is available
// If this is a interconnect slave node, send all scancodes to master node
if ( !Connect_master )
{
if ( macroTriggerListBufferSize > 0 )
{
dbug_msg("Yuh");
printHex( macroTriggerListBufferSize );
print( NL );
//Connect_send_ScanCode( Connect_id, macroTriggerListBuffer, macroTriggerListBufferSize );
macroTriggerListBufferSize = 0;
}
return;
}
#endif

// Only do one round of macro processing between Output Module timer sends // Only do one round of macro processing between Output Module timer sends
if ( USBKeys_Sent != 0 ) if ( USBKeys_Sent != 0 )
return; return;

+ 1
- 1
Scan/MDErgo1/defaultMap.kll View File

0xFF, 0x00, /* C2-1 -> C2-16 */ 0xFF, 0x00, /* C2-1 -> C2-16 */
0xFF, 0x00, /* C3-1 -> C3-16 */ 0xFF, 0x00, /* C3-1 -> C3-16 */
0xFF, 0x00, /* C4-1 -> C4-16 */ 0xFF, 0x00, /* C4-1 -> C4-16 */
0xFC, 0x00, /* C5-1 -> C5-16 */
0x3F, 0x00, /* C5-1 -> C5-16 */
0x00, 0x00, /* C6-1 -> C6-16 */ 0x00, 0x00, /* C6-1 -> C6-16 */
0x00, 0x00, /* C7-1 -> C7-16 */ 0x00, 0x00, /* C7-1 -> C7-16 */
0x00, 0x00, /* C8-1 -> C8-16 */ 0x00, 0x00, /* C8-1 -> C8-16 */

+ 5
- 0
Scan/UARTConnect/capabilities.kll View File

UARTConnectCableCheckLength => UARTConnectCableCheckLength_define; UARTConnectCableCheckLength => UARTConnectCableCheckLength_define;
UARTConnectCableCheckLength = 2; UARTConnectCableCheckLength = 2;


# Connect Enable
# Define used to indicate to non-connect modules that support should be compiled in
ConnectEnabled => ConnectEnabled_define;
ConnectEnabled = 1;


+ 44
- 18
Scan/UARTConnect/connect_scan.c View File

// Macro for adding to each uart Tx ring buffer // Macro for adding to each uart Tx ring buffer
#define uart_addTxBuffer( uartNum ) \ #define uart_addTxBuffer( uartNum ) \
case uartNum: \ case uartNum: \
/* Delay UART copy until there's some space left */ \
while ( uart##uartNum##_buffer_items + count > uart_buffer_size ) \ while ( uart##uartNum##_buffer_items + count > uart_buffer_size ) \
{ \ { \
warn_msg("Too much data to send on UART0, waiting..."); \ warn_msg("Too much data to send on UART0, waiting..."); \
delay( 1 ); \ delay( 1 ); \
} \ } \
/* Append data to ring buffer */ \
for ( uint8_t c = 0; c < count; c++ ) \ for ( uint8_t c = 0; c < count; c++ ) \
{ \ { \
if ( Connect_debug ) \ if ( Connect_debug ) \
UART##uartNum##_CFIFO = UART_CFIFO_RXFLUSH; \ UART##uartNum##_CFIFO = UART_CFIFO_RXFLUSH; \
return; \ return; \
} \ } \
/* Process each byte in the UART buffer */ \
while ( available-- > 0 ) \ while ( available-- > 0 ) \
{ \ { \
uint8_t byteRead = UART##uartNum##_D; \ uint8_t byteRead = UART##uartNum##_D; \
{ \ { \
print(" CMD "); \ print(" CMD "); \
} \ } \
/* Call specific UARTConnect command receive function */ \
uint8_t (*rcvFunc)(uint8_t, uint16_t(*), uint8_t) = (uint8_t(*)(uint8_t, uint16_t(*), uint8_t))(Connect_receiveFunctions[ uart##uartNum##_rx_command ]); \ uint8_t (*rcvFunc)(uint8_t, uint16_t(*), uint8_t) = (uint8_t(*)(uint8_t, uint16_t(*), uint8_t))(Connect_receiveFunctions[ uart##uartNum##_rx_command ]); \
if ( rcvFunc( byteRead, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ) ) \ if ( rcvFunc( byteRead, (uint16_t*)&uart##uartNum##_rx_bytes_waiting, uartNum ) ) \
uart##uartNum##_rx_status = UARTStatus_Wait; \ uart##uartNum##_rx_status = UARTStatus_Wait; \
uint8_t Connect_cableOkMaster = 0; uint8_t Connect_cableOkMaster = 0;
uint8_t Connect_cableOkSlave = 0; uint8_t Connect_cableOkSlave = 0;


uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_CableCheck( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
{ {
// Check if this is the first byte // Check if this is the first byte
if ( *pending_bytes == 0xFFFF ) if ( *pending_bytes == 0xFFFF )
warn_print("Cable Fault!"); warn_print("Cable Fault!");


// Check which side of the chain // Check which side of the chain
if ( to_master )
if ( to_slave )
{ {
Connect_cableFaultsMaster++; Connect_cableFaultsMaster++;
Connect_cableOkMaster = 0; Connect_cableOkMaster = 0;
// If cable check was successful, set cable ok // If cable check was successful, set cable ok
if ( *pending_bytes == 0 ) if ( *pending_bytes == 0 )
{ {
if ( to_master )
if ( to_slave )
{ {
Connect_cableOkMaster = 1; Connect_cableOkMaster = 1;
} }
return *pending_bytes == 0 ? 1 : 0; return *pending_bytes == 0 ? 1 : 0;
} }


uint8_t Connect_receive_IdRequest( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_IdRequest( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
{ {
dbug_print("IdRequest"); dbug_print("IdRequest");
// Check the directionality // Check the directionality
if ( to_master )
if ( to_slave )
{ {
erro_print("Invalid IdRequest direction..."); erro_print("Invalid IdRequest direction...");
} }
return 1; return 1;
} }


uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_IdEnumeration( uint8_t id, uint16_t *pending_bytes, uint8_t to_slave )
{ {
dbug_print("IdEnumeration"); dbug_print("IdEnumeration");
// Check the directionality // Check the directionality
if ( !to_master )
if ( !to_slave )
{ {
erro_print("Invalid IdEnumeration direction..."); erro_print("Invalid IdEnumeration direction...");
} }
return 1; return 1;
} }


uint8_t Connect_receive_IdReport( uint8_t id, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_IdReport( uint8_t id, uint16_t *pending_bytes, uint8_t to_slave )
{ {
dbug_print("IdReport"); dbug_print("IdReport");
// Check the directionality // Check the directionality
if ( to_master )
if ( to_slave )
{ {
erro_print("Invalid IdRequest direction..."); erro_print("Invalid IdRequest direction...");
} }
uint8_t Connect_receive_ScanCodeBufferPos; uint8_t Connect_receive_ScanCodeBufferPos;
uint8_t Connect_receive_ScanCodeDeviceId; uint8_t Connect_receive_ScanCodeDeviceId;


uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_ScanCode( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
{ {
dbug_print("ScanCode"); dbug_print("ScanCode");
// Check the directionality // Check the directionality
if ( !to_master )
if ( to_slave )
{ {
erro_print("Invalid ScanCode direction..."); erro_print("Invalid ScanCode direction...");
} }
// Master node, trigger scan codes // Master node, trigger scan codes
if ( Connect_master ) switch ( (*pending_bytes)-- ) if ( Connect_master ) switch ( (*pending_bytes)-- )
{ {
// Byte count always starts at 0xFFFF
case 0xFFFF: // Device Id case 0xFFFF: // Device Id
Connect_receive_ScanCodeDeviceId = byte; Connect_receive_ScanCodeDeviceId = byte;
break; break;


case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3) case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3)
*pending_bytes = byte * 3;
*pending_bytes = byte * sizeof( TriggerGuide );
Connect_receive_ScanCodeBufferPos = 0; Connect_receive_ScanCodeBufferPos = 0;
break; break;


// Set the specific TriggerGuide entry // Set the specific TriggerGuide entry
((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte; ((uint8_t*)&Connect_receive_ScanCodeBuffer)[ Connect_receive_ScanCodeBufferPos++ ] = byte;


// Reset the BufferPos if higher than 3
// Reset the BufferPos if higher than sizeof TriggerGuide
// And send the TriggerGuide to the Macro Module // And send the TriggerGuide to the Macro Module
if ( Connect_receive_ScanCodeBufferPos > 3 )
if ( Connect_receive_ScanCodeBufferPos > sizeof( TriggerGuide ) )
{ {
Connect_receive_ScanCodeBufferPos = 0; Connect_receive_ScanCodeBufferPos = 0;
Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 );

// Adjust ScanCode offset
if ( Connect_receive_ScanCodeDeviceId > 0 )
{
// This variable is in generatedKeymaps.h
extern uint8_t InterconnectOffsetList[];
Connect_receive_ScanCodeBuffer.scanCode = Connect_receive_ScanCodeBuffer.scanCode + InterconnectOffsetList[ Connect_receive_ScanCodeDeviceId - 1 ];
}

// ScanCode receive debug
dbug_print("");
printHex( Connect_receive_ScanCodeBuffer.type );
print(" ");
printHex( Connect_receive_ScanCodeBuffer.state );
print(" ");
printHex( Connect_receive_ScanCodeBuffer.scanCode );
print( NL );

// Send ScanCode to macro module
// TODO
//Macro_triggerState( &Connect_receive_ScanCodeBuffer, 1 );
} }


break; break;
// Propagate ScanCode packet // Propagate ScanCode packet
else switch ( (*pending_bytes)-- ) else switch ( (*pending_bytes)-- )
{ {
// Byte count always starts at 0xFFFF
case 0xFFFF: // Device Id case 0xFFFF: // Device Id
{ {
Connect_receive_ScanCodeDeviceId = byte; Connect_receive_ScanCodeDeviceId = byte;
Connect_addBytes( header, sizeof( header ), 1 ); // Master Connect_addBytes( header, sizeof( header ), 1 ); // Master
break; break;
} }
case 0xFFFE: // Number of TriggerGuides in bytes (byte * 3)
*pending_bytes = byte * 3;
case 0xFFFE: // Number of TriggerGuides in bytes
*pending_bytes = byte * sizeof( TriggerGuide );
Connect_receive_ScanCodeBufferPos = 0; Connect_receive_ScanCodeBufferPos = 0;


// Pass through byte // Pass through byte
return *pending_bytes == 0 ? 1 : 0; return *pending_bytes == 0 ? 1 : 0;
} }


uint8_t Connect_receive_Animation( uint8_t byte, uint16_t *pending_bytes, uint8_t to_master )
uint8_t Connect_receive_Animation( uint8_t byte, uint16_t *pending_bytes, uint8_t to_slave )
{ {
dbug_print("Animation"); dbug_print("Animation");
return 1; return 1;

+ 9
- 0
Scan/UARTConnect/connect_scan.h View File







// ----- Variables -----

extern uint8_t Connect_id;
extern uint8_t Connect_master; // Set if master



// ----- Functions ----- // ----- Functions -----


void Connect_setup( uint8_t master ); void Connect_setup( uint8_t master );
void Connect_scan(); void Connect_scan();


void Connect_send_ScanCode( uint8_t id, TriggerGuide *scanCodeStateList, uint8_t numScanCodes );