µ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++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2016-2025 Liviu Ionescu. All rights reserved.
4 * Copyright (c) 2013-2014 ARM Ltd.
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
13/*
14 * The code is inspired by ARM CMSIS Driver_USBH.h file, v2.01,
15 * and tries to remain functionally close to the CMSIS specifications.
16 */
17
20#include <cassert>
21
22// ----------------------------------------------------------------------------
23
24#if defined(__clang__)
25#pragma clang diagnostic ignored "-Wc++98-compat"
26#endif
27
28// ----------------------------------------------------------------------------
29
30namespace os
31{
32 namespace driver
33 {
34 namespace usb
35 {
36 // ----------------------------------------------------------------------
37
38 Host::Host () noexcept
39 {
40 trace::printf ("%s() %p\n", __func__, this);
41
42 cb_port_func_ = nullptr;
43 cb_port_object_ = nullptr;
44
45 cb_pipe_func_ = nullptr;
46 cb_pipe_object_ = nullptr;
47 }
48
49 Host::~Host () noexcept
50 {
51 trace::printf ("%s() %p\n", __func__, this);
52 }
53
54 void
56 const void* cb_object) noexcept
57 {
58 cb_port_func_ = cb_func;
59 cb_port_object_ = cb_object;
60 }
61
62 void
64 const void* cb_object) noexcept
65 {
66 cb_pipe_func_ = cb_func;
67 cb_pipe_object_ = cb_object;
68 }
69
70 // ----------------------------------------------------------------------
71
73 Host::transfer (pipe_t pipe, uint32_t packet, uint8_t* data,
74 std::size_t num) noexcept
75 {
76 assert (data != nullptr);
77 if (num == 0)
78 {
79 return RETURN_OK;
80 }
81 return do_transfer (pipe, packet, data, num);
82 }
83
84 // ----------------------------------------------------------------------
85
86 void
87 Host::signal_port_event (port_t port, event_t event) noexcept
88 {
89 if (cb_port_func_ != nullptr)
90 {
91 // Forward event to registered callback.
92 cb_port_func_ (cb_port_object_, port, event);
93 }
94 }
95
96 void
97 Host::signal_pipe_event (pipe_t pipe, event_t event) noexcept
98 {
99 if (cb_pipe_func_ != nullptr)
100 {
101 // Forward event to registered callback.
102 cb_pipe_func_ (cb_pipe_object_, pipe, event);
103 }
104 }
105
106 } /* namespace usb */
107 } /* namespace driver */
108} /* namespace os */
109
110// ----------------------------------------------------------------------------
host::signal_port_event_t cb_port_func_
Pointer to static function that implements the port callback.
Definition usb-host.h:372
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:55
void signal_pipe_event(pipe_t pipe, event_t event) noexcept
Definition usb-host.cpp:97
host::signal_pipe_event_t cb_pipe_func_
Pointer to static function that implements the pipe callback.
Definition usb-host.h:378
return_t transfer(pipe_t pipe, uint32_t packet, uint8_t *data, std::size_t num) noexcept
Definition usb-host.cpp:73
const void * cb_pipe_object_
Pointer to object instance associated with the pipe callback.
Definition usb-host.h:381
const void * cb_port_object_
Pointer to object instance associated with the port callback.
Definition usb-host.h:375
virtual ~Host() noexcept override
Definition usb-host.cpp:49
void register_pipe_callback(host::signal_pipe_event_t cb_func, const void *cb_object=nullptr) noexcept
Definition usb-host.cpp:63
void signal_port_event(port_t port, event_t event) noexcept
Definition usb-host.cpp:87
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59
void(* signal_pipe_event_t)(const void *object, pipe_t pipe, event_t event)
Definition usb-host.h:196
void(* signal_port_event_t)(const void *object, port_t port, event_t event)
Definition usb-host.h:193
uint32_t pipe_t
Definition usb.h:102
uint8_t port_t
Definition usb.h:103
constexpr return_t RETURN_OK
Definition common.h:52
int32_t return_t
Definition common.h:46
uint32_t event_t
Definition common.h:45
System namespace.