3#include <USBHost_t36.h>
8#include <Settings/NamespaceSettings.hpp>
13template <u
int16_t MaxPacketSize = 512>
32 void write(
const uint32_t *msgs, uint32_t num_msgs);
36 void write(
const uint32_t (&msgs)[N]) {
76 bool claim(Device_t *device,
int type,
const uint8_t *descriptors,
77 uint32_t
len)
override;
97 bool claim_if_midi(Device_t *device,
int type,
const uint8_t *descriptors,
110 Pipe_t mypipes[3] __attribute__((aligned(32)));
111 Transfer_t mytransfers[7] __attribute__((aligned(32)));
164 template <
class T,
size_t N>
165 static constexpr size_t len(T (&)[N]) {
#define BEGIN_CS_NAMESPACE
Teensy USB Host MIDI driver.
uint8_t buffer[PacketSize]
void disconnect() override
uint32_t read_finish(const Transfer_t *transfer)
void write(const uint32_t(&msgs)[N])
Send multiple MIDI USB messages. May block.
void read_start(uint8_t *buffer, uint32_t size)
static constexpr uint32_t PacketSize
USB packet size. Must be a power of two.
void setErrorTimeout(microseconds timeout)
std::atomic< uint32_t > size
uint32_t write_finish(const Transfer_t *transfer)
uint32_t write_nonblock(const uint32_t *msgs, uint32_t num_msgs)
Send multiple MIDI USB messages without blocking.
bool claim_if_midi(Device_t *device, int type, const uint8_t *descriptors, uint32_t len)
microseconds error_timeout_duration
void timer_event(USBDriverTimer *whichtimer) override
static constexpr uint32_t SizeReserved
uint32_t read()
Try reading a 4-byte MIDI USB message.
bool claim(Device_t *device, int type, const uint8_t *descriptors, uint32_t len) override
struct TeensyHostMIDI::Reading::Buffer buffers[NumRxPackets]
void send_now()
Try sending the buffered data now.
USBDriverTimer write_timeout
std::atomic< uint32_t > write_idx
std::atomic< uint32_t > active_writebuffer
void in_callback(const Transfer_t *transfer)
std::atomic< uint32_t > available
writebuf_size_tup read_writebuf_size()
void read_start_isr(uint8_t *buffer, uint32_t size)
struct TeensyHostMIDI::Reading reading
typename Reading::Buffer rbuffer_t
uint32_t getWriteError() const
Count how many USB packets were dropped.
microseconds timeout_duration
void setTimeout(microseconds timeout)
Set the timeout, the number of microseconds to buffer the outgoing MIDI messages.
static constexpr size_t len(T(&)[N])
std::atomic< Buffer * > sending
uint32_t write_impl(const uint32_t *msgs, uint32_t num_msgs, bool nonblocking)
std::tuple< uint32_t, wbuffer_t *, uint32_t > writebuf_size_tup
TeensyHostMIDI(USBHost &host)
void write_start(uint8_t *buffer, uint32_t size)
typename Writing::Buffer wbuffer_t
static void tx_callback(const Transfer_t *transfer)
void write(const uint32_t *msgs, uint32_t num_msgs)
Send multiple MIDI USB messages.
std::atomic< uint32_t > read_idx
std::atomic< bool > reading
bool send_now_impl_nonblock(uint32_t activebuf_idx)
std::atomic< bool > ready_to_send
void out_callback(const Transfer_t *transfer)
std::atomic< Buffer * > send_timeout
static constexpr uint32_t NumRxPackets
static void rx_callback(const Transfer_t *transfer)
struct TeensyHostMIDI::Writing::Buffer buffers[2]
void write(uint32_t msg)
Send a MIDI USB message.
std::chrono::microseconds microseconds
strbuf_t mystring_bufs[1]
void clearWriteError()
Clear the counter of how many USB packets were dropped.
void write_start_isr(uint8_t *buffer, uint32_t size)
struct TeensyHostMIDI::Writing writing
State for writing outgoing USB-MIDI data.
State for reading incoming USB-MIDI data.