// USB Get Character from input buffer inline int Output_getchar() { #if enableVirtualSerialPort_define == 1 return Output_callback( "serial_read", "" ); #else return 0; #endif }
// USB RawIO send buffer // XXX Must be a 64 byte buffer int Output_rawio_sendbuffer( char* buffer ) { #if enableRawIO_define == 1 return Output_callback( "rawio_tx", buffer ); #else return 0; #endif }
// USB RawIO buffer available unsigned int Output_rawio_availablechar() { #if enableRawIO_define == 1 return (unsigned int)Output_callback( "rawio_available", "" ); #else return 0; #endif }
// USB Send String to output buffer, null terminated inline int Output_putstr( char* str ) { #if enableVirtualSerialPort_define == 1 return Output_callback( "serial_write", str ); #else return 0; #endif }
// USB Input buffer available inline unsigned int Output_availablechar() { #if enableVirtualSerialPort_define == 1 return (unsigned int)Output_callback( "serial_available", "" ); #else return 0; #endif }
// USB Data Periodic inline void Output_periodic() { // Start latency measurement Latency_start_time( outputPeriodicLatencyResource ); #if enableMouse_define == 1 // Process mouse actions while ( USBMouse_Changed ) Output_callback( "mouse_send", "" ); #endif #if enableKeyboard_define == 1 // Boot Mode Only, unset stale keys if ( USBKeys_Protocol == 0 ) { for ( uint8_t c = USBKeys_Sent; c < USB_BOOT_MAX_KEYS; c++ ) { USBKeys_primary.keys[c] = 0; } } // Send keypresses while there are pending changes while ( USBKeys_primary.changed ) Output_callback( "keyboard_send", "" ); // Clear keys sent USBKeys_Sent = 0; // Signal Scan Module we are finished switch ( USBKeys_Protocol ) { case 0: // Boot Mode // Clear modifiers only in boot mode USBKeys_primary.modifiers = 0; Scan_finishedWithOutput( USBKeys_Sent <= USB_BOOT_MAX_KEYS ? USBKeys_Sent : USB_BOOT_MAX_KEYS ); break; case 1: // NKRO Mode Scan_finishedWithOutput( USBKeys_Sent ); break; } #endif // End latency measurement Latency_end_time( outputPeriodicLatencyResource ); }
// USB RawIO get buffer // XXX Must be a 64 byte buffer int Output_rawio_getbuffer( char* buffer ) { #if enableRawIO_define == 1 // TODO return Output_callback( "rawio_rx", buffer ); #else return 0; #endif }
// USB Send Character to output buffer inline int Output_putchar( char c ) { #if enableVirtualSerialPort_define == 1 char out[2] = { c, '\0' }; return Output_callback( "serial_write", out ); #else return 0; #endif }
// Soft Chip Reset inline void Output_softReset() { Output_callback( "restart", "" ); }
// Sets the device into firmware reload mode inline void Output_firmwareReload() { Output_callback( "device_reload", "" ); }
// Macro Processing Loop, called from the periodic execution thread // Called once per USB buffer send void Macro_periodic() { // Latency measurement Latency_start_time( macroLatencyResource ); #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 ( macroTriggerEventBufferSize > 0 ) { Connect_send_ScanCode( Connect_id, macroTriggerEventBuffer, macroTriggerEventBufferSize ); macroTriggerEventBufferSize = 0; } return; } #endif #if defined(ConnectEnabled_define) || defined(PressReleaseCache_define) #if defined(ConnectEnabled_define) // Check if there are any ScanCodes in the interconnect cache to process if ( Connect_master && macroInterconnectCacheSize > 0 ) #endif { // Iterate over all the cache ScanCodes uint8_t currentInterconnectCacheSize = macroInterconnectCacheSize; macroInterconnectCacheSize = 0; for ( uint8_t c = 0; c < currentInterconnectCacheSize; c++ ) { // Add to the trigger list macroTriggerEventBuffer[ macroTriggerEventBufferSize++ ] = macroInterconnectCache[ c ]; // TODO Handle other TriggerGuide types (e.g. analog) switch ( macroInterconnectCache[ c ].type ) { // Normal (Press/Hold/Release) case TriggerType_Switch1: case TriggerType_Switch2: case TriggerType_Switch3: case TriggerType_Switch4: case TriggerType_LED1: // Decide what to do based on the current state switch ( macroInterconnectCache[ c ].state ) { // Re-add to interconnect cache in hold state case ScheduleType_P: // Press //case ScheduleType_H: // Hold // XXX Why does this not work? -HaaTa macroInterconnectCache[ c ].state = ScheduleType_H; macroInterconnectCache[ macroInterconnectCacheSize++ ] = macroInterconnectCache[ c ]; break; case ScheduleType_R: // Release break; // Otherwise, do not re-add default: break; } break; // Not implemented default: erro_msg("Interconnect Trigger Event Type - Not Implemented "); printInt8( macroInterconnectCache[ c ].type ); print( NL ); break; } } } #endif // Macro incoming state debug switch ( macroDebugMode ) { case 1: case 2: // Iterate over incoming triggers for ( uint16_t trigger = 0; trigger < macroTriggerEventBufferSize; trigger++ ) { // Show debug info about incoming trigger Macro_showTriggerEvent( ¯oTriggerEventBuffer[trigger] ); print( NL ); } case 3: default: break; } // Check macroTriggerEventBufferSize to make sure no overflow if ( macroTriggerEventBufferSize >= MaxScanCode_KLL ) { // No scancodes defined if ( MaxScanCode_KLL == 0 ) { warn_print("No scancodes defined! Check your BaseMap!"); } // Bug! else { erro_msg("Macro Trigger Event Overflow! Serious Bug! "); printInt16( macroTriggerEventBufferSize ); print( NL ); macroTriggerEventBufferSize = 0; } } // If the pause flag is set, only process if the step counter is non-zero if ( macroPauseMode ) { if ( macroStepCounter == 0 ) return; // Proceed, decrementing the step counter macroStepCounter--; dbug_print("Macro Step"); } // Process Trigger Macros Trigger_process(); // Store events processed var_uint_t macroTriggerEventBufferSize_processed = macroTriggerEventBufferSize; // Reset TriggerList buffer macroTriggerEventBufferSize = 0; // Process result macros Result_process(); // Signal buffer that we've used it Scan_finishedWithMacro( macroTriggerEventBufferSize_processed ); #if defined(_host_) // Signal host to read layer state Output_callback( "layerState", "" ); #endif // Latency measurement Latency_end_time( macroLatencyResource ); // If Macro debug mode is set, clear the USB Buffer #if defined(Output_USBEnabled_define) if ( macroDebugMode == 1 || macroDebugMode == 3 ) { USBKeys_primary.changed = 0; } #endif }