Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
TeensyHostMIDI< MaxPacketSize > Class Template Reference

#include <MIDI_Interfaces/USBMIDI/Teensy-host/TeensyHostMIDI.hpp>

Detailed Description

template<uint16_t MaxPacketSize = 512>
class TeensyHostMIDI< MaxPacketSize >

Teensy USB Host MIDI driver.

Definition at line 16 of file TeensyHostMIDI.hpp.

Inheritance diagram for TeensyHostMIDI< MaxPacketSize >:
Collaboration diagram for TeensyHostMIDI< MaxPacketSize >:

Public Types

using microseconds = std::chrono::microseconds

Public Member Functions

 TeensyHostMIDI (USBHost &)
uint32_t read ()
 Try reading a 4-byte MIDI USB message.
void setTimeout (microseconds timeout)
 Set the timeout, the number of microseconds to buffer the outgoing MIDI messages.
void setErrorTimeout (microseconds timeout)
bool connectedForWrite () const

Protected Types

using MessageType
using MessageType

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 ()
void start_timeout ()
void cancel_timeout ()
void tx_start (const void *data, uint32_t size)
void tx_start_timeout (const void *data, uint32_t size)
void tx_start_isr (const void *data, uint32_t size)
void rx_start (void *data, uint32_t size)
void rx_start_isr (void *data, uint32_t size)
bool read (MessageType &message)
 Try reading a single message.
void reset (uint16_t packet_size=MaxPacketSize)
void rx_callback (uint32_t num_bytes_read)
void write (MessageType msg)
 Send a MIDI USB message.
uint32_t write_nonblock (const MessageType *msgs, uint32_t num_msgs)
 Send multiple MIDI USB messages without blocking.
void send_now ()
 Try sending the buffered data now.
bool is_done () const
 Check if all transfers have completed.
uint32_t getWriteError () const
 Get the number messages that failed to send.
uint32_t clearWriteError ()
 Get and clear the number messages that failed to send.
void reset (uint16_t packet_size=MaxPacketSize)
bool wait_connect ()
void tx_callback ()

Static Protected Member Functions

static void rx_callback (const Transfer_t *transfer)
static void tx_callback (const Transfer_t *transfer)

Protected Attributes

