µOS++ IIIe Reference  v6.3.15
“Perfekt ist nicht gut genug”
The third edition of µOS++, a POSIX inspired open source system, written in C++.
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 
29 #include <cmsis-plus/diag/trace.h>
30 #include <Driver_USBH.h>
31 
32 #include <cassert>
33 #include <utility>
34 #include <cstdio>
35 
36 // ----------------------------------------------------------------------------
37 
38 namespace 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 
96  return_t
97  usbh_wrapper::do_power (Power state) noexcept
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 
122  return_t
124  {
125  return driver_->PortVbusOnOff (port, vbus);
126  }
127 
128  return_t
130  {
131  return driver_->PortReset (port);
132  }
133 
134  return_t
136  {
137  return driver_->PortSuspend (port);
138  }
139 
140  return_t
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 
161  return_t
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 
173  return_t
175  {
176  return driver_->PipeDelete (pipe);
177  }
178 
179  return_t
181  {
182  return driver_->PipeReset (pipe);
183  }
184 
185  return_t
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 
199  return_t
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 state.
Definition: usb-host.h:97
virtual return_t do_reset_pipe(usb::pipe_t pipe) noexcept override
uint8_t port_t
Definition: usb.h:116
ARM_USBH_SignalPortEvent_t c_cb_port_func_
Definition: usbh-wrapper.h:153
uint8_t polling_interval_t
Definition: usb.h:121
virtual return_t do_suspend_port(usb::port_t port) noexcept override
System namespace.
USB host driver capabilities.
Definition: usb-host.h:63
virtual return_t do_delete_pipe(usb::pipe_t pipe) noexcept override
uint8_t endpoint_t
Definition: usb.h:74
virtual usb::host::Status & do_get_port_status(usb::port_t port) noexcept override
virtual const usb::host::Capabilities & do_get_capabilities(void) noexcept override
virtual ~usbh_wrapper() noexcept
ARM_USBH_SignalPipeEvent_t c_cb_pipe_func_
Definition: usbh-wrapper.h:154
usb::host::Capabilities capa_
Definition: usbh-wrapper.h:165
void(* ARM_USBH_SignalPortEvent_t)(uint8_t port, uint32_t event)
Pointer to port event callback.
Definition: usbh-wrapper.h:41
ARM_DRIVER_USBH * driver_
Pointer to CMSIS USBD Keil driver.
Definition: usbh-wrapper.h:149
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition: trace.cpp:74
usbh_wrapper(ARM_DRIVER_USBH *driver, ARM_USBH_SignalPortEvent_t c_cb_port_func, ARM_USBH_SignalPipeEvent_t c_cb_pipe_func) noexcept
virtual uint16_t do_get_frame_number(void) noexcept override
void(* ARM_USBH_SignalPipeEvent_t)(ARM_USBH_PIPE_HANDLE pipe_hndl, uint32_t event)
Pointer to pipe event callback.
Definition: usbh-wrapper.h:43
uint8_t hub_addr_t
Definition: usb.h:118
uint8_t device_address_t
Definition: usb.h:112
virtual return_t do_reset_port(usb::port_t port) noexcept override
virtual return_t do_power(Power state) noexcept override
virtual std::size_t do_get_transfer_count(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 const Version & do_get_version(void) noexcept override
virtual return_t do_abort_transfer(usb::pipe_t pipe) noexcept override
usb::host::Status status_
Definition: usbh-wrapper.h:166
struct _ARM_DRIVER_USBH const ARM_DRIVER_USBH
Definition: usbh-wrapper.h:46
virtual return_t do_power_port_vbus(usb::port_t port, bool vbus) noexcept override
uint32_t pipe_t
Definition: usb.h:115
uint8_t speed_t
Definition: usb.h:52
uint8_t hub_port_t
Definition: usb.h:119
uint16_t packet_size_t
Definition: usb.h:105
virtual return_t do_resume_port(usb::port_t port) noexcept override
int32_t return_t
Definition: common.h:51
uint8_t endpoint_type_t
Definition: usb.h:81
uint16_t frame_number_t
Definition: usb.h:110
virtual return_t do_transfer(usb::pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) 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