Control Surface main
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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 = MessageTypeT
 
using MessageType = MessageTypeT
 

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.
 
void write (const MessageType *msgs, uint32_t num_msgs)
 Send multiple MIDI USB messages.
 
template<size_t N>
void write (const MessageType(&msgs)[N])
 Send multiple MIDI USB messages. May block.
 
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 = std::remove_reference_t<decltype(reading.buffers[0])>
 
using wbuffer_t = typename Writing::Buffer
 

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 = false
 

Static Private Attributes

static constexpr uint16_t MaxPacketSize = MaxPacketSizeV
 
static constexpr uint16_t SizeReserved = MaxPacketSize + 1
 
static constexpr uint16_t NumRxPackets = MaxPacketSize == 64 ? 16 : 4
 
static constexpr std::memory_order mo_seq = std::memory_order_seq_cst
 
static constexpr std::memory_order mo_rel = std::memory_order_release
 
static constexpr std::memory_order mo_acq = std::memory_order_acquire
 
static constexpr std::memory_order mo_rlx = std::memory_order_relaxed
 
static constexpr std::memory_order mo_acq_rel = std::memory_order_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]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
using MessageType = MessageTypeT
inherited

Definition at line 14 of file BulkRX.hpp.

◆ rbuffer_t

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
using rbuffer_t = std::remove_reference_t<decltype(reading.buffers[0])>
privateinherited

Definition at line 56 of file BulkRX.hpp.

◆ MessageType [2/2]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
using MessageType = MessageTypeT
inherited

Definition at line 14 of file BulkTX.hpp.

◆ wbuffer_t

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
using wbuffer_t = typename Writing::Buffer
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>
static void rx_callback ( const Transfer_t * transfer)
staticprotected

◆ tx_callback() [1/2]

template<uint16_t MaxPacketSize = 512>
static 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>
static constexpr size_t len ( T(&) [N])
inlinestaticconstexprprivate

Definition at line 111 of file TeensyHostMIDI.hpp.

◆ read() [2/2]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
bool read ( MessageType & message)
inherited

Try reading a single message.

Returns
Whether a message was available.

◆ reset() [1/2]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
void reset ( uint16_t packet_size = MaxPacketSize)
protectedinherited

◆ rx_callback() [2/2]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
void rx_callback ( uint32_t num_bytes_read)
protectedinherited

◆ write() [1/3]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
void write ( MessageType msg)
inherited

Send a MIDI USB message.

May block.

Parameters
msgThe 4-byte MIDI USB message to send.

◆ write() [2/3]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
void write ( const MessageType * msgs,
uint32_t num_msgs )
inherited

Send multiple MIDI USB messages.

May block.

Parameters
msgsAn array of 4-byte MIDI USB messages to send.
num_msgsThe number of messages in the array.

◆ write() [3/3]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
template<size_t N>
void write ( const MessageType(&) msgs[N])
inlineinherited

Send multiple MIDI USB messages. May block.

Definition at line 32 of file BulkTX.hpp.

◆ write_nonblock()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
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()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
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()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
bool is_done ( ) const
inherited

Check if all transfers have completed.

◆ getWriteError()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
uint32_t getWriteError ( ) const
inlineinherited

Get the number messages that failed to send.

Definition at line 54 of file BulkTX.hpp.

◆ clearWriteError()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
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]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
void reset ( uint16_t packet_size = MaxPacketSize)
protectedinherited

◆ wait_connect()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
bool wait_connect ( )
protectedinherited

◆ index_of()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
uint32_t index_of ( wbuffer_t * p) const
inlineprivateinherited

Definition at line 104 of file BulkTX.hpp.

◆ other_buf()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
wbuffer_t * other_buf ( wbuffer_t * p)
inlineprivateinherited

Definition at line 105 of file BulkTX.hpp.

◆ write_impl()

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
uint32_t write_impl ( const MessageType * msgs,
uint32_t num_msgs )
privateinherited

◆ tx_callback() [2/2]

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
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

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr uint16_t MaxPacketSize = MaxPacketSizeV
staticconstexprprivateinherited

Definition at line 24 of file BulkRX.hpp.

◆ SizeReserved

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr uint16_t SizeReserved = MaxPacketSize + 1
staticconstexprprivateinherited

Definition at line 25 of file BulkRX.hpp.

◆ NumRxPackets

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr uint16_t NumRxPackets = MaxPacketSize == 64 ? 16 : 4
staticconstexprprivateinherited

Definition at line 26 of file BulkRX.hpp.

◆ mo_seq

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr std::memory_order mo_seq = std::memory_order_seq_cst
staticconstexprprivateinherited

Definition at line 37 of file BulkRX.hpp.

◆ mo_rel

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr std::memory_order mo_rel = std::memory_order_release
staticconstexprprivateinherited

Definition at line 38 of file BulkRX.hpp.

◆ mo_acq

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr std::memory_order mo_acq = std::memory_order_acquire
staticconstexprprivateinherited

Definition at line 39 of file BulkRX.hpp.

◆ mo_rlx

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr std::memory_order mo_rlx = std::memory_order_relaxed
staticconstexprprivateinherited

Definition at line 40 of file BulkRX.hpp.

◆ mo_acq_rel

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
constexpr std::memory_order mo_acq_rel = std::memory_order_acq_rel
staticconstexprprivateinherited

Definition at line 41 of file BulkRX.hpp.

◆ reading

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
struct BulkRX::Reading reading
privateinherited

◆ writing

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
struct BulkTX::Writing writing
privateinherited

◆ disconnected

template<class Derived , class MessageTypeT , uint16_t MaxPacketSizeV>
bool disconnected = false
privateinherited

Definition at line 102 of file BulkTX.hpp.


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