USBDriverTimer write_timeout {this}
microseconds write_timeout_duration {1'000}
microseconds write_error_timeout_duration {40'000}

Private Types

using rbuffer_t
using wbuffer_t

Private Member Functions

void timeout_callback ()
void in_callback (const Transfer_t *transfer)
void out_callback (const Transfer_t *transfer)
uint32_t index_of (wbuffer_t *p) const
wbuffer_tother_buf (wbuffer_t *p)
uint32_t write_impl (const MessageType *msgs, uint32_t num_msgs)

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 BulkRX::Reading reading
struct BulkTX::Writing writing
bool disconnected

Static Private Attributes

static constexpr uint16_t MaxPacketSize
static constexpr uint16_t SizeReserved
static constexpr uint16_t NumRxPackets
static constexpr std::memory_order mo_seq
static constexpr std::memory_order mo_rel
static constexpr std::memory_order mo_acq
static constexpr std::memory_order mo_rlx
static constexpr std::memory_order mo_acq_rel

Member Typedef Documentation

◆ microseconds

template<uint16_t MaxPacketSize = 512>
using microseconds = std::chrono::microseconds

Definition at line 23 of file TeensyHostMIDI.hpp.

◆ MessageType [1/2]

using MessageType
inherited

Definition at line 14 of file BulkRX.hpp.

◆ rbuffer_t

using rbuffer_t
privateinherited

Definition at line 56 of file BulkRX.hpp.

◆ MessageType [2/2]

using MessageType
inherited

Definition at line 14 of file BulkTX.hpp.

◆ wbuffer_t

using wbuffer_t
privateinherited

Definition at line 101 of file BulkTX.hpp.

Constructor & Destructor Documentation

◆ TeensyHostMIDI()

template<uint16_t MaxPacketSize = 512>
TeensyHostMIDI ( USBHost & )
inline

Definition at line 21 of file TeensyHostMIDI.hpp.

Member Function Documentation

◆ read() [1/2]

template<uint16_t MaxPacketSize = 512>
uint32_t read ( )
inline

Try reading a 4-byte MIDI USB message.

Returns
The message or 0x00000000 if no messages available.

Definition at line 28 of file TeensyHostMIDI.hpp.

◆ setTimeout()

template<uint16_t MaxPacketSize = 512>
void setTimeout ( microseconds timeout)
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 44 of file TeensyHostMIDI.hpp.

◆ setErrorTimeout()

template<uint16_t MaxPacketSize = 512>
void setErrorTimeout ( microseconds timeout)
inline

Definition at line 46 of file TeensyHostMIDI.hpp.

◆ connectedForWrite()

template<uint16_t MaxPacketSize = 512>
bool connectedForWrite ( ) const
inline

Definition at line 50 of file TeensyHostMIDI.hpp.

◆ claim()

template<uint16_t MaxPacketSize = 512>
bool claim ( Device_t * device,
int type,
const uint8_t * descriptors,
uint32_t len )
overrideprotected

◆ disconnect()

template<uint16_t MaxPacketSize = 512>
void disconnect ( )
overrideprotected

◆ timer_event()

template<uint16_t MaxPacketSize = 512>
void timer_event ( USBDriverTimer * whichtimer)
overrideprotected

◆ rx_callback() [1/2]

template<uint16_t MaxPacketSize = 512>
void rx_callback ( const Transfer_t * transfer)
staticprotected

◆ tx_callback() [1/2]

template<uint16_t MaxPacketSize = 512>
void tx_callback ( const Transfer_t * transfer)
staticprotected

◆ write_start()

template<uint16_t MaxPacketSize = 512>
void write_start ( uint8_t * buffer,
uint32_t size )
protected

◆ write_start_isr()

template<uint16_t MaxPacketSize = 512>
void write_start_isr ( uint8_t * buffer,
uint32_t size )
protected

◆ write_finish()

template<uint16_t MaxPacketSize = 512>
uint32_t write_finish ( const Transfer_t * transfer)
protected

◆ read_start()

template<uint16_t MaxPacketSize = 512>
void read_start ( uint8_t * buffer,
uint32_t size )
protected

◆ read_start_isr()

template<uint16_t MaxPacketSize = 512>
void read_start_isr ( uint8_t * buffer,
uint32_t size )
protected

◆ read_finish()

template<uint16_t MaxPacketSize = 512>
uint32_t read_finish ( const Transfer_t * transfer)
protected

◆ claim_if_midi()

template<uint16_t MaxPacketSize = 512>
bool claim_if_midi ( Device_t * device,
int type,
const uint8_t * descriptors,
uint32_t len )
protected

◆ init()

template<uint16_t MaxPacketSize = 512>
void init ( )
protected

◆ start_timeout()

template<uint16_t MaxPacketSize = 512>
void start_timeout ( )
protected

◆ cancel_timeout()

template<uint16_t MaxPacketSize = 512>
void cancel_timeout ( )
protected

◆ tx_start()

template<uint16_t MaxPacketSize = 512>
void tx_start ( const void * data,
uint32_t size )
protected

◆ tx_start_timeout()

template<uint16_t MaxPacketSize = 512>
void tx_start_timeout ( const void * data,
uint32_t size )
protected

◆ tx_start_isr()

template<uint16_t MaxPacketSize = 512>
void tx_start_isr ( const void * data,
uint32_t size )
protected

◆ rx_start()

template<uint16_t MaxPacketSize = 512>
void rx_start ( void * data,
uint32_t size )
protected

◆ rx_start_isr()

template<uint16_t MaxPacketSize = 512>
void rx_start_isr ( void * data,
uint32_t size )
protected

◆ timeout_callback()

template<uint16_t MaxPacketSize = 512>
void timeout_callback ( )
private

◆ in_callback()

template<uint16_t MaxPacketSize = 512>
void in_callback ( const Transfer_t * transfer)
private

◆ out_callback()

template<uint16_t MaxPacketSize = 512>
void out_callback ( const Transfer_t * transfer)
private

◆ len()

template<uint16_t MaxPacketSize = 512>
template<class T, size_t N>
constexpr size_t len ( T(&) [N])
inlinestaticconstexprprivate

Definition at line 111 of file TeensyHostMIDI.hpp.

◆ read() [2/2]

bool read ( MessageType & message)
inherited

Try reading a single message.

Returns
Whether a message was available.

◆ reset() [1/2]

void reset ( uint16_t packet_size = MaxPacketSize)
protectedinherited

◆ rx_callback() [2/2]

void rx_callback ( uint32_t num_bytes_read)
protectedinherited

◆ write()

void write ( MessageType msg)
inherited

Send a MIDI USB message.

May block.

Parameters
msgThe 4-byte MIDI USB message to send.

◆ write_nonblock()

uint32_t write_nonblock ( const MessageType * msgs,
uint32_t num_msgs )
inherited

Send multiple MIDI USB messages without blocking.

Parameters
msgsAn array of 4-byte MIDI USB messages to send.
num_msgsThe number of messages in the array.
Returns
The number of messages that were actually sent.

◆ send_now()

void send_now ( )
inherited

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.

◆ is_done()

bool is_done ( ) const
inherited

Check if all transfers have completed.

◆ getWriteError()

uint32_t getWriteError ( ) const
inlineinherited

Get the number messages that failed to send.

Definition at line 54 of file BulkTX.hpp.

◆ clearWriteError()

uint32_t clearWriteError ( )
inlineinherited

Get and clear the number messages that failed to send.

Definition at line 56 of file BulkTX.hpp.

◆ reset() [2/2]

void reset ( uint16_t packet_size = MaxPacketSize)
protectedinherited

◆ wait_connect()

bool wait_connect ( )
protectedinherited

◆ index_of()

uint32_t index_of ( wbuffer_t * p) const
inlineprivateinherited

Definition at line 104 of file BulkTX.hpp.

◆ other_buf()

wbuffer_t * other_buf ( wbuffer_t * p)
inlineprivateinherited

Definition at line 105 of file BulkTX.hpp.

◆ write_impl()

uint32_t write_impl ( const MessageType * msgs,
uint32_t num_msgs )
privateinherited

◆ tx_callback() [2/2]

void tx_callback ( )
protectedinherited

Member Data Documentation

◆ rxpipe

template<uint16_t MaxPacketSize = 512>
Pipe_t* rxpipe
private

Definition at line 79 of file TeensyHostMIDI.hpp.

◆ txpipe

template<uint16_t MaxPacketSize = 512>
Pipe_t * txpipe
private

Definition at line 79 of file TeensyHostMIDI.hpp.

◆ rx_size

template<uint16_t MaxPacketSize = 512>
uint16_t rx_size
private

Definition at line 80 of file TeensyHostMIDI.hpp.

◆ tx_size

template<uint16_t MaxPacketSize = 512>
uint16_t tx_size
private

Definition at line 80 of file TeensyHostMIDI.hpp.

◆ rx_ep

template<uint16_t MaxPacketSize = 512>
uint8_t rx_ep
private

Definition at line 81 of file TeensyHostMIDI.hpp.

◆ tx_ep

template<uint16_t MaxPacketSize = 512>
uint8_t tx_ep
private

Definition at line 81 of file TeensyHostMIDI.hpp.

◆ rx_ep_type

template<uint16_t MaxPacketSize = 512>
uint8_t rx_ep_type
private

Definition at line 82 of file TeensyHostMIDI.hpp.

◆ tx_ep_type

template<uint16_t MaxPacketSize = 512>
uint8_t tx_ep_type
private

Definition at line 82 of file TeensyHostMIDI.hpp.

◆ mystring_bufs

template<uint16_t MaxPacketSize = 512>
strbuf_t mystring_bufs[1]
private

Definition at line 85 of file TeensyHostMIDI.hpp.

◆ write_timeout

template<uint16_t MaxPacketSize = 512>
USBDriverTimer write_timeout {this}
protected

Definition at line 95 of file TeensyHostMIDI.hpp.

◆ write_timeout_duration

template<uint16_t MaxPacketSize = 512>
microseconds write_timeout_duration {1'000}
protected

Definition at line 96 of file TeensyHostMIDI.hpp.

◆ write_error_timeout_duration

template<uint16_t MaxPacketSize = 512>
microseconds write_error_timeout_duration {40'000}
protected

Definition at line 97 of file TeensyHostMIDI.hpp.

◆ MaxPacketSize

uint16_t MaxPacketSize
staticconstexprprivateinherited

Definition at line 24 of file BulkRX.hpp.

◆ SizeReserved

uint16_t SizeReserved
staticconstexprprivateinherited

Definition at line 25 of file BulkRX.hpp.

◆ NumRxPackets

uint16_t NumRxPackets
staticconstexprprivateinherited

Definition at line 26 of file BulkRX.hpp.

◆ mo_seq

std::memory_order mo_seq
staticconstexprprivateinherited

Definition at line 37 of file BulkRX.hpp.

◆ mo_rel

std::memory_order mo_rel
staticconstexprprivateinherited

Definition at line 38 of file BulkRX.hpp.

◆ mo_acq

std::memory_order mo_acq
staticconstexprprivateinherited

Definition at line 39 of file BulkRX.hpp.

◆ mo_rlx

std::memory_order mo_rlx
staticconstexprprivateinherited

Definition at line 40 of file BulkRX.hpp.

◆ mo_acq_rel

std::memory_order mo_acq_rel
staticconstexprprivateinherited

Definition at line 41 of file BulkRX.hpp.

◆ reading

struct BulkRX::Reading reading
privateinherited

◆ writing

struct BulkTX::Writing writing
privateinherited

◆ disconnected

bool disconnected
privateinherited

Definition at line 102 of file BulkTX.hpp.


The documentation for this class was generated from the following file: