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