Stefan Kerkmann 2 weeks ago
committed by GitHub
parent
commit
dd792f9434
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
5 changed files with 118 additions and 110 deletions
  1. +7
    -7
      tmk_core/protocol/chibios/usb_driver.c
  2. +5
    -5
      tmk_core/protocol/chibios/usb_driver.h
  3. +19
    -19
      tmk_core/protocol/chibios/usb_endpoints.c
  4. +49
    -41
      tmk_core/protocol/chibios/usb_report_handling.c
  5. +38
    -38
      tmk_core/protocol/chibios/usb_report_handling.h

+ 7
- 7
tmk_core/protocol/chibios/usb_driver.c View File

@ -124,8 +124,8 @@ void usb_endpoint_in_stop(usb_endpoint_in_t *endpoint) {
bqSuspendI(&endpoint->obqueue);
obqResetI(&endpoint->obqueue);
if (endpoint->report_storage != NULL) {
endpoint->report_storage->reset_report(endpoint->report_storage->reports);
if (endpoint->report_handler != NULL) {
endpoint->report_handler->reset_report(endpoint->report_handler->reports);
}
osalOsRescheduleS();
osalSysUnlock();
@ -147,8 +147,8 @@ void usb_endpoint_in_suspend_cb(usb_endpoint_in_t *endpoint) {
bqSuspendI(&endpoint->obqueue);
obqResetI(&endpoint->obqueue);
if (endpoint->report_storage != NULL) {
endpoint->report_storage->reset_report(endpoint->report_storage->reports);
if (endpoint->report_handler != NULL) {
endpoint->report_handler->reset_report(endpoint->report_handler->reports);
}
}
@ -186,7 +186,7 @@ void usb_endpoint_out_configure_cb(usb_endpoint_out_t *endpoint) {
void usb_endpoint_in_tx_complete_cb(USBDriver *usbp, usbep_t ep) {
usb_endpoint_in_t *endpoint = usbp->in_params[ep - 1U];
size_t n;
uint8_t * buffer;
uint8_t *buffer;
if (endpoint == NULL) {
return;
@ -201,9 +201,9 @@ void usb_endpoint_in_tx_complete_cb(USBDriver *usbp, usbep_t ep) {
if (!obqIsEmptyI(&endpoint->obqueue) && usbp->epc[ep]->in_state->txsize > 0U) {
/* Store the last send report in the endpoint to be retrieved by a
* GET_REPORT request or IDLE report handling. */
if (endpoint->report_storage != NULL) {
if (endpoint->report_handler != NULL) {
buffer = obqGetFullBufferI(&endpoint->obqueue, &n);
endpoint->report_storage->set_report(endpoint->report_storage->reports, buffer, n);
endpoint->report_handler->store_report(endpoint->report_handler->reports, buffer, n);
}
obqReleaseEmptyBufferI(&endpoint->obqueue);
}


+ 5
- 5
tmk_core/protocol/chibios/usb_driver.h View File

@ -33,9 +33,9 @@
* Given `USBv1/hal_usb_lld.h` marks the field as "not currently used" this code file
* makes the assumption this is safe to avoid littering with preprocessor directives.
*/
#define QMK_USB_ENDPOINT_IN(mode, ep_size, ep_num, _buffer_capacity, _usb_requests_cb, _report_storage) \
#define QMK_USB_ENDPOINT_IN(mode, ep_size, ep_num, _buffer_capacity, _usb_requests_cb, _report_handler) \
{ \
.usb_requests_cb = _usb_requests_cb, .report_storage = _report_storage, \
.usb_requests_cb = _usb_requests_cb, .report_handler = _report_handler, \
.ep_config = \
{ \
mode, /* EP Mode */ \
@ -84,9 +84,9 @@
#else
# define QMK_USB_ENDPOINT_IN_SHARED(mode, ep_size, ep_num, _buffer_capacity, _usb_requests_cb, _report_storage) \
# define QMK_USB_ENDPOINT_IN_SHARED(mode, ep_size, ep_num, _buffer_capacity, _usb_requests_cb, _report_handler) \
{ \
.usb_requests_cb = _usb_requests_cb, .is_shared = true, .report_storage = _report_storage, \
.usb_requests_cb = _usb_requests_cb, .is_shared = true, .report_handler = _report_handler, \
.ep_config = \
{ \
mode, /* EP Mode */ \
@ -165,7 +165,7 @@ typedef struct {
usb_endpoint_config_t config;
usbreqhandler_t usb_requests_cb;
bool timed_out;
usb_report_storage_t *report_storage;
usb_report_handler_t *report_handler;
} usb_endpoint_in_t;
typedef struct {


+ 19
- 19
tmk_core/protocol/chibios/usb_endpoints.c View File

@ -13,35 +13,35 @@ usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT] = {
// clang-format off
#if defined(SHARED_EP_ENABLE)
[USB_ENDPOINT_IN_SHARED] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, SHARED_EPSIZE, SHARED_IN_EPNUM, SHARED_IN_CAPACITY, NULL,
QMK_USB_REPORT_STORAGE(
QMK_USB_REPORT_HANDLER(
&usb_shared_get_report,
&usb_shared_set_report,
&usb_shared_store_report,
&usb_shared_reset_report,
&usb_shared_get_idle_rate,
&usb_shared_set_idle_rate,
&usb_shared_idle_timer_elapsed,
(REPORT_ID_COUNT + 1),
#if defined(KEYBOARD_SHARED_EP)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_KEYBOARD, sizeof(report_keyboard_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_KEYBOARD, report_keyboard_t),
#endif
#if defined(MOUSE_SHARED_EP)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_MOUSE, sizeof(report_mouse_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_MOUSE, report_mouse_t),
#endif
#if defined(EXTRAKEY_ENABLE)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_SYSTEM, sizeof(report_extra_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_CONSUMER, sizeof(report_extra_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_SYSTEM, report_extra_t),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_CONSUMER, report_extra_t),
#endif
#if defined(PROGRAMMABLE_BUTTON_ENABLE)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_PROGRAMMABLE_BUTTON, sizeof(report_programmable_button_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_PROGRAMMABLE_BUTTON, report_programmable_button_t),
#endif
#if defined(NKRO_ENABLE)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_NKRO, sizeof(report_nkro_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_NKRO, report_nkro_t),
#endif
#if defined(JOYSTICK_SHARED_EP)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_JOYSTICK, sizeof(report_joystick_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_JOYSTICK, report_joystick_t),
#endif
#if defined(DIGITIZER_SHARED_EP)
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_DIGITIZER, sizeof(report_digitizer_t)),
QMK_USB_REPORT_STROAGE_ENTRY(REPORT_ID_DIGITIZER, report_digitizer_t),
#endif
)
),
@ -49,34 +49,34 @@ usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT] = {
// clang-format on
#if !defined(KEYBOARD_SHARED_EP)
[USB_ENDPOINT_IN_KEYBOARD] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, KEYBOARD_EPSIZE, KEYBOARD_IN_EPNUM, KEYBOARD_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_keyboard_t))),
[USB_ENDPOINT_IN_KEYBOARD] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, KEYBOARD_EPSIZE, KEYBOARD_IN_EPNUM, KEYBOARD_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(report_keyboard_t)),
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
[USB_ENDPOINT_IN_MOUSE] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, MOUSE_EPSIZE, MOUSE_IN_EPNUM, MOUSE_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_mouse_t))),
[USB_ENDPOINT_IN_MOUSE] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, MOUSE_EPSIZE, MOUSE_IN_EPNUM, MOUSE_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(report_mouse_t)),
#endif
#if defined(JOYSTICK_ENABLE) && !defined(JOYSTICK_SHARED_EP)
[USB_ENDPOINT_IN_JOYSTICK] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, JOYSTICK_EPSIZE, JOYSTICK_IN_EPNUM, JOYSTICK_IN_CAPACITY, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_joystick_t))),
[USB_ENDPOINT_IN_JOYSTICK] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, JOYSTICK_EPSIZE, JOYSTICK_IN_EPNUM, JOYSTICK_IN_CAPACITY, QMK_USB_REPORT_HANDLER_DEFAULT(report_joystick_t)),
#endif
#if defined(DIGITIZER_ENABLE) && !defined(DIGITIZER_SHARED_EP)
[USB_ENDPOINT_IN_JOYSTICK] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, DIGITIZER_EPSIZE, DIGITIZER_IN_EPNUM, DIGITIZER_IN_CAPACITY, QMK_USB_REPORT_STORAGE_DEFAULT(sizeof(report_digitizer_t))),
[USB_ENDPOINT_IN_JOYSTICK] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, DIGITIZER_EPSIZE, DIGITIZER_IN_EPNUM, DIGITIZER_IN_CAPACITY, QMK_USB_REPORT_HANDLER_DEFAULT(report_digitizer_t)),
#endif
#if defined(CONSOLE_ENABLE)
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
[USB_ENDPOINT_IN_CONSOLE] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, CONSOLE_EPSIZE, CONSOLE_IN_EPNUM, CONSOLE_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(CONSOLE_EPSIZE)),
[USB_ENDPOINT_IN_CONSOLE] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, CONSOLE_EPSIZE, CONSOLE_IN_EPNUM, CONSOLE_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(uint8_t[CONSOLE_EPSIZE])),
# else
[USB_ENDPOINT_IN_CONSOLE] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, CONSOLE_EPSIZE, CONSOLE_IN_EPNUM, CONSOLE_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(CONSOLE_EPSIZE)),
[USB_ENDPOINT_IN_CONSOLE] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, CONSOLE_EPSIZE, CONSOLE_IN_EPNUM, CONSOLE_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(uint8_t[CONSOLE_EPSIZE])),
# endif
#endif
#if defined(RAW_ENABLE)
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
[USB_ENDPOINT_IN_RAW] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, RAW_EPSIZE, RAW_IN_EPNUM, RAW_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(RAW_EPSIZE)),
[USB_ENDPOINT_IN_RAW] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_INTR, RAW_EPSIZE, RAW_IN_EPNUM, RAW_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(uint8_t[RAW_EPSIZE])),
# else
[USB_ENDPOINT_IN_RAW] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, RAW_EPSIZE, RAW_IN_EPNUM, RAW_IN_CAPACITY, NULL, QMK_USB_REPORT_STORAGE_DEFAULT(RAW_EPSIZE)),
[USB_ENDPOINT_IN_RAW] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, RAW_EPSIZE, RAW_IN_EPNUM, RAW_IN_CAPACITY, NULL, QMK_USB_REPORT_HANDLER_DEFAULT(uint8_t[RAW_EPSIZE])),
# endif
#endif
@ -84,7 +84,7 @@ usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT] = {
# if defined(USB_ENDPOINTS_ARE_REORDERABLE)
[USB_ENDPOINT_IN_MIDI] = QMK_USB_ENDPOINT_IN_SHARED(USB_EP_MODE_TYPE_BULK, MIDI_STREAM_EPSIZE, MIDI_STREAM_IN_EPNUM, MIDI_STREAM_IN_CAPACITY, NULL, NULL),
# else
[USB_ENDPOINT_IN_MIDI] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_BULK, MIDI_STREAM_EPSIZE, MIDI_STREAM_IN_EPNUM, MIDI_STREAM_IN_CAPACITY, NULL, NULL),
[USB_ENDPOINT_IN_MIDI] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_BULK, MIDI_STREAM_EPSIZE, MIDI_STREAM_IN_EPNUM, MIDI_STREAM_IN_CAPACITY, NULL, NULL),
# endif
#endif


