Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
PluggableUSBMIDI.cpp
Go to the documentation of this file.
1#if defined(ARDUINO_ARCH_MBED)
2
4#include <AH/Debug/Debug.hpp>
5
6#include <cstring> // memcpy
7
9
10// ------------------------- CONSTRUCTOR/DESTRUCTOR ------------------------- //
11
12PluggableUSBMIDI::PluggableUSBMIDI() : PluggableUSBModule(2) {
13 PluggableUSBD().plug(this);
14}
15
16PluggableUSBMIDI::~PluggableUSBMIDI() { PluggableUSBD().deinit(); }
17
18// ----------------------------- INITIALIZATION ----------------------------- //
19
20void PluggableUSBMIDI::init(EndpointResolver &resolver) {
21 bulk_in_ep = resolver.endpoint_in(USB_EP_TYPE_BULK, get_packet_size());
22 bulk_out_ep = resolver.endpoint_out(USB_EP_TYPE_BULK, get_packet_size());
23 assert(resolver.valid());
24}
25
26bool PluggableUSBMIDI::connected() const {
27 return usb_connected.load(std::memory_order_relaxed);
28}
29
30// --------------------------------- USB API -------------------------------- //
31
32void PluggableUSBMIDI::callback_state_change(DeviceState new_state) {
33 assert_locked();
34 usb_connected.store(new_state == USBDevice::Configured,
35 std::memory_order_relaxed);
36}
37
38uint32_t PluggableUSBMIDI::callback_request(const setup_packet_t *setup,
39 USBDevice::RequestResult *result,
40 uint8_t **data) {
41 assert_locked();
42 *result = USBDevice::PassThrough;
43 *data = nullptr;
44 return 0;
45}
46
47bool PluggableUSBMIDI::callback_request_xfer_done(const setup_packet_t *setup,
48 bool aborted) {
49 assert_locked();
50 return false;
51}
52
53bool PluggableUSBMIDI::callback_set_configuration(uint8_t configuration) {
54 assert_locked();
55
56 PluggableUSBD().endpoint_add(
57 bulk_in_ep, get_packet_size(), USB_EP_TYPE_BULK,
58 mbed::callback(this, &PluggableUSBMIDI::in_callback));
59 PluggableUSBD().endpoint_add(
60 bulk_out_ep, get_packet_size(), USB_EP_TYPE_BULK,
61 mbed::callback(this, &PluggableUSBMIDI::out_callback));
62
63 timeout.detach();
66
67 return true;
68}
69
70void PluggableUSBMIDI::callback_set_interface(uint16_t interface,
71 uint8_t alternate) {
72 assert_locked();
73}
74
76
77#endif
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
void callback_state_change(DeviceState new_state) override
void callback_set_interface(uint16_t interface, uint8_t alternate) override
interrupt_atomic< bool > usb_connected
bool callback_set_configuration(uint8_t configuration) override
bool connected() const
Check if this class is connected and ready.
void init(EndpointResolver &resolver) override
uint32_t callback_request(const setup_packet_t *setup, USBDevice::RequestResult *result, uint8_t **data) override
bool callback_request_xfer_done(const setup_packet_t *setup, bool aborted) override
static constexpr uint32_t get_packet_size()
T load(std::memory_order o) const
Definition Atomic.hpp:124
void store(T t, std::memory_order o) noexcept
Definition Atomic.hpp:132
void reset(uint16_t packet_size=MaxPacketSize)
void reset(uint16_t packet_size=MaxPacketSize)