diff --git a/tmk_core/common.mk b/tmk_core/common.mk index 8033016a..6805fa62 100644 --- a/tmk_core/common.mk +++ b/tmk_core/common.mk @@ -17,7 +17,10 @@ SRC += $(COMMON_DIR)/host.c \ $(COMMON_DIR)/avr/bootloader.c -# Option modules +ifeq (yes,$(strip $(NO_KEYBOARD))) + OPT_DEFS += -DNO_KEYBOARD +endif + ifeq (yes,$(strip $(UNIMAP_ENABLE))) SRC += $(COMMON_DIR)/unimap.c OPT_DEFS += -DUNIMAP_ENABLE diff --git a/tmk_core/common/avr/suspend.c b/tmk_core/common/avr/suspend.c index ea8099d0..7a17edbf 100644 --- a/tmk_core/common/avr/suspend.c +++ b/tmk_core/common/avr/suspend.c @@ -115,21 +115,25 @@ void suspend_power_down(void) bool suspend_wakeup_condition(void) { +#ifndef NO_KEYBOARD matrix_power_up(); matrix_scan(); matrix_power_down(); for (uint8_t r = 0; r < MATRIX_ROWS; r++) { if (matrix_get_row(r)) return true; } +#endif return false; } // run immediately after wakeup void suspend_wakeup_init(void) { +#ifndef NO_KEYBOARD // clear keyboard state matrix_clear(); clear_keyboard(); +#endif #ifdef BACKLIGHT_ENABLE backlight_init(); #endif diff --git a/tmk_core/common/hook.c b/tmk_core/common/hook.c index 22be9a30..6cf9977d 100644 --- a/tmk_core/common/hook.c +++ b/tmk_core/common/hook.c @@ -22,6 +22,9 @@ along with this program. If not, see . * Definitions of default hooks * ------------------------------------------------- */ +__attribute__((weak)) +void hook_main_loop(void) {} + __attribute__((weak)) void hook_keyboard_loop(void) {} diff --git a/tmk_core/common/hook.h b/tmk_core/common/hook.h index ddd05c6f..77f10845 100644 --- a/tmk_core/common/hook.h +++ b/tmk_core/common/hook.h @@ -56,6 +56,10 @@ void hook_usb_wakeup(void); /* Default behaviour: do nothing. */ void hook_usb_startup_wait_loop(void); +/* Called periodically from main loop */ +/* Default behaviour: do nothing. */ +void hook_main_loop(void); + /* ------------------------------------- * Keyboard hooks diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index 9eec9191..4f72f865 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h @@ -100,6 +100,12 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); #else /* NO_PRINT */ #define xprintf(s,...) ((void)0) +#define xsprintf(s,...) ((void)0) +#define xfprintf(s,...) ((void)0) +#define xputs(s) ((void)0) +#define xputc(c) ((void)0) +#define xitoa(v, r, w) ((void)0) +#define xatoi(s, r) ((void)0) #define print(s) ((void)0) #define println(s) ((void)0) #define print_set_sendchar(func) ((void)0) diff --git a/tmk_core/protocol/lufa/descriptor.c b/tmk_core/protocol/lufa/descriptor.c index 1dbaac03..f365222d 100644 --- a/tmk_core/protocol/lufa/descriptor.c +++ b/tmk_core/protocol/lufa/descriptor.c @@ -44,6 +44,7 @@ /******************************************************************************* * HID Report Descriptors ******************************************************************************/ +#ifndef NO_KEYBOARD const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = { #ifndef NKRO_ENABLE @@ -118,6 +119,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = HID_RI_END_COLLECTION(0), #endif }; +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] = @@ -240,7 +242,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = }; #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) const USB_Descriptor_HIDReport_Datatype_t PROGMEM NKROReport[] = { HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */ @@ -326,6 +328,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * Keyboard */ +#ifndef NO_KEYBOARD .Keyboard_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -367,6 +370,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = .PollingIntervalMS = 0x0A #endif }, +#endif /* * Mouse @@ -470,7 +474,7 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = /* * NKRO */ -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) .NKRO_Interface = { .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, @@ -583,10 +587,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, break; case HID_DTYPE_HID: switch (wIndex) { +#ifndef NO_KEYBOARD case KEYBOARD_INTERFACE: Address = &ConfigurationDescriptor.Keyboard_HID; Size = sizeof(USB_HID_Descriptor_HID_t); break; +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) case MOUSE_INTERFACE: Address = &ConfigurationDescriptor.Mouse_HID; @@ -599,7 +605,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Size = sizeof(USB_HID_Descriptor_HID_t); break; #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) case NKRO_INTERFACE: Address = &ConfigurationDescriptor.NKRO_HID; Size = sizeof(USB_HID_Descriptor_HID_t); @@ -609,10 +615,12 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, break; case HID_DTYPE_Report: switch (wIndex) { +#ifndef NO_KEYBOARD case KEYBOARD_INTERFACE: Address = &KeyboardReport; Size = sizeof(KeyboardReport); break; +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) case MOUSE_INTERFACE: Address = &MouseReport; @@ -625,7 +633,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, Size = sizeof(ConsoleReport); break; #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) case NKRO_INTERFACE: Address = &NKROReport; Size = sizeof(NKROReport); diff --git a/tmk_core/protocol/lufa/descriptor.h b/tmk_core/protocol/lufa/descriptor.h index 5c09be30..4bba0cc0 100644 --- a/tmk_core/protocol/lufa/descriptor.h +++ b/tmk_core/protocol/lufa/descriptor.h @@ -52,10 +52,12 @@ typedef struct { USB_Descriptor_Configuration_Header_t Config; +#ifndef NO_KEYBOARD // Keyboard HID Interface USB_Descriptor_Interface_t Keyboard_Interface; USB_HID_Descriptor_HID_t Keyboard_HID; USB_Descriptor_Endpoint_t Keyboard_INEndpoint; +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) // Mouse HID Interface @@ -72,7 +74,7 @@ typedef struct USB_Descriptor_Endpoint_t Console_OUTEndpoint; #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) // NKRO HID Interface USB_Descriptor_Interface_t NKRO_Interface; USB_HID_Descriptor_HID_t NKRO_HID; @@ -82,7 +84,11 @@ typedef struct /* index of interface */ -#define KEYBOARD_INTERFACE 0 +#ifndef NO_KEYBOARD +# define KEYBOARD_INTERFACE 0 +#else +# define KEYBOARD_INTERFACE -1 +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) # define MOUSE_INTERFACE (KEYBOARD_INTERFACE + 1) @@ -96,7 +102,7 @@ typedef struct # define CONSOLE_INTERFACE MOUSE_INTERFACE #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) # define NKRO_INTERFACE (CONSOLE_INTERFACE + 1) #else # define NKRO_INTERFACE CONSOLE_INTERFACE @@ -108,7 +114,11 @@ typedef struct // Endopoint number and size -#define KEYBOARD_IN_EPNUM 1 +#ifndef NO_KEYBOARD +# define KEYBOARD_IN_EPNUM 1 +#else +# define KEYBOARD_IN_EPNUM 0 +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) # define MOUSE_IN_EPNUM (KEYBOARD_IN_EPNUM + 1) @@ -123,7 +133,7 @@ typedef struct # define CONSOLE_OUT_EPNUM MOUSE_IN_EPNUM #endif -#ifdef NKRO_6KRO_ENABLE +#if !defined(NO_KEYBOARD) && defined(NKRO_6KRO_ENABLE) # define NKRO_IN_EPNUM (CONSOLE_OUT_EPNUM + 1) #else # define NKRO_IN_EPNUM CONSOLE_OUT_EPNUM diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index dadd4adc..8653c46e 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c @@ -68,27 +68,35 @@ //#define TMK_LUFA_DEBUG +#ifndef NO_KEYBOARD uint8_t keyboard_idle = 0; /* 0: Boot Protocol, 1: Report Protocol(default) */ uint8_t keyboard_protocol = 1; -uint8_t mouse_protocol = 1; static uint8_t keyboard_led_stats = 0; - static report_keyboard_t keyboard_report_sent; +#endif + +#ifdef MOUSE_ENABLE +uint8_t mouse_protocol = 1; +#endif /* Host driver */ +#ifndef NO_KEYBOARD static uint8_t keyboard_leds(void); static void send_keyboard(report_keyboard_t *report); +#endif static void send_mouse(report_mouse_t *report); static void send_system(uint16_t data); static void send_consumer(uint16_t data); host_driver_t lufa_driver = { - keyboard_leds, - send_keyboard, - send_mouse, - send_system, - send_consumer +#ifndef NO_KEYBOARD + .keyboard_leds = keyboard_leds, + .send_keyboard = send_keyboard, +#endif + .send_mouse = send_mouse, + .send_system = send_system, + .send_consumer = send_consumer }; @@ -328,6 +336,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) #endif bool ConfigSuccess = true; +#ifndef NO_KEYBOARD /* Setup Keyboard HID Report Endpoints */ ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN, #ifdef NKRO_ENABLE @@ -336,6 +345,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) KEYBOARD_EPSIZE, #endif ENDPOINT_BANK_SINGLE); +#endif #if defined(MOUSE_ENABLE) || defined(EXTRAKEY_ENABLE) /* Setup Mouse HID Report Endpoint */ @@ -378,15 +388,16 @@ Other Device Required Optional Optional Optional Optional Opti */ void EVENT_USB_Device_ControlRequest(void) { - uint8_t* ReportData = NULL; - uint8_t ReportSize = 0; - /* Handle HID Class specific requests */ switch (USB_ControlRequest.bRequest) { case HID_REQ_GetReport: +#ifndef NO_KEYBOARD if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { + uint8_t* ReportData = NULL; + uint8_t ReportSize = 0; + Endpoint_ClearSETUP(); // Interface @@ -405,6 +416,7 @@ void EVENT_USB_Device_ControlRequest(void) xprintf("[r%d]", USB_ControlRequest.wIndex); #endif } +#endif break; case HID_REQ_SetReport: @@ -413,6 +425,7 @@ void EVENT_USB_Device_ControlRequest(void) // Interface switch (USB_ControlRequest.wIndex) { +#ifndef NO_KEYBOARD case KEYBOARD_INTERFACE: #ifdef NKRO_6KRO_ENABLE case NKRO_INTERFACE: @@ -431,6 +444,7 @@ void EVENT_USB_Device_ControlRequest(void) xprintf("[L%d]", USB_ControlRequest.wIndex); #endif break; +#endif } } @@ -440,6 +454,7 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_GetProtocol: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { +#ifndef NO_KEYBOARD if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())); @@ -450,6 +465,7 @@ void EVENT_USB_Device_ControlRequest(void) print("[p]"); #endif } +#endif #if defined(MOUSE_ENABLE) if (USB_ControlRequest.wIndex == MOUSE_INTERFACE) { Endpoint_ClearSETUP(); @@ -465,6 +481,7 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_SetProtocol: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { +#ifndef NO_KEYBOARD if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) { Endpoint_ClearSETUP(); Endpoint_ClearStatusStage(); @@ -475,6 +492,7 @@ void EVENT_USB_Device_ControlRequest(void) print("[P]"); #endif } +#endif #if defined(MOUSE_ENABLE) if (USB_ControlRequest.wIndex == MOUSE_INTERFACE) { Endpoint_ClearSETUP(); @@ -490,12 +508,14 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_SetIdle: if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { +#ifndef NO_KEYBOARD Endpoint_ClearSETUP(); Endpoint_ClearStatusStage(); keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8); #ifdef TMK_LUFA_DEBUG xprintf("[I%d]%d", USB_ControlRequest.wIndex, (USB_ControlRequest.wValue & 0xFF00) >> 8); +#endif #endif } @@ -503,6 +523,7 @@ void EVENT_USB_Device_ControlRequest(void) case HID_REQ_GetIdle: if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { +#ifndef NO_KEYBOARD Endpoint_ClearSETUP(); while (!(Endpoint_IsINReady())); Endpoint_Write_8(keyboard_idle); @@ -510,6 +531,7 @@ void EVENT_USB_Device_ControlRequest(void) Endpoint_ClearStatusStage(); #ifdef TMK_LUFA_DEBUG print("[i]"); +#endif #endif } @@ -520,6 +542,7 @@ void EVENT_USB_Device_ControlRequest(void) /******************************************************************************* * Host driver ******************************************************************************/ +#ifndef NO_KEYBOARD static uint8_t keyboard_leds(void) { return keyboard_led_stats; @@ -568,6 +591,7 @@ static void send_keyboard(report_keyboard_t *report) keyboard_report_sent = *report; } +#endif static void send_mouse(report_mouse_t *report) { @@ -713,16 +737,27 @@ int main(void) "/UHS2:" STR(TMK_USB_HOST_SHIELD_VERSION) #endif "\n"); + hook_early_init(); + +#ifndef NO_KEYBOARD keyboard_setup(); +#endif + setup_usb(); + #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif sei(); +#ifndef NO_KEYBOARD keyboard_init(); +#else + // TODO: keyboard_init() should be used only for things related to keyboard + timer_init(); +#endif #ifndef NO_USB_STARTUP_WAIT_LOOP /* wait for USB startup */ @@ -739,7 +774,7 @@ int main(void) hook_late_init(); - print("\nKeyboard start.\n"); + print("\nLoop start.\n"); while (1) { #ifndef NO_USB_SUSPEND_LOOP while (USB_DeviceState == DEVICE_STATE_Suspended) { @@ -747,7 +782,11 @@ int main(void) } #endif + hook_main_loop(); + +#ifndef NO_KEYBOARD keyboard_task(); +#endif #ifdef CONSOLE_ENABLE console_task(); @@ -767,10 +806,13 @@ void hook_early_init(void) {} __attribute__((weak)) void hook_late_init(void) {} +#ifndef NO_KEYBOARD static uint8_t _led_stats = 0; +#endif __attribute__((weak)) void hook_usb_suspend_entry(void) { +#ifndef NO_KEYBOARD // Turn off LED to save power and keep its status to resotre it later. // LED status will be updated by keyboard_task() in main loop hopefully. _led_stats = keyboard_led_stats; @@ -780,6 +822,7 @@ void hook_usb_suspend_entry(void) matrix_clear(); clear_keyboard(); +#endif #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif @@ -805,8 +848,10 @@ void hook_usb_wakeup(void) sleep_led_disable(); #endif +#ifndef NO_KEYBOARD // Restore LED status and update at keyboard_task() in main loop keyboard_led_stats = _led_stats; +#endif // Calling long task here can prevent USB state transition }