From d562e7a0a6d29db105d5301edc34df6b63a6ba87 Mon Sep 17 00:00:00 2001 From: Haithem Rahmani Date: Thu, 20 Nov 2025 16:01:44 +0100 Subject: [PATCH 1/9] fix (host/storage): prevent stack overflow from infinite partition recursion - Add a partition entry counter (ux_host_class_storage_mounted_partitions_count) and a configurable maximum (UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT) to limit the number of partition entries processed during mounting. - Counter is incremented for every partition entry, and checked both before and during the partition parsing loop. - If the limit is exceeded, the function aborts and returns UX_HOST_CLASS_STORAGE_ERROR_MEDIA_NOT_READ. - This prevents stack overflow and infinite recursion in case of malformed or cyclic MBR/EBR partition tables. - Default partition entry limit set to 8 by default for safety and compatibility with typical devices. Fixes CVE-2025-55095 Signed-off-by: Haithem Rahmani --- .../inc/ux_host_class_storage.h | 2 + .../ux_host_class_storage_device_initialize.c | 6 ++ .../ux_host_class_storage_partition_read.c | 66 ++++++++++--------- ports/arm9/iar/inc/ux_port.h | 4 ++ ports/cortex_a5/gnu/inc/ux_port.h | 4 ++ ports/cortex_a5/iar/inc/ux_port.h | 4 ++ ports/cortex_a7/gnu/inc/ux_port.h | 4 ++ ports/cortex_a7/iar/inc/ux_port.h | 4 ++ ports/cortex_a8/gnu/inc/ux_port.h | 4 ++ ports/cortex_a8/iar/inc/ux_port.h | 4 ++ ports/cortex_a9/gnu/inc/ux_port.h | 4 ++ ports/cortex_a9/iar/inc/ux_port.h | 4 ++ ports/cortex_m4/gnu/inc/ux_port.h | 4 ++ ports/cortex_m4/iar/inc/ux_port.h | 4 ++ ports/cortex_m7/gnu/inc/ux_port.h | 4 ++ ports/cortex_m7/iar/inc/ux_port.h | 4 ++ ports/cortex_r4/gnu/inc/ux_port.h | 4 ++ ports/cortex_r4/iar/inc/ux_port.h | 4 ++ ports/cortex_r5/gnu/inc/ux_port.h | 4 ++ ports/cortex_r5/iar/inc/ux_port.h | 4 ++ ports/linux/gnu/inc/ux_port.h | 4 ++ 21 files changed, 115 insertions(+), 31 deletions(-) diff --git a/common/usbx_host_classes/inc/ux_host_class_storage.h b/common/usbx_host_classes/inc/ux_host_class_storage.h index 4c85a2ac..c54c8ed0 100644 --- a/common/usbx_host_classes/inc/ux_host_class_storage.h +++ b/common/usbx_host_classes/inc/ux_host_class_storage.h @@ -486,6 +486,8 @@ typedef struct UX_HOST_CLASS_STORAGE_STRUCT UINT ux_host_class_storage_lun_types[UX_MAX_HOST_LUN]; #if defined(UX_HOST_CLASS_STORAGE_NO_FILEX) ULONG ux_host_class_storage_last_sector_number; +#else + ULONG ux_host_class_storage_mounted_partitions_count; #endif ULONG ux_host_class_storage_sector_size; ULONG ux_host_class_storage_data_phase_length; diff --git a/common/usbx_host_classes/src/ux_host_class_storage_device_initialize.c b/common/usbx_host_classes/src/ux_host_class_storage_device_initialize.c index d1aa9c85..373a8a0e 100644 --- a/common/usbx_host_classes/src/ux_host_class_storage_device_initialize.c +++ b/common/usbx_host_classes/src/ux_host_class_storage_device_initialize.c @@ -166,6 +166,12 @@ UINT inst_index; case UX_HOST_CLASS_STORAGE_MEDIA_IOMEGA_CLICK: #if !defined(UX_HOST_CLASS_STORAGE_NO_FILEX) + /* the ux_host_class_storage_mounted_partitions_count is needed to avoid + infinite recursive loops when mounting extended partions. + The value is checked against the UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT + */ + storage -> ux_host_class_storage_mounted_partitions_count = 0; + /* Try to read the device media in search for a partition table or boot sector. We are at the root of the disk, so use sector 0 as the starting point. */ _ux_host_class_storage_media_mount(storage, 0); diff --git a/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c b/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c index d70e3a64..4f86b280 100644 --- a/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c +++ b/common/usbx_host_classes/src/ux_host_class_storage_partition_read.c @@ -27,8 +27,6 @@ #include "ux_api.h" #include "ux_host_class_storage.h" #include "ux_host_stack.h" - - /**************************************************************************/ /* */ /* FUNCTION RELEASE */ @@ -90,49 +88,55 @@ UINT _ux_host_class_storage_partition_read(UX_HOST_CLASS_STORAGE *storage, UCHA UINT status = UX_ERROR; UINT partition_index; + /* Check recursion/mount count before processing. */ + if (storage -> ux_host_class_storage_mounted_partitions_count > UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT) + { + return UX_HOST_CLASS_STORAGE_ERROR_MEDIA_NOT_READ; + } /* Point the sector buffer to the first partition entry. */ sector_memory += UX_HOST_CLASS_STORAGE_PARTITION_TABLE_START; - + /* There are 4 partitions in a partition table. */ for (partition_index = 0; partition_index < 4; partition_index++) { + /* Increment the mounted partition count for every entry processed. */ + storage -> ux_host_class_storage_mounted_partitions_count++; + + /* Check again after incrementing. */ + if (storage -> ux_host_class_storage_mounted_partitions_count > UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT) + { + /* Too many partition entries processed, abort to prevent stack overflow. */ + return UX_HOST_CLASS_STORAGE_ERROR_MEDIA_NOT_READ; + } /* Check if we recognize this partition entry. */ switch(*(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_TYPE)) { - - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_12: - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16: - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16L: - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16_LBA_MAPPED: - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_1: - case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_2: - case UX_HOST_CLASS_STORAGE_PARTITION_EXFAT: - - /* We have found a legal partition entry pointing to a potential boot sector. */ - status = _ux_host_class_storage_media_open(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE)); - break; - - case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED: - case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED_LBA_MAPPED: - - /* We have found an entry to an extended partition. We need to read that partition sector - and recursively mount all partitions found. */ - status = _ux_host_class_storage_media_mount(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE)); - break; - - default: - - /* We have found something which is not a DOS recognized partition, or an empty entry. - Ignore it and proceed with the rest. */ - break; + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_12: + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16: + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16L: + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_16_LBA_MAPPED: + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_1: + case UX_HOST_CLASS_STORAGE_PARTITION_FAT_32_2: + case UX_HOST_CLASS_STORAGE_PARTITION_EXFAT: + /* We have found a legal partition entry pointing to a potential boot sector. */ + status = _ux_host_class_storage_media_open(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE)); + break; + case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED: + case UX_HOST_CLASS_STORAGE_PARTITION_EXTENDED_LBA_MAPPED: + /* We have found an entry to an extended partition. We need to read that partition sector + and recursively mount all partitions found. */ + status = _ux_host_class_storage_media_mount(storage, sector + _ux_utility_long_get(sector_memory + UX_HOST_CLASS_STORAGE_PARTITION_SECTORS_BEFORE)); + break; + default: + /* We have found something which is not a DOS recognized partition, or an empty entry. + Ignore it and proceed with the rest. */ + break; } - /* Move to the next partition entry. */ sector_memory += UX_HOST_CLASS_STORAGE_PARTITION_TABLE_SIZE; } - /* Return completion status. */ return(status); #endif diff --git a/ports/arm9/iar/inc/ux_port.h b/ports/arm9/iar/inc/ux_port.h index 32be4e73..061cede9 100644 --- a/ports/arm9/iar/inc/ux_port.h +++ b/ports/arm9/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a5/gnu/inc/ux_port.h b/ports/cortex_a5/gnu/inc/ux_port.h index f5e62964..bf4435ca 100644 --- a/ports/cortex_a5/gnu/inc/ux_port.h +++ b/ports/cortex_a5/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a5/iar/inc/ux_port.h b/ports/cortex_a5/iar/inc/ux_port.h index f760c8ae..c03566e7 100644 --- a/ports/cortex_a5/iar/inc/ux_port.h +++ b/ports/cortex_a5/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a7/gnu/inc/ux_port.h b/ports/cortex_a7/gnu/inc/ux_port.h index f5094ba9..53016d53 100644 --- a/ports/cortex_a7/gnu/inc/ux_port.h +++ b/ports/cortex_a7/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a7/iar/inc/ux_port.h b/ports/cortex_a7/iar/inc/ux_port.h index c23ce61b..98d90893 100644 --- a/ports/cortex_a7/iar/inc/ux_port.h +++ b/ports/cortex_a7/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a8/gnu/inc/ux_port.h b/ports/cortex_a8/gnu/inc/ux_port.h index d9e90b56..de0b53f7 100644 --- a/ports/cortex_a8/gnu/inc/ux_port.h +++ b/ports/cortex_a8/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a8/iar/inc/ux_port.h b/ports/cortex_a8/iar/inc/ux_port.h index dbce55ca..5e580f69 100644 --- a/ports/cortex_a8/iar/inc/ux_port.h +++ b/ports/cortex_a8/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a9/gnu/inc/ux_port.h b/ports/cortex_a9/gnu/inc/ux_port.h index 3294109d..4515b3be 100644 --- a/ports/cortex_a9/gnu/inc/ux_port.h +++ b/ports/cortex_a9/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_a9/iar/inc/ux_port.h b/ports/cortex_a9/iar/inc/ux_port.h index 4b5b6e3f..5c9e2f2b 100644 --- a/ports/cortex_a9/iar/inc/ux_port.h +++ b/ports/cortex_a9/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_m4/gnu/inc/ux_port.h b/ports/cortex_m4/gnu/inc/ux_port.h index 4cdc0255..199f01db 100644 --- a/ports/cortex_m4/gnu/inc/ux_port.h +++ b/ports/cortex_m4/gnu/inc/ux_port.h @@ -206,6 +206,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_m4/iar/inc/ux_port.h b/ports/cortex_m4/iar/inc/ux_port.h index b3a7b6fb..4554a1b3 100644 --- a/ports/cortex_m4/iar/inc/ux_port.h +++ b/ports/cortex_m4/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_m7/gnu/inc/ux_port.h b/ports/cortex_m7/gnu/inc/ux_port.h index b71a2197..badf4446 100644 --- a/ports/cortex_m7/gnu/inc/ux_port.h +++ b/ports/cortex_m7/gnu/inc/ux_port.h @@ -206,6 +206,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_m7/iar/inc/ux_port.h b/ports/cortex_m7/iar/inc/ux_port.h index d2ac860d..6c36c827 100644 --- a/ports/cortex_m7/iar/inc/ux_port.h +++ b/ports/cortex_m7/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_r4/gnu/inc/ux_port.h b/ports/cortex_r4/gnu/inc/ux_port.h index b1497c63..47b999ad 100644 --- a/ports/cortex_r4/gnu/inc/ux_port.h +++ b/ports/cortex_r4/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_r4/iar/inc/ux_port.h b/ports/cortex_r4/iar/inc/ux_port.h index b512ba5a..6b18f7bb 100644 --- a/ports/cortex_r4/iar/inc/ux_port.h +++ b/ports/cortex_r4/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_r5/gnu/inc/ux_port.h b/ports/cortex_r5/gnu/inc/ux_port.h index 352b1914..19385d55 100644 --- a/ports/cortex_r5/gnu/inc/ux_port.h +++ b/ports/cortex_r5/gnu/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/cortex_r5/iar/inc/ux_port.h b/ports/cortex_r5/iar/inc/ux_port.h index 483c7456..29b76197 100644 --- a/ports/cortex_r5/iar/inc/ux_port.h +++ b/ports/cortex_r5/iar/inc/ux_port.h @@ -204,6 +204,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif diff --git a/ports/linux/gnu/inc/ux_port.h b/ports/linux/gnu/inc/ux_port.h index 25d3bc30..fe455cfb 100644 --- a/ports/linux/gnu/inc/ux_port.h +++ b/ports/linux/gnu/inc/ux_port.h @@ -210,6 +210,10 @@ typedef LONG SLONG; #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 #endif +#ifndef UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT +#define UX_HOST_CLASS_STORAGE_MAX_PARTITIONS_COUNT 8 +#endif + #ifndef UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH #define UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH 256 #endif From 474cc4636954788b74a8d8dd80f5befaed935547 Mon Sep 17 00:00:00 2001 From: MAY Date: Sat, 15 Nov 2025 01:41:22 +0100 Subject: [PATCH 2/9] add demo usbx device hid mouse rtos and standalone --- samples/demo_device_hid_mouse_rtos.c | 733 +++++++++++++++++++++ samples/demo_device_hid_mouse_standalone.c | 718 ++++++++++++++++++++ 2 files changed, 1451 insertions(+) create mode 100644 samples/demo_device_hid_mouse_rtos.c create mode 100644 samples/demo_device_hid_mouse_standalone.c diff --git a/samples/demo_device_hid_mouse_rtos.c b/samples/demo_device_hid_mouse_rtos.c new file mode 100644 index 00000000..d9a33ecb --- /dev/null +++ b/samples/demo_device_hid_mouse_rtos.c @@ -0,0 +1,733 @@ +/*************************************************************************** + * 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 + **************************************************************************/ + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** Overview */ +/** */ +/** This example works as a USB HID device. It will appear as a USB */ +/** mouse device on PC. This application demo is running in rtos */ +/** mode. */ +/** */ +/** Note */ +/** */ +/** This demonstration is not optimized, to optimize application user */ +/** should configure related class flag in ux_user.h and adjust */ +/** DEMO_STACK_SIZE and UX_DEVICE_MEMORY_STACK_SIZE */ +/** */ +/** */ +/** AUTHOR */ +/** */ +/** Mohamed AYED */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#include "tx_api.h" +#include "ux_api.h" +#include "ux_device_class_hid.h" + +/* if defined mouse with absolute positioning is a type of USB HID mouse that reports its position using + absolute coordinates rather than relative movement deltas. This is common in touch devices, graphics tablets, + and some remote control devices, where the report indicates an (X, Y) position within a defined logical range, + not just movement increments.*/ +/* #define UX_DEMO_MOUSE_ABSOLUTE */ + +/* Defined the mouse will act as boot device. */ +#define DEMO_HID_BOOT_DEVICE + +/**************************************************/ +/** Define constants */ +/**************************************************/ +#define DEMO_STACK_SIZE 4*1024 +#define UX_DEVICE_MEMORY_STACK_SIZE 7*1024 + +#define UX_DEMO_HID_DEVICE_VID 0x090A +#define UX_DEMO_HID_DEVICE_PID 0x4036 + +#define UX_DEMO_MAX_EP0_SIZE 0x40U +#define UX_DEMO_HID_CONFIG_DESC_SIZE 0x22U +#define UX_DEMO_BCD_USB 0x0200 +#define UX_DEMO_BCD_HID 0x0110 + +#define UX_DEMO_HID_ENDPOINT_SIZE 0x08 +#define UX_DEMO_HID_ENDPOINT_ADDRESS 0x81 +#define UX_DEMO_HID_ENDPOINT_BINTERVAL 0x08 + +#ifdef DEMO_HID_BOOT_DEVICE +#define UX_DEMO_HID_SUBCLASS 0x01 +#else /* DEMO_HID_BOOT_DEVICE */ +#define UX_DEMO_HID_SUBCLASS 0x00 +#endif + +#ifdef UX_DEMO_MOUSE_ABSOLUTE +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE 350 +#else /* UX_DEMO_MOUSE_ABSOLUTE */ +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE 3 +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE_N 100 +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +#define UX_MOUSE_CURSOR_MOVE_RIGHT 0x00 +#define UX_MOUSE_CURSOR_MOVE_DOWN 0x01 +#define UX_MOUSE_CURSOR_MOVE_LEFT 0x02 +#define UX_MOUSE_CURSOR_MOVE_UP 0x03 + +/**************************************************/ +/** usbx device hid demo callbacks */ +/**************************************************/ +VOID ux_demo_device_hid_instance_activate(VOID *hid_instance); +VOID ux_demo_device_hid_instance_deactivate(VOID *hid_instance); +UINT ux_demo_device_hid_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event); +UINT ux_demo_device_hid_get_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event); + +/**************************************************/ +/** usbx application initialization with RTOS */ +/**************************************************/ +VOID tx_application_define(VOID *first_unused_memory); + +/**************************************************/ +/** usbx device hid demo thread */ +/**************************************************/ +VOID ux_demo_device_hid_thread_entry(ULONG thread_input); + +/**************************************************/ +/** usbx device hid demo mouse */ +/**************************************************/ +UINT ux_demo_hid_mouse_buttons(UX_SLAVE_CLASS_HID *device_hid); +UINT ux_demo_hid_mouse_scroll_wheel(UX_SLAVE_CLASS_HID *device_hid); +#ifndef UX_DEMO_MOUSE_ABSOLUTE +UINT ux_demo_hid_mouse_cursor_move(UX_SLAVE_CLASS_HID *device_hid); +#else +UINT ux_demo_hid_mouse_absolute_cursor_move(UX_SLAVE_CLASS_HID *device_hid); +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +/**************************************************/ +/** usbx callback error */ +/**************************************************/ +VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code); + +#ifndef EXTERNAL_MAIN +extern int board_setup(void); +#endif /* EXTERNAL_MAIN */ +extern int usb_device_dcd_initialize(void *param); + +/**************************************************/ +/** usbx device hid mouse instance */ +/**************************************************/ +UX_SLAVE_CLASS_HID *hid_mouse; + +/**************************************************/ +/** thread object */ +/**************************************************/ +static TX_THREAD ux_hid_thread; + +/**************************************************/ +/** HID Report descriptor */ +/**************************************************/ +UCHAR hid_mouse_report[] = { + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + + /* Pointer and Physical are required by Apple Recovery */ + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + + /* 3 Buttons */ + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x03, // REPORT_COUNT (3) -> 3 buttons + 0x81, 0x02, // INPUT (Data, Variable, Absolute) -> Buttons + + 0x75, 0x05, // REPORT_SIZE (5) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Constant, Variable, Absolute) -> Padding bits + + /* X, Y */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) +#ifdef UX_DEMO_MOUSE_ABSOLUTE + 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xFF, 0x7F, // LOGICAL_MAXIMUM (32767) (0x7FFF) + 0x75, 0x10, // REPORT_SIZE (16) (2 bytes per axis) + 0x95, 0x02, // REPORT_COUNT (2) -> X, Y position + 0x81, 0x02, // INPUT (Data, Variable, Absolute) -> Absolute X, Y position +#else /* UX_DEMO_MOUSE_ABSOLUTE */ + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) (1 bytes per axis) + 0x95, 0x02, // REPORT_COUNT (2) -> X, Y movement + 0x81, 0x06, // INPUT (Data, Variable, Relative) -> X, Y are relative +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + + /* Wheel */ + 0x09, 0x38, // USAGE (Mouse Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) -> Wheel movement + 0x81, 0x06, // INPUT (Data, Variable, Relative) -> Wheel + + /* End */ + 0xC0, // END_COLLECTION + 0xC0 // END_COLLECTION +}; + +#define UX_HID_MOUSE_REPORT_LENGTH (sizeof(hid_mouse_report)/sizeof(hid_mouse_report[0])) + +#define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(ux_demo_device_framework_full_speed) + +UCHAR ux_demo_device_framework_full_speed[] = { + /* Device descriptor */ + 0x12, /* bLength */ + 0x01, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + UX_W0(UX_DEMO_HID_DEVICE_VID), UX_W1(UX_DEMO_HID_DEVICE_VID), /* idVendor : ... */ + UX_W0(UX_DEMO_HID_DEVICE_PID), UX_W1(UX_DEMO_HID_DEVICE_PID), /* idProduct */ + 0x00, 0x00, /* bcdDevice */ + 0x01, /* iManufacturer */ + 0x02, /* iProduct */ + 0x03, /* iSerialNumber */ + 0x01, /* bNumConfigurations */ + + /* Configuration Descriptor, total 34 */ + 0x09, /* bLength */ + 0x02, /* bDescriptorType */ + UX_W0(UX_DEMO_HID_CONFIG_DESC_SIZE), /* wTotalLength */ + UX_W1(UX_DEMO_HID_CONFIG_DESC_SIZE), + 0x01, /* bNumInterfaces */ + 0x01, /* bConfigurationValue */ + 0x04, /* iConfiguration */ + 0xC0, /* bmAttributes */ + /* D6 : 0x1 : Self-powered */ + /* D5, Remote Wakeup : 0x0 : Not supported */ + 0x32, /* bMaxPower : 50 : 100mA */ + + /* Interface descriptor */ + 0x09, /* bLength */ + 0x04, /* bDescriptorType */ + 0x00, /* bInterfaceNumber */ + 0x00, /* bAlternateSetting */ + 0x01, /* bNumEndpoints */ + 0x03, /* bInterfaceClass : 0x03 : HID */ + UX_DEMO_HID_SUBCLASS, /* bInterfaceSubClass : ... : Boot/non-boot Subclass */ + 0x02, /* bInterfaceProtocol : 0x00 : Undefined */ + 0x06, /* iInterface */ + + /* HID Descriptor */ + 0x09, /* bLength : 9 */ + 0x21, /* bDescriptorType : 0x21 : HID descriptor */ + 0x10, 0x01, /* bcdHID : 0x0110 */ + 0x21, /* bCountryCode : 33 : US */ + 0x01, /* bNumDescriptors */ + 0x22, /* bReportDescriptorType1 : 0x22 : Report descriptor */ + UX_W0(UX_HID_MOUSE_REPORT_LENGTH), /* wDescriptorLength1 */ + UX_W1(UX_HID_MOUSE_REPORT_LENGTH), + + /* Endpoint Descriptor */ + 0x07, /* bLength */ + 0x05, /* bDescriptorType */ + UX_DEMO_HID_ENDPOINT_ADDRESS, /* bEndpointAddress */ + /* D7, Direction : 0x01 */ + /* D3..0, Endpoint number : 2 */ + 0x03, /* bmAttributes */ + /* D1..0, Transfer Type : 0x3 : Interrupt */ + /* D3..2, Synchronization Type : 0x0 : No Synchronization */ + /* D5..4, Usage Type : 0x0 : Data endpoint */ + UX_W0(UX_DEMO_HID_ENDPOINT_SIZE), /* wMaxPacketSize */ + UX_W1(UX_DEMO_HID_ENDPOINT_SIZE), /* D10..0, Max Packet Size */ + /* D12..11, Additional transactions : 0x00 */ + UX_DEMO_HID_ENDPOINT_BINTERVAL, /* bInterval : 8 : 8ms / x128 (FS 128ms/HS 16ms) */ +}; + +#define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(ux_demo_device_framework_high_speed) +UCHAR ux_demo_device_framework_high_speed[] = { + /* Device descriptor */ + 0x12, /* bLength */ + 0x01, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + UX_W0(UX_DEMO_HID_DEVICE_VID), UX_W1(UX_DEMO_HID_DEVICE_VID), /* idVendor : ... */ + UX_W0(UX_DEMO_HID_DEVICE_PID), UX_W1(UX_DEMO_HID_DEVICE_PID), /* idProduct */ + 0x01, 0x00, /* bcdDevice */ + 0x01, /* iManufacturer */ + 0x02, /* iProduct */ + 0x03, /* iSerialNumber */ + 0x01, /* bNumConfigurations */ + + /* Device qualifier descriptor */ + 0x0A, /* bLength */ + 0x06, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + 0x01, /* bNumConfigurations */ + 0x00, /* bReserved */ + + /* Configuration descriptor */ + 0x09, /* bLength */ + 0x02, /* bDescriptorType */ + UX_W0(UX_DEMO_HID_CONFIG_DESC_SIZE), /* wTotalLength */ + UX_W1(UX_DEMO_HID_CONFIG_DESC_SIZE), + 0x01, /* bNumInterfaces */ + 0x01, /* bConfigurationValue */ + 0x05, /* iConfiguration */ + 0xC0, /* bmAttributes */ + /* D6 : 0x1 : Self-powered */ + /* D5, Remote Wakeup : 0x0 : Not supported */ + 0x19, /* bMaxPower : 50 : 100mA */ + + /* Interface descriptor */ + 0x09, /* bLength */ + 0x04, /* bDescriptorType */ + 0x00, /* bInterfaceNumber */ + 0x00, /* bAlternateSetting */ + 0x01, /* bNumEndpoints */ + 0x03, /* bInterfaceClass : 0x03 : HID */ + UX_DEMO_HID_SUBCLASS, /* bInterfaceSubClass : ... : Boot/non-boot Subclass */ + 0x02, /* bInterfaceProtocol : 0x00 : Undefined */ + 0x06, /* iInterface */ + + /* HID Descriptor */ + 0x09, /* bLength : 9 */ + 0x21, /* bDescriptorType : 0x21 : HID descriptor */ + UX_W0(UX_DEMO_BCD_HID), UX_W1(UX_DEMO_BCD_HID), /* bcdHID : 0x0110 */ + 0x21, /* bCountryCode : 33 : US */ + 0x01, /* bNumDescriptors */ + 0x22, /* bReportDescriptorType1 : 0x22 : Report descriptor */ + UX_W0(UX_HID_MOUSE_REPORT_LENGTH), /* wDescriptorLength1 */ + UX_W1(UX_HID_MOUSE_REPORT_LENGTH), + + /* Endpoint Descriptor (Interrupt In) */ + 0x07, /* bLength */ + 0x05, /* bDescriptorType */ + UX_DEMO_HID_ENDPOINT_ADDRESS, /* bEndpointAddress */ + /* D7, Direction : 0x01 */ + /* D3..0, Endpoint number : 2 */ + 0x03, /* bmAttributes */ + /* D1..0, Transfer Type : 0x3 : Interrupt */ + /* D3..2, Synchronization Type : 0x0 : No Synchronization */ + /* D5..4, Usage Type : 0x0 : Data endpoint */ + UX_W0(UX_DEMO_HID_ENDPOINT_SIZE), /* wMaxPacketSize */ + UX_W1(UX_DEMO_HID_ENDPOINT_SIZE), /* D10..0, Max Packet Size */ + /* D12..11, Additional transactions : 0x00 */ + UX_DEMO_HID_ENDPOINT_BINTERVAL, /* bInterval : 8 : 8ms / x128 (FS 128ms/HS 16ms) */ +}; + + +/* String Device Framework : + Byte 0 and 1 : Word containing the language ID : 0x0904 for US + Byte 2 : Byte containing the index of the descriptor + Byte 3 : Byte containing the length of the descriptor string +*/ +#define STRING_FRAMEWORK_LENGTH sizeof(ux_demo_string_framework) +UCHAR ux_demo_string_framework[] = { + + /* iManufacturer string descriptor : Index 1 */ + 0x09, 0x04, 0x01, 12, + 'U', 'S', 'B', 'X', ' ', 'e', 'c', 'l', 'i', 'p', 's', 'e', + + /* iProduct string descriptor : Index 2 */ + 0x09, 0x04, 0x02, 14, + 'H', 'I', 'D', ' ', 'M', 'o', 'u', 's', 'e', ' ', 'D', 'e', 'm', 'o', + + /* iSerialNumber Number string descriptor : Index 3 */ + 0x09, 0x04, 0x03, 13, + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', + + /* iConfiguration string descriptor : Index 4 */ + 0x09, 0x04, 0x04, 10, + 'F', 'U', 'L', 'L', ' ', 'S', 'P', 'E', 'E', 'D', + + /* iConfiguration string descriptor : Index 5 */ + 0x09, 0x04, 0x05, 10, + 'H', 'I', 'G', 'H', ' ', 'S', 'P', 'E', 'E', 'D', + + /* iInterface string descriptor : Index 6 */ + 0x09, 0x04, 0x06, 5, + 'M', 'o', 'u', 's', 'e' +}; + + +/* Multiple languages are supported on the device, to add a language besides english, + the unicode language code must be appended to the ux_demo_language_id_framework array and the length + adjusted accordingly. +*/ +#define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(ux_demo_language_id_framework) +UCHAR ux_demo_language_id_framework[] = { + /* English. */ + 0x09, 0x04 +}; + +#ifndef EXTERNAL_MAIN +int main(void) +{ + /* Initialize the board. */ + board_setup(); + + /* Enter the ThreadX kernel. */ + tx_kernel_enter(); +} +#endif /* EXTERNAL_MAIN */ + +VOID tx_application_define(VOID *first_unused_memory) +{ +CHAR *stack_pointer; +CHAR *memory_pointer; +UINT status; +UX_SLAVE_CLASS_HID_PARAMETER hid_mouse_parameter; + + /* Initialize the free memory pointer. */ + stack_pointer = (CHAR *) first_unused_memory; + + /* Initialize the RAM disk memory. */ + memory_pointer = stack_pointer + DEMO_STACK_SIZE; + + /* Initialize USBX Memory */ + status = ux_system_initialize(memory_pointer, UX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0); + + if(status != UX_SUCCESS) + return; + + /* Install the device portion of USBX. */ + status = ux_device_stack_initialize(ux_demo_device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED, + ux_demo_device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED, + ux_demo_string_framework, STRING_FRAMEWORK_LENGTH, + ux_demo_language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, + UX_NULL); + + if(status != UX_SUCCESS) + return; + + /* Initialize the hid mouse class parameters for the device */ + hid_mouse_parameter.ux_slave_class_hid_instance_activate = ux_demo_device_hid_instance_activate; + hid_mouse_parameter.ux_slave_class_hid_instance_deactivate = ux_demo_device_hid_instance_deactivate; + hid_mouse_parameter.ux_device_class_hid_parameter_report_address = hid_mouse_report; + hid_mouse_parameter.ux_device_class_hid_parameter_report_length = UX_HID_MOUSE_REPORT_LENGTH; + hid_mouse_parameter.ux_device_class_hid_parameter_report_id = UX_FALSE; + hid_mouse_parameter.ux_device_class_hid_parameter_callback = ux_demo_device_hid_callback; + hid_mouse_parameter.ux_device_class_hid_parameter_get_callback = ux_demo_device_hid_get_callback; + + /* Initialize the device hid class. The class is connected with interface 0 on configuration 1. */ + status = ux_device_stack_class_register(_ux_system_slave_class_hid_name, ux_device_class_hid_entry, + 1, 0, (VOID *)&hid_mouse_parameter); + + if(status != UX_SUCCESS) + return; + + /* Create the main demo thread. */ + status = ux_utility_thread_create(&ux_hid_thread, "hid_usbx_app_thread_entry", + ux_demo_device_hid_thread_entry, 0, stack_pointer, + 512, 20, 20, 1, TX_AUTO_START); + + if(status != UX_SUCCESS) + return; + + /* Register error callback. */ + ux_utility_error_callback_register(ux_demo_error_callback); +} + +/********************************************************************/ +/** ux_demo_device_hid_instance_activate */ +/********************************************************************/ +VOID ux_demo_device_hid_instance_activate(VOID *hid_instance) +{ + if (hid_mouse == UX_NULL) + hid_mouse = (UX_SLAVE_CLASS_HID*) hid_instance; +} + +/********************************************************************/ +/** ux_demo_device_hid_instance_deactivate */ +/********************************************************************/ +VOID ux_demo_device_hid_instance_deactivate(VOID *hid_instance) +{ + if (hid_instance == (VOID *)hid_mouse) + hid_mouse = UX_NULL; +} + +/********************************************************************/ +/** ux_demo_device_hid_callback */ +/********************************************************************/ +UINT ux_demo_device_hid_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event) +{ + UX_PARAMETER_NOT_USED(hid_instance); + UX_PARAMETER_NOT_USED(hid_event); + + return UX_SUCCESS; +} + +/********************************************************************/ +/** ux_demo_device_hid_get_callback */ +/********************************************************************/ +UINT ux_demo_device_hid_get_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event) +{ + UX_PARAMETER_NOT_USED(hid_instance); + UX_PARAMETER_NOT_USED(hid_event); + + return UX_SUCCESS; +} + +/********************************************************************/ +/** ux_demo_device_hid_thread_entry: hid demo thread */ +/********************************************************************/ +VOID ux_demo_device_hid_thread_entry(ULONG thread_input) +{ + + UX_PARAMETER_NOT_USED(thread_input); + + /* Register the USB device controllers available in this system */ + usb_device_dcd_initialize(UX_NULL); + + while (1) + { + /* Check if the device state already configured. */ + if ((UX_SLAVE_DEVICE_CHECK_STATE(UX_DEVICE_CONFIGURED)) && (hid_mouse != UX_NULL)) + { +#ifdef UX_DEMO_MOUSE_ABSOLUTE + ux_demo_hid_mouse_absolute_cursor_move(hid_mouse); +#else /* UX_DEMO_MOUSE_ABSOLUTE */ + ux_demo_hid_mouse_cursor_move(hid_mouse); +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + } + else + { + /* Sleep thread for 10ms. */ + ux_utility_delay_ms(MS_TO_TICK(10)); + } + } +} + +#ifndef UX_DEMO_MOUSE_ABSOLUTE +/********************************************************************/ +/** ux_demo_hid_mouse_cursor_move: show how to move mouse cursor */ +/********************************************************************/ +UINT ux_demo_hid_mouse_cursor_move(UX_SLAVE_CLASS_HID *device_hid) +{ +UINT status; +UX_SLAVE_CLASS_HID_EVENT device_hid_event; +static UCHAR mouse_x; +static UCHAR mouse_y; +static UCHAR mouse_move_dir; +static UCHAR mouse_move_count; + + /* Sleep thread for 10ms. */ + ux_utility_delay_ms(MS_TO_TICK(10)); + + /* Initialize mouse event. */ + device_hid_event.ux_device_class_hid_event_report_id = 0; + device_hid_event.ux_device_class_hid_event_report_type = UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT; + device_hid_event.ux_device_class_hid_event_length = 4; + device_hid_event.ux_device_class_hid_event_buffer[0] = 0; /* ...R|M|L */ + device_hid_event.ux_device_class_hid_event_buffer[1] = mouse_x; /* X */ + device_hid_event.ux_device_class_hid_event_buffer[2] = mouse_y; /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[3] = 0; /* Wheel */ + + /* Move cursor. */ + switch(mouse_move_dir) + { + case UX_MOUSE_CURSOR_MOVE_RIGHT: /* +x. */ + + mouse_x = UX_DEMO_HID_MOUSE_CURSOR_MOVE; + mouse_y = 0; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_DOWN; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_DOWN: /* +y. */ + + mouse_x = 0; + mouse_y = UX_DEMO_HID_MOUSE_CURSOR_MOVE; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_LEFT; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_LEFT: /* -x. */ + + mouse_x = (CHAR)(-UX_DEMO_HID_MOUSE_CURSOR_MOVE); + mouse_y = 0; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_UP; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_UP: /* -y. */ + + mouse_x = 0; + mouse_y = (UCHAR)(-UX_DEMO_HID_MOUSE_CURSOR_MOVE); + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_RIGHT; + } + + break; + + default: + + mouse_x = 0; + mouse_y = 0; + + ux_utility_memory_set(&device_hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT)); + + break; + } + + status = ux_device_class_hid_event_set(device_hid, &device_hid_event); + + if(status != UX_SUCCESS) + return UX_ERROR; + + return mouse_move_dir; +} +#else /* UX_DEMO_MOUSE_ABSOLUTE */ +/***************************************************************************************/ +/** ux_demo_hid_mouse_absolute_cursor_move: */ +/** show how to daw a rectangle with width 10000, height 10000, step size 500 */ +/***************************************************************************************/ +UINT ux_demo_hid_mouse_absolute_cursor_move(UX_SLAVE_CLASS_HID *device_hid) +{ +UINT status; +UX_SLAVE_CLASS_HID_EVENT device_hid_event; +ULONG start_mouse_x = 8000; +ULONG start_mouse_y = 8000; +ULONG width = 10000; +ULONG height = 10000; +static ULONG mouse_x; +static ULONG mouse_y; +static UCHAR mouse_move_dir; + + /* Sleep thread for 100ms. */ + ux_utility_delay_ms(MS_TO_TICK(100)); + + /* Initialize mouse event. */ + device_hid_event.ux_device_class_hid_event_report_id = 0; + device_hid_event.ux_device_class_hid_event_report_type = UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT; + device_hid_event.ux_device_class_hid_event_length = 6; + device_hid_event.ux_device_class_hid_event_buffer[0] = 0; /* ...M|R|L */ + device_hid_event.ux_device_class_hid_event_buffer[1] = UX_W0(mouse_x); /* X */ + device_hid_event.ux_device_class_hid_event_buffer[2] = UX_W1(mouse_x); /* X */ + device_hid_event.ux_device_class_hid_event_buffer[3] = UX_W0(mouse_y); /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[4] = UX_W1(mouse_y); /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[5] = 0; /* Wheel */ + + + switch (mouse_move_dir) + { + case UX_MOUSE_CURSOR_MOVE_RIGHT: /* +x. */ + + mouse_x += UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_x >= start_mouse_x + width) + { + mouse_x = start_mouse_x + width; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_DOWN; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_DOWN: /* +y. */ + + mouse_y += UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_y >= start_mouse_y + height) + { + mouse_y = start_mouse_y + height; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_LEFT; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_LEFT: /* -y. */ + + mouse_x -= UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_x <= start_mouse_x) + { + mouse_x = start_mouse_x; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_UP; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_UP: /* -y. */ + + mouse_y -= UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_y <= start_mouse_y) + { + mouse_y = start_mouse_y; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_RIGHT; + } + + break; + + default: + + mouse_x = 0; + mouse_y = 0; + + ux_utility_memory_set(&device_hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT)); + + break; + } + + /* Set the mouse event. */ + status = ux_device_class_hid_event_set(device_hid, &device_hid_event); + + if(status != UX_SUCCESS) + return UX_ERROR; + + return mouse_move_dir; +} +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code) +{ + /* + * Refer to ux_api.h. For example, + * UX_SYSTEM_LEVEL_INTERRUPT, UX_SYSTEM_CONTEXT_DCD, UX_DEVICE_HANDLE_UNKNOWN + */ + printf("USBX error: system level(%d), context(%d), error code(0x%x)\r\n", system_level, system_context, error_code); +} diff --git a/samples/demo_device_hid_mouse_standalone.c b/samples/demo_device_hid_mouse_standalone.c new file mode 100644 index 00000000..4a7a1222 --- /dev/null +++ b/samples/demo_device_hid_mouse_standalone.c @@ -0,0 +1,718 @@ +/*************************************************************************** + * 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 + **************************************************************************/ + +/**************************************************************************/ +/**************************************************************************/ +/** */ +/** Overview */ +/** */ +/** This example works as a USB HID device. It will appear as a USB */ +/** mouse device on PC. This application demo is running in standalone */ +/** mode. */ +/** */ +/** Note */ +/** */ +/** This demonstration is not optimized, to optimize application user */ +/** should configure related class flag in ux_user.h and adjust */ +/** DEMO_STACK_SIZE and UX_DEVICE_MEMORY_STACK_SIZE */ +/** */ +/** */ +/** AUTHOR */ +/** */ +/** Mohamed AYED */ +/** */ +/**************************************************************************/ +/**************************************************************************/ + +#include "ux_api.h" +#include "ux_device_class_hid.h" + +/* if defined mouse with absolute positioning is a type of USB HID mouse that reports its position using + absolute coordinates rather than relative movement deltas. This is common in touch devices, graphics tablets, + and some remote control devices, where the report indicates an (X, Y) position within a defined logical range, + not just movement increments.*/ +/* #define UX_DEMO_MOUSE_ABSOLUTE */ + +/* Defined the mouse will act as boot device. */ +#define DEMO_HID_BOOT_DEVICE + +/**************************************************/ +/** Define constants */ +/**************************************************/ +#define UX_DEVICE_MEMORY_STACK_SIZE 7*1024 + +#define UX_DEMO_HID_DEVICE_VID 0x090A +#define UX_DEMO_HID_DEVICE_PID 0x4036 + +#define UX_DEMO_MAX_EP0_SIZE 0x40U +#define UX_DEMO_HID_CONFIG_DESC_SIZE 0x22U +#define UX_DEMO_BCD_USB 0x0200 +#define UX_DEMO_BCD_HID 0x0110 + +#define UX_DEMO_HID_ENDPOINT_SIZE 0x08 +#define UX_DEMO_HID_ENDPOINT_ADDRESS 0x81 +#define UX_DEMO_HID_ENDPOINT_BINTERVAL 0x08 + +#ifdef DEMO_HID_BOOT_DEVICE +#define UX_DEMO_HID_SUBCLASS 0x01 +#else /* DEMO_HID_BOOT_DEVICE */ +#define UX_DEMO_HID_SUBCLASS 0x00 +#endif + +#ifdef UX_DEMO_MOUSE_ABSOLUTE +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE 350 +#else /* UX_DEMO_MOUSE_ABSOLUTE */ +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE 3 +#define UX_DEMO_HID_MOUSE_CURSOR_MOVE_N 100 +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +#define UX_MOUSE_CURSOR_MOVE_RIGHT 0x00 +#define UX_MOUSE_CURSOR_MOVE_DOWN 0x01 +#define UX_MOUSE_CURSOR_MOVE_LEFT 0x02 +#define UX_MOUSE_CURSOR_MOVE_UP 0x03 + +/**************************************************/ +/** usbx device hid demo callbacks */ +/**************************************************/ +VOID ux_demo_device_hid_instance_activate(VOID *hid_instance); +VOID ux_demo_device_hid_instance_deactivate(VOID *hid_instance); +UINT ux_demo_device_hid_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event); +UINT ux_demo_device_hid_get_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event); + +/**************************************************/ +/** usbx application initialization with RTOS */ +/**************************************************/ +VOID tx_application_define(VOID *first_unused_memory); + +/**************************************************/ +/** usbx device hid demo thread */ +/**************************************************/ +VOID ux_demo_device_hid_thread_entry(ULONG thread_input); + +/**************************************************/ +/** usbx device hid demo mouse */ +/**************************************************/ +UINT ux_demo_hid_mouse_buttons(UX_SLAVE_CLASS_HID *device_hid); +UINT ux_demo_hid_mouse_scroll_wheel(UX_SLAVE_CLASS_HID *device_hid); +#ifndef UX_DEMO_MOUSE_ABSOLUTE +UINT ux_demo_hid_mouse_cursor_move(UX_SLAVE_CLASS_HID *device_hid); +#else +UINT ux_demo_hid_mouse_absolute_cursor_move(UX_SLAVE_CLASS_HID *device_hid); +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +/**************************************************/ +/** usbx callback error */ +/**************************************************/ +VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code); + +#ifndef EXTERNAL_MAIN +extern int board_setup(void); +#endif /* EXTERNAL_MAIN */ +extern int usb_device_dcd_initialize(void *param); + +/**************************************************/ +/** usbx device hid mouse instance */ +/**************************************************/ +UX_SLAVE_CLASS_HID *hid_mouse; + +VOID ux_application_define(VOID); +VOID ux_demo_device_hid_task(VOID); +static CHAR ux_system_memory_pool[UX_DEVICE_MEMORY_STACK_SIZE]; + +/**************************************************/ +/** HID Report descriptor */ +/**************************************************/ +UCHAR hid_mouse_report[] = { + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x02, // USAGE (Mouse) + 0xa1, 0x01, // COLLECTION (Application) + + /* Pointer and Physical are required by Apple Recovery */ + 0x09, 0x01, // USAGE (Pointer) + 0xa1, 0x00, // COLLECTION (Physical) + + /* 3 Buttons */ + 0x05, 0x09, // USAGE_PAGE (Button) + 0x19, 0x01, // USAGE_MINIMUM (Button 1) + 0x29, 0x03, // USAGE_MAXIMUM (Button 3) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x75, 0x01, // REPORT_SIZE (1) + 0x95, 0x03, // REPORT_COUNT (3) -> 3 buttons + 0x81, 0x02, // INPUT (Data, Variable, Absolute) -> Buttons + + 0x75, 0x05, // REPORT_SIZE (5) + 0x95, 0x01, // REPORT_COUNT (1) + 0x81, 0x03, // INPUT (Constant, Variable, Absolute) -> Padding bits + + /* X, Y */ + 0x05, 0x01, // USAGE_PAGE (Generic Desktop) + 0x09, 0x30, // USAGE (X) + 0x09, 0x31, // USAGE (Y) +#ifdef UX_DEMO_MOUSE_ABSOLUTE + 0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0) + 0x26, 0xFF, 0x7F, // LOGICAL_MAXIMUM (32767) (0x7FFF) + 0x75, 0x10, // REPORT_SIZE (16) (2 bytes per axis) + 0x95, 0x02, // REPORT_COUNT (2) -> X, Y position + 0x81, 0x02, // INPUT (Data, Variable, Absolute) -> Absolute X, Y position +#else /* UX_DEMO_MOUSE_ABSOLUTE */ + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) (1 bytes per axis) + 0x95, 0x02, // REPORT_COUNT (2) -> X, Y movement + 0x81, 0x06, // INPUT (Data, Variable, Relative) -> X, Y are relative +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + + /* Wheel */ + 0x09, 0x38, // USAGE (Mouse Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7F, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x95, 0x01, // REPORT_COUNT (1) -> Wheel movement + 0x81, 0x06, // INPUT (Data, Variable, Relative) -> Wheel + + /* End */ + 0xC0, // END_COLLECTION + 0xC0 // END_COLLECTION +}; + +#define UX_HID_MOUSE_REPORT_LENGTH (sizeof(hid_mouse_report)/sizeof(hid_mouse_report[0])) + +#define DEVICE_FRAMEWORK_LENGTH_FULL_SPEED sizeof(ux_demo_device_framework_full_speed) + +UCHAR ux_demo_device_framework_full_speed[] = { + /* Device descriptor */ + 0x12, /* bLength */ + 0x01, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + UX_W0(UX_DEMO_HID_DEVICE_VID), UX_W1(UX_DEMO_HID_DEVICE_VID), /* idVendor : ... */ + UX_W0(UX_DEMO_HID_DEVICE_PID), UX_W1(UX_DEMO_HID_DEVICE_PID), /* idProduct */ + 0x00, 0x00, /* bcdDevice */ + 0x01, /* iManufacturer */ + 0x02, /* iProduct */ + 0x03, /* iSerialNumber */ + 0x01, /* bNumConfigurations */ + + /* Configuration Descriptor, total 34 */ + 0x09, /* bLength */ + 0x02, /* bDescriptorType */ + UX_W0(UX_DEMO_HID_CONFIG_DESC_SIZE), /* wTotalLength */ + UX_W1(UX_DEMO_HID_CONFIG_DESC_SIZE), + 0x01, /* bNumInterfaces */ + 0x01, /* bConfigurationValue */ + 0x04, /* iConfiguration */ + 0xC0, /* bmAttributes */ + /* D6 : 0x1 : Self-powered */ + /* D5, Remote Wakeup : 0x0 : Not supported */ + 0x32, /* bMaxPower : 50 : 100mA */ + + /* Interface descriptor */ + 0x09, /* bLength */ + 0x04, /* bDescriptorType */ + 0x00, /* bInterfaceNumber */ + 0x00, /* bAlternateSetting */ + 0x01, /* bNumEndpoints */ + 0x03, /* bInterfaceClass : 0x03 : HID */ + UX_DEMO_HID_SUBCLASS, /* bInterfaceSubClass : ... : Boot/non-boot Subclass */ + 0x02, /* bInterfaceProtocol : 0x00 : Undefined */ + 0x06, /* iInterface */ + + /* HID Descriptor */ + 0x09, /* bLength : 9 */ + 0x21, /* bDescriptorType : 0x21 : HID descriptor */ + 0x10, 0x01, /* bcdHID : 0x0110 */ + 0x21, /* bCountryCode : 33 : US */ + 0x01, /* bNumDescriptors */ + 0x22, /* bReportDescriptorType1 : 0x22 : Report descriptor */ + UX_W0(UX_HID_MOUSE_REPORT_LENGTH), /* wDescriptorLength1 */ + UX_W1(UX_HID_MOUSE_REPORT_LENGTH), + + /* Endpoint Descriptor */ + 0x07, /* bLength */ + 0x05, /* bDescriptorType */ + UX_DEMO_HID_ENDPOINT_ADDRESS, /* bEndpointAddress */ + /* D7, Direction : 0x01 */ + /* D3..0, Endpoint number : 2 */ + 0x03, /* bmAttributes */ + /* D1..0, Transfer Type : 0x3 : Interrupt */ + /* D3..2, Synchronization Type : 0x0 : No Synchronization */ + /* D5..4, Usage Type : 0x0 : Data endpoint */ + UX_W0(UX_DEMO_HID_ENDPOINT_SIZE), /* wMaxPacketSize */ + UX_W1(UX_DEMO_HID_ENDPOINT_SIZE), /* D10..0, Max Packet Size */ + /* D12..11, Additional transactions : 0x00 */ + UX_DEMO_HID_ENDPOINT_BINTERVAL, /* bInterval : 8 : 8ms / x128 (FS 128ms/HS 16ms) */ +}; + +#define DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED sizeof(ux_demo_device_framework_high_speed) +UCHAR ux_demo_device_framework_high_speed[] = { + /* Device descriptor */ + 0x12, /* bLength */ + 0x01, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + UX_W0(UX_DEMO_HID_DEVICE_VID), UX_W1(UX_DEMO_HID_DEVICE_VID), /* idVendor : ... */ + UX_W0(UX_DEMO_HID_DEVICE_PID), UX_W1(UX_DEMO_HID_DEVICE_PID), /* idProduct */ + 0x01, 0x00, /* bcdDevice */ + 0x01, /* iManufacturer */ + 0x02, /* iProduct */ + 0x03, /* iSerialNumber */ + 0x01, /* bNumConfigurations */ + + /* Device qualifier descriptor */ + 0x0A, /* bLength */ + 0x06, /* bDescriptorType */ + UX_W0(UX_DEMO_BCD_USB), UX_W1(UX_DEMO_BCD_USB), /* bcdUSB */ + 0x00, /* bDeviceClass : 0x00 : Interface-defined */ + 0x00, /* bDeviceSubClass : 0x00 : Reset */ + 0x00, /* bDeviceProtocol : 0x00 : Reset */ + UX_DEMO_MAX_EP0_SIZE, /* bMaxPacketSize0 */ + 0x01, /* bNumConfigurations */ + 0x00, /* bReserved */ + + /* Configuration descriptor */ + 0x09, /* bLength */ + 0x02, /* bDescriptorType */ + UX_W0(UX_DEMO_HID_CONFIG_DESC_SIZE), /* wTotalLength */ + UX_W1(UX_DEMO_HID_CONFIG_DESC_SIZE), + 0x01, /* bNumInterfaces */ + 0x01, /* bConfigurationValue */ + 0x05, /* iConfiguration */ + 0xC0, /* bmAttributes */ + /* D6 : 0x1 : Self-powered */ + /* D5, Remote Wakeup : 0x0 : Not supported */ + 0x19, /* bMaxPower : 50 : 100mA */ + + /* Interface descriptor */ + 0x09, /* bLength */ + 0x04, /* bDescriptorType */ + 0x00, /* bInterfaceNumber */ + 0x00, /* bAlternateSetting */ + 0x01, /* bNumEndpoints */ + 0x03, /* bInterfaceClass : 0x03 : HID */ + UX_DEMO_HID_SUBCLASS, /* bInterfaceSubClass : ... : Boot/non-boot Subclass */ + 0x02, /* bInterfaceProtocol : 0x00 : Undefined */ + 0x06, /* iInterface */ + + /* HID Descriptor */ + 0x09, /* bLength : 9 */ + 0x21, /* bDescriptorType : 0x21 : HID descriptor */ + UX_W0(UX_DEMO_BCD_HID), UX_W1(UX_DEMO_BCD_HID), /* bcdHID : 0x0110 */ + 0x21, /* bCountryCode : 33 : US */ + 0x01, /* bNumDescriptors */ + 0x22, /* bReportDescriptorType1 : 0x22 : Report descriptor */ + UX_W0(UX_HID_MOUSE_REPORT_LENGTH), /* wDescriptorLength1 */ + UX_W1(UX_HID_MOUSE_REPORT_LENGTH), + + /* Endpoint Descriptor (Interrupt In) */ + 0x07, /* bLength */ + 0x05, /* bDescriptorType */ + UX_DEMO_HID_ENDPOINT_ADDRESS, /* bEndpointAddress */ + /* D7, Direction : 0x01 */ + /* D3..0, Endpoint number : 2 */ + 0x03, /* bmAttributes */ + /* D1..0, Transfer Type : 0x3 : Interrupt */ + /* D3..2, Synchronization Type : 0x0 : No Synchronization */ + /* D5..4, Usage Type : 0x0 : Data endpoint */ + UX_W0(UX_DEMO_HID_ENDPOINT_SIZE), /* wMaxPacketSize */ + UX_W1(UX_DEMO_HID_ENDPOINT_SIZE), /* D10..0, Max Packet Size */ + /* D12..11, Additional transactions : 0x00 */ + UX_DEMO_HID_ENDPOINT_BINTERVAL, /* bInterval : 8 : 8ms / x128 (FS 128ms/HS 16ms) */ +}; + + +/* String Device Framework : + Byte 0 and 1 : Word containing the language ID : 0x0904 for US + Byte 2 : Byte containing the index of the descriptor + Byte 3 : Byte containing the length of the descriptor string +*/ +#define STRING_FRAMEWORK_LENGTH sizeof(ux_demo_string_framework) +UCHAR ux_demo_string_framework[] = { + + /* iManufacturer string descriptor : Index 1 */ + 0x09, 0x04, 0x01, 12, + 'U', 'S', 'B', 'X', ' ', 'e', 'c', 'l', 'i', 'p', 's', 'e', + + /* iProduct string descriptor : Index 2 */ + 0x09, 0x04, 0x02, 14, + 'H', 'I', 'D', ' ', 'M', 'o', 'u', 's', 'e', ' ', 'D', 'e', 'm', 'o', + + /* iSerialNumber Number string descriptor : Index 3 */ + 0x09, 0x04, 0x03, 13, + '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', + + /* iConfiguration string descriptor : Index 4 */ + 0x09, 0x04, 0x04, 10, + 'F', 'U', 'L', 'L', ' ', 'S', 'P', 'E', 'E', 'D', + + /* iConfiguration string descriptor : Index 5 */ + 0x09, 0x04, 0x05, 10, + 'H', 'I', 'G', 'H', ' ', 'S', 'P', 'E', 'E', 'D', + + /* iInterface string descriptor : Index 6 */ + 0x09, 0x04, 0x06, 5, + 'M', 'o', 'u', 's', 'e' +}; + + +/* Multiple languages are supported on the device, to add a language besides english, + the unicode language code must be appended to the ux_demo_language_id_framework array and the length + adjusted accordingly. +*/ +#define LANGUAGE_ID_FRAMEWORK_LENGTH sizeof(ux_demo_language_id_framework) +UCHAR ux_demo_language_id_framework[] = { + /* English. */ + 0x09, 0x04 +}; + +#ifndef EXTERNAL_MAIN +int main(void) +{ + /* Initialize the board. */ + board_setup(); + + + ux_application_define(); + + while (1) + { + ux_system_tasks_run(); + ux_demo_device_hid_task(); + } + +} +#endif /* EXTERNAL_MAIN */ + + +VOID ux_application_define(VOID) +{ +CHAR *memory_pointer; +UINT status; +UX_SLAVE_CLASS_HID_PARAMETER hid_mouse_parameter; + + + /* Use static memory block. */ + memory_pointer = ux_system_memory_pool; + + /* Initialize USBX Memory */ + status = ux_system_initialize(memory_pointer, UX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0); + + if(status != UX_SUCCESS) + return; + + /* Install the device portion of USBX. */ + status = ux_device_stack_initialize(ux_demo_device_framework_high_speed, DEVICE_FRAMEWORK_LENGTH_HIGH_SPEED, + ux_demo_device_framework_full_speed, DEVICE_FRAMEWORK_LENGTH_FULL_SPEED, + ux_demo_string_framework, STRING_FRAMEWORK_LENGTH, + ux_demo_language_id_framework, LANGUAGE_ID_FRAMEWORK_LENGTH, + UX_NULL); + + if(status != UX_SUCCESS) + return; + + /* Initialize the hid mouse class parameters for the device */ + hid_mouse_parameter.ux_slave_class_hid_instance_activate = ux_demo_device_hid_instance_activate; + hid_mouse_parameter.ux_slave_class_hid_instance_deactivate = ux_demo_device_hid_instance_deactivate; + hid_mouse_parameter.ux_device_class_hid_parameter_report_address = hid_mouse_report; + hid_mouse_parameter.ux_device_class_hid_parameter_report_length = UX_HID_MOUSE_REPORT_LENGTH; + hid_mouse_parameter.ux_device_class_hid_parameter_report_id = UX_FALSE; + hid_mouse_parameter.ux_device_class_hid_parameter_callback = ux_demo_device_hid_callback; + hid_mouse_parameter.ux_device_class_hid_parameter_get_callback = ux_demo_device_hid_get_callback; + + /* Initialize the device hid class. The class is connected with interface 0 on configuration 1. */ + status = ux_device_stack_class_register(_ux_system_slave_class_hid_name, ux_device_class_hid_entry, + 1, 0, (VOID *)&hid_mouse_parameter); + + if(status != UX_SUCCESS) + return; + + /* Register error callback. */ + ux_utility_error_callback_register(ux_demo_error_callback); + + + /* Register the USB device controllers available in this system. */ + usb_device_dcd_initialize(UX_NULL); +} + +/********************************************************************/ +/** ux_demo_device_hid_instance_activate */ +/********************************************************************/ +VOID ux_demo_device_hid_instance_activate(VOID *hid_instance) +{ + if (hid_mouse == UX_NULL) + hid_mouse = (UX_SLAVE_CLASS_HID*) hid_instance; +} + +/********************************************************************/ +/** ux_demo_device_hid_instance_deactivate */ +/********************************************************************/ +VOID ux_demo_device_hid_instance_deactivate(VOID *hid_instance) +{ + if (hid_instance == (VOID *)hid_mouse) + hid_mouse = UX_NULL; +} + +/********************************************************************/ +/** ux_demo_device_hid_callback */ +/********************************************************************/ +UINT ux_demo_device_hid_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event) +{ + UX_PARAMETER_NOT_USED(hid_instance); + UX_PARAMETER_NOT_USED(hid_event); + + return UX_SUCCESS; +} + +/********************************************************************/ +/** ux_demo_device_hid_get_callback */ +/********************************************************************/ +UINT ux_demo_device_hid_get_callback(UX_SLAVE_CLASS_HID *hid_instance, UX_SLAVE_CLASS_HID_EVENT *hid_event) +{ + UX_PARAMETER_NOT_USED(hid_instance); + UX_PARAMETER_NOT_USED(hid_event); + + return UX_SUCCESS; +} + +/********************************************************************/ +/** ux_demo_device_hid_task: hid demo task */ +/********************************************************************/ +VOID ux_demo_device_hid_task(VOID) +{ + + /* Check if the device state already configured. */ + if ((UX_SLAVE_DEVICE_CHECK_STATE(UX_DEVICE_CONFIGURED)) && (hid_mouse != UX_NULL)) + { +#ifdef UX_DEMO_MOUSE_ABSOLUTE + ux_demo_hid_mouse_absolute_cursor_move(hid_mouse); +#else /* UX_DEMO_MOUSE_ABSOLUTE */ + ux_demo_hid_mouse_cursor_move(hid_mouse); +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + } +} + +#ifndef UX_DEMO_MOUSE_ABSOLUTE +/********************************************************************/ +/** ux_demo_hid_mouse_cursor_move: show how to move mouse cursor */ +/********************************************************************/ +UINT ux_demo_hid_mouse_cursor_move(UX_SLAVE_CLASS_HID *device_hid) +{ +UINT status; +UX_SLAVE_CLASS_HID_EVENT device_hid_event; +static UCHAR mouse_x; +static UCHAR mouse_y; +static UCHAR mouse_move_dir; +static UCHAR mouse_move_count; + + /* Sleep thread for 10ms. */ + ux_utility_delay_ms(MS_TO_TICK(10)); + + /* Initialize mouse event. */ + device_hid_event.ux_device_class_hid_event_report_id = 0; + device_hid_event.ux_device_class_hid_event_report_type = UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT; + device_hid_event.ux_device_class_hid_event_length = 4; + device_hid_event.ux_device_class_hid_event_buffer[0] = 0; /* ...R|M|L */ + device_hid_event.ux_device_class_hid_event_buffer[1] = mouse_x; /* X */ + device_hid_event.ux_device_class_hid_event_buffer[2] = mouse_y; /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[3] = 0; /* Wheel */ + + /* Move cursor. */ + switch(mouse_move_dir) + { + case UX_MOUSE_CURSOR_MOVE_RIGHT: /* +x. */ + + mouse_x = UX_DEMO_HID_MOUSE_CURSOR_MOVE; + mouse_y = 0; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_DOWN; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_DOWN: /* +y. */ + + mouse_x = 0; + mouse_y = UX_DEMO_HID_MOUSE_CURSOR_MOVE; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_LEFT; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_LEFT: /* -x. */ + + mouse_x = (CHAR)(-UX_DEMO_HID_MOUSE_CURSOR_MOVE); + mouse_y = 0; + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_UP; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_UP: /* -y. */ + + mouse_x = 0; + mouse_y = (UCHAR)(-UX_DEMO_HID_MOUSE_CURSOR_MOVE); + mouse_move_count ++; + + if (mouse_move_count >= UX_DEMO_HID_MOUSE_CURSOR_MOVE_N) + { + mouse_move_count = 0; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_RIGHT; + } + + break; + + default: + + mouse_x = 0; + mouse_y = 0; + + ux_utility_memory_set(&device_hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT)); + + break; + } + + status = ux_device_class_hid_event_set(device_hid, &device_hid_event); + + if(status != UX_SUCCESS) + return UX_ERROR; + + return mouse_move_dir; +} +#else /* UX_DEMO_MOUSE_ABSOLUTE */ +/***************************************************************************************/ +/** ux_demo_hid_mouse_absolute_cursor_move: */ +/** show how to daw a rectangle with width 10000, height 10000, step size 500 */ +/***************************************************************************************/ +UINT ux_demo_hid_mouse_absolute_cursor_move(UX_SLAVE_CLASS_HID *device_hid) +{ +UINT status; +UX_SLAVE_CLASS_HID_EVENT device_hid_event; +ULONG start_mouse_x = 8000; +ULONG start_mouse_y = 8000; +ULONG width = 10000; +ULONG height = 10000; +static ULONG mouse_x; +static ULONG mouse_y; +static UCHAR mouse_move_dir; + + /* Sleep thread for 100ms. */ + ux_utility_delay_ms(MS_TO_TICK(100)); + + /* Initialize mouse event. */ + device_hid_event.ux_device_class_hid_event_report_id = 0; + device_hid_event.ux_device_class_hid_event_report_type = UX_DEVICE_CLASS_HID_REPORT_TYPE_INPUT; + device_hid_event.ux_device_class_hid_event_length = 6; + device_hid_event.ux_device_class_hid_event_buffer[0] = 0; /* ...M|R|L */ + device_hid_event.ux_device_class_hid_event_buffer[1] = UX_W0(mouse_x); /* X */ + device_hid_event.ux_device_class_hid_event_buffer[2] = UX_W1(mouse_x); /* X */ + device_hid_event.ux_device_class_hid_event_buffer[3] = UX_W0(mouse_y); /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[4] = UX_W1(mouse_y); /* Y */ + device_hid_event.ux_device_class_hid_event_buffer[5] = 0; /* Wheel */ + + + switch (mouse_move_dir) + { + case UX_MOUSE_CURSOR_MOVE_RIGHT: /* +x. */ + + mouse_x += UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_x >= start_mouse_x + width) + { + mouse_x = start_mouse_x + width; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_DOWN; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_DOWN: /* +y. */ + + mouse_y += UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_y >= start_mouse_y + height) + { + mouse_y = start_mouse_y + height; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_LEFT; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_LEFT: /* -y. */ + + mouse_x -= UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_x <= start_mouse_x) + { + mouse_x = start_mouse_x; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_UP; + } + + break; + + case UX_MOUSE_CURSOR_MOVE_UP: /* -y. */ + + mouse_y -= UX_DEMO_HID_MOUSE_CURSOR_MOVE; + + if (mouse_y <= start_mouse_y) + { + mouse_y = start_mouse_y; + mouse_move_dir = UX_MOUSE_CURSOR_MOVE_RIGHT; + } + + break; + + default: + + mouse_x = 0; + mouse_y = 0; + + ux_utility_memory_set(&device_hid_event, 0, sizeof(UX_SLAVE_CLASS_HID_EVENT)); + + break; + } + + /* Set the mouse event. */ + status = ux_device_class_hid_event_set(device_hid, &device_hid_event); + + if(status != UX_SUCCESS) + return UX_ERROR; + + return mouse_move_dir; +} +#endif /* UX_DEMO_MOUSE_ABSOLUTE */ + +VOID ux_demo_error_callback(UINT system_level, UINT system_context, UINT error_code) +{ + /* + * Refer to ux_api.h. For example, + * UX_SYSTEM_LEVEL_INTERRUPT, UX_SYSTEM_CONTEXT_DCD, UX_DEVICE_HANDLE_UNKNOWN + */ + printf("USBX error: system level(%d), context(%d), error code(0x%x)\r\n", system_level, system_context, error_code); +} From 4ea08807e95cc7211741b83ceb3cbd92e01f1441 Mon Sep 17 00:00:00 2001 From: MAY Date: Wed, 26 Nov 2025 19:46:53 +0100 Subject: [PATCH 3/9] fix typo ALIGNMENT -> ALIGNMENT --- .../inc/ux_device_class_cdc_ecm.h | 76 ++++++------- .../inc/ux_device_class_rndis.h | 2 +- .../ux_device_class_rndis_msg_initialize.c | 100 +++++++++--------- 3 files changed, 89 insertions(+), 89 deletions(-) diff --git a/common/usbx_device_classes/inc/ux_device_class_cdc_ecm.h b/common/usbx_device_classes/inc/ux_device_class_cdc_ecm.h index fded67e9..1331cc35 100644 --- a/common/usbx_device_classes/inc/ux_device_class_cdc_ecm.h +++ b/common/usbx_device_classes/inc/ux_device_class_cdc_ecm.h @@ -1,42 +1,42 @@ /*************************************************************************** - * 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 */ /** */ /** CDC_ECM Class */ /** */ /**************************************************************************/ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* COMPONENT DEFINITION RELEASE */ -/* */ -/* ux_device_class_cdc_ecm.h PORTABLE C */ +/**************************************************************************/ +/* */ +/* COMPONENT DEFINITION RELEASE */ +/* */ +/* ux_device_class_cdc_ecm.h PORTABLE C */ /* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This file defines the equivalences for the USBX Device Class */ -/* CDC_ECM component. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* This file defines the equivalences for the USBX Device Class */ +/* CDC_ECM component. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* used UX prefix to refer to */ @@ -65,15 +65,15 @@ #ifndef UX_DEVICE_CLASS_CDC_ECM_H #define UX_DEVICE_CLASS_CDC_ECM_H -/* Determine if a C++ compiler is being used. If so, ensure that standard - C is used to process the API information. */ +/* Determine if a C++ compiler is being used. If so, ensure that standard + C is used to process the API information. */ -#ifdef __cplusplus +#ifdef __cplusplus -/* Yes, C++ compiler is present. Use standard C. */ -extern "C" { +/* Yes, C++ compiler is present. Use standard C. */ +extern "C" { -#endif +#endif #if !defined(UX_DEVICE_STANDALONE) #include "nx_api.h" @@ -142,10 +142,10 @@ VOID _ux_network_driver_link_down(VOID *ux_network_handle); #define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_IP 0x0800 #define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_ARP 0x0806 #define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_RARP 0x8035 -#define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_PACKET_SIZE 1536 +#define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_PACKET_SIZE 1536 #define UX_DEVICE_CLASS_CDC_ECM_NX_ALIGN_PADDING 2 #ifndef UX_DEVICE_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES -#define UX_DEVICE_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES 16 +#define UX_DEVICE_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES 16 #endif #define UX_DEVICE_CLASS_CDC_ECM_NX_PACKET_SIZE sizeof(NX_PACKET) @@ -174,10 +174,10 @@ VOID _ux_network_driver_link_down(VOID *ux_network_handle); #define UX_DEVICE_CLASS_CDC_ECM_NX_ETHERNET_POOL_ALLOCSIZE (UX_DEVICE_CLASS_CDC_ECM_NX_PKPOOL_ENTRIES * UX_DEVICE_CLASS_CDC_ECM_NX_BUFF_SIZE + 32) #define UX_DEVICE_CLASS_CDC_ECM_ETHERNET_SIZE 14 -#define UX_DEVICE_CLASS_CDC_ECM_NODE_ID_LENGTH 6 -#define UX_DEVICE_CLASS_CDC_ECM_VENDOR_DESCRIPTION_MAX_LENGTH 64 +#define UX_DEVICE_CLASS_CDC_ECM_NODE_ID_LENGTH 6 +#define UX_DEVICE_CLASS_CDC_ECM_VENDOR_DESCRIPTION_MAX_LENGTH 64 #define UX_DEVICE_CLASS_CDC_ECM_MAC_OPTIONS 8 -#define UX_DEVICE_CLASS_CDC_ECM_PACKET_HEADER_MSG 1 +#define UX_DEVICE_CLASS_CDC_ECM_PACKET_HEADER_MSG 1 /* Device CDC_ECM Requests */ #define UX_DEVICE_CLASS_CDC_ECM_SEND_ENCAPSULATED_COMMAND 0x00 @@ -202,7 +202,7 @@ VOID _ux_network_driver_link_down(VOID *ux_network_handle); /* Define CDC_ECM Packet size and types supported. */ #define UX_DEVICE_CLASS_CDC_ECM_MAX_PACKET_PER_TRANSFER 0x00000001 #define UX_DEVICE_CLASS_CDC_ECM_MAX_PACKET_TRANSFER_SIZE 0x00000640 -#define UX_DEVICE_CLASS_CDC_ECM_PACKET_ALIGNEMENT_FACTOR 0x00000003 +#define UX_DEVICE_CLASS_CDC_ECM_PACKET_ALIGNMENT_FACTOR 0x00000003 #define UX_DEVICE_CLASS_CDC_ECM_MAX_FRAME_SIZE 0x000005DC #define UX_DEVICE_CLASS_CDC_ECM_MAX_PACKET_LENGTH 0x000005EA @@ -381,7 +381,7 @@ typedef struct UX_SLAVE_CLASS_CDC_ECM_STRUCT ULONG ux_slave_class_cdc_ecm_link_state; VOID *ux_slave_class_cdc_ecm_network_handle; - + } UX_SLAVE_CLASS_CDC_ECM; /* Define CDC ECM endpoint buffer settings (when CDC ECM owns buffer). */ @@ -403,14 +403,14 @@ typedef struct UX_SLAVE_CLASS_CDC_ECM_STRUCT /* Requests - Ethernet Networking Control Model */ -#define UX_DEVICE_CLASS_CDC_ECM_SEND_ENCAPSULATED_COMMAND 0x00 +#define UX_DEVICE_CLASS_CDC_ECM_SEND_ENCAPSULATED_COMMAND 0x00 /* Issues a command in the format of the supported control protocol. The intent of this mechanism is to support networking devices (e.g., host-based cable modems) that require an additional vendor-defined interface for media specific hardware configuration and management. */ -#define UX_DEVICE_CLASS_CDC_ECM_GET_ENCAPSULATED_RESPONSE 0x01 +#define UX_DEVICE_CLASS_CDC_ECM_GET_ENCAPSULATED_RESPONSE 0x01 /* Requests a response in the format of the supported control protocol. */ @@ -438,13 +438,13 @@ VOID _ux_device_class_cdc_ecm_interrupt_thread(ULONG cdc_ecm_class); /* Define Device CDC Class API prototypes. */ #define ux_device_class_cdc_ecm_entry _ux_device_class_cdc_ecm_entry -#define ux_device_class_cdc_ecm_read _ux_device_class_cdc_ecm_read +#define ux_device_class_cdc_ecm_read _ux_device_class_cdc_ecm_read #define ux_device_class_cdc_ecm_write _ux_device_class_cdc_ecm_write -/* Determine if a C++ compiler is being used. If so, complete the standard - C conditional started above. */ +/* Determine if a C++ compiler is being used. If so, complete the standard + C conditional started above. */ #ifdef __cplusplus -} -#endif +} +#endif #endif /* UX_DEVICE_CLASS_CDC_ECM_H */ diff --git a/common/usbx_device_classes/inc/ux_device_class_rndis.h b/common/usbx_device_classes/inc/ux_device_class_rndis.h index 3a4857b9..6eda3fad 100644 --- a/common/usbx_device_classes/inc/ux_device_class_rndis.h +++ b/common/usbx_device_classes/inc/ux_device_class_rndis.h @@ -201,7 +201,7 @@ VOID _ux_network_driver_link_down(VOID *ux_network_handle); /* Define RNDIS Packet size and types supported. */ #define UX_DEVICE_CLASS_RNDIS_MAX_PACKET_PER_TRANSFER 0x00000001 #define UX_DEVICE_CLASS_RNDIS_MAX_PACKET_TRANSFER_SIZE 0x00000640 -#define UX_DEVICE_CLASS_RNDIS_PACKET_ALIGNEMENT_FACTOR 0x00000003 +#define UX_DEVICE_CLASS_RNDIS_PACKET_ALIGNMENT_FACTOR 0x00000003 #define UX_DEVICE_CLASS_RNDIS_MAX_FRAME_SIZE 0x000005DC #define UX_DEVICE_CLASS_RNDIS_MAX_PACKET_LENGTH 0x000005EA diff --git a/common/usbx_device_classes/src/ux_device_class_rndis_msg_initialize.c b/common/usbx_device_classes/src/ux_device_class_rndis_msg_initialize.c index 683b7a7a..995376fe 100644 --- a/common/usbx_device_classes/src/ux_device_class_rndis_msg_initialize.c +++ b/common/usbx_device_classes/src/ux_device_class_rndis_msg_initialize.c @@ -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 RNDIS Class */ /** */ @@ -28,43 +28,43 @@ #include "ux_device_stack.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_device_class_rndis_msg_initialize PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_device_class_rndis_msg_initialize PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function analyzes and replies to the MSG INITIALIZE */ -/* endpoints with a CLASS or VENDOR SPECIFIC type. */ -/* */ -/* INPUT */ -/* */ -/* rndis Pointer to rndis class */ -/* transfer_request Pointer to the transfer request */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* This function analyzes and replies to the MSG INITIALIZE */ +/* endpoints with a CLASS or VENDOR SPECIFIC type. */ +/* */ +/* INPUT */ +/* */ +/* rndis Pointer to rndis class */ +/* transfer_request Pointer to the transfer request */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_long_get Get 32-bit value */ /* _ux_utility_long_put Put 32-bit value */ -/* */ -/* CALLED BY */ -/* */ +/* */ +/* CALLED BY */ +/* */ /* RNDIS 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), */ /* resulting in version 6.1 */ @@ -78,16 +78,16 @@ UCHAR *rndis_response; /* Get the pointer to the RNDIS message. */ rndis_msg = transfer_request -> ux_slave_transfer_request_data_pointer; - + /* Get the request ID and keep it for the response. */ rndis -> ux_slave_class_rndis_request_id = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_REQUEST_ID); - + /* Get the major version and store it into the RNDIS instance. */ rndis -> ux_slave_class_rndis_major_version = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MAJOR_VERSION); - + /* Get the minor version and store it into the RNDIS instance. */ rndis -> ux_slave_class_rndis_minor_version = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MINOR_VERSION); - + /* Get the max transfer size and store it into the RNDIS instance. */ rndis -> ux_slave_class_rndis_max_transfer_size = _ux_utility_long_get(rndis_msg + UX_DEVICE_CLASS_RNDIS_MSG_INITIALIZE_MAX_TRANSFER_SIZE); @@ -96,48 +96,48 @@ UCHAR *rndis_response; /* Now prepare the response. */ rndis_response = rndis -> ux_slave_class_rndis_response; - + /* First store the command. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MESSAGE_TYPE, UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE); - + /* Then the length of the response. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MESSAGE_LENGTH, UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_RESPONSE_LENGTH); /* Store the request ID. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_REQUEST_ID, rndis -> ux_slave_class_rndis_request_id); - + /* Force the status to SUCCESS. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_STATUS, UX_DEVICE_CLASS_RNDIS_STATUS_SUCCESS); - + /* Set the major version of the device */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAJOR_VERSION, UX_DEVICE_CLASS_RNDIS_VERSION_MAJOR); - + /* Set the minor version of the device */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MINOR_VERSION, UX_DEVICE_CLASS_RNDIS_VERSION_MINOR); /* Set the type of connection supported. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_DEVICE_FLAGS, UX_DEVICE_CLASS_RNDIS_DF_CONNECTION_SUPPORTED); - + /* Set the type of media supported. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MEDIUM, UX_DEVICE_CLASS_RNDIS_MEDIUM_SUPPORTED); - + /* Set the max packet per transfer. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAX_PACKETS_PER_TRANSFER, UX_DEVICE_CLASS_RNDIS_MAX_PACKET_PER_TRANSFER); - + /* Set the max transfer size. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_MAX_TRANSFER_SIZE, UX_DEVICE_CLASS_RNDIS_MAX_PACKET_TRANSFER_SIZE); - + /* Set the packet alignment factor. */ - _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_PACKET_ALIGNMENT, UX_DEVICE_CLASS_RNDIS_PACKET_ALIGNEMENT_FACTOR); - + _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_PACKET_ALIGNMENT, UX_DEVICE_CLASS_RNDIS_PACKET_ALIGNMENT_FACTOR); + /* Set AFListOffset and AFListSize fields to 0. */ _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_AFL_LIST_OFFSET, 0); _ux_utility_long_put(rndis_response + UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_AFL_LIST_SIZE, 0); - + /* Set the response length. */ rndis -> ux_slave_class_rndis_response_length = UX_DEVICE_CLASS_RNDIS_CMPLT_INITIALIZE_RESPONSE_LENGTH; /* We are done. Return UX_SUCCESS. */ - return(UX_SUCCESS); + return(UX_SUCCESS); } From 2db1b7bd2c0a87683d2bbacf5ac61de23d6c3f32 Mon Sep 17 00:00:00 2001 From: MAY Date: Thu, 27 Nov 2025 01:25:55 +0100 Subject: [PATCH 4/9] Add check for optional device hid out endpoint --- .../src/ux_device_class_hid_deactivate.c | 82 +++++++++++-------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c b/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c index cf414049..55033ca0 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c @@ -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 */ /** */ @@ -28,40 +28,40 @@ #include "ux_device_stack.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_device_class_hid_deactivate PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_device_class_hid_deactivate PORTABLE C */ /* 6.1.12 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function deactivate an instance of the hid class. */ -/* */ -/* INPUT */ -/* */ -/* command Pointer to a class command */ -/* */ -/* OUTPUT */ -/* */ -/* Completion Status */ -/* */ -/* CALLS */ -/* */ -/* _ux_device_stack_transfer_all_request_abort Abort all transfers */ -/* */ -/* CALLED BY */ -/* */ +/* */ +/* This function deactivate an instance of the hid class. */ +/* */ +/* INPUT */ +/* */ +/* command Pointer to a class command */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* _ux_device_stack_transfer_all_request_abort Abort all transfers */ +/* */ +/* 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), */ /* resulting in version 6.1 */ @@ -73,9 +73,10 @@ /**************************************************************************/ UINT _ux_device_class_hid_deactivate(UX_SLAVE_CLASS_COMMAND *command) { - + UX_SLAVE_CLASS_HID *hid; UX_SLAVE_CLASS *class_ptr; +UX_SLAVE_ENDPOINT *endpoint; /* Get the class container. */ class_ptr = command -> ux_slave_class_command_class_ptr; @@ -83,11 +84,20 @@ UX_SLAVE_CLASS *class_ptr; /* Get the class instance in the container. */ hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance; - /* Terminate the transactions pending on the endpoints. */ - _ux_device_stack_transfer_all_request_abort(hid -> ux_device_class_hid_interrupt_endpoint, UX_TRANSFER_BUS_RESET); + /* Locate the hid interrupt in endpoint. */ + endpoint = hid -> ux_device_class_hid_interrupt_endpoint; + + /* Terminate the transactions pending on the endpoint. */ + if (endpoint) + _ux_device_stack_transfer_all_request_abort(endpoint, UX_TRANSFER_BUS_RESET); #if defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT) - _ux_device_stack_transfer_all_request_abort(hid -> ux_device_class_hid_read_endpoint, UX_TRANSFER_BUS_RESET); + /* Locate the hid interrupt out endpoint. */ + endpoint = hid -> ux_device_class_hid_read_endpoint; + + /* Terminate the transactions pending on the endpoint. */ + if (endpoint) + _ux_device_stack_transfer_all_request_abort(endpoint, UX_TRANSFER_BUS_RESET); #endif /* If there is a deactivate function call it. */ From 3632bd433077df08e937f940b82907f968fbf8f2 Mon Sep 17 00:00:00 2001 From: MAY Date: Thu, 27 Nov 2025 12:37:44 +0100 Subject: [PATCH 5/9] Fix compilation issue when debug log option is enabled expose UX_ENABLE_DEBUG_LOG option in ux_user_sample.h --- common/core/inc/ux_api.h | 5 +- common/core/inc/ux_user_sample.h | 102 +++++++++-------- common/core/inc/ux_utility.h | 1 + common/core/src/ux_system_uninitialize.c | 71 ++++++------ common/core/src/ux_utility_debug_log.c | 136 +++++++++++------------ 5 files changed, 163 insertions(+), 152 deletions(-) diff --git a/common/core/inc/ux_api.h b/common/core/inc/ux_api.h index 87b6b9c0..748d5881 100644 --- a/common/core/inc/ux_api.h +++ b/common/core/inc/ux_api.h @@ -441,7 +441,9 @@ typedef signed char SCHAR; /* Map the error log macros to internal USBX function. */ -#define UX_DEBUG_LOG(debug_location, debug_message, debug_code, debug_parameter_1, debug_parameter_2) _ux_utility_debug_log((UCHAR *) debug_location, (UCHAR *) debug_message, (ULONG) debug_code, (ULONG) debug_parameter_1, (ULONG) debug_parameter_2); +#define UX_DEBUG_LOG(debug_location, debug_message, debug_code, debug_parameter_1, debug_parameter_2) \ + _ux_utility_debug_log((UCHAR *) debug_location, (UCHAR *) debug_message, (ULONG) debug_code, \ + (ULONG) debug_parameter_1, (ULONG) debug_parameter_2); VOID _ux_utility_debug_log(UCHAR *debug_location, UCHAR *debug_message, ULONG debug_code, ULONG debug_parameter_1, ULONG debug_parameter_2); @@ -449,7 +451,6 @@ VOID _ux_utility_debug_log(UCHAR *debug_location, UCHAR *debug_message, ULONG de /* If error log is enabled, insert this error message into the log buffer. */ /* UX_DEBUG_LOG("_ux_host_stack_rh_device_insertion", "Device insertion", port_index, port_index, 0) */ - #else /* If Log is not defined, map it to nothing so that debug messages can stay in the code. */ diff --git a/common/core/inc/ux_user_sample.h b/common/core/inc/ux_user_sample.h index 1cd62c1c..1246bbaa 100644 --- a/common/core/inc/ux_user_sample.h +++ b/common/core/inc/ux_user_sample.h @@ -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 */ /** */ /** User Specific */ @@ -20,11 +20,11 @@ /**************************************************************************/ -/**************************************************************************/ -/* */ -/* PORT SPECIFIC C INFORMATION RELEASE */ -/* */ -/* ux_user.h PORTABLE C */ +/**************************************************************************/ +/* */ +/* PORT SPECIFIC C INFORMATION RELEASE */ +/* */ +/* ux_user.h PORTABLE C */ /* 6.3.0 */ /* */ /* AUTHOR */ @@ -32,17 +32,17 @@ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This file contains user defines for configuring USBX in specific */ -/* ways. This file will have an effect only if the application and */ -/* USBX library are built with UX_INCLUDE_USER_DEFINE_FILE defined. */ -/* Note that all the defines in this file may also be made on the */ -/* command line when building USBX library and application objects. */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* This file contains user defines for configuring USBX in specific */ +/* ways. This file will have an effect only if the application and */ +/* USBX library are built with UX_INCLUDE_USER_DEFINE_FILE defined. */ +/* Note that all the defines in this file may also be made on the */ +/* command line when building USBX library and application objects. */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ @@ -115,15 +115,15 @@ /* Define various build options for the USBX port. The application should either make changes - here by commenting or un-commenting the conditional compilation defined OR supply the defines + here by commenting or un-commenting the conditional compilation defined OR supply the defines though the compiler's equivalent of the -D option. */ /* Define USBX Generic Thread Stack Size. */ /* #define UX_THREAD_STACK_SIZE (2 * 1024) */ /* Define USBX Host Enum Thread Stack Size. The default is to use UX_THREAD_STACK_SIZE */ -/* -#define UX_HOST_ENUM_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE +/* +#define UX_HOST_ENUM_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE */ @@ -137,14 +137,14 @@ #define UX_HOST_HNP_POLLING_THREAD_STACK UX_THREAD_STACK_SIZE */ -/* Override various options with default values already assigned in ux_api.h or ux_port.h. Please +/* Override various options with default values already assigned in ux_api.h or ux_port.h. Please also refer to ux_port.h for descriptions on each of these options. */ /* Defined, this value represents minimal allocated memory alignment in number of bytes. The default is UX_ALIGN_8 (0x07) to align allocated memory to 8 bytes. */ /* #define UX_ALIGN_MIN UX_ALIGN_8 */ -/* Defined, this value represents how many ticks per seconds for a specific hardware platform. +/* Defined, this value represents how many ticks per seconds for a specific hardware platform. The default is 1000 indicating 1 tick per millisecond. */ /* #define UX_PERIODIC_RATE 1000 @@ -167,7 +167,7 @@ /* Defined, this value is the maximum number of classes that can be loaded by USBX. This value represents the class container and not the number of instances of a class. For instance, if a particular implementation of USBX needs the hub class, the printer class, and the storage - class, then the UX_MAX_CLASSES value can be set to 3 regardless of the number of devices + class, then the UX_MAX_CLASSES value can be set to 3 regardless of the number of devices that belong to these classes. */ /* #define UX_MAX_CLASSES 3 @@ -185,9 +185,9 @@ /* #define UX_MAX_SLAVE_INTERFACES 16 */ -/* Defined, this value represents the number of different host controllers available in the system. - For USB 1.1 support, this value will usually be 1. For USB 2.0 support, this value can be more - than 1. This value represents the number of concurrent host controllers running at the same time. +/* Defined, this value represents the number of different host controllers available in the system. + For USB 1.1 support, this value will usually be 1. For USB 2.0 support, this value can be more + than 1. This value represents the number of concurrent host controllers running at the same time. If for instance there are two instances of OHCI running, or one EHCI and one OHCI controller running, the UX_MAX_HCD should be set to 2. */ @@ -196,8 +196,8 @@ /* Defined, this value represents the maximum number of devices that can be attached to the USB. - Normally, the theoretical maximum number on a single USB is 127 devices. This value can be - scaled down to conserve memory. Note that this value represents the total number of devices + Normally, the theoretical maximum number on a single USB is 127 devices. This value can be + scaled down to conserve memory. Note that this value represents the total number of devices regardless of the number of USB buses in the system. */ /* #define UX_MAX_DEVICES 127 @@ -213,7 +213,7 @@ /* Defined, this value represents the maximum number of SCSI logical units represented in the host storage class driver. */ - + /* #define UX_MAX_HOST_LUN 1 */ @@ -274,13 +274,13 @@ /* Defined, this value represents the maximum number of bytes that can be received or transmitted - on any endpoint. This value cannot be less than the maximum packet size of any endpoint. The default - is 4096 bytes but can be reduced in memory constrained environments. For cd-rom support in the storage + on any endpoint. This value cannot be less than the maximum packet size of any endpoint. The default + is 4096 bytes but can be reduced in memory constrained environments. For cd-rom support in the storage class, this value cannot be less than 2048. */ #define UX_SLAVE_REQUEST_DATA_MAX_LENGTH (1024 * 2) -/* Defined, this enables processing of Get String Descriptor requests with zero Language ID. +/* Defined, this enables processing of Get String Descriptor requests with zero Language ID. The first language ID in the language ID framwork will be used if the request has a zero Language ID. */ /* #define UX_DEVICE_ENABLE_GET_STRING_WITH_ZERO_LANGUAGE_ID */ @@ -297,7 +297,7 @@ /* Define USBX Mass Storage Thread Stack Size. The default is to use UX_THREAD_STACK_SIZE. */ -/* #define UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE +/* #define UX_HOST_CLASS_STORAGE_THREAD_STACK_SIZE UX_THREAD_STACK_SIZE */ /* Defined, this value represents the maximum number of Ed, regular TDs and Isochronous TDs. These values @@ -313,13 +313,13 @@ #define UX_HOST_CLASS_HID_DECOMPRESSION_BUFFER 4096 -/* Defined, this value represents the maximum number of HID usages for a HID device. +/* Defined, this value represents the maximum number of HID usages for a HID device. Default is 2048 but for simple HID devices like keyboard and mouse it can be reduced a lot. */ #define UX_HOST_CLASS_HID_USAGES 2048 -/* By default, each key in each HID report from the device is reported by ux_host_class_hid_keyboard_key_get +/* By default, each key in each HID report from the device is reported by ux_host_class_hid_keyboard_key_get (a HID report from the device is received whenever there is a change in a key state i.e. when a key is pressed or released. The report contains every key that is down). There are limitations to this method such as not being able to determine when a key has been released. @@ -352,13 +352,13 @@ /* #define UX_HOST_CLASS_HID_KEYBOARD_EVENTS_KEY_CHANGES_MODE_REPORT_MODIFIER_KEYS */ -/* Defined, this value represents the maximum number of media for the host storage class. +/* Defined, this value represents the maximum number of media for the host storage class. Default is 8 but for memory constrained resource systems this can ne reduced to 1. */ #define UX_HOST_CLASS_STORAGE_MAX_MEDIA 2 /* Defined, this value includes code to handle storage devices that use the CB - or CBI protocol (such as floppy disks). It is off by default because these + or CBI protocol (such as floppy disks). It is off by default because these protocols are obsolete, being superseded by the Bulk Only Transport (BOT) protocol which virtually all modern storage devices use. */ @@ -415,8 +415,8 @@ /* #define UX_DEVICE_CLASS_HID_EVENT_BUFFER_LENGTH 64 */ -/* Defined, this value represents the the maximum number of HID events/reports - that can be queued at once. +/* Defined, this value represents the the maximum number of HID events/reports + that can be queued at once. */ /* #define UX_DEVICE_CLASS_HID_MAX_EVENTS_QUEUE 8 */ @@ -485,7 +485,7 @@ /* #define UX_DEVICE_BIDIRECTIONAL_ENDPOINT_SUPPORT */ /* Defined, this macro disables interface alternate setting support. - Device stalls + Device stalls */ /* UX_DEVICE_ALTERNATE_SETTING_SUPPORT_DISABLE */ @@ -563,13 +563,13 @@ /* Defined, this value will include the OTG polling thread. OTG can only be active if both host/device are present. */ -#ifndef UX_HOST_SIDE_ONLY -#ifndef UX_DEVICE_SIDE_ONLY +#ifndef UX_HOST_SIDE_ONLY +#ifndef UX_DEVICE_SIDE_ONLY /* #define UX_OTG_SUPPORT */ -#endif -#endif +#endif +#endif /* Defined, this macro will enable the standalone mode of usbx. */ /* #define UX_STANDALONE */ @@ -592,6 +592,10 @@ #define UX_HOST_CLASS_STORAGE_MAX_TRANSFER_SIZE (1024 * 1) +/* Defined, this option enables error log. */ + +/* #define UX_ENABLE_DEBUG_LOG */ + /* Defined, this value represents the size of the log pool. */ #define UX_DEBUG_LOG_SIZE (1024 * 16) @@ -641,7 +645,7 @@ #include "usbh_hcs.h" #include "usbh_stdreq.h" #include "usbh_core.h" -#endif +#endif -#endif +#endif diff --git a/common/core/inc/ux_utility.h b/common/core/inc/ux_utility.h index c2fd8f4b..555bf635 100644 --- a/common/core/inc/ux_utility.h +++ b/common/core/inc/ux_utility.h @@ -451,6 +451,7 @@ VOID* _ux_utility_memory_allocate_add_safe(ULONG align,ULONG cache,UL #define ux_utility_event_flags_set _ux_utility_event_flags_set #define ux_utility_unicode_to_string _ux_utility_unicode_to_string #define ux_utility_string_to_unicode _ux_utility_string_to_unicode +#define ux_utility_debug_callback_register _ux_utility_debug_callback_register #define ux_utility_delay_ms _ux_utility_delay_ms #define ux_utility_error_callback_register _ux_utility_error_callback_register #define ux_system_error_handler _ux_system_error_handler diff --git a/common/core/src/ux_system_uninitialize.c b/common/core/src/ux_system_uninitialize.c index 3a80b24a..46873ee7 100644 --- a/common/core/src/ux_system_uninitialize.c +++ b/common/core/src/ux_system_uninitialize.c @@ -1,18 +1,18 @@ /*************************************************************************** - * 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 */ /** */ /** System */ /** */ @@ -29,39 +29,39 @@ #include "ux_utility.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_system_uninitialize PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_system_uninitialize PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function uninitializes the various control data structures for */ -/* the USBX system. */ -/* */ -/* INPUT */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* This function uninitializes the various control data structures for */ +/* the USBX system. */ +/* */ +/* INPUT */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ -/* _ux_utility_mutex_delete ThreadX delete mutex */ -/* */ -/* CALLED BY */ -/* */ -/* Application */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLS */ +/* */ +/* _ux_utility_mutex_delete ThreadX delete mutex */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ @@ -73,10 +73,15 @@ UINT _ux_system_uninitialize(VOID) { +#ifdef UX_ENABLE_DEBUG_LOG + + /* Free memory for debug log buffer. */ + if ( _ux_system -> ux_system_debug_log_buffer != UX_NULL) + _ux_utility_memory_free( _ux_system -> ux_system_debug_log_buffer); +#endif /* UX_ENABLE_DEBUG_LOG */ + /* Delete the Mutex object used by USBX to control critical sections. */ _ux_system_mutex_delete(&_ux_system -> ux_system_mutex); return(UX_SUCCESS); } - - diff --git a/common/core/src/ux_utility_debug_log.c b/common/core/src/ux_utility_debug_log.c index 7d5f27e6..c72d02b7 100644 --- a/common/core/src/ux_utility_debug_log.c +++ b/common/core/src/ux_utility_debug_log.c @@ -1,18 +1,18 @@ /*************************************************************************** - * 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 */ /** */ /** Utility */ /** */ @@ -28,50 +28,50 @@ #ifdef UX_ENABLE_DEBUG_LOG -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_debug_log PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_debug_log PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function logs a debug msg in a circular queue. The queue */ -/* must be initialized during the init of USBX. */ -/* */ -/* */ -/* INPUT */ -/* */ +/* */ +/* This function logs a debug msg in a circular queue. The queue */ +/* must be initialized during the init of USBX. */ +/* */ +/* */ +/* INPUT */ +/* */ /* debug_location C string to locate the debug, */ /* for example source file name. */ /* debug_message C string of message */ /* debug_code Debug code */ /* debug_parameter_1 First parameter */ /* debug_parameter_2 Second parameter */ -/* */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_string_length_check Check C string and return */ /* its length if null-terminated */ /* _tx_time_get Return system clock time */ -/* */ -/* CALLED BY */ -/* */ -/* Application */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ @@ -97,13 +97,13 @@ UX_INTERRUPT_SAVE_AREA /* Is USBX system completely initialized ? */ if (_ux_system -> ux_system_debug_log_size == 0) - + /* Not yet. */ return; /* Entering critical area. Disable interrupts. */ UX_DISABLE - + /* Store the debug value as the last debug value recorded. */ _ux_system -> ux_system_debug_code = debug_code; @@ -112,20 +112,20 @@ UX_INTERRUPT_SAVE_AREA /* Calculate the string length. */ debug_location_string_length = UX_DEBUG_LOG_SIZE; - _ux_utility_string_length_check(source, &debug_location_string_length, UX_DEBUG_LOG_SIZE); + _ux_utility_string_length_check(debug_location, &debug_location_string_length, UX_DEBUG_LOG_SIZE); debug_message_string_length = UX_DEBUG_LOG_SIZE; - _ux_utility_string_length_check(source, &debug_message_string_length, UX_DEBUG_LOG_SIZE); - + _ux_utility_string_length_check(debug_message, &debug_message_string_length, UX_DEBUG_LOG_SIZE); + /* Calculate the length of the entire message string. 1 fixed string, then 1 hexa - decimal, then 2 strings then 2 hexa decimal numbers in the format 0x00000000 + decimal, then 2 strings then 2 hexa decimal numbers in the format 0x00000000 separated by commas and . at the end, zero terminated. */ total_debug_message_length = debug_location_string_length + debug_message_string_length + 10 + 10 + 10 + 10 + 5; /* Can we accommodate this debug value message at the current location ? */ if (total_debug_message_length >= _ux_system -> ux_system_debug_log_size) return; - if (_ux_system -> ux_system_debug_log_head + total_debug_message_length > - ux_system -> ux_system_debug_log_buffer + _ux_system -> ux_system_debug_log_size) + if (_ux_system -> ux_system_debug_log_head + total_debug_message_length > + _ux_system -> ux_system_debug_log_buffer + _ux_system -> ux_system_debug_log_size) { /* The debug value log to insert goes beyond the end of the log buffer, rewind to the beginning. */ @@ -137,7 +137,7 @@ UX_INTERRUPT_SAVE_AREA _ux_system -> ux_system_debug_log_head += 10; /* Get the time value from TX. */ - current_time = _tx_time_get(); + current_time = _tx_time_get(); /* Reset the value of the length.*/ parameter_length = 0; @@ -148,33 +148,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (current_time >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the comma after the time. */ *_ux_system -> ux_system_debug_log_head = ','; @@ -205,33 +205,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (debug_parameter_1 >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the comma between the 2 hexa values. */ *_ux_system -> ux_system_debug_log_head = ','; @@ -252,33 +252,33 @@ UX_INTERRUPT_SAVE_AREA /* We parse the hexa value parameter and build the hexa value one byte at a type. */ while(parameter_length < 8) { - + /* Shift the 4 bit value we are interested in. We keep the lowest nibble. */ local_parameter_value = (debug_parameter_2 >> parameter_shift) & 0x0f; - + /* See if this value is from 0-9 or A to F. */ if (local_parameter_value <= 9) - + /* We have a digit. */ parameter_hexa = (UCHAR) (local_parameter_value + '0'); - + else /* We have 'A' to 'F' value. */ parameter_hexa = (UCHAR) (local_parameter_value - 10 + 'A'); - + /* Store the converted hexa value. */ *_ux_system -> ux_system_debug_log_head = parameter_hexa; /* Next position. */ _ux_system -> ux_system_debug_log_head++; - + /* Update length. */ parameter_length++; /* Continue shifting by one nibble. */ - parameter_shift = parameter_shift - 4; - } + parameter_shift = parameter_shift - 4; + } /* Add the termination dot at the end. */ *_ux_system -> ux_system_debug_log_head = '.'; @@ -294,11 +294,11 @@ UX_INTERRUPT_SAVE_AREA *_ux_system -> ux_system_debug_log_head = 0x00; _ux_system -> ux_system_debug_log_head++; - /* The log string is put into the log buffer. It can stay here until + /* The log string is put into the log buffer. It can stay here until a break into debugger by the developer or be passed to a callback registered by the application. */ if (_ux_system -> ux_system_debug_callback_function != UX_NULL) - { + { /* The callback function is defined, call it. */ _ux_system -> ux_system_debug_callback_function(_ux_system -> ux_system_debug_log_tail, debug_code); From 04d43112de4ceecfcf01139a7e2ed759772cb82f Mon Sep 17 00:00:00 2001 From: MAY Date: Sat, 29 Nov 2025 22:10:37 +0100 Subject: [PATCH 6/9] refer to UX prefix to avoid compilation issue in standalone mode --- common/core/src/ux_utility_debug_log.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/core/src/ux_utility_debug_log.c b/common/core/src/ux_utility_debug_log.c index c72d02b7..34b4172d 100644 --- a/common/core/src/ux_utility_debug_log.c +++ b/common/core/src/ux_utility_debug_log.c @@ -62,7 +62,7 @@ /* */ /* _ux_utility_string_length_check Check C string and return */ /* its length if null-terminated */ -/* _tx_time_get Return system clock time */ +/* _ux_utility_time_get Return system clock time */ /* */ /* CALLED BY */ /* */ @@ -79,6 +79,10 @@ /* refer to TX symbols instead */ /* of using them directly, */ /* resulting in version 6.1 */ +/* 30-11-2025 Mohamed Ayed Modified comment(s), */ +/* used UX prefix to refer to */ +/* TX symbols instead of using */ +/* them directly, */ /* */ /**************************************************************************/ VOID _ux_utility_debug_log(UCHAR *debug_location, UCHAR *debug_message, ULONG debug_code, @@ -136,8 +140,8 @@ UX_INTERRUPT_SAVE_AREA _ux_utility_memory_copy(_ux_system -> ux_system_debug_log_head, "At time : ", 10); /* Use case of memcpy is verified. */ _ux_system -> ux_system_debug_log_head += 10; - /* Get the time value from TX. */ - current_time = _tx_time_get(); + /* Get the time value. */ + current_time = _ux_utility_time_get(); /* Reset the value of the length.*/ parameter_length = 0; From a2f906cd0089e1212cdce6ec72e87e42a3c054a3 Mon Sep 17 00:00:00 2001 From: MAY Date: Mon, 1 Dec 2025 19:14:10 +0100 Subject: [PATCH 7/9] Fix CI compilation issue --- .../ux_host_class_audio_raw_sampling_parse.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common/usbx_host_classes/src/ux_host_class_audio_raw_sampling_parse.c b/common/usbx_host_classes/src/ux_host_class_audio_raw_sampling_parse.c index 0a850bd3..0e511cd2 100644 --- a/common/usbx_host_classes/src/ux_host_class_audio_raw_sampling_parse.c +++ b/common/usbx_host_classes/src/ux_host_class_audio_raw_sampling_parse.c @@ -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 **************************************************************************/ @@ -185,7 +185,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_DESCRIPTOR_CORRUPTED); } @@ -200,7 +200,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_DESCRIPTOR_CORRUPTED); } @@ -225,7 +225,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_DESCRIPTOR_CORRUPTED); } @@ -252,7 +252,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) return(UX_DESCRIPTOR_CORRUPTED); } @@ -339,7 +339,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) return(0); } @@ -634,7 +634,7 @@ UINT descriptor_length = packed_audio_descriptor[0]; _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_DESCRIPTOR_CORRUPTED); /* If trace is enabled, insert this event into the trace buffer. */ - UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor, 0, 0, UX_TRACE_ERRORS, 0, 0) + UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DESCRIPTOR_CORRUPTED, descriptor_length, 0, 0, UX_TRACE_ERRORS, 0, 0) parser -> status = UX_DESCRIPTOR_CORRUPTED; return(1); From f8422a657ec42f0043a2b375ec7d465b74cd63f4 Mon Sep 17 00:00:00 2001 From: MAY Date: Fri, 5 Dec 2025 01:28:02 +0100 Subject: [PATCH 8/9] Terminate the hid out interrupt out endpoint on deactivate --- .../src/ux_host_class_hid_deactivate.c | 106 ++++++++++-------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/common/usbx_host_classes/src/ux_host_class_hid_deactivate.c b/common/usbx_host_classes/src/ux_host_class_hid_deactivate.c index 0119ed55..c129a735 100644 --- a/common/usbx_host_classes/src/ux_host_class_hid_deactivate.c +++ b/common/usbx_host_classes/src/ux_host_class_hid_deactivate.c @@ -1,18 +1,18 @@ /*************************************************************************** - * 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 */ /** */ /** HID Class */ /** */ @@ -29,50 +29,49 @@ #include "ux_host_stack.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_host_class_hid_deactivate PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_host_class_hid_deactivate PORTABLE C */ /* 6.1.10 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This function is called when this instance of the HID has been */ -/* removed from the bus either directly or indirectly. The interrupt */ -/* pipe will be destroyed and the instanced removed. */ -/* */ -/* INPUT */ -/* */ -/* command Pointer to command */ -/* */ -/* OUTPUT */ -/* */ -/* Completion Status */ -/* */ -/* CALLS */ -/* */ -/* (ux_host_class_hid_client_handler) HID client handler */ -/* _ux_host_class_hid_instance_clean HID instance clean */ -/* _ux_host_stack_class_instance_destroy Destroy the class instance */ +/* removed from the bus either directly or indirectly. The interrupt */ +/* pipe will be destroyed and the instanced removed. */ +/* */ +/* INPUT */ +/* */ +/* command Pointer to command */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ +/* (ux_host_class_hid_client_handler) HID client handler */ +/* _ux_host_class_hid_instance_clean HID instance clean */ +/* _ux_host_stack_class_instance_destroy Destroy the class instance */ /* _ux_host_stack_endpoint_transfer_abort */ -/* Abort transfer */ -/* _ux_utility_memory_free Release memory block */ -/* _ux_host_semaphore_delete Delete semaphore */ -/* _ux_host_semaphore_get Get semaphore */ -/* _ux_utility_thread_schedule_other Schedule other threads */ -/* */ -/* CALLED BY */ -/* */ -/* HID Class */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* Abort transfer */ +/* _ux_utility_memory_free Release memory block */ +/* _ux_host_semaphore_delete Delete semaphore */ +/* _ux_host_semaphore_get Get semaphore */ +/* */ +/* CALLED BY */ +/* */ +/* HID Class */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ @@ -124,6 +123,22 @@ UINT status; _ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer); } +#if defined(UX_HOST_CLASS_HID_INTERRUPT_OUT_SUPPORT) + if (hid -> ux_host_class_hid_interrupt_out_endpoint) + { + + /* We need to abort transactions on the interrupt pipe. */ + _ux_host_stack_endpoint_transfer_abort(hid -> ux_host_class_hid_interrupt_out_endpoint); + + /* If the Hid class instance has a interrupt pipe with a data payload associated with it + it must be freed. */ + transfer_request = &hid -> ux_host_class_hid_interrupt_out_endpoint -> ux_endpoint_transfer_request; + + /* Then de allocate the memory. */ + _ux_utility_memory_free(transfer_request -> ux_transfer_request_data_pointer); + } +#endif + #if defined(UX_HOST_STANDALONE) if (hid -> ux_host_class_hid_allocated) _ux_utility_memory_free(hid -> ux_host_class_hid_allocated); @@ -133,7 +148,7 @@ UINT status; hid_client_command.ux_host_class_hid_client_command_instance = (VOID *) hid; hid_client_command.ux_host_class_hid_client_command_container = (VOID *) hid -> ux_host_class_hid_class; hid_client_command.ux_host_class_hid_client_command_request = UX_HOST_CLASS_COMMAND_DEACTIVATE; - + /* Call the HID client with a deactivate command if there was a client registered. */ if (hid -> ux_host_class_hid_client != UX_NULL) hid -> ux_host_class_hid_client -> ux_host_class_hid_client_handler(&hid_client_command); @@ -143,7 +158,7 @@ UINT status; /* The enumeration thread needs to sleep a while to allow the application or the class that may be using endpoints to exit properly. */ - _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM); + _ux_host_thread_schedule_other(UX_THREAD_PRIORITY_ENUM); /* Destroy the instance. */ _ux_host_stack_class_instance_destroy(hid -> ux_host_class_hid_class, (VOID *) hid); @@ -155,7 +170,7 @@ UINT status; that the device is removed. */ if (_ux_system_host -> ux_system_host_change_function != UX_NULL) { - + /* Inform the application the device is removed. */ _ux_system_host -> ux_system_host_change_function(UX_DEVICE_REMOVAL, hid -> ux_host_class_hid_class, (VOID *) hid); } @@ -170,6 +185,5 @@ UINT status; _ux_utility_memory_free(hid); /* Return successful completion. */ - return(UX_SUCCESS); + return(UX_SUCCESS); } - From becc8d08e0916e3c12c4c85c02cf05b48f40c7fb Mon Sep 17 00:00:00 2001 From: MAY Date: Sun, 14 Dec 2025 03:20:46 +0100 Subject: [PATCH 9/9] Cleanup hid device class files --- .../inc/ux_device_class_hid.h | 46 ++++----- .../src/ux_device_class_hid_activate.c | 8 +- .../src/ux_device_class_hid_control_request.c | 75 +++++++-------- .../src/ux_device_class_hid_deactivate.c | 1 + .../src/ux_device_class_hid_descriptor_send.c | 73 +++++++-------- .../src/ux_device_class_hid_entry.c | 6 +- .../src/ux_device_class_hid_event_get.c | 7 +- .../src/ux_device_class_hid_event_set.c | 87 ++++++++--------- .../src/ux_device_class_hid_initialize.c | 81 ++++++++-------- .../ux_device_class_hid_interrupt_thread.c | 93 ++++++++++--------- .../src/ux_device_class_hid_read.c | 11 ++- .../src/ux_device_class_hid_read_run.c | 13 +-- .../ux_device_class_hid_receiver_event_free.c | 7 +- .../ux_device_class_hid_receiver_event_get.c | 9 +- .../ux_device_class_hid_receiver_initialize.c | 12 ++- .../ux_device_class_hid_receiver_tasks_run.c | 9 +- .../src/ux_device_class_hid_receiver_thread.c | 13 +-- ...x_device_class_hid_receiver_uninitialize.c | 10 +- .../src/ux_device_class_hid_tasks_run.c | 15 +-- .../src/ux_device_class_hid_uninitialize.c | 2 +- 20 files changed, 298 insertions(+), 280 deletions(-) diff --git a/common/usbx_device_classes/inc/ux_device_class_hid.h b/common/usbx_device_classes/inc/ux_device_class_hid.h index 5dead7db..dfa588a1 100644 --- a/common/usbx_device_classes/inc/ux_device_class_hid.h +++ b/common/usbx_device_classes/inc/ux_device_class_hid.h @@ -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 **************************************************************************/ @@ -14,7 +14,7 @@ /** */ /** USBX Component */ /** */ -/** HID Class */ +/** Device HID Class */ /** */ /**************************************************************************/ /**************************************************************************/ @@ -389,7 +389,7 @@ typedef struct UX_SLAVE_CLASS_HID_PARAMETER_STRUCT /* Define HID Class function prototypes. */ UINT _ux_device_class_hid_descriptor_send(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, - ULONG request_index, ULONG host_length); + ULONG request_index, ULONG host_length); UINT _ux_device_class_hid_activate(UX_SLAVE_CLASS_COMMAND *command); UINT _ux_device_class_hid_deactivate(UX_SLAVE_CLASS_COMMAND *command); UINT _ux_device_class_hid_control_request(UX_SLAVE_CLASS_COMMAND *command); @@ -398,18 +398,18 @@ VOID _ux_device_class_hid_interrupt_thread(ULONG hid_class); UINT _ux_device_class_hid_initialize(UX_SLAVE_CLASS_COMMAND *command); UINT _ux_device_class_hid_uninitialize(UX_SLAVE_CLASS_COMMAND *command); UINT _ux_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_EVENT *hid_event); + UX_SLAVE_CLASS_HID_EVENT *hid_event); UINT _ux_device_class_hid_event_check(UX_SLAVE_CLASS_HID *hid, UX_DEVICE_CLASS_HID_EVENT **hid_event); VOID _ux_device_class_hid_event_free(UX_SLAVE_CLASS_HID *hid); UINT _ux_device_class_hid_event_get(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_EVENT *hid_event); + UX_SLAVE_CLASS_HID_EVENT *hid_event); UINT _ux_device_class_hid_report_set(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, - ULONG request_index, ULONG host_length); + ULONG request_index, ULONG host_length); UINT _ux_device_class_hid_report_get(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, - ULONG request_index, ULONG host_length); + ULONG request_index, ULONG host_length); -UINT _ux_device_class_hid_tasks_run(VOID *class_instance); +UINT _ux_device_class_hid_tasks_run(VOID *hid_instance); UINT _ux_device_class_hid_read(UX_SLAVE_CLASS_HID *hid, UCHAR *buffer, ULONG requested_length, @@ -417,16 +417,16 @@ UINT _ux_device_class_hid_read(UX_SLAVE_CLASS_HID *hid, VOID _ux_device_class_hid_receiver_thread(ULONG hid_class); UINT _ux_device_class_hid_receiver_initialize(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_PARAMETER *parameter, - UX_DEVICE_CLASS_HID_RECEIVER **receiver); + UX_SLAVE_CLASS_HID_PARAMETER *parameter, + UX_DEVICE_CLASS_HID_RECEIVER **receiver); VOID _ux_device_class_hid_receiver_uninitialize(UX_DEVICE_CLASS_HID_RECEIVER *receiver); UINT _ux_device_class_hid_receiver_event_get(UX_SLAVE_CLASS_HID *hid, - UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event); + UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event); UINT _ux_device_class_hid_receiver_event_free(UX_SLAVE_CLASS_HID *hid); UINT _ux_device_class_hid_read_run(UX_SLAVE_CLASS_HID *hid, - UCHAR *buffer, ULONG requested_length, - ULONG *actual_length); + UCHAR *buffer, ULONG requested_length, + ULONG *actual_length); UINT _ux_device_class_hid_receiver_tasks_run(UX_SLAVE_CLASS_HID *hid); @@ -436,16 +436,16 @@ UINT _uxe_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, UINT _uxe_device_class_hid_event_get(UX_SLAVE_CLASS_HID *hid, UX_SLAVE_CLASS_HID_EVENT *hid_event); UINT _uxe_device_class_hid_read(UX_SLAVE_CLASS_HID *hid, - UCHAR *buffer, ULONG requested_length, - ULONG *actual_length); + UCHAR *buffer, ULONG requested_length, + ULONG *actual_length); UINT _uxe_device_class_hid_read_run(UX_SLAVE_CLASS_HID *hid, - UCHAR *buffer, ULONG requested_length, - ULONG *actual_length); + UCHAR *buffer, ULONG requested_length, + ULONG *actual_length); UINT _uxe_device_class_hid_receiver_initialize(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_PARAMETER *parameter, - UX_DEVICE_CLASS_HID_RECEIVER **receiver); + UX_SLAVE_CLASS_HID_PARAMETER *parameter, + UX_DEVICE_CLASS_HID_RECEIVER **receiver); UINT _uxe_device_class_hid_receiver_event_get(UX_SLAVE_CLASS_HID *hid, - UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event); + UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event); UINT _uxe_device_class_hid_receiver_event_free(UX_SLAVE_CLASS_HID *hid); @@ -493,4 +493,4 @@ UINT _uxe_device_class_hid_receiver_event_free(UX_SLAVE_CLASS_HID *hid); } #endif -#endif +#endif /* UX_DEVICE_CLASS_HID_H */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_activate.c b/common/usbx_device_classes/src/ux_device_class_hid_activate.c index 5bc715a4..08cdc109 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_activate.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_activate.c @@ -1,13 +1,15 @@ /*************************************************************************** - * 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 */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_control_request.c b/common/usbx_device_classes/src/ux_device_class_hid_control_request.c index 83305021..edecc7b0 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_control_request.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_control_request.c @@ -1,17 +1,18 @@ /*************************************************************************** - * 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 */ /** */ @@ -28,44 +29,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 */ +/* */ +/* command Pointer to hid command */ +/* */ +/* 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, */ @@ -119,10 +120,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; @@ -149,8 +150,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: diff --git a/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c b/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c index 55033ca0..6b11308f 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_deactivate.c @@ -8,6 +8,7 @@ * SPDX-License-Identifier: MIT **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_descriptor_send.c b/common/usbx_device_classes/src/ux_device_class_hid_descriptor_send.c index 833469f0..a5c124ec 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_descriptor_send.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_descriptor_send.c @@ -1,18 +1,18 @@ /*************************************************************************** - * 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 */ /** */ @@ -51,23 +51,23 @@ /* */ /* OUTPUT */ /* */ -/* Completion Status */ +/* Completion Status */ +/* */ +/* CALLS */ /* */ -/* CALLS */ -/* */ -/* (ux_slave_dcd_function) DCD dispatch function */ +/* (ux_slave_dcd_function) DCD dispatch function */ /* _ux_device_stack_transfer_request Process transfer request */ -/* _ux_utility_memory_copy Memory copy */ -/* */ -/* CALLED BY */ -/* */ -/* Application */ +/* _ux_utility_memory_copy Memory copy */ +/* */ +/* CALLED BY */ +/* */ +/* Application */ /* Device Stack */ -/* */ -/* 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), */ /* verified memset and memcpy */ @@ -78,8 +78,8 @@ /* resulting in version 6.1.8 */ /* */ /**************************************************************************/ -UINT _ux_device_class_hid_descriptor_send(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, - ULONG request_index, ULONG host_length) +UINT _ux_device_class_hid_descriptor_send(UX_SLAVE_CLASS_HID *hid, ULONG descriptor_type, + ULONG request_index, ULONG host_length) { UX_SLAVE_DCD *dcd; @@ -103,7 +103,7 @@ UCHAR interface_number = 0xFF; /* Get the pointer to the device. */ device = &_ux_system_slave -> ux_system_slave_device; - + /* Get the control endpoint associated with the device. */ endpoint = &device -> ux_slave_device_control_endpoint; @@ -112,7 +112,7 @@ UCHAR interface_number = 0xFF; /* Set the direction to OUT. */ transfer_request -> ux_slave_transfer_request_phase = UX_TRANSFER_PHASE_DATA_OUT; - + /* Shift the descriptor type in the low byte field. */ descriptor_type = (UCHAR) ((descriptor_type >> 8) & 0xff); @@ -121,12 +121,12 @@ UCHAR interface_number = 0xFF; { case UX_DEVICE_CLASS_HID_DESCRIPTOR_HID: - + /* We should have a HID descriptor as part of the config descriptor. */ device_framework = _ux_system_slave -> ux_system_slave_device_framework; device_framework_end = device_framework + _ux_system_slave -> ux_system_slave_device_framework_length; - /* Parse the device framework and locate the HID descriptor. + /* Parse the device framework and locate the HID descriptor. There is only one HID descriptor. */ while (device_framework < device_framework_end) { @@ -150,8 +150,8 @@ UCHAR interface_number = 0xFF; and do not return more than what is allowed. */ if (descriptor_length < host_length) length = descriptor_length; - else - length = host_length; + else + length = host_length; /* Check buffer length, since descriptor length may exceed buffer... */ if (length > UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH) @@ -169,13 +169,13 @@ UCHAR interface_number = 0xFF; } /* Copy the device descriptor into the transfer request memory. */ - _ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer, + _ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer, device_framework, length); /* Use case of memcpy is verified. */ /* We can return the configuration descriptor. */ status = _ux_device_stack_transfer_request(transfer_request, length, host_length); break; - + } /* Point to the next descriptor. */ @@ -189,7 +189,7 @@ UCHAR interface_number = 0xFF; break; case UX_DEVICE_CLASS_HID_DESCRIPTOR_REPORT: - + /* Get the length of entire configuration descriptor. */ descriptor_length = hid -> ux_device_class_hid_report_length; @@ -197,8 +197,8 @@ UCHAR interface_number = 0xFF; and do not return more than what is allowed. */ if (descriptor_length < host_length) length = descriptor_length; - else - length = host_length; + else + length = host_length; /* Check buffer length, since total descriptors length may exceed buffer... */ if (length > UX_SLAVE_REQUEST_CONTROL_MAX_LENGTH) @@ -216,17 +216,17 @@ UCHAR interface_number = 0xFF; } /* Copy the device descriptor into the transfer request memory. */ - _ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer, + _ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer, hid -> ux_device_class_hid_report_address, length); /* Use case of memcpy is verified. */ /* We can return the report descriptor. */ status = _ux_device_stack_transfer_request(transfer_request, length, host_length); break; - + case UX_DEVICE_CLASS_HID_DESCRIPTOR_PHYSICAL: - + /* Not treated for now. Fall through and Stall endpoint. */ - + default: /* Stall the endpoint. */ @@ -237,4 +237,3 @@ UCHAR interface_number = 0xFF; /* Return the status to the caller. */ return(status); } - diff --git a/common/usbx_device_classes/src/ux_device_class_hid_entry.c b/common/usbx_device_classes/src/ux_device_class_hid_entry.c index 27cae494..22222e7e 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_entry.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_entry.c @@ -8,6 +8,7 @@ * SPDX-License-Identifier: MIT **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -75,10 +76,10 @@ /* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ /* added error checks support, */ /* resulting in version 6.3.0 */ -/* xx-xx-xxxx Mohamed ayed Modified comment(s), */ +/* 24-02-2025 Mohamed ayed Modified comment(s), */ /* fix typo, */ /* remove extra spaces, */ -/* resulting in version 6.x */ +/* resulting in version 6.4.2 */ /* */ /**************************************************************************/ UINT _ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND *command) @@ -156,4 +157,3 @@ UINT status; return(UX_FUNCTION_NOT_SUPPORTED); } } - diff --git a/common/usbx_device_classes/src/ux_device_class_hid_event_get.c b/common/usbx_device_classes/src/ux_device_class_hid_event_get.c index a9d074e1..eae13247 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_event_get.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_event_get.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_event_set.c b/common/usbx_device_classes/src/ux_device_class_hid_event_set.c index 1dccc46f..84b99e2f 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_event_set.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_event_set.c @@ -1,17 +1,18 @@ /*************************************************************************** - * 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 */ /** */ @@ -28,43 +29,43 @@ #include "ux_device_stack.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_device_class_hid_event_set PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_device_class_hid_event_set PORTABLE C */ /* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function sends an event to the hid class. It is processed */ -/* asynchronously by the interrupt thread. */ -/* */ -/* INPUT */ -/* */ -/* hid Address of hid class */ -/* event Pointer of the event */ -/* */ -/* OUTPUT */ -/* */ -/* status UX_SUCCESS if there is an */ -/* event */ -/* CALLS */ -/* */ +/* */ +/* This function sends an event to the hid class. It is processed */ +/* asynchronously by the interrupt thread. */ +/* */ +/* INPUT */ +/* */ +/* hid Address of hid class */ +/* event Pointer of the event */ +/* */ +/* OUTPUT */ +/* */ +/* status UX_SUCCESS if there is an */ +/* event */ +/* CALLS */ +/* */ /* _ux_utility_memory_copy Copy memory */ /* _ux_device_event_flags_set Set event flags */ -/* */ -/* CALLED BY */ -/* */ -/* ThreadX */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* ThreadX */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ @@ -83,8 +84,8 @@ /* resulting in version 6.3.0 */ /* */ /**************************************************************************/ -UINT _ux_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_EVENT *hid_event) +UINT _ux_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, + UX_SLAVE_CLASS_HID_EVENT *hid_event) { UX_DEVICE_CLASS_HID_EVENT *current_hid_event; @@ -100,7 +101,7 @@ UCHAR *next_position; /* If the pointer is NULL, the round robin buffer has not been activated. */ if (current_hid_event == UX_NULL) return (UX_ERROR); - + /* Calculate the next position. */ next_position = (UCHAR *)current_hid_event + UX_DEVICE_CLASS_HID_EVENT_QUEUE_ITEM_SIZE(hid); if (next_position >= (UCHAR *)hid -> ux_device_class_hid_event_array_end) @@ -143,13 +144,13 @@ UCHAR *next_position; _ux_utility_memory_copy(UX_DEVICE_CLASS_HID_EVENT_BUFFER(current_hid_event) + 1, hid_event -> ux_device_class_hid_event_buffer, hid_event -> ux_device_class_hid_event_length); /* Use case of memcpy is verified. */ - + /* fill in the event structure from the user. */ - current_hid_event -> ux_device_class_hid_event_length = hid_event -> ux_device_class_hid_event_length + 1; + current_hid_event -> ux_device_class_hid_event_length = hid_event -> ux_device_class_hid_event_length + 1; } else { - + /* No report ID to consider. */ /* Store copy of data so application can free event there (easier use). */ @@ -158,7 +159,7 @@ UCHAR *next_position; hid_event -> ux_device_class_hid_event_length); /* Use case of memcpy is verified. */ /* fill in the event structure from the user. */ - current_hid_event -> ux_device_class_hid_event_length = hid_event -> ux_device_class_hid_event_length; + current_hid_event -> ux_device_class_hid_event_length = hid_event -> ux_device_class_hid_event_length; } #if defined(UX_DEVICE_STANDALONE) @@ -170,7 +171,7 @@ UCHAR *next_position; #else /* Set an event to wake up the interrupt thread. */ - _ux_device_event_flags_set(&hid -> ux_device_class_hid_event_flags_group, UX_DEVICE_CLASS_HID_NEW_EVENT, UX_OR); + _ux_device_event_flags_set(&hid -> ux_device_class_hid_event_flags_group, UX_DEVICE_CLASS_HID_NEW_EVENT, UX_OR); #endif /* Return event status to the user. */ @@ -216,7 +217,7 @@ UCHAR *next_position; /* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */ /* */ /**************************************************************************/ -UINT _uxe_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, +UINT _uxe_device_class_hid_event_set(UX_SLAVE_CLASS_HID *hid, UX_SLAVE_CLASS_HID_EVENT *hid_event) { diff --git a/common/usbx_device_classes/src/ux_device_class_hid_initialize.c b/common/usbx_device_classes/src/ux_device_class_hid_initialize.c index a23aca30..2366cdee 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_initialize.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_initialize.c @@ -1,16 +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 */ /** */ @@ -27,46 +28,46 @@ #include "ux_device_stack.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_device_class_hid_initialize PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_device_class_hid_initialize PORTABLE C */ /* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function initializes the USB HID device. */ -/* This function is called by the class register function. It is only */ -/* done once. */ -/* */ -/* INPUT */ -/* */ -/* command Pointer to hid command */ -/* */ -/* OUTPUT */ -/* */ -/* Completion Status */ -/* */ -/* CALLS */ -/* */ +/* */ +/* This function initializes the USB HID device. */ +/* This function is called by the class register function. It is only */ +/* done once. */ +/* */ +/* INPUT */ +/* */ +/* command Pointer to hid command */ +/* */ +/* OUTPUT */ +/* */ +/* Completion Status */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_memory_allocate Allocate memory */ /* _ux_utility_memory_free Free memory */ /* _ux_device_thread_create Create thread */ /* _ux_device_thread_delete Delete thread */ /* _ux_utility_event_flags_create Create event flags group */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Source Code */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Source Code */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* used UX prefix to refer to */ @@ -97,7 +98,7 @@ /**************************************************************************/ UINT _ux_device_class_hid_initialize(UX_SLAVE_CLASS_COMMAND *command) { - + UX_SLAVE_CLASS_HID *hid; UX_SLAVE_CLASS_HID_PARAMETER *hid_parameter; UX_SLAVE_CLASS *class_ptr; @@ -149,9 +150,9 @@ UCHAR *buffer; #if !defined(UX_DEVICE_STANDALONE) /* Allocate some memory for the thread stack. */ - class_ptr -> ux_slave_class_thread_stack = + class_ptr -> ux_slave_class_thread_stack = _ux_utility_memory_allocate(UX_NO_ALIGN, UX_REGULAR_MEMORY, UX_DEVICE_CLASS_HID_THREAD_STACK_SIZE); - + /* Check for successful allocation. */ if (class_ptr -> ux_slave_class_thread_stack == UX_NULL) status = UX_MEMORY_INSUFFICIENT; @@ -160,7 +161,7 @@ UCHAR *buffer; a new thread. We pass a pointer to the class to the new thread. This thread does not start until we have a instance of the class. */ if (status == UX_SUCCESS) - status = _ux_device_thread_create(&class_ptr -> ux_slave_class_thread, "ux_slave_hid_thread", + status = _ux_device_thread_create(&class_ptr -> ux_slave_class_thread, "ux_slave_hid_thread", _ux_device_class_hid_interrupt_thread, (ULONG) (ALIGN_TYPE) class_ptr, (VOID *) class_ptr -> ux_slave_class_thread_stack, UX_DEVICE_CLASS_HID_THREAD_STACK_SIZE, UX_THREAD_PRIORITY_CLASS, @@ -263,7 +264,7 @@ UCHAR *buffer; if (hid -> ux_device_class_hid_event_array != UX_NULL) { - /* Initialize the head and tail of the notification round robin buffers. + /* Initialize the head and tail of the notification round robin buffers. At first, the head and tail are pointing to the beginning of the array. */ hid -> ux_device_class_hid_event_array_head = hid -> ux_device_class_hid_event_array; hid -> ux_device_class_hid_event_array_tail = hid -> ux_device_class_hid_event_array; @@ -392,7 +393,7 @@ UCHAR *buffer; /* */ /* INPUT */ /* */ -/* command Pointer to hid command */ +/* command Pointer to hid command */ /* */ /* OUTPUT */ /* */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_interrupt_thread.c b/common/usbx_device_classes/src/ux_device_class_hid_interrupt_thread.c index 2ce0c1fb..2d785723 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_interrupt_thread.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_interrupt_thread.c @@ -1,17 +1,18 @@ /*************************************************************************** - * 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 */ /** */ @@ -29,47 +30,47 @@ #if !defined(UX_DEVICE_STANDALONE) -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_device_class_hid_interrupt_thread PORTABLE C */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_device_class_hid_interrupt_thread PORTABLE C */ /* 6.3.0 */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ -/* This function is the thread of the hid interrupt (IN) endpoint */ -/* */ +/* */ +/* This function is the thread of the hid interrupt (IN) endpoint */ +/* */ /* It's for RTOS mode. */ -/* */ -/* INPUT */ -/* */ -/* hid_class Address of hid class */ -/* container */ -/* */ -/* OUTPUT */ -/* */ -/* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* INPUT */ +/* */ +/* hid_class Address of hid class */ +/* container */ +/* */ +/* OUTPUT */ +/* */ +/* None */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_event_flags_get Get event flags */ /* _ux_device_class_hid_event_get Get HID event */ -/* _ux_device_stack_transfer_request Request transfer */ -/* _ux_utility_memory_copy Copy memory */ +/* _ux_device_stack_transfer_request Request transfer */ +/* _ux_utility_memory_copy Copy memory */ /* _ux_device_thread_suspend Suspend thread */ -/* */ -/* CALLED BY */ -/* */ -/* ThreadX */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* ThreadX */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* verified memset and memcpy */ @@ -103,13 +104,13 @@ ULONG actual_flags; /* Cast properly the hid instance. */ UX_THREAD_EXTENSION_PTR_GET(class_ptr, UX_SLAVE_CLASS, hid_class) - + /* Get the hid instance from this class container. */ hid = (UX_SLAVE_CLASS_HID *) class_ptr -> ux_slave_class_instance; - + /* Get the pointer to the device. */ device = &_ux_system_slave -> ux_system_slave_device; - + /* This thread runs forever but can be suspended or resumed. */ while(1) { @@ -119,7 +120,7 @@ ULONG actual_flags; /* As long as the device is in the CONFIGURED state. */ while (device -> ux_slave_device_state == UX_DEVICE_CONFIGURED) - { + { /* Wait until we have a event sent by the application or a change in the idle state to send last or empty report. */ @@ -156,7 +157,7 @@ ULONG actual_flags; } /* Send the request to the device controller. */ - status = _ux_device_stack_transfer_request(transfer_request_in, + status = _ux_device_stack_transfer_request(transfer_request_in, transfer_request_in -> ux_slave_transfer_request_requested_length, transfer_request_in -> ux_slave_transfer_request_requested_length); @@ -195,13 +196,13 @@ ULONG actual_flags; #else /* Prepare the event data payload from the hid event structure. Get a pointer to the buffer area. */ buffer = transfer_request_in -> ux_slave_transfer_request_data_pointer; - + /* Copy the event buffer into the target buffer. */ _ux_utility_memory_copy(buffer, UX_DEVICE_CLASS_HID_EVENT_BUFFER(hid_event), hid_event -> ux_device_class_hid_event_length); /* Use case of memcpy is verified. */ #endif /* Send the request to the device controller. */ - status = _ux_device_stack_transfer_request(transfer_request_in, hid_event -> ux_device_class_hid_event_length, + status = _ux_device_stack_transfer_request(transfer_request_in, hid_event -> ux_device_class_hid_event_length, hid_event -> ux_device_class_hid_event_length); /* The queue tail is handled and should be freed. */ @@ -213,11 +214,11 @@ ULONG actual_flags; /* Error trap. */ _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, status); - } + } } - + /* We need to suspend ourselves. We will be resumed by the device enumeration module. */ _ux_device_thread_suspend(&class_ptr -> ux_slave_class_thread); } } -#endif +#endif /* !UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_read.c b/common/usbx_device_classes/src/ux_device_class_hid_read.c index 2f3831a6..feb4b352 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_read.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_read.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -273,7 +274,7 @@ ULONG local_requested_length; /* */ /**************************************************************************/ UINT _uxe_device_class_hid_read(UX_SLAVE_CLASS_HID *hid, UCHAR *buffer, - ULONG requested_length, ULONG *actual_length) + ULONG requested_length, ULONG *actual_length) { /* Sanity checks. */ @@ -287,4 +288,4 @@ UINT _uxe_device_class_hid_read(UX_SLAVE_CLASS_HID *hid, UCHAR *buffer, /* Invoke function to read data. */ return(_ux_device_class_hid_read(hid, buffer, requested_length, actual_length)); } -#endif +#endif /* !UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_read_run.c b/common/usbx_device_classes/src/ux_device_class_hid_read_run.c index 35de1d5a..99948ad2 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_read_run.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_read_run.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -274,7 +275,7 @@ UINT status= UX_SUCCESS; /* Keep waiting. */ return(UX_STATE_WAIT); - + /* Receiver running states. */ case UX_DEVICE_CLASS_HID_RECEIVER_START: /* Fall through. */ case UX_DEVICE_CLASS_HID_RECEIVER_WAIT: /* Fall through. */ @@ -337,7 +338,7 @@ UINT status= UX_SUCCESS; /* */ /**************************************************************************/ UINT _uxe_device_class_hid_read_run(UX_SLAVE_CLASS_HID *hid, UCHAR *buffer, - ULONG requested_length, ULONG *actual_length) + ULONG requested_length, ULONG *actual_length) { /* Sanity checks. */ @@ -351,4 +352,4 @@ UINT _uxe_device_class_hid_read_run(UX_SLAVE_CLASS_HID *hid, UCHAR *buffer, /* Invoke function to run reading state machine. */ return(_ux_device_class_hid_read_run(hid, buffer, requested_length, actual_length)); } -#endif +#endif /* UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_free.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_free.c index 9ee83860..98a03634 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_free.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_free.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_get.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_get.c index a2f45c05..0a2e4225 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_get.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_event_get.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -156,7 +157,7 @@ UX_DEVICE_CLASS_HID_RECEIVED_EVENT *pos; /* */ /**************************************************************************/ UINT _uxe_device_class_hid_receiver_event_get(UX_SLAVE_CLASS_HID *hid, - UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event) + UX_DEVICE_CLASS_HID_RECEIVED_EVENT *event) { /* Sanity check. */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_initialize.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_initialize.c index 819ca03a..45d16b34 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_initialize.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_initialize.c @@ -1,13 +1,15 @@ /*************************************************************************** - * 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 */ @@ -82,8 +84,8 @@ /* */ /**************************************************************************/ UINT _ux_device_class_hid_receiver_initialize(UX_SLAVE_CLASS_HID *hid, - UX_SLAVE_CLASS_HID_PARAMETER *parameter, - UX_DEVICE_CLASS_HID_RECEIVER **receiver) + UX_SLAVE_CLASS_HID_PARAMETER *parameter, + UX_DEVICE_CLASS_HID_RECEIVER **receiver) { #if !defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT) UX_PARAMETER_NOT_USED(hid); diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_tasks_run.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_tasks_run.c index b9c710b2..4ce8fbfa 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_tasks_run.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_tasks_run.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -213,4 +214,4 @@ ULONG temp; /* Task is idle. */ return(UX_STATE_IDLE); } -#endif +#endif /* UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT && UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_thread.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_thread.c index bc6dd891..79d0d75b 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_thread.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_thread.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -45,7 +46,7 @@ /* */ /* INPUT */ /* */ -/* hid_class Address of hid class */ +/* hid_instance Address of hid class */ /* container */ /* */ /* OUTPUT */ @@ -145,7 +146,7 @@ ULONG temp; #endif /* Issue the transfer request. */ - status = _ux_device_stack_transfer_request(transfer, + status = _ux_device_stack_transfer_request(transfer, receiver -> ux_device_class_hid_receiver_event_buffer_size, receiver -> ux_device_class_hid_receiver_event_buffer_size); @@ -188,4 +189,4 @@ ULONG temp; receiver -> ux_device_class_hid_receiver_event_callback(hid); } } -#endif +#endif /* UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT && !UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_receiver_uninitialize.c b/common/usbx_device_classes/src/ux_device_class_hid_receiver_uninitialize.c index 6605db03..ee46b3a4 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_receiver_uninitialize.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_receiver_uninitialize.c @@ -1,13 +1,15 @@ /*************************************************************************** - * 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 */ @@ -88,4 +90,4 @@ VOID _ux_device_class_hid_receiver_uninitialize(UX_DEVICE_CLASS_HID_RECEIVER *re /* Free receiver and events memory. */ _ux_utility_memory_free(receiver); } -#endif +#endif /* UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_tasks_run.c b/common/usbx_device_classes/src/ux_device_class_hid_tasks_run.c index 49bc51b9..56b27e55 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_tasks_run.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_tasks_run.c @@ -1,13 +1,14 @@ /*************************************************************************** - * 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 **************************************************************************/ + /**************************************************************************/ /**************************************************************************/ /** */ @@ -47,7 +48,7 @@ /* */ /* INPUT */ /* */ -/* hid_class Address of hid class */ +/* hid_instance Address of hid class */ /* container */ /* */ /* OUTPUT */ @@ -77,7 +78,7 @@ /* resulting in version 6.3.0 */ /* */ /**************************************************************************/ -UINT _ux_device_class_hid_tasks_run(VOID *instance) +UINT _ux_device_class_hid_tasks_run(VOID *hid_instance) { UX_SLAVE_CLASS_HID *hid; @@ -89,7 +90,7 @@ UINT status; /* Get HID instance. */ - hid = (UX_SLAVE_CLASS_HID *) instance; + hid = (UX_SLAVE_CLASS_HID *) hid_instance; /* Get the pointer to the device. */ device = &_ux_system_slave -> ux_system_slave_device; @@ -208,4 +209,4 @@ UINT status; return(UX_STATE_IDLE); } } -#endif +#endif /* UX_DEVICE_STANDALONE */ diff --git a/common/usbx_device_classes/src/ux_device_class_hid_uninitialize.c b/common/usbx_device_classes/src/ux_device_class_hid_uninitialize.c index 1c67a5dd..0060ce23 100644 --- a/common/usbx_device_classes/src/ux_device_class_hid_uninitialize.c +++ b/common/usbx_device_classes/src/ux_device_class_hid_uninitialize.c @@ -8,6 +8,7 @@ * SPDX-License-Identifier: MIT **************************************************************************/ +/**************************************************************************/ /**************************************************************************/ /** */ /** USBX Component */ @@ -149,4 +150,3 @@ UX_SLAVE_CLASS *class_ptr; /* Return completion status. */ return(UX_SUCCESS); } -