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