µOS++ IIIe Reference 6.3.17
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
usb-host.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2016 Liviu Ionescu.
5 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * The code is inspired by ARM CMSIS Driver_USBH.h file, v2.01,
31 * and tries to remain functionally close to the CMSIS specifications.
32 */
33
34#ifndef CMSIS_PLUS_DRIVER_USB_HOST_H_
35#define CMSIS_PLUS_DRIVER_USB_HOST_H_
36
37// ----------------------------------------------------------------------------
38
39#ifdef __cplusplus
40
43
44#include <cstdint>
45#include <cstddef>
46
47namespace os
48{
49 namespace driver
50 {
51 namespace usb
52 {
53 namespace host
54 {
55 // ==================================================================
56
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wpadded"
59
64 {
65 public:
66
67 // For compatibility with ARM CMSIS, these bits should be
68 // exactly in this order.
69
71 uint32_t port_mask :15;
72
74 bool auto_split :1;
75
78
81
84 };
85
86#pragma GCC diagnostic pop
87
88 // ==================================================================
89 // ----- USB Host Status -----
90
91#pragma GCC diagnostic push
92#pragma GCC diagnostic ignored "-Wpadded"
93
97 class Status
98 {
99 public:
100
101 bool
102 is_connected (void) const noexcept;
103
104 bool
105 is_overcurrent (void) const noexcept;
106
107 speed_t
108 get_speed (void) const noexcept;
109
110 // ----------------------------------------------------------------
111
112 public:
113
114 // For compatibility with ARM CMSIS, these bits should be
115 // exactly in this order.
116
118 bool connected :1;
119
121 bool overcurrent :1;
122
125 };
126
127#pragma GCC diagnostic pop
128
129 // ==================================================================
130 // ----- USB Host Port Events -----
131
136 : event_t
137 {
138 //
139
141 connect = (1UL << 0),
142
144 disconnect = (1UL << 1),
145
147 overcurrent = (1UL << 2),
148
150 reset = (1UL << 3),
151
153 suspend = (1UL << 4),
154
156 resume = (1UL << 5),
157
159 remote_hangup = (1UL << 6)
160 };
161
162 // ==================================================================
163 // ----- USB Host Pipe Event -----
164
169 : event_t
170 {
171 //
172
174 transfer_complete = (1UL << 0),
175
177 handshake_nak = (1UL << 1),
178
180 handshake_nyet = (1UL << 2),
181
183 handshake_mdata = (1UL << 3),
184
186 handshake_stall = (1UL << 4),
187
189 handshake_err = (1UL << 5),
190
192 bus_err = (1UL << 6)
193 };
194
195 // ------------------------------------------------------------------
196
197 typedef void
198 (*signal_port_event_t) (const void* object, port_t port, event_t event);
199
200 typedef void
201 (*signal_pipe_event_t) (const void* object, pipe_t pipe, event_t event);
202
203 } /* namespace host */
204
205 // ====================================================================
206
207#pragma GCC diagnostic push
208#pragma GCC diagnostic ignored "-Wpadded"
209
210 class Host : public Base
211 {
212
213 public:
214
215 // ------------------------------------------------------------------
216
217 Host () noexcept;
218
219 Host (const Host&) = delete;
220
221 Host (Host&&) = delete;
222
223 Host&
224 operator= (const Host&) = delete;
225
226 Host&
227 operator= (Host&&) = delete;
228
229 virtual
230 ~Host () noexcept;
231
232 // ------------------------------------------------------------------
233
239 void
240 register_port_callback (host::signal_port_event_t cb_func,
241 const void* cb_object = nullptr) noexcept;
242
243 void
244 register_pipe_callback (host::signal_pipe_event_t cb_func,
245 const void* cb_object = nullptr) noexcept;
246
247 // ------------------------------------------------------------------
248
249 const host::Capabilities&
250 get_capabilities (void) noexcept;
251
253 power_port_vbus (port_t port, bool vbus) noexcept;
254
256 reset_port (port_t port) noexcept;
257
259 suspend_port (port_t port) noexcept;
260
262 resume_port (port_t port) noexcept;
263
264 host::Status&
265 get_port_status (port_t port) noexcept;
266
267 pipe_t
268 create_pipe (device_address_t dev_addr, speed_t dev_speed,
269 hub_addr_t hub_addr, hub_port_t hub_port,
270 endpoint_t ep_addr, endpoint_type_t ep_type,
271 packet_size_t ep_max_packet_size,
272 polling_interval_t ep_interval) noexcept;
273
275 modify_pipe (pipe_t pipe, device_address_t dev_addr, speed_t dev_speed,
276 hub_addr_t hub_addr, hub_port_t hub_port,
277 packet_size_t ep_max_packet_size) noexcept;
278
280 delete_pipe (pipe_t pipe) noexcept;
281
283 reset_pipe (pipe_t pipe) noexcept;
284
286 transfer (pipe_t pipe, uint32_t packet, uint8_t* data, std::size_t num)
287 noexcept;
288
289 std::size_t
290 get_transfer_count (pipe_t pipe) noexcept;
291
293 abort_transfer (pipe_t pipe) noexcept;
294
295 uint16_t
296 get_frame_number (void) noexcept;
297
298 void
299 signal_port_event (port_t port, event_t event) noexcept;
300
301 void
302 signal_pipe_event (pipe_t pipe, event_t event) noexcept;
303
304 protected:
305
306 virtual const host::Capabilities&
307 do_get_capabilities (void) noexcept = 0;
308
309 virtual return_t
310 do_power_port_vbus (port_t port, bool vbus) noexcept = 0;
311
312 virtual return_t
313 do_reset_port (port_t port) noexcept = 0;
314
315 virtual return_t
316 do_suspend_port (port_t port) noexcept = 0;
317
318 virtual return_t
319 do_resume_port (port_t port) noexcept = 0;
320
321 virtual host::Status&
322 do_get_port_status (port_t port) noexcept = 0;
323
324 virtual pipe_t
326 hub_addr_t hub_addr, hub_port_t hub_port,
327 endpoint_t ep_addr, endpoint_type_t ep_type,
328 packet_size_t ep_max_packet_size,
329 polling_interval_t ep_interval) noexcept = 0;
330
331 virtual return_t
333 speed_t dev_speed, hub_addr_t hub_addr,
334 hub_port_t hub_port, packet_size_t ep_max_packet_size)
335 noexcept = 0;
336
337 virtual return_t
338 do_delete_pipe (pipe_t pipe) noexcept = 0;
339
340 virtual return_t
341 do_reset_pipe (pipe_t pipe) noexcept = 0;
342
343 virtual return_t
344 do_transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
345 std::size_t num) noexcept = 0;
346
347 virtual std::size_t
348 do_get_transfer_count (pipe_t pipe) noexcept = 0;
349
350 virtual return_t
351 do_abort_transfer (pipe_t pipe) noexcept = 0;
352
353 virtual uint16_t
354 do_get_frame_number (void) noexcept = 0;
355
356 private:
357
359 host::signal_port_event_t cb_port_func_;
360
362 const void* cb_port_object_;
363
365 host::signal_pipe_event_t cb_pipe_func_;
366
368 const void* cb_pipe_object_;
369
370 protected:
371
372 host::Status status_;
373 };
374
375#pragma GCC diagnostic pop
376
377 // --------------------------------------------------------------------
378 // ----- Definitions -----
379
380 namespace host
381 {
382 // ------------------------------------------------------------------
383
384 inline bool
385 Status::is_connected (void) const noexcept
386 {
387 return connected;
388 }
389
390 inline bool
391 Status::is_overcurrent (void) const noexcept
392 {
393 return overcurrent;
394 }
395
396 inline speed_t
397 Status::get_speed (void) const noexcept
398 {
399 return speed;
400 }
401
402 } /* namespace host */
403
404 // --------------------------------------------------------------------
405
406 inline const host::Capabilities&
408 {
409 return do_get_capabilities ();
410 }
411
412 inline return_t
413 Host::power_port_vbus (port_t port, bool vbus) noexcept
414 {
415 return do_power_port_vbus (port, vbus);
416 }
417
418 inline return_t
419 Host::reset_port (port_t port) noexcept
420 {
421 return do_reset_port (port);
422 }
423
424 inline return_t
426 {
427 return do_suspend_port (port);
428 }
429
430 inline return_t
431 Host::resume_port (port_t port) noexcept
432 {
433 return do_resume_port (port);
434 }
435
436 inline host::Status&
438 {
439 return do_get_port_status (port);
440 }
441
442 inline pipe_t
444 hub_addr_t hub_addr, hub_port_t hub_port,
445 endpoint_t ep_addr, endpoint_type_t ep_type,
446 packet_size_t ep_max_packet_size,
447 polling_interval_t ep_interval) noexcept
448 {
449 return do_create_pipe (dev_addr, dev_speed, hub_addr, hub_port, ep_addr,
450 ep_type, ep_max_packet_size, ep_interval);
451 }
452
453 inline return_t
455 speed_t dev_speed, hub_addr_t hub_addr,
456 hub_port_t hub_port, packet_size_t ep_max_packet_size) noexcept
457 {
458 return do_modify_pipe (pipe, dev_addr, dev_speed, hub_addr, hub_port,
459 ep_max_packet_size);
460 }
461
462 inline return_t
463 Host::delete_pipe (pipe_t pipe) noexcept
464 {
465 return do_delete_pipe (pipe);
466 }
467
468 inline return_t
469 Host::reset_pipe (pipe_t pipe) noexcept
470 {
471 return do_reset_pipe (pipe);
472 }
473
474 inline std::size_t
476 {
477 return do_get_transfer_count (pipe);
478 }
479
480 inline return_t
482 {
483 return do_abort_transfer (pipe);
484 }
485
486 inline uint16_t
488 {
489 return do_get_frame_number ();
490 }
491
492 } /* namespace usb */
493 } /* namespace driver */
494} /* namespace os */
495
496#endif /* __cplusplus */
497
498// ----------------------------------------------------------------------------
499
500#endif /* CMSIS_PLUS_DRIVER_USB_HOST_H_ */
Host(const Host &)=delete
virtual return_t do_power_port_vbus(port_t port, bool vbus) noexcept=0
host::signal_port_event_t cb_port_func_
Pointer to static function that implements the port callback.
Definition usb-host.h:359
virtual return_t do_suspend_port(port_t port) noexcept=0
return_t reset_port(port_t port) noexcept
Definition usb-host.h:419
return_t delete_pipe(pipe_t pipe) noexcept
Definition usb-host.h:463
Host & operator=(const Host &)=delete
const host::Capabilities & get_capabilities(void) noexcept
Definition usb-host.h:407
virtual host::Status & do_get_port_status(port_t port) noexcept=0
virtual return_t do_reset_pipe(pipe_t pipe) noexcept=0
virtual return_t do_delete_pipe(pipe_t pipe) noexcept=0
Host(Host &&)=delete
host::Status & get_port_status(port_t port) noexcept
Definition usb-host.h:437
pipe_t create_pipe(device_address_t dev_addr, speed_t dev_speed, hub_addr_t hub_addr, hub_port_t hub_port, endpoint_t ep_addr, endpoint_type_t ep_type, packet_size_t ep_max_packet_size, polling_interval_t ep_interval) noexcept
Definition usb-host.h:443
void register_port_callback(host::signal_port_event_t cb_func, const void *cb_object=nullptr) noexcept
Register port event callback.
Definition usb-host.cpp:65
virtual return_t do_resume_port(port_t port) noexcept=0
void signal_pipe_event(pipe_t pipe, event_t event) noexcept
Definition usb-host.cpp:107
virtual uint16_t do_get_frame_number(void) noexcept=0
virtual return_t do_modify_pipe(pipe_t pipe, device_address_t dev_addr, speed_t dev_speed, hub_addr_t hub_addr, hub_port_t hub_port, packet_size_t ep_max_packet_size) noexcept=0
host::signal_pipe_event_t cb_pipe_func_
Pointer to static function that implements the pipe callback.
Definition usb-host.h:365
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition usb-host.cpp:83
return_t power_port_vbus(port_t port, bool vbus) noexcept
Definition usb-host.h:413
return_t resume_port(port_t port) noexcept
Definition usb-host.h:431
virtual return_t do_abort_transfer(pipe_t pipe) noexcept=0
return_t modify_pipe(pipe_t pipe, device_address_t dev_addr, speed_t dev_speed, hub_addr_t hub_addr, hub_port_t hub_port, packet_size_t ep_max_packet_size) noexcept
Definition usb-host.h:454
virtual pipe_t do_create_pipe(device_address_t dev_addr, speed_t dev_speed, hub_addr_t hub_addr, hub_port_t hub_port, endpoint_t ep_addr, endpoint_type_t ep_type, packet_size_t ep_max_packet_size, polling_interval_t ep_interval) noexcept=0
const void * cb_pipe_object_
Pointer to object instance associated with the pipe callback.
Definition usb-host.h:368
virtual const host::Capabilities & do_get_capabilities(void) noexcept=0
virtual std::size_t do_get_transfer_count(pipe_t pipe) noexcept=0
return_t suspend_port(port_t port) noexcept
Definition usb-host.h:425
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition usb-host.h:362
return_t reset_pipe(pipe_t pipe) noexcept
Definition usb-host.h:469
std::size_t get_transfer_count(pipe_t pipe) noexcept
Definition usb-host.h:475
uint16_t get_frame_number(void) noexcept
Definition usb-host.h:487
host::Status status_
Definition usb-host.h:372
virtual return_t do_reset_port(port_t port) noexcept=0
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition usb-host.cpp:73
void signal_port_event(port_t port, event_t event) noexcept
Definition usb-host.cpp:97
virtual ~Host() noexcept
Definition usb-host.cpp:59
return_t abort_transfer(pipe_t pipe) noexcept
Definition usb-host.h:481
virtual return_t do_transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept=0
USB host driver capabilities.
Definition usb-host.h:64
bool event_connect
Signal Disconnect event.
Definition usb-host.h:77
uint32_t port_mask
< Root HUB available Ports Mask
Definition usb-host.h:71
bool auto_split
Signal Connect event.
Definition usb-host.h:74
bool event_disconnect
Signal Overcurrent event.
Definition usb-host.h:80
speed_t get_speed(void) const noexcept
Definition usb-host.h:397
bool is_connected(void) const noexcept
Definition usb-host.h:385
bool is_overcurrent(void) const noexcept
Definition usb-host.h:391
bool overcurrent
USB Host Port speed setting (ARM_USB_SPEED_xxx)
Definition usb-host.h:121
bool connected
< USB Host Port connected flag
Definition usb-host.h:118
Port_event
USB Host Port Events.
Definition usb-host.h:137
@ resume
USB Device activated Remote Wakeup.
Definition usb-host.h:156
@ disconnect
USB Device caused Overcurrent.
Definition usb-host.h:144
@ suspend
USB Resume occurred.
Definition usb-host.h:153
@ overcurrent
USB Reset completed.
Definition usb-host.h:147
@ connect
USB Device Connected to Port.
Definition usb-host.h:141
@ reset
USB Suspend occurred.
Definition usb-host.h:150
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition usb-host.h:201
Pipe_event
USB Host Pipe Event.
Definition usb-host.h:170
@ handshake_nak
NYET Handshake received.
Definition usb-host.h:177
@ transfer_complete
Transfer completed.
Definition usb-host.h:174
@ handshake_stall
ERR Handshake received.
Definition usb-host.h:186
@ handshake_err
Bus Error detected.
Definition usb-host.h:189
@ handshake_mdata
STALL Handshake received.
Definition usb-host.h:183
@ handshake_nyet
MDATA Handshake received.
Definition usb-host.h:180
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition usb-host.h:198
uint8_t speed_t
Definition usb.h:52
uint8_t endpoint_t
Definition usb.h:74
uint32_t pipe_t
Definition usb.h:115
uint8_t hub_addr_t
Definition usb.h:118
uint8_t device_address_t
Definition usb.h:112
uint8_t endpoint_type_t
Definition usb.h:81
uint16_t packet_size_t
Definition usb.h:105
uint8_t port_t
Definition usb.h:116
uint8_t polling_interval_t
Definition usb.h:121
uint8_t hub_port_t
Definition usb.h:119
int32_t return_t
Definition common.h:51
uint32_t event_t
Definition common.h:50
System namespace.
Standard std namespace.