blob: 33a3643dc8261a3ce112a5af9dadfa94adeee7fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Device HID Class */
/** */
/**************************************************************************/
/**************************************************************************/
#define UX_SOURCE_CODE
/* Include necessary system files. */
#include "ux_api.h"
#include "ux_device_class_hid.h"
#include "ux_device_stack.h"
#if defined(UX_DEVICE_STANDALONE)
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_hid_tasks_run PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function is the background task of the hid. */
/* */
/* It's for standalone mode. */
/* */
/* INPUT */
/* */
/* hid_instance Address of hid class */
/* container */
/* */
/* OUTPUT */
/* */
/* State machine status */
/* UX_STATE_EXIT Device not configured */
/* UX_STATE_IDLE No interrupt transfer running */
/* UX_STATE_WAIT Interrupt IN transfer running */
/* */
/* CALLS */
/* */
/* _ux_device_class_hid_event_get Get HID event */
/* _ux_device_stack_transfer_run Run transfer state machine */
/* _ux_utility_memory_copy Copy memory */
/* */
/* CALLED BY */
/* */
/* USBX Device Stack */
/* */
/**************************************************************************/
UINT _ux_device_class_hid_tasks_run(VOID *hid_instance)
{
UX_SLAVE_CLASS_HID *hid;
UX_SLAVE_DEVICE *device;
UX_DEVICE_CLASS_HID_EVENT *hid_event;
UX_SLAVE_TRANSFER *trans;
ULONG tick, elapsed;
UINT status;
/* Get HID instance. */
hid = (UX_SLAVE_CLASS_HID *) hid_instance;
/* Get the pointer to the device. */
device = &_ux_system_slave -> ux_system_slave_device;
/* Check if the device is configured. */
if (device -> ux_slave_device_state != UX_DEVICE_CONFIGURED)
{
hid -> ux_device_class_hid_event_state = UX_STATE_EXIT;
return(UX_STATE_EXIT);
}
#if defined(UX_DEVICE_CLASS_HID_INTERRUPT_OUT_SUPPORT)
if (hid -> ux_device_class_hid_receiver)
hid -> ux_device_class_hid_receiver -> ux_device_class_hid_receiver_tasks_run(hid);
#endif
/* Get access to current event instance. */
hid_event = &hid -> ux_device_class_hid_event;
/* Run HID state machine. */
switch(hid -> ux_device_class_hid_event_state)
{
case UX_STATE_EXIT:
/* There is nothing to do in this state. */
return (UX_STATE_EXIT);
case UX_STATE_RESET:
/* Start timeout waiting. */
hid -> ux_device_class_hid_event_wait_start = _ux_utility_time_get();
hid -> ux_device_class_hid_event_state = UX_STATE_IDLE;
/* Fall through. */
case UX_STATE_IDLE:
/* Check if there is event ready. */
status = _ux_device_class_hid_event_check(hid, &hid_event);
/* If there is no event, check idle rate. */
if (status != UX_SUCCESS)
{
/* Check idle rate setting. */
if (hid -> ux_device_class_hid_event_wait_timeout == UX_WAIT_FOREVER)
{
/* There is no background idle report, keep waiting. */
return(UX_STATE_IDLE);
}
/* Check wait timeout. */
tick = _ux_utility_time_get();
elapsed = _ux_utility_time_elapsed(hid -> ux_device_class_hid_event_wait_start, tick);
if (elapsed < hid -> ux_device_class_hid_event_wait_timeout)
{
/* Keep waiting. */
return(UX_STATE_IDLE);
}
/* Send the last event in buffer. */
}
/* Prepare the request to send event. */
trans = &hid -> ux_device_class_hid_interrupt_endpoint ->
ux_slave_endpoint_transfer_request;
#if (UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1) && defined(UX_DEVICE_CLASS_HID_ZERO_COPY)
/* Directly use event buffer for transfer. */
trans -> ux_slave_transfer_request_data_pointer =
hid_event -> ux_device_class_hid_event_buffer;
#else
/* Copy event data to endpoint buffer. */
_ux_utility_memory_copy(trans -> ux_slave_transfer_request_data_pointer,
UX_DEVICE_CLASS_HID_EVENT_BUFFER(hid_event),
hid_event -> ux_device_class_hid_event_length); /* Use case of memcpy is verified. */
#endif
trans -> ux_slave_transfer_request_requested_length =
hid_event -> ux_device_class_hid_event_length;
UX_SLAVE_TRANSFER_STATE_RESET(trans);
hid -> ux_device_class_hid_event_state = UX_STATE_WAIT;
/* Fall through. */
case UX_STATE_WAIT:
/* Run transfer state machine. */
trans = &hid -> ux_device_class_hid_interrupt_endpoint ->
ux_slave_endpoint_transfer_request;
status = _ux_device_stack_transfer_run(trans,
hid_event -> ux_device_class_hid_event_length,
hid_event -> ux_device_class_hid_event_length);
/* Any error or success case. */
if (status <= UX_STATE_NEXT)
{
/* Event handled and the tail should be freed. */
_ux_device_class_hid_event_free(hid);
/* Next round. */
hid -> ux_device_class_hid_event_state = UX_STATE_RESET;
return(UX_STATE_IDLE);
}
/* Wait. */
return(UX_STATE_WAIT);
default:
/* Just go back to normal state. */
hid -> ux_device_class_hid_event_state = UX_STATE_RESET;
return(UX_STATE_IDLE);
}
}
#endif /* UX_DEVICE_STANDALONE */
|