µ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 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
30#include <Driver_USBH.h>
31
32#include <cassert>
33#include <utility>
34#include <cstdio>
35
36// ----------------------------------------------------------------------------
37
38namespace os
39{
40 namespace driver
41 {
42 // ----------------------------------------------------------------------
43
45 ARM_USBH_SignalPortEvent_t c_cb_port_func,
46 ARM_USBH_SignalPipeEvent_t c_cb_pipe_func) noexcept :
47 driver_ (driver),
48 c_cb_port_func_ (c_cb_port_func),
49 c_cb_pipe_func_ (c_cb_pipe_func)
50 {
51 trace::printf("%s() %p\n", __func__, this);
52 }
53
55 {
56 trace::printf ("%s() %p\n", __func__, this);
57
58 driver_ = nullptr;
59 }
60
61 // ----------------------------------------------------------------------
62
63#pragma GCC diagnostic push
64#pragma GCC diagnostic ignored "-Waggregate-return"
65#pragma GCC diagnostic ignored "-Wstrict-aliasing"
66
67 const Version&
69 {
70 // Overwrite the C++ instance. Assume same layout.
71 *(reinterpret_cast<ARM_DRIVER_VERSION*> (&version_)) =
72 driver_->GetVersion ();
73 return version_;
74 }
75
78 {
79 // Overwrite the C++ instance. Assume same layout.
80 *(reinterpret_cast<ARM_USBH_CAPABILITIES*> (&capa_)) =
81 driver_->GetCapabilities ();
82 return capa_;
83 }
84
87 {
88 // Overwrite the C++ instance. Assume same layout.
89 *(reinterpret_cast<ARM_USBH_PORT_STATE*> (&status_)) =
90 driver_->PortGetState (port);
91 return status_;
92 }
93
94#pragma GCC diagnostic pop
95
98 {
99 assert (driver_ != nullptr);
100
101 return_t status;
102
103 if (state == Power::full)
104 {
105 status = driver_->Initialize (c_cb_port_func_, c_cb_pipe_func_);
106 if (status != ARM_DRIVER_OK)
107 {
108 return status;
109 }
110 }
111
112 status = driver_->PowerControl (static_cast<ARM_POWER_STATE> (state));
113
114 if (state == Power::off)
115 {
116 driver_->Uninitialize ();
117 }
118
119 return status;
120 }
121
124 {
125 return driver_->PortVbusOnOff (port, vbus);
126 }
127
130 {
131 return driver_->PortReset (port);
132 }
133
136 {
137 return driver_->PortSuspend (port);
138 }
139
142 {
143 return driver_->PortResume (port);
144 }
145
148 usb::speed_t dev_speed,
149 usb::hub_addr_t hub_addr,
150 usb::hub_port_t hub_port,
151 usb::endpoint_t ep_addr,
152 usb::endpoint_type_t ep_type,
153 usb::packet_size_t ep_max_packet_size,
154 usb::polling_interval_t ep_interval) noexcept
155 {
156 return driver_->PipeCreate (dev_addr, dev_speed, hub_addr, hub_port,
157 ep_addr, ep_type, ep_max_packet_size,
158 ep_interval);
159 }
160
163 usb::device_address_t dev_addr,
164 usb::speed_t dev_speed,
165 usb::hub_addr_t hub_addr,
166 usb::hub_port_t hub_port,
167 usb::packet_size_t ep_max_packet_size) noexcept
168 {
169 return driver_->PipeModify (pipe, dev_addr, dev_speed, hub_addr, hub_port,
170 ep_max_packet_size);
171 }
172
175 {
176 return driver_->PipeDelete (pipe);
177 }
178
181 {
182 return driver_->PipeReset (pipe);
183 }
184
186 usbh_wrapper::do_transfer (usb::pipe_t pipe, uint32_t packet, uint8_t* data,
187 std::size_t num) noexcept
188 {
189 return driver_->PipeTransfer (pipe, packet, data,
190 static_cast<uint32_t> (num));
191 }
192
193 std::size_t
195 {
196 return driver_->PipeTransferGetResult (pipe);
197 }
198
201 {
202 return driver_->PipeTransferAbort (pipe);
203 }
204
207 {
208 return driver_->GetFrameNumber ();
209 }
210
211 } /* namespace driver */
212} /* namespace os */
213
214// ----------------------------------------------------------------------------
USB host driver capabilities.
Definition usb-host.h:76
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:74
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
uint16_t frame_number_t
Definition usb.h:120
int32_t return_t
Definition common.h:63
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