#include <MIDI_Interfaces/USBMIDI/Teensy-host/TeensyHostMIDI.hpp>
Teensy USB Host MIDI driver.
Definition at line 14 of file TeensyHostMIDI.hpp.
Classes | |
struct | Reading |
State for reading incoming USB-MIDI data. More... | |
struct | Writing |
State for writing outgoing USB-MIDI data. More... | |
Public Types | |
using | microseconds = std::chrono::microseconds |
Public Member Functions | |
TeensyHostMIDI (USBHost &host) | |
void | write (uint32_t msg) |
Send a MIDI USB message. More... | |
void | write (const uint32_t *msgs, uint32_t num_msgs) |
Send multiple MIDI USB messages. More... | |
template<size_t N> | |
void | write (const uint32_t(&msgs)[N]) |
Send multiple MIDI USB messages. May block. More... | |
uint32_t | write_nonblock (const uint32_t *msgs, uint32_t num_msgs) |
Send multiple MIDI USB messages without blocking. More... | |
uint32_t | read () |
Try reading a 4-byte MIDI USB message. More... | |
void | send_now () |
Try sending the buffered data now. More... | |
void | setTimeout (microseconds timeout) |
Set the timeout, the number of microseconds to buffer the outgoing MIDI messages. More... | |
void | setErrorTimeout (microseconds timeout) |
uint32_t | getWriteError () const |
Count how many USB packets were dropped. More... | |
void | clearWriteError () |
Clear the counter of how many USB packets were dropped. More... | |
Static Public Attributes | |
static constexpr uint32_t | PacketSize = MaxPacketSize |
USB packet size. Must be a power of two. More... | |
Protected Types | |
using | rbuffer_t = typename Reading::Buffer |
using | wbuffer_t = typename Writing::Buffer |
using | writebuf_size_tup = std::tuple< uint32_t, wbuffer_t *, uint32_t > |
Protected Member Functions | |
bool | claim (Device_t *device, int type, const uint8_t *descriptors, uint32_t len) override |
void | disconnect () override |
void | timer_event (USBDriverTimer *whichtimer) override |
void | write_start (uint8_t *buffer, uint32_t size) |
void | write_start_isr (uint8_t *buffer, uint32_t size) |
uint32_t | write_finish (const Transfer_t *transfer) |
void | read_start (uint8_t *buffer, uint32_t size) |
void | read_start_isr (uint8_t *buffer, uint32_t size) |
uint32_t | read_finish (const Transfer_t *transfer) |
bool | claim_if_midi (Device_t *device, int type, const uint8_t *descriptors, uint32_t len) |
void | init () |
uint32_t | write_impl (const uint32_t *msgs, uint32_t num_msgs, bool nonblocking) |
writebuf_size_tup | read_writebuf_size () |
bool | send_now_impl_nonblock (uint32_t activebuf_idx) |
void | timeout_callback () |
void | in_callback (const Transfer_t *transfer) |
void | out_callback (const Transfer_t *transfer) |
Static Protected Member Functions | |
static void | rx_callback (const Transfer_t *transfer) |
static void | tx_callback (const Transfer_t *transfer) |
Protected Attributes | |
struct TeensyHostMIDI::Reading | reading |
struct TeensyHostMIDI::Writing | writing |
USBDriverTimer | write_timeout {this} |
Static Protected Attributes | |
static constexpr uint32_t | SizeReserved = PacketSize + 1 |
static constexpr uint32_t | NumRxPackets = 2 |
Static Private Member Functions | |
template<class T , size_t N> | |
static constexpr size_t | len (T(&)[N]) |
Private Attributes | |
Pipe_t * | rxpipe |
Pipe_t * | txpipe |
uint16_t | rx_size |
uint16_t | tx_size |
uint8_t | rx_ep |
uint8_t | tx_ep |
uint8_t | rx_ep_type |
uint8_t | tx_ep_type |
strbuf_t | mystring_bufs [1] |
struct TeensyHostMIDI::Reading |
Class Members | ||
---|---|---|
struct Buffer | buffers[NumRxPackets] | |
atomic< uint32_t > | available | |
atomic< uint32_t > | read_idx | |
atomic< uint32_t > | write_idx | |
atomic< bool > | reading |
struct TeensyHostMIDI::Writing |
Class Members | ||
---|---|---|
struct Buffer | buffers[2] | |
atomic< uint32_t > | active_writebuffer | |
atomic< Buffer * > | sending | |
atomic< Buffer * > | send_timeout | |
microseconds | timeout_duration | |
microseconds | error_timeout_duration | |
uint32_t | errors |
using microseconds = std::chrono::microseconds |
Definition at line 18 of file TeensyHostMIDI.hpp.
|
protected |
Definition at line 134 of file TeensyHostMIDI.hpp.
|
protected |
Definition at line 150 of file TeensyHostMIDI.hpp.
|
protected |
Definition at line 156 of file TeensyHostMIDI.hpp.
|
inline |
Definition at line 16 of file TeensyHostMIDI.hpp.
void write | ( | uint32_t | msg | ) |
Send a MIDI USB message.
May block.
msg | The 4-byte MIDI USB message to send. |
void write | ( | const uint32_t * | msgs, |
uint32_t | num_msgs | ||
) |
Send multiple MIDI USB messages.
May block.
msgs | An array of 4-byte MIDI USB messages to send. |
num_msgs | The number of messages in the array. |
|
inline |
Send multiple MIDI USB messages. May block.
Definition at line 36 of file TeensyHostMIDI.hpp.
uint32_t write_nonblock | ( | const uint32_t * | msgs, |
uint32_t | num_msgs | ||
) |
Send multiple MIDI USB messages without blocking.
msgs | An array of 4-byte MIDI USB messages to send. |
num_msgs | The number of messages in the array. |
uint32_t read | ( | ) |
Try reading a 4-byte MIDI USB message.
void send_now | ( | ) |
Try sending the buffered data now.
Start transmitting the latest packet if possible, even if it isn't full yet. If the latest packet is empty, this function has no effect.
|
inline |
Set the timeout, the number of microseconds to buffer the outgoing MIDI messages.
A shorter timeout usually results in lower latency, but also causes more overhead, because more packets might be required.
Definition at line 62 of file TeensyHostMIDI.hpp.
|
inline |
Definition at line 66 of file TeensyHostMIDI.hpp.
|
inline |
Count how many USB packets were dropped.
Definition at line 71 of file TeensyHostMIDI.hpp.
|
inline |
Clear the counter of how many USB packets were dropped.
Definition at line 73 of file TeensyHostMIDI.hpp.
|
overrideprotected |
|
overrideprotected |
|
overrideprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
inlinestaticconstexprprivate |
Definition at line 165 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 102 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 103 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 104 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 105 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 106 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 107 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 108 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 109 of file TeensyHostMIDI.hpp.
|
private |
Definition at line 112 of file TeensyHostMIDI.hpp.
|
staticconstexpr |
USB packet size. Must be a power of two.
Definition at line 116 of file TeensyHostMIDI.hpp.
|
staticconstexprprotected |
Definition at line 119 of file TeensyHostMIDI.hpp.
|
staticconstexprprotected |
Definition at line 120 of file TeensyHostMIDI.hpp.
|
protected |
|
protected |
|
protected |
Definition at line 151 of file TeensyHostMIDI.hpp.