1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** USBX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Device HID Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
#define UX_SOURCE_CODE |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
/* Include necessary system files. */ |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_device_class_hid.h" |
30 |
|
|
#include "ux_device_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_device_class_hid_entry PORTABLE C */ |
38 |
|
|
/* 6.x */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function is the entry point of the hid class. It */ |
46 |
|
|
/* will be called by the device stack enumeration module when the */ |
47 |
|
|
/* host has sent a SET_CONFIGURATION command and the hid interface */ |
48 |
|
|
/* needs to be mounted. */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* command Pointer to class command */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _ux_device_class_hid_initialize Initialize hid class */ |
61 |
|
|
/* _ux_device_class_hid_uninitialize Uninitialize hid class */ |
62 |
|
|
/* _ux_device_class_hid_activate Activate hid class */ |
63 |
|
|
/* _ux_device_class_hid_deactivate Deactivate hid class */ |
64 |
|
|
/* _ux_device_class_hid_control_request Request control */ |
65 |
|
|
/* */ |
66 |
|
|
/* CALLED BY */ |
67 |
|
|
/* */ |
68 |
|
|
/* HID Class */ |
69 |
|
|
/* */ |
70 |
|
|
/**************************************************************************/ |
71 |
|
3269 |
UINT _ux_device_class_hid_entry(UX_SLAVE_CLASS_COMMAND *command) |
72 |
|
|
{ |
73 |
|
|
|
74 |
|
|
UINT status; |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* The command request will tell us we need to do here, either a enumeration |
78 |
|
|
query, an activation or a deactivation. */ |
79 |
✓✓✓✓ ✓✓✓ |
3269 |
switch (command -> ux_slave_class_command_request) |
80 |
|
|
{ |
81 |
|
|
|
82 |
|
204 |
case UX_SLAVE_CLASS_COMMAND_INITIALIZE: |
83 |
|
|
|
84 |
|
|
/* Call the init function of the HID class. */ |
85 |
|
|
#if defined(UX_DEVICE_CLASS_HID_ENABLE_ERROR_CHECKING) |
86 |
|
|
status = _uxe_device_class_hid_initialize(command); |
87 |
|
|
#else |
88 |
|
204 |
status = _ux_device_class_hid_initialize(command); |
89 |
|
|
#endif |
90 |
|
|
|
91 |
|
|
/* Return the completion status. */ |
92 |
|
204 |
return(status); |
93 |
|
|
|
94 |
|
158 |
case UX_SLAVE_CLASS_COMMAND_UNINITIALIZE: |
95 |
|
|
|
96 |
|
|
/* Call the uninit function of the HID class. */ |
97 |
|
158 |
status = _ux_device_class_hid_uninitialize(command); |
98 |
|
|
|
99 |
|
|
/* Return the completion status. */ |
100 |
|
158 |
return(status); |
101 |
|
|
|
102 |
|
691 |
case UX_SLAVE_CLASS_COMMAND_QUERY: |
103 |
|
|
|
104 |
|
|
/* Check the CLASS definition in the interface descriptor. */ |
105 |
✓✓ |
691 |
if (command -> ux_slave_class_command_class == UX_DEVICE_CLASS_HID_CLASS) |
106 |
|
690 |
return(UX_SUCCESS); |
107 |
|
|
else |
108 |
|
1 |
return(UX_NO_CLASS_MATCH); |
109 |
|
|
|
110 |
|
690 |
case UX_SLAVE_CLASS_COMMAND_ACTIVATE: |
111 |
|
|
|
112 |
|
|
/* The activate command is used when the host has sent a SET_CONFIGURATION command |
113 |
|
|
and this interface has to be mounted. Both Bulk endpoints have to be mounted |
114 |
|
|
and the hid thread needs to be activated. */ |
115 |
|
690 |
status = _ux_device_class_hid_activate(command); |
116 |
|
|
|
117 |
|
|
/* Return the completion status. */ |
118 |
|
690 |
return(status); |
119 |
|
|
|
120 |
|
677 |
case UX_SLAVE_CLASS_COMMAND_DEACTIVATE: |
121 |
|
|
|
122 |
|
|
/* The deactivate command is used when the device has been extracted. |
123 |
|
|
The device endpoints have to be dismounted and the hid thread canceled. */ |
124 |
|
677 |
status = _ux_device_class_hid_deactivate(command); |
125 |
|
|
|
126 |
|
|
/* Return the completion status. */ |
127 |
|
677 |
return(status); |
128 |
|
|
|
129 |
|
848 |
case UX_SLAVE_CLASS_COMMAND_REQUEST: |
130 |
|
|
|
131 |
|
|
/* The request command is used when the host sends a command on the control endpoint. */ |
132 |
|
848 |
status = _ux_device_class_hid_control_request(command); |
133 |
|
|
|
134 |
|
|
/* Return the completion status. */ |
135 |
|
848 |
return(status); |
136 |
|
|
|
137 |
|
1 |
default: |
138 |
|
|
|
139 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
140 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0) |
141 |
|
|
|
142 |
|
|
/* Return an error. */ |
143 |
|
1 |
return(UX_FUNCTION_NOT_SUPPORTED); |
144 |
|
|
} |
145 |
|
|
} |