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
5 changes: 5 additions & 0 deletions common/usbx_device_classes/inc/ux_device_class_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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 @@ -331,6 +332,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
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,28 @@ UX_SLAVE_CLASS_HID *hid;

case UX_DEVICE_CLASS_HID_COMMAND_GET_PROTOCOL:

/* Send the protocol. */
/* 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);
}

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

/* 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);

break;

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* SPDX-License-Identifier: MIT
**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
Expand Down Expand Up @@ -166,6 +167,7 @@ UCHAR *buffer;
/* Store the callback function. */
hid -> ux_device_class_hid_callback = hid_parameter -> ux_device_class_hid_parameter_callback;
hid -> ux_device_class_hid_get_callback = hid_parameter -> ux_device_class_hid_parameter_get_callback;
hid -> ux_device_class_hid_set_protocol_callback = hid_parameter -> ux_device_class_hid_parameter_set_protocol_callback;

#if defined(UX_DEVICE_CLASS_HID_FLEXIBLE_EVENTS_QUEUE)

Expand Down
2 changes: 2 additions & 0 deletions common/usbx_host_classes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_get.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_set.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_idle_set_run.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_protocol_set.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_protocol_get.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_instance_clean.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_interrupt_endpoint_search.c
${CMAKE_CURRENT_LIST_DIR}/src/ux_host_class_hid_item_data_get.c
Expand Down
19 changes: 14 additions & 5 deletions common/usbx_host_classes/inc/ux_host_class_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/** */
/** USBX Component */
/** */
/** HID Class */
/** Host HID Class */
/** */
/**************************************************************************/
/**************************************************************************/
Expand Down Expand Up @@ -548,7 +548,7 @@ extern "C" {
#define UX_HOST_CLASS_HID_CONSUMER_ALTERNATE_AUDIO_DECREMENT 0x173
#define UX_HOST_CLASS_HID_CONSUMER_APPLICATION_LAUNCH_BUTTONS 0x174
#define UX_HOST_CLASS_HID_CONSUMER_AL_LAUNCH_BUTTON_CONFIGURATION 0x180
#define UX_HOST_CLASS_HID_CONSUMER_AL_PROGRAMMABLE_BUTTON 0x181
#define UX_HOST_CLASS_HID_CONSUMER_AL_PROGRAMMABLE_BUTTON 0x181
#define UX_HOST_CLASS_HID_CONSUMER_AL_CONSUMER_CONTROL_CONFIGURATION 0x182
#define UX_HOST_CLASS_HID_CONSUMER_AL_WORD_PROCESSOR 0x183
#define UX_HOST_CLASS_HID_CONSUMER_AL_TEXT_EDITOR 0x184
Expand Down Expand Up @@ -764,6 +764,10 @@ extern "C" {
#define UX_HOST_CLASS_HID_REPORT_TRANSFER_TIMEOUT 10000
#endif

/* HID protocol values. */
#define UX_HOST_CLASS_HID_PROTOCOL_BOOT 0x00
#define UX_HOST_CLASS_HID_PROTOCOL_REPORT 0x01

/* Define HID Class descriptor. */

typedef struct UX_HID_DESCRIPTOR_STRUCT
Expand Down Expand Up @@ -1077,7 +1081,8 @@ VOID _ux_host_class_hid_transfer_request_completed(UX_TRANSFER *transfer_requ
UINT _ux_host_class_hid_tasks_run(UX_HOST_CLASS *hid_class);
UINT _ux_host_class_hid_idle_set_run(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id);
UINT _ux_host_class_hid_report_set_run(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_CLIENT_REPORT *client_report);

UINT _ux_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol);
UINT _ux_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol);

UINT _uxe_host_class_hid_client_register(UCHAR *hid_client_name,
UINT (*hid_client_handler)(struct UX_HOST_CLASS_HID_CLIENT_COMMAND_STRUCT *));
Expand All @@ -1095,7 +1100,8 @@ UINT _uxe_host_class_hid_report_set(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID

UINT _uxe_host_class_hid_idle_set_run(UX_HOST_CLASS_HID *hid, USHORT idle_time, USHORT report_id);
UINT _uxe_host_class_hid_report_set_run(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS_HID_CLIENT_REPORT *client_report);

UINT _uxe_host_class_hid_protocol_set(UX_HOST_CLASS_HID *hid, USHORT protocol);
UINT _uxe_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol);

/* Define HID Class API prototypes. */

Expand All @@ -1122,6 +1128,8 @@ UINT _uxe_host_class_hid_report_set_run(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS
#define ux_host_class_hid_report_id_get _uxe_host_class_hid_report_id_get
#define ux_host_class_hid_report_get _uxe_host_class_hid_report_get
#define ux_host_class_hid_report_set _uxe_host_class_hid_report_set
#define ux_host_class_hid_protocol_set _uxe_host_class_hid_protocol_set
#define ux_host_class_hid_protocol_get _uxe_host_class_hid_protocol_get

#else

Expand All @@ -1137,6 +1145,8 @@ UINT _uxe_host_class_hid_report_set_run(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS
#define ux_host_class_hid_report_id_get _ux_host_class_hid_report_id_get
#define ux_host_class_hid_report_get _ux_host_class_hid_report_get
#define ux_host_class_hid_report_set _ux_host_class_hid_report_set
#define ux_host_class_hid_protocol_set _ux_host_class_hid_protocol_set
#define ux_host_class_hid_protocol_get _ux_host_class_hid_protocol_get

#endif

Expand All @@ -1148,4 +1158,3 @@ UINT _uxe_host_class_hid_report_set_run(UX_HOST_CLASS_HID *hid, UX_HOST_CLASS
#endif

#endif

142 changes: 142 additions & 0 deletions common/usbx_host_classes/src/ux_host_class_hid_protocol_get.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/***************************************************************************
* Copyright (c) 2025-present Eclipse ThreadX Contributors
*
* 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 */
/** */
/** Host HID Class */
/** */
/**************************************************************************/
/**************************************************************************/

/* Include necessary system files. */

#define UX_SOURCE_CODE

#include "ux_api.h"
#include "ux_host_class_hid.h"
#include "ux_host_stack.h"

/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_hid_protocol_get PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function performs a GET_PROTOCOL to the HID device to read */
/* current protocol (BOOT=0 or REPORT=1). */
/* */
/* INPUT */
/* */
/* hid Pointer to HID class */
/* protocol Destination for protocol */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLED BY */
/* */
/* Application */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/**************************************************************************/
UINT _ux_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol)
{

UX_ENDPOINT *control_endpoint;
UX_TRANSFER *transfer_request;
UINT status;

/* Ensure the instance is valid. */
if (_ux_host_stack_class_instance_verify(_ux_system_host_class_hid_name, (VOID *) hid) != UX_SUCCESS)
{

/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, hid, 0, 0, UX_TRACE_ERRORS, 0, 0)

#if defined(UX_HOST_STANDALONE)
hid -> ux_host_class_hid_status = UX_HOST_CLASS_INSTANCE_UNKNOWN;
#endif

return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
}

_ux_utility_memory_set(protocol, 0, sizeof(USHORT));

/* Get the default control endpoint transfer request pointer. */
control_endpoint = &hid -> ux_host_class_hid_device -> ux_device_control_endpoint;
transfer_request = &control_endpoint -> ux_endpoint_transfer_request;

#if !defined(UX_HOST_STANDALONE)

/* Protect thread reentry to this instance. */
status = _ux_host_semaphore_get(&hid -> ux_host_class_hid_semaphore, UX_WAIT_FOREVER);
if (status != UX_SUCCESS)
return(status);

#endif

/* Create a transfer request for the GET_PROTOCOL request. */
transfer_request -> ux_transfer_request_data_pointer = (UCHAR *) protocol;
transfer_request -> ux_transfer_request_requested_length = 1;
transfer_request -> ux_transfer_request_function = UX_HOST_CLASS_HID_GET_PROTOCOL;
transfer_request -> ux_transfer_request_type = UX_REQUEST_IN | UX_REQUEST_TYPE_CLASS | UX_REQUEST_TARGET_INTERFACE;
transfer_request -> ux_transfer_request_value = 0;
transfer_request -> ux_transfer_request_index = hid -> ux_host_class_hid_interface -> ux_interface_descriptor.bInterfaceNumber;

/* Send request to HCD layer. */
status = _ux_host_stack_transfer_request(transfer_request);

#if !defined(UX_HOST_STANDALONE)
/* Unprotect thread reentry to this instance. */
_ux_host_semaphore_put(&hid -> ux_host_class_hid_semaphore);
#endif

return(status);
}

/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _uxe_host_class_hid_protocol_get PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function checks errors in HID protocol get function call. */
/* */
/* INPUT */
/* */
/* hid Pointer to HID class */
/* protocol Destination for protocol */
/* */
/* OUTPUT */
/* */
/* Status */
/* */
/**************************************************************************/
UINT _uxe_host_class_hid_protocol_get(UX_HOST_CLASS_HID *hid, USHORT *protocol)
{
/* Sanity check. */
if (hid == UX_NULL || protocol == UX_NULL)
return(UX_INVALID_PARAMETER);

/* Invoke protocol get function. */
return(_ux_host_class_hid_protocol_get(hid, protocol));
}
Loading