summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tmk_core/common/report.h5
-rw-r--r--tmk_core/protocol/arm_atsam/main_arm_atsam.c26
-rw-r--r--tmk_core/protocol/chibios/usb_main.h14
-rw-r--r--tmk_core/protocol/lufa/lufa.c27
-rw-r--r--tmk_core/protocol/lufa/lufa.h6
-rw-r--r--tmk_core/protocol/vusb/vusb.c26
6 files changed, 39 insertions, 65 deletions
diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index ccc6d599b3..2a9dad8811 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -151,6 +151,11 @@ typedef union {
} __attribute__((packed)) report_keyboard_t;
typedef struct {
+ uint8_t report_id;
+ uint16_t usage;
+} __attribute__((packed)) report_extra_t;
+
+typedef struct {
#ifdef MOUSE_SHARED_EP
uint8_t report_id;
#endif
diff --git a/tmk_core/protocol/arm_atsam/main_arm_atsam.c b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
index a42d9daf38..e15d51a263 100644
--- a/tmk_core/protocol/arm_atsam/main_arm_atsam.c
+++ b/tmk_core/protocol/arm_atsam/main_arm_atsam.c
@@ -110,40 +110,34 @@ void send_mouse(report_mouse_t *report) {
#endif // MOUSEKEY_ENABLE
}
-void send_system(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
+void send_extra(uint8_t report_id, uint16_t data) {
uint32_t irqflags;
irqflags = __get_PRIMASK();
__disable_irq();
__DMB();
- udi_hid_exk_report.desc.report_id = REPORT_ID_SYSTEM;
- if (data != 0) data = data - SYSTEM_POWER_DOWN + 1;
+ udi_hid_exk_report.desc.report_id = report_id;
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
+
+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
}
void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
- uint32_t irqflags;
-
- 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);
+ send_extra(REPORT_ID_CONSUMER, data);
#endif // EXTRAKEY_ENABLE
}
diff --git a/tmk_core/protocol/chibios/usb_main.h b/tmk_core/protocol/chibios/usb_main.h
index cd2bb695ba..17041b4f2f 100644
--- a/tmk_core/protocol/chibios/usb_main.h
+++ b/tmk_core/protocol/chibios/usb_main.h
@@ -72,20 +72,6 @@ void mouse_in_cb(USBDriver *usbp, usbep_t ep);
/* shared IN request callback handler */
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
* --------------
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index 4f9ab4f62c..c632b35c6e 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -774,17 +774,17 @@ static void send_mouse(report_mouse_t *report) {
#endif
}
-/** \brief Send System
+/** \brief Send Extra
*
* FIXME: Needs doc
*/
-static void send_system(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
+static void send_extra(uint8_t report_id, uint16_t data) {
uint8_t timeout = 255;
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);
/* Check if write ready for a polling interval around 10ms */
@@ -793,6 +793,16 @@ static void send_system(uint16_t data) {
Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
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
}
@@ -802,7 +812,6 @@ static void send_system(uint16_t data) {
*/
static void send_consumer(uint16_t data) {
#ifdef EXTRAKEY_ENABLE
- uint8_t timeout = 255;
uint8_t where = where_to_send();
# ifdef BLUETOOTH_ENABLE
@@ -841,15 +850,7 @@ static void send_consumer(uint16_t data) {
return;
}
- report_extra_t r = {.report_id = REPORT_ID_CONSUMER, .usage = 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();
+ send_extra(REPORT_ID_CONSUMER, data);
#endif
}
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h
index 652e4e79b7..1b88060f14 100644
--- a/tmk_core/protocol/lufa/lufa.h
+++ b/tmk_core/protocol/lufa/lufa.h
@@ -58,12 +58,6 @@ extern host_driver_t lufa_driver;
}
#endif
-/* extra report structure */
-typedef struct {
- uint8_t report_id;
- uint16_t usage;
-} __attribute__((packed)) report_extra_t;
-
#ifdef API_ENABLE
# include "api.h"
#endif
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c
index 72445e00bb..1a2acc11b7 100644
--- a/tmk_core/protocol/vusb/vusb.c
+++ b/tmk_core/protocol/vusb/vusb.c
@@ -113,31 +113,25 @@ static void send_mouse(report_mouse_t *report) {
}
}
-typedef struct {
- uint8_t report_id;
- uint16_t usage;
-} __attribute__((packed)) report_extra_t;
-
-static void send_system(uint16_t data) {
+static void send_extra(uint8_t report_id, uint16_t data) {
+ static uint8_t last_id = 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;
- report_extra_t report = {.report_id = REPORT_ID_SYSTEM, .usage = data};
+ report_extra_t report = {.report_id = report_id, .usage = data};
if (usbInterruptIsReady3()) {
usbSetInterrupt3((void *)&report, sizeof(report));
}
}
-static void send_consumer(uint16_t data) {
- static uint16_t last_data = 0;
- if (data == last_data) return;
- last_data = data;
+static void send_system(uint16_t data) {
+ send_extra(REPORT_ID_SYSTEM, data);
+}
- report_extra_t report = {.report_id = REPORT_ID_CONSUMER, .usage = data};
- if (usbInterruptIsReady3()) {
- usbSetInterrupt3((void *)&report, sizeof(report));
- }
+static void send_consumer(uint16_t data) {
+ send_extra(REPORT_ID_CONSUMER, data);
}
/*------------------------------------------------------------------*