µOS++ IIIe Reference 7.0.0
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-2023 Liviu Ionescu. All rights reserved.
5 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission to use, copy, modify, and/or distribute this software
8 * for any purpose is hereby granted, under the terms of the MIT license.
9 *
10 * If a copy of the license was not distributed with this file, it can
11 * be obtained from https://opensource.org/licenses/mit/.
12 */
13
14/*
15 * The code is inspired by ARM CMSIS Driver_USBH.h file, v2.01,
16 * and tries to remain functionally close to the CMSIS specifications.
17 */
18
19#ifndef CMSIS_PLUS_DRIVER_USB_HOST_H_
20#define CMSIS_PLUS_DRIVER_USB_HOST_H_
21
22// ----------------------------------------------------------------------------
23
24#ifdef __cplusplus
25
26// ----------------------------------------------------------------------------
27
30
31#include <cstdint>
32#include <cstddef>
33
34// ----------------------------------------------------------------------------
35
36#pragma GCC diagnostic push
37#if defined(__clang__)
38#pragma clang diagnostic ignored "-Wc++98-compat"
39#endif
40
41// ----------------------------------------------------------------------------
42
43namespace os
44{
45 namespace driver
46 {
47 namespace usb
48 {
49 namespace host
50 {
51 // ==================================================================
52
53#pragma GCC diagnostic push
54#if defined(__clang__)
55#pragma clang diagnostic ignored "-Wpadded"
56#elif defined(__GNUC__)
57#pragma GCC diagnostic ignored "-Wpadded"
58#endif
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#if defined(__clang__)
93#pragma clang diagnostic ignored "-Wpadded"
94#elif defined(__GNUC__)
95#pragma GCC diagnostic ignored "-Wpadded"
96#endif
97
101 class Status
102 {
103 public:
104
105 bool
106 is_connected (void) const noexcept;
107
108 bool
109 is_overcurrent (void) const noexcept;
110
111 speed_t
112 get_speed (void) const noexcept;
113
114 // ----------------------------------------------------------------
115
116 public:
117
118 // For compatibility with ARM CMSIS, these bits should be
119 // exactly in this order.
120
122 bool connected :1;
123
125 bool overcurrent :1;
126
129 };
130
131#pragma GCC diagnostic pop
132
133 // ==================================================================
134 // ----- USB Host Port Events -----
135
140 : event_t
141 {
142 //
143
145 connect = (1UL << 0),
146
148 disconnect = (1UL << 1),
149
151 overcurrent = (1UL << 2),
152
154 reset = (1UL << 3),
155
157 suspend = (1UL << 4),
158
160 resume = (1UL << 5),
161
163 remote_hangup = (1UL << 6)
164 };
165
166 // ==================================================================
167 // ----- USB Host Pipe Event -----
168
175 : event_t
176 {
177 //
178
180 transfer_complete = (1UL << 0),
181
183 handshake_nak = (1UL << 1),
184
186 handshake_nyet = (1UL << 2),
187
189 handshake_mdata = (1UL << 3),
190
192 handshake_stall = (1UL << 4),
193
195 handshake_err = (1UL << 5),
196
198 bus_err = (1UL << 6)
199 };
200
201 // ------------------------------------------------------------------
202
203 typedef void
204 (*signal_port_event_t) (const void* object, port_t port, event_t event);
205
206 typedef void
207 (*signal_pipe_event_t) (const void* object, pipe_t pipe, event_t event);
208
209 } /* namespace host */
210
211 // ====================================================================
212
213#pragma GCC diagnostic push
214#if defined(__clang__)
215#pragma clang diagnostic ignored "-Wpadded"
216#elif defined(__GNUC__)
217#pragma GCC diagnostic ignored "-Wpadded"
218#endif
219
220 class Host : public Base
221 {
222
223 public:
224
225 // ------------------------------------------------------------------
226
227 Host () noexcept;
228
229 Host (const Host&) = delete;
230
231 Host (Host&&) = delete;
232
233 Host&
234 operator= (const Host&) = delete;
235
236 Host&
237 operator= (Host&&) = delete;
238
239 virtual
240 ~Host () noexcept override;
241
242 // ------------------------------------------------------------------
243
249 void
250 register_port_callback (host::signal_port_event_t cb_func,
251 const void* cb_object = nullptr) noexcept;
252
253 void
254 register_pipe_callback (host::signal_pipe_event_t cb_func,
255 const void* cb_object = nullptr) noexcept;
256
257 // ------------------------------------------------------------------
258
259 const host::Capabilities&
260 get_capabilities (void) noexcept;
261
263 power_port_vbus (port_t port, bool vbus) noexcept;
264
266 reset_port (port_t port) noexcept;
267
269 suspend_port (port_t port) noexcept;
270
272 resume_port (port_t port) noexcept;
273
274 host::Status&
275 get_port_status (port_t port) noexcept;
276
277 pipe_t
278 create_pipe (device_address_t dev_addr, speed_t dev_speed,
279 hub_addr_t hub_addr, hub_port_t hub_port,
280 endpoint_t ep_addr, endpoint_type_t ep_type,
281 packet_size_t ep_max_packet_size,
282 polling_interval_t ep_interval) noexcept;
283
285 modify_pipe (pipe_t pipe, device_address_t dev_addr, speed_t dev_speed,
286 hub_addr_t hub_addr, hub_port_t hub_port,
287 packet_size_t ep_max_packet_size) noexcept;
288
290 delete_pipe (pipe_t pipe) noexcept;
291
293 reset_pipe (pipe_t pipe) noexcept;
294
296 transfer (pipe_t pipe, uint32_t packet, uint8_t* data, std::size_t num)
297 noexcept;
298
299 std::size_t
300 get_transfer_count (pipe_t pipe) noexcept;
301
303 abort_transfer (pipe_t pipe) noexcept;
304
305 uint16_t
306 get_frame_number (void) noexcept;
307
308 void
309 signal_port_event (port_t port, event_t event) noexcept;
310
311 void
312 signal_pipe_event (pipe_t pipe, event_t event) noexcept;
313
314 protected:
315
316 virtual const host::Capabilities&
317 do_get_capabilities (void) noexcept = 0;
318
319 virtual return_t
320 do_power_port_vbus (port_t port, bool vbus) noexcept = 0;
321
322 virtual return_t
323 do_reset_port (port_t port) noexcept = 0;
324
325 virtual return_t
326 do_suspend_port (port_t port) noexcept = 0;
327
328 virtual return_t
329 do_resume_port (port_t port) noexcept = 0;
330
331 virtual host::Status&
332 do_get_port_status (port_t port) noexcept = 0;
333
334 virtual pipe_t
336 hub_addr_t hub_addr, hub_port_t hub_port,
337 endpoint_t ep_addr, endpoint_type_t ep_type,
338 packet_size_t ep_max_packet_size,
339 polling_interval_t ep_interval) noexcept = 0;
340
341 virtual return_t
343 speed_t dev_speed, hub_addr_t hub_addr,
344 hub_port_t hub_port, packet_size_t ep_max_packet_size)
345 noexcept = 0;
346
347 virtual return_t
348 do_delete_pipe (pipe_t pipe) noexcept = 0;
349
350 virtual return_t
351 do_reset_pipe (pipe_t pipe) noexcept = 0;
352
353 virtual return_t
354 do_transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
355 std::size_t num) noexcept = 0;
356
357 virtual std::size_t
358 do_get_transfer_count (pipe_t pipe) noexcept = 0;
359
360 virtual return_t
361 do_abort_transfer (pipe_t pipe) noexcept = 0;
362
363 virtual uint16_t
364 do_get_frame_number (void) noexcept = 0;
365
366 private:
367
369 host::signal_port_event_t cb_port_func_;
370
372 const void* cb_port_object_;
373
375 host::signal_pipe_event_t cb_pipe_func_;
376
378 const void* cb_pipe_object_;
379
380 protected:
381
382 host::Status status_;
383 };
384
385#pragma GCC diagnostic pop
386
387 // --------------------------------------------------------------------
388 // ----- Definitions -----
389
390 namespace host
391 {
392 // ------------------------------------------------------------------
393
394 inline bool
395 Status::is_connected (void) const noexcept
396 {
397 return connected;
398 }
399
400 inline bool
401 Status::is_overcurrent (void) const noexcept
402 {
403 return overcurrent;
404 }
405
406 inline speed_t
407 Status::get_speed (void) const noexcept
408 {
409 return speed;
410 }
411
412 } /* namespace host */
413
414 // --------------------------------------------------------------------
415
416 inline const host::Capabilities&
418 {
419 return do_get_capabilities ();
420 }
421
422 inline return_t
423 Host::power_port_vbus (port_t port, bool vbus) noexcept
424 {
425 return do_power_port_vbus (port, vbus);
426 }
427
428 inline return_t
429 Host::reset_port (port_t port) noexcept
430 {
431 return do_reset_port (port);
432 }
433
434 inline return_t
436 {
437 return do_suspend_port (port);
438 }
439
440 inline return_t
441 Host::resume_port (port_t port) noexcept
442 {
443 return do_resume_port (port);
444 }
445
446 inline host::Status&
448 {
449 return do_get_port_status (port);
450 }
451
452 inline pipe_t
454 hub_addr_t hub_addr, hub_port_t hub_port,
455 endpoint_t ep_addr, endpoint_type_t ep_type,
456 packet_size_t ep_max_packet_size,
457 polling_interval_t ep_interval) noexcept
458 {
459 return do_create_pipe (dev_addr, dev_speed, hub_addr, hub_port, ep_addr,
460 ep_type, ep_max_packet_size, ep_interval);
461 }
462
463 inline return_t
465 speed_t dev_speed, hub_addr_t hub_addr,
466 hub_port_t hub_port, packet_size_t ep_max_packet_size) noexcept
467 {
468 return do_modify_pipe (pipe, dev_addr, dev_speed, hub_addr, hub_port,
469 ep_max_packet_size);
470 }
471
472 inline return_t
473 Host::delete_pipe (pipe_t pipe) noexcept
474 {
475 return do_delete_pipe (pipe);
476 }
477
478 inline return_t
479 Host::reset_pipe (pipe_t pipe) noexcept
480 {
481 return do_reset_pipe (pipe);
482 }
483
484 inline std::size_t
486 {
487 return do_get_transfer_count (pipe);
488 }
489
490 inline return_t
492 {
493 return do_abort_transfer (pipe);
494 }
495
496 inline uint16_t
498 {
499 return do_get_frame_number ();
500 }
501
502 } /* namespace usb */
503 } /* namespace driver */
504} /* namespace os */
505
506#pragma GCC diagnostic pop
507
508// ----------------------------------------------------------------------------
509
510#endif /* __cplusplus */
511
512// ----------------------------------------------------------------------------
513
514#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:369
virtual return_t do_suspend_port(port_t port) noexcept=0
return_t reset_port(port_t port) noexcept
Definition usb-host.h:429
return_t delete_pipe(pipe_t pipe) noexcept
Definition usb-host.h:473
Host & operator=(const Host &)=delete
const host::Capabilities & get_capabilities(void) noexcept
Definition usb-host.h:417
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:447
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:453
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:56
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:98
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:375
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition usb-host.cpp:74
return_t power_port_vbus(port_t port, bool vbus) noexcept
Definition usb-host.h:423
return_t resume_port(port_t port) noexcept
Definition usb-host.h:441
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:464
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:378
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:435
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition usb-host.h:372
return_t reset_pipe(pipe_t pipe) noexcept
Definition usb-host.h:479
std::size_t get_transfer_count(pipe_t pipe) noexcept
Definition usb-host.h:485
uint16_t get_frame_number(void) noexcept
Definition usb-host.h:497
host::Status status_
Definition usb-host.h:382
virtual return_t do_reset_port(port_t port) noexcept=0
virtual ~Host() noexcept override
Definition usb-host.cpp:50
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition usb-host.cpp:64
void signal_port_event(port_t port, event_t event) noexcept
Definition usb-host.cpp:88
return_t abort_transfer(pipe_t pipe) noexcept
Definition usb-host.h:491
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:407
bool is_connected(void) const noexcept
Definition usb-host.h:395
bool is_overcurrent(void) const noexcept
Definition usb-host.h:401
bool overcurrent
USB Host Port speed setting (ARM_USB_SPEED_xxx)
Definition usb-host.h:125
bool connected
< USB Host Port connected flag
Definition usb-host.h:122
Port_event
USB Host Port Events.
Definition usb-host.h:141
@ resume
USB Device activated Remote Wakeup.
Definition usb-host.h:160
@ disconnect
USB Device caused Overcurrent.
Definition usb-host.h:148
@ suspend
USB Resume occurred.
Definition usb-host.h:157
@ overcurrent
USB Reset completed.
Definition usb-host.h:151
@ connect
USB Device Connected to Port.
Definition usb-host.h:145
@ reset
USB Suspend occurred.
Definition usb-host.h:154
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition usb-host.h:207
Pipe_event
USB Host Pipe Event.
Definition usb-host.h:176
@ handshake_nak
NYET Handshake received.
Definition usb-host.h:183
@ transfer_complete
Transfer completed.
Definition usb-host.h:180
@ handshake_stall
ERR Handshake received.
Definition usb-host.h:192
@ handshake_err
Bus Error detected.
Definition usb-host.h:195
@ handshake_mdata
STALL Handshake received.
Definition usb-host.h:189
@ handshake_nyet
MDATA Handshake received.
Definition usb-host.h:186
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition usb-host.h:204
uint8_t speed_t
Definition usb.h:46
uint8_t endpoint_t
Definition usb.h:68
uint32_t pipe_t
Definition usb.h:109
uint8_t hub_addr_t
Definition usb.h:112
uint8_t device_address_t
Definition usb.h:106
uint8_t endpoint_type_t
Definition usb.h:75
uint16_t packet_size_t
Definition usb.h:99
uint8_t port_t
Definition usb.h:110
uint8_t polling_interval_t
Definition usb.h:115
uint8_t hub_port_t
Definition usb.h:113
int32_t return_t
Definition common.h:47
uint32_t event_t
Definition common.h:46
System namespace.
Standard std namespace.