Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
BulkRX.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6#include <Settings/NamespaceSettings.hpp>
7
9
11template <class Derived, class MessageTypeT, uint16_t MaxPacketSizeV>
12struct BulkRX {
13 public:
14 using MessageType = MessageTypeT;
15
18 bool read(MessageType &message);
19
20 protected:
21 void reset(uint16_t packet_size = MaxPacketSize);
22
23 private:
24 static constexpr uint16_t MaxPacketSize = MaxPacketSizeV;
25 static constexpr uint16_t SizeReserved = MaxPacketSize + 1;
26 static constexpr uint16_t NumRxPackets = MaxPacketSize == 64 ? 16 : 4;
27
28 protected:
29 // Derived should implement the following methods:
30
32 void rx_start(void *data, uint32_t size) = delete;
34 void rx_start_isr(void *data, uint32_t size) = delete;
35
36 private:
37 constexpr static std::memory_order mo_seq = std::memory_order_seq_cst;
38 constexpr static std::memory_order mo_rel = std::memory_order_release;
39 constexpr static std::memory_order mo_acq = std::memory_order_acquire;
40 constexpr static std::memory_order mo_rlx = std::memory_order_relaxed;
41 constexpr static std::memory_order mo_acq_rel = std::memory_order_acq_rel;
42
56 using rbuffer_t = std::remove_reference_t<decltype(reading.buffers[0])>;
57
58 protected:
59 void rx_callback(uint32_t num_bytes_read);
60};
61
63
64#include "BulkRX.ipp"
#define END_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Wrapper that provides atomic access to variables shared between the main program and interrupt handle...
Definition Atomic.hpp:81
uint8_t buffer[MaxPacketSize]
Definition BulkRX.hpp:48
State for reading incoming USB data.
Definition BulkRX.hpp:44
struct BulkRX::Reading::Buffer buffers[NumRxPackets]
uint32_t read_idx
Definition BulkRX.hpp:51
interrupt_atomic< uint32_t > available
Definition BulkRX.hpp:50
interrupt_atomic< bool > reading
Definition BulkRX.hpp:53
interrupt_atomic< uint32_t > write_idx
Definition BulkRX.hpp:52
uint16_t packet_size
Definition BulkRX.hpp:54
Receives Bulk packets (OUT for device mode, IN for host mode)
Definition BulkRX.hpp:12
static constexpr std::memory_order mo_seq
Definition BulkRX.hpp:37
struct BulkRX::Reading reading
static constexpr std::memory_order mo_acq
Definition BulkRX.hpp:39
void rx_start_isr(void *data, uint32_t size)=delete
Start a USB transfer (from the USB interrupt handler).
static constexpr std::memory_order mo_rlx
Definition BulkRX.hpp:40
void rx_callback(uint32_t num_bytes_read)
std::remove_reference_t< decltype(reading.buffers[0])> rbuffer_t
Definition BulkRX.hpp:56
MessageTypeT MessageType
Definition BulkRX.hpp:14
static constexpr std::memory_order mo_acq_rel
Definition BulkRX.hpp:41
bool read(MessageType &message)
Try reading a single message.
static constexpr uint16_t MaxPacketSize
Definition BulkRX.hpp:24
void reset(uint16_t packet_size=MaxPacketSize)
void rx_start(void *data, uint32_t size)=delete
Start a USB transfer (from the main program).
static constexpr uint16_t SizeReserved
Definition BulkRX.hpp:25
static constexpr uint16_t NumRxPackets
Definition BulkRX.hpp:26
static constexpr std::memory_order mo_rel
Definition BulkRX.hpp:38