Refactor send_extra
(#18615)
This commit is contained in:
parent
cbe1c22d46
commit
6dbbeea46a
16 changed files with 68 additions and 107 deletions
|
@ -37,7 +37,7 @@ void main_subtasks(void);
|
|||
uint8_t keyboard_leds(void);
|
||||
void send_keyboard(report_keyboard_t *report);
|
||||
void send_mouse(report_mouse_t *report);
|
||||
void send_extra(uint8_t report_id, uint16_t data);
|
||||
void send_extra(report_extra_t *report);
|
||||
|
||||
#ifdef DEFERRED_EXEC_ENABLE
|
||||
void deferred_exec_task(void);
|
||||
|
@ -113,7 +113,7 @@ void send_mouse(report_mouse_t *report) {
|
|||
#endif // MOUSEKEY_ENABLE
|
||||
}
|
||||
|
||||
void send_extra(uint8_t report_id, uint16_t data) {
|
||||
void send_extra(report_extra_t *report) {
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
uint32_t irqflags;
|
||||
|
||||
|
@ -121,9 +121,8 @@ void send_extra(uint8_t report_id, uint16_t data) {
|
|||
__disable_irq();
|
||||
__DMB();
|
||||
|
||||
udi_hid_exk_report.desc.report_id = report_id;
|
||||
udi_hid_exk_report.desc.report_data = data;
|
||||
udi_hid_exk_b_report_valid = 1;
|
||||
memcpy(udi_hid_exk_report, report, UDI_HID_EXK_REPORT_SIZE);
|
||||
udi_hid_exk_b_report_valid = 1;
|
||||
udi_hid_exk_send_report();
|
||||
|
||||
__DMB();
|
||||
|
|
|
@ -352,21 +352,9 @@ typedef struct {
|
|||
|
||||
// clang-format on
|
||||
|
||||
// set report buffer (from host)
|
||||
extern uint8_t udi_hid_exk_report_set;
|
||||
|
||||
// report buffer
|
||||
# define UDI_HID_EXK_REPORT_SIZE 3
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
uint8_t report_id;
|
||||
uint16_t report_data;
|
||||
} desc;
|
||||
uint8_t raw[UDI_HID_EXK_REPORT_SIZE];
|
||||
} udi_hid_exk_report_t;
|
||||
|
||||
extern udi_hid_exk_report_t udi_hid_exk_report;
|
||||
extern uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE];
|
||||
|
||||
COMPILER_PACK_RESET()
|
||||
|
||||
|
|
|
@ -371,13 +371,13 @@ static uint8_t udi_hid_exk_rate;
|
|||
COMPILER_WORD_ALIGNED
|
||||
static uint8_t udi_hid_exk_protocol;
|
||||
|
||||
COMPILER_WORD_ALIGNED
|
||||
uint8_t udi_hid_exk_report_set;
|
||||
// COMPILER_WORD_ALIGNED
|
||||
// uint8_t udi_hid_exk_report_set;
|
||||
|
||||
bool udi_hid_exk_b_report_valid;
|
||||
|
||||
COMPILER_WORD_ALIGNED
|
||||
udi_hid_exk_report_t udi_hid_exk_report;
|
||||
uint8_t udi_hid_exk_report[UDI_HID_EXK_REPORT_SIZE];
|
||||
|
||||
static bool udi_hid_exk_b_report_trans_ongoing;
|
||||
|
||||
|
@ -415,39 +415,24 @@ UDC_DESC_STORAGE udi_hid_exk_report_desc_t udi_hid_exk_report_desc = {{
|
|||
//clang-format on
|
||||
}};
|
||||
|
||||
static bool udi_hid_exk_setreport(void);
|
||||
|
||||
static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent, udd_ep_id_t ep);
|
||||
|
||||
static void udi_hid_exk_setreport_valid(void);
|
||||
|
||||
bool udi_hid_exk_enable(void) {
|
||||
// Initialize internal values
|
||||
udi_hid_exk_rate = 0;
|
||||
udi_hid_exk_protocol = 0;
|
||||
udi_hid_exk_b_report_trans_ongoing = false;
|
||||
memset(udi_hid_exk_report.raw, 0, UDI_HID_EXK_REPORT_SIZE);
|
||||
memset(udi_hid_exk_report, 0, UDI_HID_EXK_REPORT_SIZE);
|
||||
udi_hid_exk_b_report_valid = false;
|
||||
return UDI_HID_EXK_ENABLE_EXT();
|
||||
}
|
||||
|
||||
void udi_hid_exk_disable(void) { UDI_HID_EXK_DISABLE_EXT(); }
|
||||
|
||||
bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, udi_hid_exk_setreport); }
|
||||
bool udi_hid_exk_setup(void) { return udi_hid_setup(&udi_hid_exk_rate, &udi_hid_exk_protocol, (uint8_t *)&udi_hid_exk_report_desc, NULL); }
|
||||
|
||||
uint8_t udi_hid_exk_getsetting(void) { return 0; }
|
||||
|
||||
static bool udi_hid_exk_setreport(void) {
|
||||
if ((USB_HID_REPORT_TYPE_OUTPUT == (udd_g_ctrlreq.req.wValue >> 8)) && (0 == (0xFF & udd_g_ctrlreq.req.wValue)) && (1 == udd_g_ctrlreq.req.wLength)) {
|
||||
// Report OUT type on report ID 0 from USB Host
|
||||
udd_g_ctrlreq.payload = &udi_hid_exk_report_set;
|
||||
udd_g_ctrlreq.callback = udi_hid_exk_setreport_valid;
|
||||
udd_g_ctrlreq.payload_size = 1;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool udi_hid_exk_send_report(void) {
|
||||
if (!main_b_exk_enable) {
|
||||
return false;
|
||||
|
@ -457,7 +442,7 @@ bool udi_hid_exk_send_report(void) {
|
|||
return false;
|
||||
}
|
||||
|
||||
memcpy(udi_hid_exk_report_trans, udi_hid_exk_report.raw, UDI_HID_EXK_REPORT_SIZE);
|
||||
memcpy(udi_hid_exk_report_trans, udi_hid_exk_report, UDI_HID_EXK_REPORT_SIZE);
|
||||
udi_hid_exk_b_report_valid = false;
|
||||
udi_hid_exk_b_report_trans_ongoing = udd_ep_run(UDI_HID_EXK_EP_IN | USB_EP_DIR_IN, false, udi_hid_exk_report_trans, UDI_HID_EXK_REPORT_SIZE, udi_hid_exk_report_sent);
|
||||
|
||||
|
@ -474,8 +459,6 @@ static void udi_hid_exk_report_sent(udd_ep_status_t status, iram_size_t nb_sent,
|
|||
}
|
||||
}
|
||||
|
||||
static void udi_hid_exk_setreport_valid(void) {}
|
||||
|
||||
#endif // EXTRAKEY_ENABLE
|
||||
|
||||
//********************************************************************************************
|
||||
|
|
|
@ -79,7 +79,6 @@ bool udi_hid_nkro_send_report(void);
|
|||
#ifdef EXTRAKEY_ENABLE
|
||||
extern UDC_DESC_STORAGE udi_api_t udi_api_hid_exk;
|
||||
extern bool udi_hid_exk_b_report_valid;
|
||||
extern uint8_t udi_hid_exk_report_set;
|
||||
bool udi_hid_exk_send_report(void);
|
||||
#endif // EXTRAKEY_ENABLE
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
uint8_t keyboard_leds(void);
|
||||
void send_keyboard(report_keyboard_t *report);
|
||||
void send_mouse(report_mouse_t *report);
|
||||
void send_extra(uint8_t report_id, uint16_t data);
|
||||
void send_extra(report_extra_t *report);
|
||||
|
||||
/* host struct */
|
||||
host_driver_t chibios_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||
|
|
|
@ -943,7 +943,7 @@ void shared_in_cb(USBDriver *usbp, usbep_t ep) {
|
|||
* ---------------------------------------------------------
|
||||
*/
|
||||
|
||||
void send_extra(uint8_t report_id, uint16_t data) {
|
||||
void send_extra(report_extra_t *report) {
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
osalSysLock();
|
||||
if (usbGetDriverStateI(&USB_DRIVER) != USB_ACTIVE) {
|
||||
|
@ -962,10 +962,7 @@ void send_extra(uint8_t report_id, uint16_t data) {
|
|||
}
|
||||
}
|
||||
|
||||
static report_extra_t report;
|
||||
report = (report_extra_t){.report_id = report_id, .usage = data};
|
||||
|
||||
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)&report, sizeof(report_extra_t));
|
||||
usbStartTransmitI(&USB_DRIVER, SHARED_IN_EPNUM, (uint8_t *)report, sizeof(report_extra_t));
|
||||
osalSysUnlock();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -41,8 +41,8 @@ extern keymap_config_t keymap_config;
|
|||
#endif
|
||||
|
||||
static host_driver_t *driver;
|
||||
static uint16_t last_system_report = 0;
|
||||
static uint16_t last_consumer_report = 0;
|
||||
static uint16_t last_system_usage = 0;
|
||||
static uint16_t last_consumer_usage = 0;
|
||||
|
||||
void host_set_driver(host_driver_t *d) {
|
||||
driver = d;
|
||||
|
@ -126,27 +126,37 @@ void host_mouse_send(report_mouse_t *report) {
|
|||
(*driver->send_mouse)(report);
|
||||
}
|
||||
|
||||
void host_system_send(uint16_t report) {
|
||||
if (report == last_system_report) return;
|
||||
last_system_report = report;
|
||||
void host_system_send(uint16_t usage) {
|
||||
if (usage == last_system_usage) return;
|
||||
last_system_usage = usage;
|
||||
|
||||
if (!driver) return;
|
||||
(*driver->send_extra)(REPORT_ID_SYSTEM, report);
|
||||
|
||||
report_extra_t report = {
|
||||
.report_id = REPORT_ID_SYSTEM,
|
||||
.usage = usage,
|
||||
};
|
||||
(*driver->send_extra)(&report);
|
||||
}
|
||||
|
||||
void host_consumer_send(uint16_t report) {
|
||||
if (report == last_consumer_report) return;
|
||||
last_consumer_report = report;
|
||||
void host_consumer_send(uint16_t usage) {
|
||||
if (usage == last_consumer_usage) return;
|
||||
last_consumer_usage = usage;
|
||||
|
||||
#ifdef BLUETOOTH_ENABLE
|
||||
if (where_to_send() == OUTPUT_BLUETOOTH) {
|
||||
bluetooth_send_consumer(report);
|
||||
bluetooth_send_consumer(usage);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!driver) return;
|
||||
(*driver->send_extra)(REPORT_ID_CONSUMER, report);
|
||||
|
||||
report_extra_t report = {
|
||||
.report_id = REPORT_ID_CONSUMER,
|
||||
.usage = usage,
|
||||
};
|
||||
(*driver->send_extra)(&report);
|
||||
}
|
||||
|
||||
#ifdef JOYSTICK_ENABLE
|
||||
|
@ -232,10 +242,10 @@ void host_programmable_button_send(uint32_t data) {
|
|||
|
||||
__attribute__((weak)) void send_programmable_button(report_programmable_button_t *report) {}
|
||||
|
||||
uint16_t host_last_system_report(void) {
|
||||
return last_system_report;
|
||||
uint16_t host_last_system_usage(void) {
|
||||
return last_system_usage;
|
||||
}
|
||||
|
||||
uint16_t host_last_consumer_report(void) {
|
||||
return last_consumer_report;
|
||||
uint16_t host_last_consumer_usage(void) {
|
||||
return last_consumer_usage;
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ uint8_t host_keyboard_leds(void);
|
|||
led_t host_keyboard_led_state(void);
|
||||
void host_keyboard_send(report_keyboard_t *report);
|
||||
void host_mouse_send(report_mouse_t *report);
|
||||
void host_system_send(uint16_t data);
|
||||
void host_consumer_send(uint16_t data);
|
||||
void host_system_send(uint16_t usage);
|
||||
void host_consumer_send(uint16_t usage);
|
||||
void host_programmable_button_send(uint32_t data);
|
||||
|
||||
uint16_t host_last_system_report(void);
|
||||
uint16_t host_last_consumer_report(void);
|
||||
uint16_t host_last_system_usage(void);
|
||||
uint16_t host_last_consumer_usage(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ typedef struct {
|
|||
uint8_t (*keyboard_leds)(void);
|
||||
void (*send_keyboard)(report_keyboard_t *);
|
||||
void (*send_mouse)(report_mouse_t *);
|
||||
void (*send_extra)(uint8_t, uint16_t);
|
||||
void (*send_extra)(report_extra_t *);
|
||||
} host_driver_t;
|
||||
|
||||
void send_joystick(report_joystick_t *report);
|
||||
|
|
|
@ -84,7 +84,7 @@ static report_keyboard_t keyboard_report_sent;
|
|||
static uint8_t keyboard_leds(void);
|
||||
static void send_keyboard(report_keyboard_t *report);
|
||||
static void send_mouse(report_mouse_t *report);
|
||||
static void send_extra(uint8_t report_id, uint16_t data);
|
||||
static void send_extra(report_extra_t *report);
|
||||
host_driver_t lufa_driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||
|
||||
#ifdef VIRTSER_ENABLE
|
||||
|
@ -663,11 +663,9 @@ static void send_report(void *report, size_t size) {
|
|||
*
|
||||
* FIXME: Needs doc
|
||||
*/
|
||||
static void send_extra(uint8_t report_id, uint16_t data) {
|
||||
static void send_extra(report_extra_t *report) {
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
static report_extra_t r;
|
||||
r = (report_extra_t){.report_id = report_id, .usage = data};
|
||||
send_report(&r, sizeof(r));
|
||||
send_report(report, sizeof(report_extra_t));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -224,7 +224,7 @@ void console_task(void) {
|
|||
static uint8_t keyboard_leds(void);
|
||||
static void send_keyboard(report_keyboard_t *report);
|
||||
static void send_mouse(report_mouse_t *report);
|
||||
static void send_extra(uint8_t report_id, uint16_t data);
|
||||
static void send_extra(report_extra_t *report);
|
||||
|
||||
static host_driver_t driver = {keyboard_leds, send_keyboard, send_mouse, send_extra};
|
||||
|
||||
|
@ -267,18 +267,10 @@ static void send_mouse(report_mouse_t *report) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static void send_extra(uint8_t report_id, uint16_t data) {
|
||||
static void send_extra(report_extra_t *report) {
|
||||
#ifdef EXTRAKEY_ENABLE
|
||||
static uint8_t last_id = 0;
|
||||
static uint16_t last_data = 0;
|
||||
if ((report_id == last_id) && (data == last_data)) return;
|
||||
last_id = report_id;
|
||||
last_data = data;
|
||||
|
||||
static report_extra_t report;
|
||||
report = (report_extra_t){.report_id = report_id, .usage = data};
|
||||
if (usbInterruptIsReadyShared()) {
|
||||
usbSetInterruptShared((void *)&report, sizeof(report_extra_t));
|
||||
usbSetInterruptShared((void *)report, sizeof(report_extra_t));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue