µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
usbh-wrapper.cpp
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 *
6 * Permission to use, copy, modify, and/or distribute this software
7 * for any purpose is hereby granted, under the terms of the MIT license.
8 *
9 * If a copy of the license was not distributed with this file, it can
10 * be obtained from https://opensource.org/licenses/mit/.
11 */
12
15#include <Driver_USBH.h>
16
17#include <cassert>
18#include <utility>
19#include <cstdio>
20
21// ----------------------------------------------------------------------------
22
23namespace os
24{
25 namespace driver
26 {
27 // ----------------------------------------------------------------------
28
30 ARM_USBH_SignalPortEvent_t c_cb_port_func,
31 ARM_USBH_SignalPipeEvent_t c_cb_pipe_func) noexcept :
32 driver_ (driver),
33 c_cb_port_func_ (c_cb_port_func),
34 c_cb_pipe_func_ (c_cb_pipe_func)
35 {
36 trace::printf("%s() %p\n", __func__, this);
37 }
38
40 {
41 trace::printf ("%s() %p\n", __func__, this);
42
43 driver_ = nullptr;
44 }
45
46 // ----------------------------------------------------------------------
47
48#pragma GCC diagnostic push
49#if defined(__clang__)
50#elif defined(__GNUC__)
51#pragma GCC diagnostic ignored "-Waggregate-return"
52#endif
53#pragma GCC diagnostic ignored "-Wstrict-aliasing"
54
55 const Version&
57 {
58 // Overwrite the C++ instance. Assume same layout.
59 *(reinterpret_cast<ARM_DRIVER_VERSION*> (&version_)) =
60 driver_->GetVersion ();
61 return version_;
62 }
63
66 {
67 // Overwrite the C++ instance. Assume same layout.
68 *(reinterpret_cast<ARM_USBH_CAPABILITIES*> (&capa_)) =
69 driver_->GetCapabilities ();
70 return capa_;
71 }
72
75 {
76 // Overwrite the C++ instance. Assume same layout.
77 *(reinterpret_cast<ARM_USBH_PORT_STATE*> (&status_)) =
78 driver_->PortGetState (port);
79 return status_;
80 }
81
82#pragma GCC diagnostic pop
83
86 {
87 assert (driver_ != nullptr);
88
89 return_t status;
90
91 if (state == Power::full)
92 {
93 status = driver_->Initialize (c_cb_port_func_, c_cb_pipe_func_);
94 if (status != ARM_DRIVER_OK)
95 {
96 return status;
97 }
98 }
99
100 status = driver_->PowerControl (static_cast<ARM_POWER_STATE> (state));
101
102 if (state == Power::off)
103 {
104 driver_->Uninitialize ();
105 }
106
107 return status;
108 }
109
112 {
113 return driver_->PortVbusOnOff (port, vbus);
114 }
115
118 {
119 return driver_->PortReset (port);
120 }
121
124 {
125 return driver_->PortSuspend (port);
126 }
127
130 {
131 return driver_->PortResume (port);
132 }
133
136 usb::speed_t dev_speed,
137 usb::hub_addr_t hub_addr,
138 usb::hub_port_t hub_port,
139 usb::endpoint_t ep_addr,
140 usb::endpoint_type_t ep_type,
141 usb::packet_size_t ep_max_packet_size,
142 usb::polling_interval_t ep_interval) noexcept
143 {
144 return driver_->PipeCreate (dev_addr, dev_speed, hub_addr, hub_port,
145 ep_addr, ep_type, ep_max_packet_size,
146 ep_interval);
147 }
148
151 usb::device_address_t dev_addr,
152 usb::speed_t dev_speed,
153 usb::hub_addr_t hub_addr,
154 usb::hub_port_t hub_port,
155 usb::packet_size_t ep_max_packet_size) noexcept
156 {
157 return driver_->PipeModify (pipe, dev_addr, dev_speed, hub_addr, hub_port,
158 ep_max_packet_size);
159 }
160
163 {
164 return driver_->PipeDelete (pipe);
165 }
166
169 {
170 return driver_->PipeReset (pipe);
171 }
172
174 usbh_wrapper::do_transfer (usb::pipe_t pipe, uint32_t packet, uint8_t* data,
175 std::size_t num) noexcept
176 {
177 return driver_->PipeTransfer (pipe, packet, data,
178 static_cast<uint32_t> (num));
179 }
180
181 std::size_t
183 {
184 return driver_->PipeTransferGetResult (pipe);
185 }
186
189 {
190 return driver_->PipeTransferAbort (pipe);
191 }
192
195 {
196 return driver_->GetFrameNumber ();
197 }
198
199 } /* namespace driver */
200} /* namespace os */
201
202// ----------------------------------------------------------------------------
USB host driver capabilities.
Definition usb-host.h:64
virtual return_t do_transfer(usb::pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept override
virtual return_t do_reset_pipe(usb::pipe_t pipe) noexcept override
virtual return_t do_modify_pipe(usb::pipe_t pipe, usb::device_address_t dev_addr, usb::speed_t dev_speed, usb::hub_addr_t hub_addr, usb::hub_port_t hub_port, usb::packet_size_t ep_max_packet_size) noexcept override
virtual ~usbh_wrapper() noexcept
virtual const usb::host::Capabilities & do_get_capabilities(void) noexcept override
virtual uint16_t do_get_frame_number(void) noexcept override
virtual const Version & do_get_version(void) noexcept override
virtual usb::pipe_t do_create_pipe(usb::device_address_t dev_addr, usb::speed_t dev_speed, usb::hub_addr_t hub_addr, usb::hub_port_t hub_port, usb::endpoint_t ep_addr, usb::endpoint_type_t ep_type, usb::packet_size_t ep_max_packet_size, usb::polling_interval_t ep_interval) noexcept override
virtual return_t do_power_port_vbus(usb::port_t port, bool vbus) noexcept override
virtual std::size_t do_get_transfer_count(usb::pipe_t pipe) noexcept override
virtual return_t do_power(Power state) noexcept override
virtual return_t do_suspend_port(usb::port_t port) noexcept override
virtual return_t do_delete_pipe(usb::pipe_t pipe) noexcept override
ARM_DRIVER_USBH * driver_
Pointer to CMSIS USBD Keil driver.
virtual return_t do_reset_port(usb::port_t port) noexcept override
virtual return_t do_resume_port(usb::port_t port) noexcept override
virtual return_t do_abort_transfer(usb::pipe_t pipe) noexcept override
usbh_wrapper(ARM_DRIVER_USBH *driver, ARM_USBH_SignalPortEvent_t c_cb_port_func, ARM_USBH_SignalPipeEvent_t c_cb_pipe_func) noexcept
virtual usb::host::Status & do_get_port_status(usb::port_t port) noexcept override
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:60
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
uint16_t frame_number_t
Definition usb.h:104
int32_t return_t
Definition common.h:47
System namespace.
void(* ARM_USBH_SignalPipeEvent_t)(ARM_USBH_PIPE_HANDLE pipe_hndl, uint32_t event)
Pointer to pipe event callback.
void(* ARM_USBH_SignalPortEvent_t)(uint8_t port, uint32_t event)
Pointer to port event callback.
struct _ARM_DRIVER_USBH const ARM_DRIVER_USBH