µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
usb-host.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 * Copyright (c) 2013-2014 ARM Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following
14 * conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
27 */
28
29/*
30 * The code is inspired by ARM CMSIS Driver_USBH.h file, v2.01,
31 * and tries to remain functionally close to the CMSIS specifications.
32 */
33
36#include <cassert>
37
38// ----------------------------------------------------------------------------
39
40#if defined(__clang__)
41#pragma clang diagnostic ignored "-Wc++98-compat"
42#endif
43
44// ----------------------------------------------------------------------------
45
46namespace os
47{
48 namespace driver
49 {
50 namespace usb
51 {
52 // ----------------------------------------------------------------------
53
54 Host::Host () noexcept
55 {
56 trace::printf ("%s() %p\n", __func__, this);
57
58 cb_port_func_ = nullptr;
59 cb_port_object_ = nullptr;
60
61 cb_pipe_func_ = nullptr;
62 cb_pipe_object_ = nullptr;
63 }
64
65 Host::~Host () noexcept
66 {
67 trace::printf ("%s() %p\n", __func__, this);
68 }
69
70 void
72 const void* cb_object) noexcept
73 {
74 cb_port_func_ = cb_func;
75 cb_port_object_ = cb_object;
76 }
77
78 void
80 const void* cb_object) noexcept
81 {
82 cb_pipe_func_ = cb_func;
83 cb_pipe_object_ = cb_object;
84 }
85
86 // ----------------------------------------------------------------------
87
89 Host::transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
90 std::size_t num) noexcept
91 {
92 assert (data != nullptr);
93 if (num == 0)
94 {
95 return RETURN_OK;
96 }
97 return do_transfer (pipe, packet, data, num);
98 }
99
100 // ----------------------------------------------------------------------
101
102 void
104 {
105 if (cb_port_func_ != nullptr)
106 {
107 // Forward event to registered callback.
108 cb_port_func_ (cb_port_object_, port, event);
109 }
110 }
111
112 void
114 {
115 if (cb_pipe_func_ != nullptr)
116 {
117 // Forward event to registered callback.
118 cb_pipe_func_ (cb_pipe_object_, pipe, event);
119 }
120 }
121
122 } /* namespace usb */
123 } /* namespace driver */
124} /* namespace os */
125
126// ----------------------------------------------------------------------------
host::signal_port_event_t cb_port_func_
Pointer to static function that implements the port callback.
Definition usb-host.h:371
void register_port_callback(host::signal_port_event_t cb_func, const void *cb_object=nullptr) noexcept
Register port event callback.
Definition usb-host.cpp:71
void signal_pipe_event(pipe_t pipe, event_t event) noexcept
Definition usb-host.cpp:113
host::signal_pipe_event_t cb_pipe_func_
Pointer to static function that implements the pipe callback.
Definition usb-host.h:377
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition usb-host.cpp:89
const void * cb_pipe_object_
Pointer to object instance associated with the pipe callback.
Definition usb-host.h:380
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition usb-host.h:374
virtual ~Host() noexcept override
Definition usb-host.cpp:65
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition usb-host.cpp:79
void signal_port_event(port_t port, event_t event) noexcept
Definition usb-host.cpp:103
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:74
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition usb-host.h:213
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition usb-host.h:210
uint32_t pipe_t
Definition usb.h:125
uint8_t port_t
Definition usb.h:126
constexpr return_t RETURN_OK
< Operation succeeded
Definition common.h:69
int32_t return_t
Definition common.h:63
uint32_t event_t
Definition common.h:62
System namespace.