Dedupe extrakey report struct, and send functions in V-USB & LUFA (#7993)
* Dedupe extrakey report struct, and send functions in V-USB & LUFA * Doc comment for consistency * Wrap it in ifdef to prevent unused function error * Do the same for ATSAM
This commit is contained in:
parent
5b91c3e0a0
commit
b2ce2f8a34
6 changed files with 39 additions and 65 deletions
|
@ -150,6 +150,11 @@ typedef union {
|
||||||
#endif
|
#endif
|
||||||
} __attribute__((packed)) report_keyboard_t;
|
} __attribute__((packed)) report_keyboard_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t report_id;
|
||||||
|
uint16_t usage;
|
||||||
|
} __attribute__((packed)) report_extra_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
#ifdef MOUSE_SHARED_EP
|
#ifdef MOUSE_SHARED_EP
|
||||||
uint8_t report_id;
|
uint8_t report_id;
|
||||||
|
|
|
@ -110,40 +110,34 @@ void send_mouse(report_mouse_t *report) {
|
||||||
#endif // MOUSEKEY_ENABLE
|
#endif // MOUSEKEY_ENABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_system(uint16_t data) {
|
|
||||||
#ifdef EXTRAKEY_ENABLE
|
#ifdef EXTRAKEY_ENABLE
|
||||||
|
void send_extra(uint8_t report_id, uint16_t data) {
|
||||||
uint32_t irqflags;
|
uint32_t irqflags;
|
||||||
|
|
||||||
irqflags = __get_PRIMASK();
|
irqflags = __get_PRIMASK();
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
__DMB();
|
__DMB();
|
||||||
|
|
||||||
udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM;
|
udi_hid_exk_report.desc.report_id = report_id;
|
||||||
if (data != 0) data = data - SYSTEM_POWER_DOWN + 1;
|
|
||||||
udi_hid_exk_report.desc.report_data = data;
|
udi_hid_exk_report.desc.report_data = data;
|
||||||
udi_hid_exk_b_report_valid = 1;
|
udi_hid_exk_b_report_valid = 1;
|
||||||
udi_hid_exk_send_report();
|
udi_hid_exk_send_report();
|
||||||
|
|
||||||
__DMB();
|
__DMB();
|
||||||
__set_PRIMASK(irqflags);
|
__set_PRIMASK(irqflags);
|
||||||
|
}
|
||||||
|
#endif // EXTRAKEY_ENABLE
|
||||||
|
|
||||||
|
void send_system(uint16_t data) {
|
||||||
|
#ifdef EXTRAKEY_ENABLE
|
||||||
|
if (data != 0) data = data - SYSTEM_POWER_DOWN + 1;
|
||||||
|
send_extra(REPORT_ID_SYSTEM, data);
|
||||||
#endif // EXTRAKEY_ENABLE
|
#endif // EXTRAKEY_ENABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_consumer(uint16_t data) {
|
void send_consumer(uint16_t data) {
|
||||||
#ifdef EXTRAKEY_ENABLE
|
#ifdef EXTRAKEY_ENABLE
|
||||||
uint32_t irqflags;
|
send_extra(REPORT_ID_CONSUMER, data);
|
||||||
|
|
||||||
irqflags = __get_PRIMASK();
|
|
||||||
__disable_irq();
|
|
||||||
__DMB();
|
|
||||||
|
|
||||||
udi_hid_exk_report.desc.report_id = REPORT_ID_CONSUMER;
|
|
||||||
udi_hid_exk_report.desc.report_data = data;
|
|
||||||
udi_hid_exk_b_report_valid = 1;
|
|
||||||
udi_hid_exk_send_report();
|
|
||||||
|
|
||||||
__DMB();
|
|
||||||
__set_PRIMASK(irqflags);
|
|
||||||
#endif // EXTRAKEY_ENABLE
|
#endif // EXTRAKEY_ENABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,20 +72,6 @@ void mouse_in_cb(USBDriver *usbp, usbep_t ep);
|
||||||
/* shared IN request callback handler */
|
/* shared IN request callback handler */
|
||||||
void shared_in_cb(USBDriver *usbp, usbep_t ep);
|
void shared_in_cb(USBDriver *usbp, usbep_t ep);
|
||||||
|
|
||||||
/* ---------------
|
|
||||||
* Extrakey header
|
|
||||||
* ---------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef EXTRAKEY_ENABLE
|
|
||||||
|
|
||||||
/* extra report structure */
|
|
||||||
typedef struct {
|
|
||||||
uint8_t report_id;
|
|
||||||
uint16_t usage;
|
|
||||||
} __attribute__((packed)) report_extra_t;
|
|
||||||
#endif /* EXTRAKEY_ENABLE */
|
|
||||||
|
|
||||||
/* --------------
|
/* --------------
|
||||||
* Console header
|
* Console header
|
||||||
* --------------
|
* --------------
|
||||||
|
|
|
@ -662,17 +662,17 @@ static void send_mouse(report_mouse_t *report) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief Send System
|
/** \brief Send Extra
|
||||||
*
|
*
|
||||||
* FIXME: Needs doc
|
* FIXME: Needs doc
|
||||||
*/
|
*/
|
||||||
static void send_system(uint16_t data) {
|
|
||||||
#ifdef EXTRAKEY_ENABLE
|
#ifdef EXTRAKEY_ENABLE
|
||||||
|
static void send_extra(uint8_t report_id, uint16_t data) {
|
||||||
uint8_t timeout = 255;
|
uint8_t timeout = 255;
|
||||||
|
|
||||||
if (USB_DeviceState != DEVICE_STATE_Configured) return;
|
if (USB_DeviceState != DEVICE_STATE_Configured) return;
|
||||||
|
|
||||||
report_extra_t r = {.report_id = REPORT_ID_SYSTEM, .usage = data - SYSTEM_POWER_DOWN + 1};
|
report_extra_t r = {.report_id = report_id, .usage = data};
|
||||||
Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
|
Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
|
||||||
|
|
||||||
/* Check if write ready for a polling interval around 10ms */
|
/* Check if write ready for a polling interval around 10ms */
|
||||||
|
@ -681,6 +681,16 @@ static void send_system(uint16_t data) {
|
||||||
|
|
||||||
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
|
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
|
||||||
Endpoint_ClearIN();
|
Endpoint_ClearIN();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** \brief Send System
|
||||||
|
*
|
||||||
|
* FIXME: Needs doc
|
||||||
|
*/
|
||||||
|
static void send_system(uint16_t data) {
|
||||||
|
#ifdef EXTRAKEY_ENABLE
|
||||||
|
send_extra(REPORT_ID_SYSTEM, data - SYSTEM_POWER_DOWN + 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -690,7 +700,6 @@ static void send_system(uint16_t data) {
|
||||||
*/
|
*/
|
||||||
static void send_consumer(uint16_t data) {
|
static void send_consumer(uint16_t data) {
|
||||||
#ifdef EXTRAKEY_ENABLE
|
#ifdef EXTRAKEY_ENABLE
|
||||||
uint8_t timeout = 255;
|
|
||||||
uint8_t where = where_to_send();
|
uint8_t where = where_to_send();
|
||||||
|
|
||||||
# ifdef BLUETOOTH_ENABLE
|
# ifdef BLUETOOTH_ENABLE
|
||||||
|
@ -729,15 +738,7 @@ static void send_consumer(uint16_t data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
report_extra_t r = {.report_id = REPORT_ID_CONSUMER, .usage = data};
|
send_extra(REPORT_ID_CONSUMER, data);
|
||||||
Endpoint_SelectEndpoint(SHARED_IN_EPNUM);
|
|
||||||
|
|
||||||
/* Check if write ready for a polling interval around 10ms */
|
|
||||||
while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
|
|
||||||
if (!Endpoint_IsReadWriteAllowed()) return;
|
|
||||||
|
|
||||||
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
|
|
||||||
Endpoint_ClearIN();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,6 @@ extern host_driver_t lufa_driver;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* extra report structure */
|
|
||||||
typedef struct {
|
|
||||||
uint8_t report_id;
|
|
||||||
uint16_t usage;
|
|
||||||
} __attribute__((packed)) report_extra_t;
|
|
||||||
|
|
||||||
#ifdef API_ENABLE
|
#ifdef API_ENABLE
|
||||||
# include "api.h"
|
# include "api.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -112,31 +112,25 @@ static void send_mouse(report_mouse_t *report) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
static void send_extra(uint8_t report_id, uint16_t data) {
|
||||||
uint8_t report_id;
|
static uint8_t last_id = 0;
|
||||||
uint16_t usage;
|
|
||||||
} __attribute__((packed)) report_extra_t;
|
|
||||||
|
|
||||||
static void send_system(uint16_t data) {
|
|
||||||
static uint16_t last_data = 0;
|
static uint16_t last_data = 0;
|
||||||
if (data == last_data) return;
|
if ((report_id == last_id) && (data == last_data)) return;
|
||||||
|
last_id = report_id;
|
||||||
last_data = data;
|
last_data = data;
|
||||||
|
|
||||||
report_extra_t report = {.report_id = REPORT_ID_SYSTEM, .usage = data};
|
report_extra_t report = {.report_id = report_id, .usage = data};
|
||||||
if (usbInterruptIsReady3()) {
|
if (usbInterruptIsReady3()) {
|
||||||
usbSetInterrupt3((void *)&report, sizeof(report));
|
usbSetInterrupt3((void *)&report, sizeof(report));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_consumer(uint16_t data) {
|
static void send_system(uint16_t data) {
|
||||||
static uint16_t last_data = 0;
|
send_extra(REPORT_ID_SYSTEM, data);
|
||||||
if (data == last_data) return;
|
}
|
||||||
last_data = data;
|
|
||||||
|
|
||||||
report_extra_t report = {.report_id = REPORT_ID_CONSUMER, .usage = data};
|
static void send_consumer(uint16_t data) {
|
||||||
if (usbInterruptIsReady3()) {
|
send_extra(REPORT_ID_CONSUMER, data);
|
||||||
usbSetInterrupt3((void *)&report, sizeof(report));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
|
|
Loading…
Reference in a new issue