Control Surface stm32
MIDI Control Surface library for Arduino
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Static Private Member Functions | 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 14 of file TeensyHostMIDI.hpp.

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

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]
 

Class Documentation

◆ TeensyHostMIDI::Reading

struct TeensyHostMIDI::Reading
+ Collaboration diagram for TeensyHostMIDI< MaxPacketSize >::Reading:
Class Members
struct Buffer buffers[NumRxPackets]
atomic< uint32_t > available
atomic< uint32_t > read_idx
atomic< uint32_t > write_idx
atomic< bool > reading

◆ TeensyHostMIDI::Writing

struct TeensyHostMIDI::Writing
+ Collaboration diagram for TeensyHostMIDI< MaxPacketSize >::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

Member Typedef Documentation

◆ microseconds

using microseconds = std::chrono::microseconds

Definition at line 18 of file TeensyHostMIDI.hpp.

◆ rbuffer_t

using rbuffer_t = typename Reading::Buffer
protected

Definition at line 134 of file TeensyHostMIDI.hpp.

◆ wbuffer_t

using wbuffer_t = typename Writing::Buffer
protected

Definition at line 150 of file TeensyHostMIDI.hpp.

◆ writebuf_size_tup

using writebuf_size_tup = std::tuple<uint32_t, wbuffer_t *, uint32_t>
protected

Definition at line 156 of file TeensyHostMIDI.hpp.

Constructor & Destructor Documentation

◆ TeensyHostMIDI()

TeensyHostMIDI ( USBHost &  host)
inline

Definition at line 16 of file TeensyHostMIDI.hpp.

Member Function Documentation

◆ write() [1/3]

void write ( uint32_t  msg)

Send a MIDI USB message.

May block.

Parameters
msgThe 4-byte MIDI USB message to send.

◆ write() [2/3]

void write ( const uint32_t *  msgs,
uint32_t  num_msgs 
)

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]

void write ( const uint32_t(&)  msgs[N])
inline

Send multiple MIDI USB messages. May block.

Definition at line 36 of file TeensyHostMIDI.hpp.

◆ write_nonblock()

uint32_t write_nonblock ( const uint32_t *  msgs,
uint32_t  num_msgs 
)

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.

◆ read()

uint32_t read ( )

Try reading a 4-byte MIDI USB message.

Returns
The message or 0x00000000 if no messages available.

◆ send_now()

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.

◆ setTimeout()

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 62 of file TeensyHostMIDI.hpp.

◆ setErrorTimeout()

void setErrorTimeout ( microseconds  timeout)
inline

Definition at line 66 of file TeensyHostMIDI.hpp.

◆ getWriteError()

uint32_t getWriteError ( ) const
inline

Count how many USB packets were dropped.

Definition at line 71 of file TeensyHostMIDI.hpp.

◆ clearWriteError()

void clearWriteError ( )
inline

Clear the counter of how many USB packets were dropped.

Definition at line 73 of file TeensyHostMIDI.hpp.

◆ claim()

bool claim ( Device_t *  device,
int  type,
const uint8_t *  descriptors,
uint32_t  len 
)
overrideprotected

◆ disconnect()

void disconnect ( )
overrideprotected

◆ timer_event()

void timer_event ( USBDriverTimer *  whichtimer)
overrideprotected

◆ rx_callback()

static void rx_callback ( const Transfer_t *  transfer)
staticprotected

◆ tx_callback()

static void tx_callback ( const Transfer_t *  transfer)
staticprotected

◆ write_start()

void write_start ( uint8_t *  buffer,
uint32_t  size 
)
protected

◆ write_start_isr()

void write_start_isr ( uint8_t *  buffer,
uint32_t  size 
)
protected

◆ write_finish()

uint32_t write_finish ( const Transfer_t *  transfer)
protected

◆ read_start()

void read_start ( uint8_t *  buffer,
uint32_t  size 
)
protected

◆ read_start_isr()

void read_start_isr ( uint8_t *  buffer,
uint32_t  size 
)
protected

◆ read_finish()

uint32_t read_finish ( const Transfer_t *  transfer)
protected

◆ claim_if_midi()

bool claim_if_midi ( Device_t *  device,
int  type,
const uint8_t *  descriptors,
uint32_t  len 
)
protected

◆ init()

void init ( )
protected

◆ write_impl()

uint32_t write_impl ( const uint32_t *  msgs,
uint32_t  num_msgs,
bool  nonblocking 
)
protected

◆ read_writebuf_size()

writebuf_size_tup read_writebuf_size ( )
protected

◆ send_now_impl_nonblock()

bool send_now_impl_nonblock ( uint32_t  activebuf_idx)
protected

◆ timeout_callback()

void timeout_callback ( )
protected

◆ in_callback()

void in_callback ( const Transfer_t *  transfer)
protected

◆ out_callback()

void out_callback ( const Transfer_t *  transfer)
protected

◆ len()

static constexpr size_t len ( T(&)  [N])
inlinestaticconstexprprivate

Definition at line 165 of file TeensyHostMIDI.hpp.

Member Data Documentation

◆ rxpipe

Pipe_t* rxpipe
private

Definition at line 102 of file TeensyHostMIDI.hpp.

◆ txpipe

Pipe_t* txpipe
private

Definition at line 103 of file TeensyHostMIDI.hpp.

◆ rx_size

uint16_t rx_size
private

Definition at line 104 of file TeensyHostMIDI.hpp.

◆ tx_size

uint16_t tx_size
private

Definition at line 105 of file TeensyHostMIDI.hpp.

◆ rx_ep

uint8_t rx_ep
private

Definition at line 106 of file TeensyHostMIDI.hpp.

◆ tx_ep

uint8_t tx_ep
private

Definition at line 107 of file TeensyHostMIDI.hpp.

◆ rx_ep_type

uint8_t rx_ep_type
private

Definition at line 108 of file TeensyHostMIDI.hpp.

◆ tx_ep_type

uint8_t tx_ep_type
private

Definition at line 109 of file TeensyHostMIDI.hpp.

◆ mystring_bufs

strbuf_t mystring_bufs[1]
private

Definition at line 112 of file TeensyHostMIDI.hpp.

◆ PacketSize

constexpr uint32_t PacketSize = MaxPacketSize
staticconstexpr

USB packet size. Must be a power of two.

Definition at line 116 of file TeensyHostMIDI.hpp.

◆ SizeReserved

constexpr uint32_t SizeReserved = PacketSize + 1
staticconstexprprotected

Definition at line 119 of file TeensyHostMIDI.hpp.

◆ NumRxPackets

constexpr uint32_t NumRxPackets = 2
staticconstexprprotected

Definition at line 120 of file TeensyHostMIDI.hpp.

◆ reading

struct TeensyHostMIDI::Reading reading
protected

◆ writing

struct TeensyHostMIDI::Writing writing
protected

◆ write_timeout

USBDriverTimer write_timeout {this}
protected

Definition at line 151 of file TeensyHostMIDI.hpp.


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