Skip to content

Commit

Permalink
[MERGE][Core] ChibiOS: variable sized reports in USB Report Storage (…
Browse files Browse the repository at this point in the history
…23388)
  • Loading branch information
drashna committed Oct 25, 2024
1 parent 09e08bd commit 47233e0
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 110 deletions.
14 changes: 7 additions & 7 deletions tmk_core/protocol/chibios/usb_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions tmk_core/protocol/chibios/usb_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ \
Expand Down Expand Up @@ -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 */ \
Expand Down Expand Up @@ -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 {
Expand Down
38 changes: 19 additions & 19 deletions tmk_core/protocol/chibios/usb_endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,70 +13,70 @@ 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
)
),
#endif
// 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, NULL, 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_DIGITIZER] = QMK_USB_ENDPOINT_IN(USB_EP_MODE_TYPE_INTR, DIGITIZER_EPSIZE, DIGITIZER_IN_EPNUM, DIGITIZER_IN_CAPACITY, NULL, 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

Expand All @@ -92,7 +92,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

Expand Down
Loading

0 comments on commit 47233e0

Please sign in to comment.