Skip to content

Commit 1f6b9e9

Browse files
committed
add host hid api to set/get protocol
1 parent fa1d17a commit 1f6b9e9

File tree

10 files changed

+861
-177
lines changed

10 files changed

+861
-177
lines changed

common/usbx_device_classes/inc/ux_device_class_hid.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ typedef struct UX_SLAVE_CLASS_HID_STRUCT
249249
UINT ux_device_class_hid_state;
250250
UINT (*ux_device_class_hid_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
251251
UINT (*ux_device_class_hid_get_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
252+
VOID (*ux_device_class_hid_set_protocol_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, ULONG protocol);
252253
VOID (*ux_slave_class_hid_instance_activate)(VOID *);
253254
VOID (*ux_slave_class_hid_instance_deactivate)(VOID *);
254255
UCHAR *ux_device_class_hid_report_address;
@@ -365,6 +366,10 @@ typedef struct UX_SLAVE_CLASS_HID_PARAMETER_STRUCT
365366
ULONG ux_device_class_hid_parameter_report_length;
366367
UINT (*ux_device_class_hid_parameter_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
367368
UINT (*ux_device_class_hid_parameter_get_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
369+
370+
/* Optional callback invoked when protocol changes (boot/report). */
371+
VOID (*ux_device_class_hid_parameter_set_protocol_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, ULONG protocol);
372+
368373
#if defined(UX_DEVICE_CLASS_HID_FLEXIBLE_EVENTS_QUEUE)
369374
ULONG ux_device_class_hid_parameter_event_max_number;
370375
ULONG ux_device_class_hid_parameter_event_max_length;

common/usbx_device_classes/src/ux_device_class_hid_control_request.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,42 @@ UX_SLAVE_CLASS_HID *hid;
205205

206206
case UX_DEVICE_CLASS_HID_COMMAND_GET_PROTOCOL:
207207

208-
/* Send the protocol. */
208+
/* Only boot subclass devices should respond to GET_PROTOCOL. */
209+
if ((hid->ux_slave_class_hid_interface == UX_NULL) ||
210+
(hid->ux_slave_class_hid_interface->ux_slave_interface_descriptor.bInterfaceSubClass != 0x01))
211+
{
212+
return (UX_ERROR);
213+
}
214+
215+
/* Send the protocol to host. */
209216
*transfer_request -> ux_slave_transfer_request_data_pointer = (UCHAR)hid -> ux_device_class_hid_protocol;
210217
_ux_device_stack_transfer_request(transfer_request, 1, request_length);
211218
break;
212219

213220
case UX_DEVICE_CLASS_HID_COMMAND_SET_PROTOCOL:
214221

222+
/* Check protocol must be 0 (Boot) or 1 (Report). */
223+
if ((request_value != UX_DEVICE_CLASS_HID_PROTOCOL_BOOT) &&
224+
(request_value != UX_DEVICE_CLASS_HID_PROTOCOL_REPORT))
225+
{
226+
/* Invalid value: not handled. */
227+
return (UX_ERROR);
228+
}
229+
230+
/* Only boot subclass devices should respond to SET_PROTOCOL. */
231+
if ((hid->ux_slave_class_hid_interface == UX_NULL) ||
232+
(hid->ux_slave_class_hid_interface->ux_slave_interface_descriptor.bInterfaceSubClass != 0x01))
233+
{
234+
return (UX_ERROR);
235+
}
236+
215237
/* Accept the protocol. */
216238
hid -> ux_device_class_hid_protocol = request_value;
239+
240+
/* If there is a callback defined by the application, send the protocol to it. */
241+
if (hid -> ux_device_class_hid_set_protocol_callback != UX_NULL)
242+
hid -> ux_device_class_hid_set_protocol_callback(hid, request_value);
243+
217244
break;
218245

219246
default:
@@ -225,4 +252,3 @@ UX_SLAVE_CLASS_HID *hid;
225252
/* It's handled. */
226253
return(UX_SUCCESS);
227254
}
228-

common/usbx_device_classes/src/ux_device_class_hid_initialize.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* SPDX-License-Identifier: MIT
99
**************************************************************************/
1010

11+
1112
/**************************************************************************/
1213
/**************************************************************************/
1314
/** */
@@ -196,6 +197,7 @@ UCHAR *buffer;
196197
/* Store the callback function. */
197198
hid -> ux_device_class_hid_callback = hid_parameter -> ux_device_class_hid_parameter_callback;
198199
hid -> ux_device_class_hid_get_callback = hid_parameter -> ux_device_class_hid_parameter_get_callback;
200+
hid -> ux_device_class_hid_set_protocol_callback = hid_parameter -> ux_device_class_hid_parameter_set_protocol_callback;
199201

200202
#if defined(UX_DEVICE_CLASS_HID_FLEXIBLE_EVENTS_QUEUE)
201203

common/usbx_host_classes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ target_sources(${PROJECT_NAME} PRIVATE
9393
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_get.c
9494
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_set.c
9595
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_set_run.c
96+
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_protocol_set.c
97+
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_protocol_get.c
9698
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_instance_clean.c
9799
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_interrupt_endpoint_search.c
98100
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_item_data_get.c

0 commit comments

Comments
 (0)