Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions common/usbx_device_classes/inc/ux_device_class_hid.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
*
* SPDX-License-Identifier: MIT
**************************************************************************/

Expand Down Expand Up @@ -249,6 +249,7 @@ typedef struct UX_SLAVE_CLASS_HID_STRUCT
UINT ux_device_class_hid_state;
UINT (*ux_device_class_hid_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
UINT (*ux_device_class_hid_get_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
VOID (*ux_device_class_hid_set_protocol_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, ULONG protocol);
VOID (*ux_slave_class_hid_instance_activate)(VOID *);
VOID (*ux_slave_class_hid_instance_deactivate)(VOID *);
UCHAR *ux_device_class_hid_report_address;
Expand Down Expand Up @@ -365,6 +366,10 @@ typedef struct UX_SLAVE_CLASS_HID_PARAMETER_STRUCT
ULONG ux_device_class_hid_parameter_report_length;
UINT (*ux_device_class_hid_parameter_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);
UINT (*ux_device_class_hid_parameter_get_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, UX_SLAVE_CLASS_HID_EVENT *);

/* Optional callback invoked when protocol changes (boot/report). */
VOID (*ux_device_class_hid_parameter_set_protocol_callback)(struct UX_SLAVE_CLASS_HID_STRUCT *hid, ULONG protocol);

#if defined(UX_DEVICE_CLASS_HID_FLEXIBLE_EVENTS_QUEUE)
ULONG ux_device_class_hid_parameter_event_max_number;
ULONG ux_device_class_hid_parameter_event_max_length;
Expand Down
105 changes: 66 additions & 39 deletions common/usbx_device_classes/src/ux_device_class_hid_control_request.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
*
* SPDX-License-Identifier: MIT
**************************************************************************/

/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** USBX Component */
/** */
/** Device HID Class */
/** */
Expand All @@ -28,44 +28,44 @@
#include "ux_device_stack.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_hid_control_request PORTABLE C */
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_hid_control_request PORTABLE C */
/* 6.1.12 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function manages the based sent by the host on the control */
/* endpoints with a CLASS or VENDOR SPECIFIC type. */
/* */
/* INPUT */
/* */
/* hid Pointer to hid class */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _ux_device_stack_transfer_request Transfer request */
/* */
/* This function manages the based sent by the host on the control */
/* endpoints with a CLASS or VENDOR SPECIFIC type. */
/* */
/* INPUT */
/* */
/* hid Pointer to hid class */
/* */
/* OUTPUT */
/* */
/* None */
/* */
/* CALLS */
/* */
/* _ux_device_stack_transfer_request Transfer request */
/* _ux_device_class_hid_report_get Process Get_Report request */
/* _ux_device_class_hid_report_set Process Set_Report request */
/* _ux_device_class_hid_descriptor_send Send requested descriptor */
/* */
/* CALLED BY */
/* */
/* */
/* CALLED BY */
/* */
/* HID Class */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* prefixed UX to MS_TO_TICK, */
Expand Down Expand Up @@ -119,10 +119,10 @@ UX_SLAVE_CLASS_HID *hid;

/* Duration - upper byte of wValue. */
duration = *(transfer_request -> ux_slave_transfer_request_setup + UX_SETUP_VALUE + 1);

/* Get the class container. */
class_ptr = command -> ux_slave_class_command_class_ptr;

/* Get the storage instance from this class container. */
hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance;

Expand All @@ -149,8 +149,8 @@ UX_SLAVE_CLASS_HID *hid;

/* Send the requested descriptor to the host. */
_ux_device_class_hid_descriptor_send(hid, request_value, request_index, request_length);
break;
break;

case UX_DEVICE_CLASS_HID_COMMAND_GET_IDLE:
case UX_DEVICE_CLASS_HID_COMMAND_SET_IDLE:

Expand Down Expand Up @@ -204,15 +204,43 @@ UX_SLAVE_CLASS_HID *hid;

case UX_DEVICE_CLASS_HID_COMMAND_GET_PROTOCOL:

/* Send the protocol. */
/* Only boot subclass devices should respond to GET_PROTOCOL. */
if ((hid->ux_slave_class_hid_interface == UX_NULL) ||
(hid->ux_slave_class_hid_interface->ux_slave_interface_descriptor.bInterfaceSubClass != 0x01))
{
return (UX_ERROR);
}

/* Send the protocol to host. */
*transfer_request -> ux_slave_transfer_request_data_pointer = (UCHAR)hid -> ux_device_class_hid_protocol;
_ux_device_stack_transfer_request(transfer_request, 1, request_length);
break;

case UX_DEVICE_CLASS_HID_COMMAND_SET_PROTOCOL:

/* Check protocol must be 0 (Boot) or 1 (Report). */
if ((request_value != UX_DEVICE_CLASS_HID_PROTOCOL_BOOT) &&
(request_value != UX_DEVICE_CLASS_HID_PROTOCOL_REPORT))
{
/* Invalid value: not handled. */
return (UX_ERROR);
}

/* Only boot subclass devices are expected to handle SET_PROTOCOL. */
if ((hid->ux_slave_class_hid_interface == UX_NULL) ||
(hid->ux_slave_class_hid_interface->ux_slave_interface_descriptor.bInterfaceSubClass != 0x01))
{
/* Not a boot subclass: not handled. */
return (UX_ERROR);
}

/* If there is a callback defined by the application, send the protocol to it. */
if (hid -> ux_device_class_hid_set_protocol_callback != UX_NULL)
hid -> ux_device_class_hid_set_protocol_callback(hid, request_value);

/* Accept the protocol. */
hid -> ux_device_class_hid_protocol = request_value;

break;

default:
Expand All @@ -224,4 +252,3 @@ UX_SLAVE_CLASS_HID *hid;
/* It's handled. */
return(UX_SUCCESS);
}

Loading