+ 49
- 41
tmk_core/protocol/chibios/usb_report_handling.c View File

@ -15,37 +15,37 @@
extern usb_endpoint_in_t usb_endpoints_in[USB_ENDPOINT_IN_COUNT];
extern usb_endpoint_in_lut_t usb_endpoint_interface_lut[TOTAL_INTERFACES];
void usb_set_report(usb_fs_report_t **reports, const uint8_t *data, size_t length) {
void usb_store_report(usb_report_t **reports, const uint8_t *data, size_t length) {
if (*reports == NULL) {
return;
}
(*reports)->last_report = chVTGetSystemTimeX();
(*reports)->length = length;
memcpy(&(*reports)->data, data, length);
memcpy((*reports)->data, data, length);
}
void usb_get_report(usb_fs_report_t **reports, uint8_t report_id, usb_fs_report_t *report) {
void usb_get_report(usb_report_t **reports, uint8_t report_id, usb_report_t *report) {
(void)report_id;
if (*reports == NULL) {
return;
}
report->length = (*reports)->length;
memcpy(&report->data, &(*reports)->data, report->length);
memcpy(report->data, (*reports)->data, report->length);
}
void usb_reset_report(usb_fs_report_t **reports) {
void usb_reset_report(usb_report_t **reports) {
if (*reports == NULL) {
return;
}
memset(&(*reports)->data, 0, (*reports)->length);
memset((*reports)->data, 0, (*reports)->length);
(*reports)->idle_rate = 0;
(*reports)->last_report = 0;
}
void usb_shared_set_report(usb_fs_report_t **reports, const uint8_t *data, size_t length) {
void usb_shared_store_report(usb_report_t **reports, const uint8_t *data, size_t length) {
uint8_t report_id = data[0];
if (report_id > REPORT_ID_COUNT || reports[report_id] == NULL) {
@ -54,24 +54,24 @@ void usb_shared_set_report(usb_fs_report_t **reports, const uint8_t *data, size_
reports[report_id]->last_report = chVTGetSystemTimeX();
reports[report_id]->length = length;
memcpy(&reports[report_id]->data, data, length);
memcpy(reports[report_id]->data, data, length);
}
void usb_shared_get_report(usb_fs_report_t **reports, uint8_t report_id, usb_fs_report_t *report) {
void usb_shared_get_report(usb_report_t **reports, uint8_t report_id, usb_report_t *report) {
if (report_id > REPORT_ID_COUNT || reports[report_id] == NULL) {
return;
}
report->length = reports[report_id]->length;
memcpy(&report->data, &reports[report_id]->data, report->length);
memcpy(report->data, reports[report_id]->data, report->length);
}
void usb_shared_reset_report(usb_fs_report_t **reports) {
void usb_shared_reset_report(usb_report_t **reports) {
for (int i = 0; i <= REPORT_ID_COUNT; i++) {
if (reports[i] == NULL) {
continue;
}
memset(&reports[i]->data, 0, reports[i]->length);
memset(reports[i]->data, 0, reports[i]->length);
reports[i]->idle_rate = 0;
reports[i]->last_report = 0;
}
@ -82,8 +82,6 @@ bool usb_get_report_cb(USBDriver *driver) {
uint8_t interface = setup->wIndex;
uint8_t report_id = setup->wValue.lbyte;
static usb_fs_report_t report;
if (!IS_VALID_INTERFACE(interface) || !IS_VALID_REPORT_ID(report_id)) {
return false;
}
@ -94,13 +92,19 @@ bool usb_get_report_cb(USBDriver *driver) {
return false;
}
usb_report_storage_t *report_storage = usb_endpoints_in[ep].report_storage;
usb_report_handler_t *report_handler = usb_endpoints_in[ep].report_handler;
if (report_storage == NULL) {
if (report_handler == NULL) {
return false;
}
report_storage->get_report(report_storage->reports, report_id, &report);
static _Alignas(4) uint8_t report_data[64];
static usb_report_t report;
// always reset the report struct, as it might point to a different report
report.data = (uint8_t *)report_data;
report.length = ARRAY_SIZE(report_data);
report_handler->get_report(report_handler->reports, report_id, &report);
usbSetupTransfer(driver, (uint8_t *)report.data, report.length, NULL);
@ -109,7 +113,7 @@ bool usb_get_report_cb(USBDriver *driver) {
static bool run_idle_task = false;
void usb_set_idle_rate(usb_fs_report_t **reports, uint8_t report_id, uint8_t idle_rate) {
void usb_set_idle_rate(usb_report_t **reports, uint8_t report_id, uint8_t idle_rate) {
(void)report_id;
if (*reports == NULL) {
@ -121,7 +125,7 @@ void usb_set_idle_rate(usb_fs_report_t **reports, uint8_t report_id, uint8_t idl
run_idle_task |= idle_rate != 0;
}
uint8_t usb_get_idle_rate(usb_fs_report_t **reports, uint8_t report_id) {
uint8_t usb_get_idle_rate(usb_report_t **reports, uint8_t report_id) {
(void)report_id;
if (*reports == NULL) {
@ -131,7 +135,7 @@ uint8_t usb_get_idle_rate(usb_fs_report_t **reports, uint8_t report_id) {
return (*reports)->idle_rate / 4;
}
bool usb_idle_timer_elapsed(usb_fs_report_t **reports, uint8_t report_id) {
bool usb_idle_timer_elapsed(usb_report_t **reports, uint8_t report_id) {
(void)report_id;
if (*reports == NULL) {
@ -150,7 +154,7 @@ bool usb_idle_timer_elapsed(usb_fs_report_t **reports, uint8_t report_id) {
return chTimeI2MS(chVTTimeElapsedSinceX(last_report)) >= idle_rate;
}
void usb_shared_set_idle_rate(usb_fs_report_t **reports, uint8_t report_id, uint8_t idle_rate) {
void usb_shared_set_idle_rate(usb_report_t **reports, uint8_t report_id, uint8_t idle_rate) {
// USB spec demands that a report_id of 0 would set the idle rate for all
// reports of that endpoint, but this can easily lead to resource
// exhaustion, therefore we deliberalty break the spec at this point.
@ -163,7 +167,7 @@ void usb_shared_set_idle_rate(usb_fs_report_t **reports, uint8_t report_id, uint
run_idle_task |= idle_rate != 0;
}
uint8_t usb_shared_get_idle_rate(usb_fs_report_t **reports, uint8_t report_id) {
uint8_t usb_shared_get_idle_rate(usb_report_t **reports, uint8_t report_id) {
if (report_id > REPORT_ID_COUNT || reports[report_id] == NULL) {
return 0;
}
@ -171,7 +175,7 @@ uint8_t usb_shared_get_idle_rate(usb_fs_report_t **reports, uint8_t report_id) {
return reports[report_id]->idle_rate / 4;
}
bool usb_shared_idle_timer_elapsed(usb_fs_report_t **reports, uint8_t report_id) {
bool usb_shared_idle_timer_elapsed(usb_report_t **reports, uint8_t report_id) {
if (report_id > REPORT_ID_COUNT || reports[report_id] == NULL) {
return false;
}
@ -193,13 +197,17 @@ void usb_idle_task(void) {
return;
}
static usb_fs_report_t report;
bool non_zero_idle_rate_found = false;
bool non_zero_idle_rate_found = false;
static _Alignas(4) uint8_t report_data[64];
static usb_report_t report;
// always reset the report struct, as it might point to a different report
report.data = (uint8_t *)report_data;
report.length = ARRAY_SIZE(report_data);
for (int ep = 0; ep < USB_ENDPOINT_IN_COUNT; ep++) {
usb_report_storage_t *report_storage = usb_endpoints_in[ep].report_storage;
usb_report_handler_t *report_handler = usb_endpoints_in[ep].report_handler;
if (report_storage == NULL) {
if (report_handler == NULL) {
continue;
}
@ -207,14 +215,14 @@ void usb_idle_task(void) {
if (ep == USB_ENDPOINT_IN_SHARED) {
for (int report_id = 1; report_id <= REPORT_ID_COUNT; report_id++) {
osalSysLock();
non_zero_idle_rate_found |= report_storage->get_idle(report_storage->reports, report_id) != 0;
non_zero_idle_rate_found |= report_handler->get_idle(report_handler->reports, report_id) != 0;
osalSysUnlock();
if (usb_endpoint_in_is_inactive(&usb_endpoints_in[ep]) && report_storage->idle_timer_elasped(report_storage->reports, report_id)) {
if (usb_endpoint_in_is_inactive(&usb_endpoints_in[ep]) && report_handler->idle_timer_elasped(report_handler->reports, report_id)) {
osalSysLock();
report_storage->get_report(report_storage->reports, report_id, &report);
report_handler->get_report(report_handler->reports, report_id, &report);
osalSysUnlock();
send_report(ep, &report.data, report.length);
send_report(ep, report.data, report.length);
}
}
continue;
@ -222,14 +230,14 @@ void usb_idle_task(void) {
#endif
osalSysLock();
non_zero_idle_rate_found |= report_storage->get_idle(report_storage->reports, 0) != 0;
non_zero_idle_rate_found |= report_handler->get_idle(report_handler->reports, 0) != 0;
osalSysUnlock();
if (usb_endpoint_in_is_inactive(&usb_endpoints_in[ep]) && report_storage->idle_timer_elasped(report_storage->reports, 0)) {
if (usb_endpoint_in_is_inactive(&usb_endpoints_in[ep]) && report_handler->idle_timer_elasped(report_handler->reports, 0)) {
osalSysLock();
report_storage->get_report(report_storage->reports, 0, &report);
report_handler->get_report(report_handler->reports, 0, &report);
osalSysUnlock();
send_report(ep, &report.data, report.length);
send_report(ep, report.data, report.length);
}
}
@ -253,13 +261,13 @@ bool usb_get_idle_cb(USBDriver *driver) {
return false;
}
usb_report_storage_t *report_storage = usb_endpoints_in[ep].report_storage;
usb_report_handler_t *report_handler = usb_endpoints_in[ep].report_handler;
if (report_storage == NULL) {
if (report_handler == NULL) {
return false;
}
idle_rate = report_storage->get_idle(report_storage->reports, report_id);
idle_rate = report_handler->get_idle(report_handler->reports, report_id);
usbSetupTransfer(driver, &idle_rate, 1, NULL);
@ -282,13 +290,13 @@ bool usb_set_idle_cb(USBDriver *driver) {
return false;
}
usb_report_storage_t *report_storage = usb_endpoints_in[ep].report_storage;
usb_report_handler_t *report_handler = usb_endpoints_in[ep].report_handler;
if (report_storage == NULL) {
if (report_handler == NULL) {
return false;
}
report_storage->set_idle(report_storage->reports, report_id, idle_rate);
report_handler->set_idle(report_handler->reports, report_id, idle_rate);
usbSetupTransfer(driver, NULL, 0, NULL);


+ 38
- 38
tmk_core/protocol/chibios/usb_report_handling.h View File

@ -12,66 +12,66 @@
typedef struct {
time_msecs_t idle_rate;
systime_t last_report;
uint8_t data[64];
size_t length;
} usb_fs_report_t;
uint8_t *data;
} usb_report_t;
typedef struct {
usb_fs_report_t **reports;
const void (*get_report)(usb_fs_report_t **, uint8_t, usb_fs_report_t *);
const void (*set_report)(usb_fs_report_t **, const uint8_t *, size_t);
const void (*reset_report)(usb_fs_report_t **);
const void (*set_idle)(usb_fs_report_t **, uint8_t, uint8_t);
const uint8_t (*get_idle)(usb_fs_report_t **, uint8_t);
const bool (*idle_timer_elasped)(usb_fs_report_t **, uint8_t);
} usb_report_storage_t;
#define QMK_USB_REPORT_STROAGE_ENTRY(_report_id, _report_size) [_report_id] = &((usb_fs_report_t){.data = {[0] = _report_id}, .length = _report_size})
#define QMK_USB_REPORT_STORAGE(_get_report, _set_report, _reset_report, _get_idle, _set_idle, _idle_timer_elasped, _report_count, _reports...) \
&((usb_report_storage_t){ \
.reports = (_Alignas(4) usb_fs_report_t *[_report_count]){_reports}, \
.get_report = _get_report, \
.set_report = _set_report, \
.reset_report = _reset_report, \
.get_idle = _get_idle, \
.set_idle = _set_idle, \
.idle_timer_elasped = _idle_timer_elasped, \
usb_report_t **reports;
const void (*get_report)(usb_report_t **, uint8_t, usb_report_t *);
const void (*store_report)(usb_report_t **, const uint8_t *, size_t);
const void (*reset_report)(usb_report_t **);
const void (*set_idle)(usb_report_t **, uint8_t, uint8_t);
const uint8_t (*get_idle)(usb_report_t **, uint8_t);
const bool (*idle_timer_elasped)(usb_report_t **, uint8_t);
} usb_report_handler_t;
#define QMK_USB_REPORT_STROAGE_ENTRY(_report_id, _report_type) [_report_id] = &((usb_report_t){.data = (_Alignas(4) uint8_t[sizeof(_report_type)]){[0] = _report_id}, .length = sizeof(_report_type)})
#define QMK_USB_REPORT_HANDLER(_get_report, _store_report, _reset_report, _get_idle, _set_idle, _idle_timer_elasped, _report_count, _reports...) \
&((usb_report_handler_t){ \
.reports = (_Alignas(4) usb_report_t *[_report_count]){_reports}, \
.get_report = _get_report, \
.store_report = _store_report, \
.reset_report = _reset_report, \
.get_idle = _get_idle, \
.set_idle = _set_idle, \
.idle_timer_elasped = _idle_timer_elasped, \
})
#define QMK_USB_REPORT_STORAGE_DEFAULT(_report_length) \
QMK_USB_REPORT_STORAGE(&usb_get_report, /* _get_report */ \
&usb_set_report, /* _set_report */ \
#define QMK_USB_REPORT_HANDLER_DEFAULT(_report_type) \
QMK_USB_REPORT_HANDLER(&usb_get_report, /* _get_report */ \
&usb_store_report, /* _store_report */ \
&usb_reset_report, /* _reset_report */ \
&usb_get_idle_rate, /* _get_idle */ \
&usb_set_idle_rate, /* _set_idle */ \
&usb_idle_timer_elapsed, /* _idle_timer_elasped */ \
1, /* _report_count */ \
QMK_USB_REPORT_STROAGE_ENTRY(0, _report_length))
QMK_USB_REPORT_STROAGE_ENTRY(0, _report_type))
// USB HID SET_REPORT and GET_REPORT handling functions
void usb_set_report(usb_fs_report_t **reports, const uint8_t *data, size_t length);
void usb_shared_set_report(usb_fs_report_t **reports, const uint8_t *data, size_t length);
void usb_store_report(usb_report_t **reports, const uint8_t *data, size_t length);
void usb_shared_store_report(usb_report_t **reports, const uint8_t *data, size_t length);
void usb_get_report(usb_fs_report_t **reports, uint8_t report_id, usb_fs_report_t *report);
void usb_shared_get_report(usb_fs_report_t **reports, uint8_t report_id, usb_fs_report_t *report);
void usb_get_report(usb_report_t **reports, uint8_t report_id, usb_report_t *report);
void usb_shared_get_report(usb_report_t **reports, uint8_t report_id, usb_report_t *report);
void usb_reset_report(usb_fs_report_t **reports);
void usb_shared_reset_report(usb_fs_report_t **reports);
void usb_reset_report(usb_report_t **reports);
void usb_shared_reset_report(usb_report_t **reports);
bool usb_get_report_cb(USBDriver *driver);
// USB HID SET_IDLE and GET_IDLE handling functions
void usb_idle_task(void);
void usb_set_idle_rate(usb_fs_report_t **timers, uint8_t report_id, uint8_t idle_rate);
void usb_shared_set_idle_rate(usb_fs_report_t **timers, uint8_t report_id, uint8_t idle_rate);
void usb_set_idle_rate(usb_report_t **timers, uint8_t report_id, uint8_t idle_rate);
void usb_shared_set_idle_rate(usb_report_t **timers, uint8_t report_id, uint8_t idle_rate);
uint8_t usb_get_idle_rate(usb_fs_report_t **timers, uint8_t report_id);
uint8_t usb_shared_get_idle_rate(usb_fs_report_t **timers, uint8_t report_id);
uint8_t usb_get_idle_rate(usb_report_t **timers, uint8_t report_id);
uint8_t usb_shared_get_idle_rate(usb_report_t **timers, uint8_t report_id);
bool usb_idle_timer_elapsed(usb_fs_report_t **timers, uint8_t report_id);
bool usb_shared_idle_timer_elapsed(usb_fs_report_t **timers, uint8_t report_id);
bool usb_idle_timer_elapsed(usb_report_t **timers, uint8_t report_id);
bool usb_shared_idle_timer_elapsed(usb_report_t **timers, uint8_t report_id);
bool usb_get_idle_cb(USBDriver *driver);
bool usb_set_idle_cb(USBDriver *driver);

Loading…
Cancel
Save