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 |
|
|
/** HID Class */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
/**************************************************************************/ |
22 |
|
|
|
23 |
|
|
|
24 |
|
|
/* Include necessary system files. */ |
25 |
|
|
|
26 |
|
|
#define UX_SOURCE_CODE |
27 |
|
|
|
28 |
|
|
#include "ux_api.h" |
29 |
|
|
#include "ux_host_class_hid.h" |
30 |
|
|
#include "ux_host_stack.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/**************************************************************************/ |
34 |
|
|
/* */ |
35 |
|
|
/* FUNCTION RELEASE */ |
36 |
|
|
/* */ |
37 |
|
|
/* _ux_host_class_hid_configure PORTABLE C */ |
38 |
|
|
/* 6.1.11 */ |
39 |
|
|
/* AUTHOR */ |
40 |
|
|
/* */ |
41 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
42 |
|
|
/* */ |
43 |
|
|
/* DESCRIPTION */ |
44 |
|
|
/* */ |
45 |
|
|
/* This function calls the USBX stack to do a SET_CONFIGURATION to the */ |
46 |
|
|
/* HID. Once the HID is configured, its interface will be activated */ |
47 |
|
|
/* and all the endpoints enumerated (1 interrupt endpoint in the case */ |
48 |
|
|
/* of the HID). */ |
49 |
|
|
/* */ |
50 |
|
|
/* INPUT */ |
51 |
|
|
/* */ |
52 |
|
|
/* hid Pointer to HID class */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* Completion Status */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* _ux_host_stack_configuration_interface_get Get interface */ |
61 |
|
|
/* _ux_host_stack_device_configuration_get Get configuration */ |
62 |
|
|
/* _ux_host_stack_device_configuration_select Select configuration */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* HID Class */ |
67 |
|
|
/* */ |
68 |
|
|
/**************************************************************************/ |
69 |
|
502 |
UINT _ux_host_class_hid_configure(UX_HOST_CLASS_HID *hid) |
70 |
|
|
{ |
71 |
|
|
|
72 |
|
|
UINT status; |
73 |
|
|
UX_CONFIGURATION *configuration; |
74 |
|
|
#if UX_MAX_DEVICES > 1 |
75 |
|
|
UX_DEVICE *device; |
76 |
|
|
UX_DEVICE *parent_device; |
77 |
|
|
#endif |
78 |
|
|
|
79 |
|
|
|
80 |
|
|
/* If the device has been configured already, we don't need to do it again. */ |
81 |
✓✓ |
502 |
if (hid -> ux_host_class_hid_device -> ux_device_state == UX_DEVICE_CONFIGURED) |
82 |
|
497 |
return(UX_SUCCESS); |
83 |
|
|
|
84 |
|
|
/* A HID normally has one configuration. So retrieve the 1st configuration only. */ |
85 |
|
5 |
status = _ux_host_stack_device_configuration_get(hid -> ux_host_class_hid_device, 0, &configuration); |
86 |
✓✓ |
5 |
if (status != UX_SUCCESS) |
87 |
|
|
{ |
88 |
|
|
|
89 |
|
|
/* Error trap. */ |
90 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONFIGURATION_HANDLE_UNKNOWN); |
91 |
|
|
|
92 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
93 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, hid -> ux_host_class_hid_device, 0, 0, UX_TRACE_ERRORS, 0, 0) |
94 |
|
|
|
95 |
|
1 |
return(UX_CONFIGURATION_HANDLE_UNKNOWN); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
#if UX_MAX_DEVICES > 1 |
99 |
|
|
/* Get the device container for this configuration. */ |
100 |
|
4 |
device = configuration -> ux_configuration_device; |
101 |
|
|
|
102 |
|
|
/* Get the parent container for this device. */ |
103 |
|
4 |
parent_device = device -> ux_device_parent; |
104 |
|
|
|
105 |
|
|
/* Check the HID power source and check the parent power source for |
106 |
|
|
incompatible connections. */ |
107 |
✓✓ |
4 |
if (hid -> ux_host_class_hid_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED) |
108 |
|
|
{ |
109 |
|
|
|
110 |
|
|
/* If the device is NULL, the parent is the root hid and we don't have to worry. |
111 |
|
|
If the parent is not the root HID, check for its power source. */ |
112 |
✓✓✓✓
|
3 |
if ((parent_device != UX_NULL) && (parent_device -> ux_device_power_source == UX_DEVICE_BUS_POWERED)) |
113 |
|
|
{ |
114 |
|
|
|
115 |
|
|
/* Error trap. */ |
116 |
|
1 |
_ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_CONNECTION_INCOMPATIBLE); |
117 |
|
|
|
118 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
119 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONNECTION_INCOMPATIBLE, hid, 0, 0, UX_TRACE_ERRORS, 0, 0) |
120 |
|
|
|
121 |
|
1 |
return(UX_CONNECTION_INCOMPATIBLE); |
122 |
|
|
} |
123 |
|
|
} |
124 |
|
|
#endif |
125 |
|
|
|
126 |
|
|
/* We have the valid configuration. Ask the USBX stack to set this configuration. */ |
127 |
|
3 |
_ux_host_stack_device_configuration_select(configuration); |
128 |
|
|
|
129 |
|
|
/* If the operation went well, the hid default alternate setting for the HID interface is active |
130 |
|
|
and the interrupt endpoint is now enabled. We have to memorize the first interface since the |
131 |
|
|
interrupt endpoint is hooked to it. */ |
132 |
|
3 |
status = _ux_host_stack_configuration_interface_get(configuration, 0, 0, &hid -> ux_host_class_hid_interface); |
133 |
|
|
|
134 |
|
|
/* Return completion status. */ |
135 |
|
3 |
return(status); |
136 |
|
|
} |
137 |
|
|
|