µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
usbd-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_USBD.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_DRIVER_USBD* driver, ARM_USBD_SignalDeviceEvent_t c_cb_device_func,
46 ARM_USBD_SignalEndpointEvent_t c_cb_endpoint_func) noexcept :
47 driver_ (driver),
48 c_cb_device_func_ (c_cb_device_func),
49 c_cb_endpoint_func_ (c_cb_endpoint_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_USBD_CAPABILITIES*> (&capa_)) =
81 driver_->GetCapabilities ();
82 return capa_;
83 }
84
87 {
88 // Overwrite the C++ instance. Assume same layout.
89 *(reinterpret_cast<ARM_USBD_STATE*> (&status_)) =
90 driver_->DeviceGetState ();
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_device_func_, c_cb_endpoint_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_->DeviceConnect ();
126 }
127
130 {
131 return driver_->DeviceDisconnect ();
132 }
133
136 {
137 return driver_->DeviceRemoteWakeup ();
138 }
139
142 {
143 return driver_->DeviceSetAddress (dev_addr);
144 }
145
148 {
149 return driver_->ReadSetupPacket (buf);
150 }
151
154 {
155 return driver_->GetFrameNumber ();
156 }
157
160 usb::Endpoint_type ep_type,
161 usb::packet_size_t ep_max_packet_size) noexcept
162 {
163 return driver_->EndpointConfigure (ep_addr,
164 static_cast<uint8_t> (ep_type),
165 ep_max_packet_size);
166 }
167
170 {
171 return driver_->EndpointUnconfigure (ep_addr);
172 }
173
176 {
177 return driver_->EndpointStall (ep_addr, stall);
178 }
179
182 std::size_t num) noexcept
183 {
184 return driver_->EndpointTransfer (ep_addr, data,
185 static_cast<uint32_t> (num));
186 }
187
188 std::size_t
190 {
191 return driver_->EndpointTransferGetResult (ep_addr);
192 }
193
196 {
197 return driver_->EndpointTransferAbort (ep_addr);
198 }
199
200 } /* namespace driver */
201} /* namespace os */
202
203// ----------------------------------------------------------------------------
USB device driver capabilities.
Definition usb-device.h:76
virtual return_t do_unconfigure_endpoint(usb::endpoint_t ep_addr) noexcept override
virtual ~usbd_wrapper() noexcept
virtual usb::device::Status & do_get_status(void) noexcept override
virtual return_t do_connect(void) noexcept override
ARM_DRIVER_USBD * driver_
Pointer to CMSIS USBD Keil driver.
const usb::device::Capabilities & do_get_capabilities(void) noexcept override
virtual usb::frame_number_t do_get_frame_number(void) noexcept override
virtual return_t do_disconnect(void) noexcept override
virtual return_t do_configure_address(usb::device_address_t dev_addr) noexcept override
virtual const Version & do_get_version(void) noexcept override
virtual return_t do_configure_endpoint(usb::endpoint_t ep_addr, usb::Endpoint_type ep_type, usb::packet_size_t ep_max_packet_size) noexcept override
virtual return_t do_abort_transfer(usb::endpoint_t ep_addr) noexcept override
virtual std::size_t do_get_transfer_count(usb::endpoint_t ep_addr) noexcept override
virtual return_t do_transfer(usb::endpoint_t ep_addr, uint8_t *data, std::size_t num) noexcept override
virtual return_t do_power(Power state) noexcept override
virtual return_t do_stall_endpoint(usb::endpoint_t ep_addr, bool stall) noexcept override
virtual return_t do_wakeup_remote(void) noexcept override
virtual return_t do_read_setup_packet(uint8_t *buf) noexcept override
usbd_wrapper(ARM_DRIVER_USBD *driver, ARM_USBD_SignalDeviceEvent_t c_cb_device_func, ARM_USBD_SignalEndpointEvent_t c_cb_endpoint_func) noexcept
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
uint8_t endpoint_t
Definition usb.h:84
uint8_t device_address_t
Definition usb.h:122
uint16_t packet_size_t
Definition usb.h:115
uint16_t frame_number_t
Definition usb.h:120
Endpoint_type
Endpoint type.
Definition usb.h:98
int32_t return_t
Definition common.h:63
System namespace.
void(* ARM_USBD_SignalEndpointEvent_t)(uint8_t ep_addr, uint32_t event)
Pointer to endpoint event callback.
void(* ARM_USBD_SignalDeviceEvent_t)(uint32_t event)
Pointer to device event callback.
struct _ARM_DRIVER_USBD const ARM_DRIVER_USBD