µ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 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
41// ----------------------------------------------------------------------------
42
45
46#include <cstdint>
47#include <cstddef>
48
49// ----------------------------------------------------------------------------
50
51#pragma GCC diagnostic push
52
53#if defined(__clang__)
54#pragma clang diagnostic ignored "-Wc++98-compat"
55#endif
56
57// ----------------------------------------------------------------------------
58
59namespace os
60{
61 namespace driver
62 {
63 namespace usb
64 {
65 namespace host
66 {
67 // ==================================================================
68
69#pragma GCC diagnostic push
70#pragma GCC diagnostic ignored "-Wpadded"
71
76 {
77 public:
78
79 // For compatibility with ARM CMSIS, these bits should be
80 // exactly in this order.
81
83 uint32_t port_mask :15;
84
86 bool auto_split :1;
87
90
93
96 };
97
98#pragma GCC diagnostic pop
99
100 // ==================================================================
101 // ----- USB Host Status -----
102
103#pragma GCC diagnostic push
104#pragma GCC diagnostic ignored "-Wpadded"
105
109 class Status
110 {
111 public:
112
113 bool
114 is_connected (void) const noexcept;
115
116 bool
117 is_overcurrent (void) const noexcept;
118
119 speed_t
120 get_speed (void) const noexcept;
121
122 // ----------------------------------------------------------------
123
124 public:
125
126 // For compatibility with ARM CMSIS, these bits should be
127 // exactly in this order.
128
130 bool connected :1;
131
133 bool overcurrent :1;
134
137 };
138
139#pragma GCC diagnostic pop
140
141 // ==================================================================
142 // ----- USB Host Port Events -----
143
148 : event_t
149 {
150 //
151
153 connect = (1UL << 0),
154
156 disconnect = (1UL << 1),
157
159 overcurrent = (1UL << 2),
160
162 reset = (1UL << 3),
163
165 suspend = (1UL << 4),
166
168 resume = (1UL << 5),
169
171 remote_hangup = (1UL << 6)
172 };
173
174 // ==================================================================
175 // ----- USB Host Pipe Event -----
176
181 : event_t
182 {
183 //
184
186 transfer_complete = (1UL << 0),
187
189 handshake_nak = (1UL << 1),
190
192 handshake_nyet = (1UL << 2),
193
195 handshake_mdata = (1UL << 3),
196
198 handshake_stall = (1UL << 4),
199
201 handshake_err = (1UL << 5),
202
204 bus_err = (1UL << 6)
205 };
206
207 // ------------------------------------------------------------------
208
209 typedef void
210 (*signal_port_event_t) (const void* object, port_t port, event_t event);
211
212 typedef void
213 (*signal_pipe_event_t) (const void* object, pipe_t pipe, event_t event);
214
215 } /* namespace host */
216
217 // ====================================================================
218
219#pragma GCC diagnostic push
220#pragma GCC diagnostic ignored "-Wpadded"
221
222 class Host : public Base
223 {
224
225 public:
226
227 // ------------------------------------------------------------------
228
229 Host () noexcept;
230
231 Host (const Host&) = delete;
232
233 Host (Host&&) = delete;
234
235 Host&
236 operator= (const Host&) = delete;
237
238 Host&
239 operator= (Host&&) = delete;
240
241 virtual
242 ~Host () noexcept override;
243
244 // ------------------------------------------------------------------
245
251 void
252 register_port_callback (host::signal_port_event_t cb_func,
253 const void* cb_object = nullptr) noexcept;
254
255 void
256 register_pipe_callback (host::signal_pipe_event_t cb_func,
257 const void* cb_object = nullptr) noexcept;
258
259 // ------------------------------------------------------------------
260
261 const host::Capabilities&
262 get_capabilities (void) noexcept;
263
265 power_port_vbus (port_t port, bool vbus) noexcept;
266
268 reset_port (port_t port) noexcept;
269
271 suspend_port (port_t port) noexcept;
272
274 resume_port (port_t port) noexcept;
275
276 host::Status&
277 get_port_status (port_t port) noexcept;
278
279 pipe_t
280 create_pipe (device_address_t dev_addr, speed_t dev_speed,
281 hub_addr_t hub_addr, hub_port_t hub_port,
282 endpoint_t ep_addr, endpoint_type_t ep_type,
283 packet_size_t ep_max_packet_size,
284 polling_interval_t ep_interval) noexcept;
285
287 modify_pipe (pipe_t pipe, device_address_t dev_addr, speed_t dev_speed,
288 hub_addr_t hub_addr, hub_port_t hub_port,
289 packet_size_t ep_max_packet_size) noexcept;
290
292 delete_pipe (pipe_t pipe) noexcept;
293
295 reset_pipe (pipe_t pipe) noexcept;
296
298 transfer (pipe_t pipe, uint32_t packet, uint8_t* data, std::size_t num)
299 noexcept;
300
301 std::size_t
302 get_transfer_count (pipe_t pipe) noexcept;
303
305 abort_transfer (pipe_t pipe) noexcept;
306
307 uint16_t
308 get_frame_number (void) noexcept;
309
310 void
311 signal_port_event (port_t port, event_t event) noexcept;
312
313 void
314 signal_pipe_event (pipe_t pipe, event_t event) noexcept;
315
316 protected:
317
318 virtual const host::Capabilities&
319 do_get_capabilities (void) noexcept = 0;
320
321 virtual return_t
322 do_power_port_vbus (port_t port, bool vbus) noexcept = 0;
323
324 virtual return_t
325 do_reset_port (port_t port) noexcept = 0;
326
327 virtual return_t
328 do_suspend_port (port_t port) noexcept = 0;
329
330 virtual return_t
331 do_resume_port (port_t port) noexcept = 0;
332
333 virtual host::Status&
334 do_get_port_status (port_t port) noexcept = 0;
335
336 virtual pipe_t
338 hub_addr_t hub_addr, hub_port_t hub_port,
339 endpoint_t ep_addr, endpoint_type_t ep_type,
340 packet_size_t ep_max_packet_size,
341 polling_interval_t ep_interval) noexcept = 0;
342
343 virtual return_t
345 speed_t dev_speed, hub_addr_t hub_addr,
346 hub_port_t hub_port, packet_size_t ep_max_packet_size)
347 noexcept = 0;
348
349 virtual return_t
350 do_delete_pipe (pipe_t pipe) noexcept = 0;
351
352 virtual return_t
353 do_reset_pipe (pipe_t pipe) noexcept = 0;
354
355 virtual return_t
356 do_transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
357 std::size_t num) noexcept = 0;
358
359 virtual std::size_t
360 do_get_transfer_count (pipe_t pipe) noexcept = 0;
361
362 virtual return_t
363 do_abort_transfer (pipe_t pipe) noexcept = 0;
364
365 virtual uint16_t
366 do_get_frame_number (void) noexcept = 0;
367
368 private:
369
371 host::signal_port_event_t cb_port_func_;
372
374 const void* cb_port_object_;
375
377 host::signal_pipe_event_t cb_pipe_func_;
378
380 const void* cb_pipe_object_;
381
382 protected:
383
384 host::Status status_;
385 };
386
387#pragma GCC diagnostic pop
388
389 // --------------------------------------------------------------------
390 // ----- Definitions -----
391
392 namespace host
393 {
394 // ------------------------------------------------------------------
395
396 inline bool
397 Status::is_connected (void) const noexcept
398 {
399 return connected;
400 }
401
402 inline bool
403 Status::is_overcurrent (void) const noexcept
404 {
405 return overcurrent;
406 }
407
408 inline speed_t
409 Status::get_speed (void) const noexcept
410 {
411 return speed;
412 }
413
414 } /* namespace host */
415
416 // --------------------------------------------------------------------
417
418 inline const host::Capabilities&
420 {
421 return do_get_capabilities ();
422 }
423
424 inline return_t
425 Host::power_port_vbus (port_t port, bool vbus) noexcept
426 {
427 return do_power_port_vbus (port, vbus);
428 }
429
430 inline return_t
431 Host::reset_port (port_t port) noexcept
432 {
433 return do_reset_port (port);
434 }
435
436 inline return_t
438 {
439 return do_suspend_port (port);
440 }
441
442 inline return_t
443 Host::resume_port (port_t port) noexcept
444 {
445 return do_resume_port (port);
446 }
447
448 inline host::Status&
450 {
451 return do_get_port_status (port);
452 }
453
454 inline pipe_t
456 hub_addr_t hub_addr, hub_port_t hub_port,
457 endpoint_t ep_addr, endpoint_type_t ep_type,
458 packet_size_t ep_max_packet_size,
459 polling_interval_t ep_interval) noexcept
460 {
461 return do_create_pipe (dev_addr, dev_speed, hub_addr, hub_port, ep_addr,
462 ep_type, ep_max_packet_size, ep_interval);
463 }
464
465 inline return_t
467 speed_t dev_speed, hub_addr_t hub_addr,
468 hub_port_t hub_port, packet_size_t ep_max_packet_size) noexcept
469 {
470 return do_modify_pipe (pipe, dev_addr, dev_speed, hub_addr, hub_port,
471 ep_max_packet_size);
472 }
473
474 inline return_t
475 Host::delete_pipe (pipe_t pipe) noexcept
476 {
477 return do_delete_pipe (pipe);
478 }
479
480 inline return_t
481 Host::reset_pipe (pipe_t pipe) noexcept
482 {
483 return do_reset_pipe (pipe);
484 }
485
486 inline std::size_t
488 {
489 return do_get_transfer_count (pipe);
490 }
491
492 inline return_t
494 {
495 return do_abort_transfer (pipe);
496 }
497
498 inline uint16_t
500 {
501 return do_get_frame_number ();
502 }
503
504 } /* namespace usb */
505 } /* namespace driver */
506} /* namespace os */
507
508#pragma GCC diagnostic pop
509
510// ----------------------------------------------------------------------------
511
512#endif /* __cplusplus */
513
514// ----------------------------------------------------------------------------
515
516#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:371
virtual return_t do_suspend_port(port_t port) noexcept=0
return_t reset_port(port_t port) noexcept
Definition usb-host.h:431
return_t delete_pipe(pipe_t pipe) noexcept
Definition usb-host.h:475
Host & operator=(const Host &)=delete
const host::Capabilities & get_capabilities(void) noexcept
Definition usb-host.h:419
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:449
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:455
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:71
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:113
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:377
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition usb-host.cpp:89
return_t power_port_vbus(port_t port, bool vbus) noexcept
Definition usb-host.h:425
return_t resume_port(port_t port) noexcept
Definition usb-host.h:443
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:466
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:380
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:437
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition usb-host.h:374
return_t reset_pipe(pipe_t pipe) noexcept
Definition usb-host.h:481
std::size_t get_transfer_count(pipe_t pipe) noexcept
Definition usb-host.h:487
uint16_t get_frame_number(void) noexcept
Definition usb-host.h:499
host::Status status_
Definition usb-host.h:384
virtual return_t do_reset_port(port_t port) noexcept=0
virtual ~Host() noexcept override
Definition usb-host.cpp:65
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition usb-host.cpp:79
void signal_port_event(port_t port, event_t event) noexcept
Definition usb-host.cpp:103
return_t abort_transfer(pipe_t pipe) noexcept
Definition usb-host.h:493
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:76
bool event_connect
Signal Disconnect event.
Definition usb-host.h:89
uint32_t port_mask
< Root HUB available Ports Mask
Definition usb-host.h:83
bool auto_split
Signal Connect event.
Definition usb-host.h:86
bool event_disconnect
Signal Overcurrent event.
Definition usb-host.h:92
speed_t get_speed(void) const noexcept
Definition usb-host.h:409
bool is_connected(void) const noexcept
Definition usb-host.h:397
bool is_overcurrent(void) const noexcept
Definition usb-host.h:403
bool overcurrent
USB Host Port speed setting (ARM_USB_SPEED_xxx)
Definition usb-host.h:133
bool connected
< USB Host Port connected flag
Definition usb-host.h:130
Port_event
USB Host Port Events.
Definition usb-host.h:149
@ resume
USB Device activated Remote Wakeup.
Definition usb-host.h:168
@ disconnect
USB Device caused Overcurrent.
Definition usb-host.h:156
@ suspend
USB Resume occurred.
Definition usb-host.h:165
@ overcurrent
USB Reset completed.
Definition usb-host.h:159
@ connect
USB Device Connected to Port.
Definition usb-host.h:153
@ reset
USB Suspend occurred.
Definition usb-host.h:162
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition usb-host.h:213
Pipe_event
USB Host Pipe Event.
Definition usb-host.h:182
@ handshake_nak
NYET Handshake received.
Definition usb-host.h:189
@ transfer_complete
Transfer completed.
Definition usb-host.h:186
@ handshake_stall
ERR Handshake received.
Definition usb-host.h:198
@ handshake_err
Bus Error detected.
Definition usb-host.h:201
@ handshake_mdata
STALL Handshake received.
Definition usb-host.h:195
@ handshake_nyet
MDATA Handshake received.
Definition usb-host.h:192
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition usb-host.h:210
uint8_t speed_t
Definition usb.h:62
uint8_t endpoint_t
Definition usb.h:84
uint32_t pipe_t
Definition usb.h:125
uint8_t hub_addr_t
Definition usb.h:128
uint8_t device_address_t
Definition usb.h:122
uint8_t endpoint_type_t
Definition usb.h:91
uint16_t packet_size_t
Definition usb.h:115
uint8_t port_t
Definition usb.h:126
uint8_t polling_interval_t
Definition usb.h:131
uint8_t hub_port_t
Definition usb.h:129
int32_t return_t
Definition common.h:63
uint32_t event_t
Definition common.h:62
System namespace.
Standard std namespace.