µ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-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_USBD.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_DRIVER_USBD* driver, ARM_USBD_SignalDeviceEvent_t c_cb_device_func,
31 ARM_USBD_SignalEndpointEvent_t c_cb_endpoint_func) noexcept :
32 driver_ (driver),
33 c_cb_device_func_ (c_cb_device_func),
34 c_cb_endpoint_func_ (c_cb_endpoint_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_USBD_CAPABILITIES*> (&capa_)) =
69 driver_->GetCapabilities ();
70 return capa_;
71 }
72
75 {
76 // Overwrite the C++ instance. Assume same layout.
77 *(reinterpret_cast<ARM_USBD_STATE*> (&status_)) =
78 driver_->DeviceGetState ();
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_device_func_, c_cb_endpoint_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_->DeviceConnect ();
114 }
115
118 {
119 return driver_->DeviceDisconnect ();
120 }
121
124 {
125 return driver_->DeviceRemoteWakeup ();
126 }
127
130 {
131 return driver_->DeviceSetAddress (dev_addr);
132 }
133
136 {
137 return driver_->ReadSetupPacket (buf);
138 }
139
142 {
143 return driver_->GetFrameNumber ();
144 }
145
148 usb::Endpoint_type ep_type,
149 usb::packet_size_t ep_max_packet_size) noexcept
150 {
151 return driver_->EndpointConfigure (ep_addr,
152 static_cast<uint8_t> (ep_type),
153 ep_max_packet_size);
154 }
155
158 {
159 return driver_->EndpointUnconfigure (ep_addr);
160 }
161
164 {
165 return driver_->EndpointStall (ep_addr, stall);
166 }
167
170 std::size_t num) noexcept
171 {
172 return driver_->EndpointTransfer (ep_addr, data,
173 static_cast<uint32_t> (num));
174 }
175
176 std::size_t
178 {
179 return driver_->EndpointTransferGetResult (ep_addr);
180 }
181
184 {
185 return driver_->EndpointTransferAbort (ep_addr);
186 }
187
188 } /* namespace driver */
189} /* namespace os */
190
191// ----------------------------------------------------------------------------
USB device driver capabilities.
Definition usb-device.h:64
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:60
uint8_t endpoint_t
Definition usb.h:68
uint8_t device_address_t
Definition usb.h:106
uint16_t packet_size_t
Definition usb.h:99
uint16_t frame_number_t
Definition usb.h:104
Endpoint_type
Endpoint type.
Definition usb.h:82
int32_t return_t
Definition common.h:47
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