mirror of
https://github.com/hathach/tinyusb.git
synced 2025-05-09 23:31:09 +08:00
- remove tuh_midi_read_poll(), auto schedule EP in when set_config() and xfer_cb as well as ep read()
- de-dup tuh_midi_get_num_rx/tx_cables - add tuh_midi_read_available()
This commit is contained in:
parent
bad6cbe489
commit
ed88fc983f
@ -38,7 +38,7 @@
|
|||||||
static uint8_t midi_dev_addr = 0;
|
static uint8_t midi_dev_addr = 0;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
// MACRO CONSTANT TYPEDEF PROTOTYPES
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
void led_blinking_task(void);
|
void led_blinking_task(void);
|
||||||
void midi_host_rx_task(void);
|
void midi_host_rx_task(void);
|
||||||
@ -92,10 +92,9 @@ void midi_host_rx_task(void) {
|
|||||||
if (!midi_dev_addr || !tuh_midi_configured(midi_dev_addr)) {
|
if (!midi_dev_addr || !tuh_midi_configured(midi_dev_addr)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (tuh_midih_get_num_rx_cables(midi_dev_addr) < 1) {
|
if (tuh_midi_get_num_rx_cables(midi_dev_addr) < 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tuh_midi_read_poll(midi_dev_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include "tusb_option.h"
|
#include "tusb_option.h"
|
||||||
|
|
||||||
#if (TUSB_OPT_HOST_ENABLED && CFG_TUH_MIDI)
|
#if (CFG_TUH_ENABLED && CFG_TUH_MIDI)
|
||||||
|
|
||||||
#include "host/usbh.h"
|
#include "host/usbh.h"
|
||||||
#include "host/usbh_pvt.h"
|
#include "host/usbh_pvt.h"
|
||||||
@ -195,8 +195,7 @@ bool midih_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for next transfer if needed
|
tu_edpt_stream_read_xfer(dev_addr, &p_midi_host->ep_stream.rx); // prepare for next transfer
|
||||||
tu_edpt_stream_read_xfer(dev_addr, &p_midi_host->ep_stream.rx);
|
|
||||||
} else if (ep_addr == p_midi_host->ep_stream.tx.ep_addr) {
|
} else if (ep_addr == p_midi_host->ep_stream.tx.ep_addr) {
|
||||||
if (tuh_midi_tx_cb) {
|
if (tuh_midi_tx_cb) {
|
||||||
tuh_midi_tx_cb(dev_addr);
|
tuh_midi_tx_cb(dev_addr);
|
||||||
@ -416,12 +415,6 @@ bool midih_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *d
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_midi_configured(uint8_t dev_addr) {
|
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
|
||||||
return p_midi_host->configured;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool midih_set_config(uint8_t dev_addr, uint8_t itf_num) {
|
bool midih_set_config(uint8_t dev_addr, uint8_t itf_num) {
|
||||||
(void) itf_num;
|
(void) itf_num;
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
@ -432,18 +425,20 @@ bool midih_set_config(uint8_t dev_addr, uint8_t itf_num) {
|
|||||||
tuh_midi_mount_cb(dev_addr, p_midi_host->ep_in, p_midi_host->ep_out, p_midi_host->num_cables_rx, p_midi_host->num_cables_tx);
|
tuh_midi_mount_cb(dev_addr, p_midi_host->ep_in, p_midi_host->ep_out, p_midi_host->num_cables_rx, p_midi_host->num_cables_tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tu_edpt_stream_read_xfer(dev_addr, &p_midi_host->ep_stream.rx); // prepare for incoming data
|
||||||
|
|
||||||
// No special config things to do for MIDI
|
// No special config things to do for MIDI
|
||||||
usbh_driver_set_config_complete(dev_addr, p_midi_host->itf_num);
|
usbh_driver_set_config_complete(dev_addr, p_midi_host->itf_num);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Stream API
|
// API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tuh_midi_read_poll(uint8_t dev_addr) {
|
bool tuh_midi_configured(uint8_t dev_addr) {
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
TU_VERIFY(p_midi_host != NULL);
|
||||||
return tu_edpt_stream_read_xfer(dev_addr, &p_midi_host->ep_stream.rx) > 0;
|
return p_midi_host->configured;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t tuh_midi_stream_write(uint8_t dev_addr, uint8_t cable_num, uint8_t const *buffer, uint32_t bufsize) {
|
uint32_t tuh_midi_stream_write(uint8_t dev_addr, uint8_t cable_num, uint8_t const *buffer, uint32_t bufsize) {
|
||||||
@ -557,24 +552,27 @@ uint32_t tuh_midi_stream_flush(uint8_t dev_addr) {
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Helper
|
// Helper
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
uint8_t tuh_midih_get_num_tx_cables (uint8_t dev_addr)
|
uint8_t tuh_midi_get_num_tx_cables (uint8_t dev_addr) {
|
||||||
{
|
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
TU_VERIFY(p_midi_host != NULL, 0);
|
||||||
TU_VERIFY(p_midi_host->ep_out != 0); // returns 0 if fails
|
TU_VERIFY(p_midi_host->ep_out != 0, 0);
|
||||||
return p_midi_host->num_cables_tx;
|
return p_midi_host->num_cables_tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tuh_midih_get_num_rx_cables (uint8_t dev_addr)
|
uint8_t tuh_midi_get_num_rx_cables (uint8_t dev_addr) {
|
||||||
{
|
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
TU_VERIFY(p_midi_host != NULL, 0);
|
||||||
TU_VERIFY(p_midi_host->ep_in != 0); // returns 0 if fails
|
TU_VERIFY(p_midi_host->ep_in != 0, 0);
|
||||||
return p_midi_host->num_cables_rx;
|
return p_midi_host->num_cables_rx;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_midi_packet_read (uint8_t dev_addr, uint8_t packet[4])
|
uint32_t tuh_midi_read_available(uint8_t dev_addr) {
|
||||||
{
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
|
TU_VERIFY(p_midi_host != NULL);
|
||||||
|
return tu_edpt_stream_read_available(&p_midi_host->ep_stream.rx);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tuh_midi_packet_read (uint8_t dev_addr, uint8_t packet[4]) {
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
TU_VERIFY(p_midi_host != NULL);
|
||||||
TU_VERIFY(tu_edpt_stream_read_available(&p_midi_host->ep_stream.rx) >= 4);
|
TU_VERIFY(tu_edpt_stream_read_available(&p_midi_host->ep_stream.rx) >= 4);
|
||||||
@ -661,6 +659,7 @@ uint32_t tuh_midi_stream_read(uint8_t dev_addr, uint8_t *p_cable_num, uint8_t *p
|
|||||||
bytes_to_add_to_stream = 1;
|
bytes_to_add_to_stream = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t idx = 1; idx <= bytes_to_add_to_stream; idx++) {
|
for (uint8_t idx = 1; idx <= bytes_to_add_to_stream; idx++) {
|
||||||
*p_buffer++ = p_midi_host->stream_read.buffer[idx];
|
*p_buffer++ = p_midi_host->stream_read.buffer[idx];
|
||||||
}
|
}
|
||||||
@ -678,30 +677,6 @@ uint32_t tuh_midi_stream_read(uint8_t dev_addr, uint8_t *p_cable_num, uint8_t *p
|
|||||||
return bytes_buffered;
|
return bytes_buffered;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t tuh_midi_get_num_rx_cables(uint8_t dev_addr)
|
|
||||||
{
|
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
|
||||||
uint8_t num_cables = 0;
|
|
||||||
if (p_midi_host)
|
|
||||||
{
|
|
||||||
num_cables = p_midi_host->num_cables_rx;
|
|
||||||
}
|
|
||||||
return num_cables;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t tuh_midi_get_num_tx_cables(uint8_t dev_addr)
|
|
||||||
{
|
|
||||||
midih_interface_t *p_midi_host = find_midi_by_daddr(dev_addr);
|
|
||||||
TU_VERIFY(p_midi_host != NULL);
|
|
||||||
uint8_t num_cables = 0;
|
|
||||||
if (p_midi_host)
|
|
||||||
{
|
|
||||||
num_cables = p_midi_host->num_cables_tx;
|
|
||||||
}
|
|
||||||
return num_cables;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CFG_MIDI_HOST_DEVSTRINGS
|
#if CFG_MIDI_HOST_DEVSTRINGS
|
||||||
static uint8_t find_string_index(midih_interface_t *ptr, uint8_t jack_id)
|
static uint8_t find_string_index(midih_interface_t *ptr, uint8_t jack_id)
|
||||||
{
|
{
|
||||||
|
@ -58,22 +58,34 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Application API (Single Interface)
|
// Application API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tuh_midi_configured (uint8_t dev_addr);
|
bool tuh_midi_configured (uint8_t dev_addr);
|
||||||
|
|
||||||
// return the number of virtual midi cables on the device's OUT endpoint
|
|
||||||
uint8_t tuh_midih_get_num_tx_cables (uint8_t dev_addr);
|
|
||||||
|
|
||||||
// return the number of virtual midi cables on the device's IN endpoint
|
// return the number of virtual midi cables on the device's IN endpoint
|
||||||
uint8_t tuh_midih_get_num_rx_cables (uint8_t dev_addr);
|
uint8_t tuh_midi_get_num_rx_cables(uint8_t dev_addr);
|
||||||
|
|
||||||
// request available data from the device. tuh_midi_message_received_cb() will
|
// return the number of virtual midi cables on the device's OUT endpoint
|
||||||
// be called if the device has any data to send. Otherwise, the device will
|
uint8_t tuh_midi_get_num_tx_cables(uint8_t dev_addr);
|
||||||
// respond NAK. This function blocks until the transfer completes or the
|
|
||||||
// devices sends NAK.
|
#if CFG_MIDI_HOST_DEVSTRINGS
|
||||||
// This function will return false if the hardware is busy.
|
uint8_t tuh_midi_get_rx_cable_istrings(uint8_t dev_addr, uint8_t* istrings, uint8_t max_istrings);
|
||||||
bool tuh_midi_read_poll( uint8_t dev_addr );
|
uint8_t tuh_midi_get_tx_cable_istrings(uint8_t dev_addr, uint8_t* istrings, uint8_t max_istrings);
|
||||||
|
uint8_t tuh_midi_get_all_istrings(uint8_t dev_addr, const uint8_t** istrings);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// return the raw number of bytes available from device endpoint.
|
||||||
|
// Note: this is related but not the same as number of stream bytes available.
|
||||||
|
uint32_t tuh_midi_read_available(uint8_t dev_addr);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Packet API
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
// Read a raw MIDI packet from the connected device
|
||||||
|
// This function does not parse the packet format
|
||||||
|
// Return true if a packet was returned
|
||||||
|
bool tuh_midi_packet_read (uint8_t dev_addr, uint8_t packet[4]);
|
||||||
|
|
||||||
// Queue a packet to the device. The application
|
// Queue a packet to the device. The application
|
||||||
// must call tuh_midi_stream_flush to actually have the
|
// must call tuh_midi_stream_flush to actually have the
|
||||||
@ -82,6 +94,10 @@ bool tuh_midi_read_poll( uint8_t dev_addr );
|
|||||||
// Returns true if the packet was successfully queued.
|
// Returns true if the packet was successfully queued.
|
||||||
bool tuh_midi_packet_write (uint8_t dev_addr, uint8_t const packet[4]);
|
bool tuh_midi_packet_write (uint8_t dev_addr, uint8_t const packet[4]);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Stream API
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// Queue a message to the device. The application
|
// Queue a message to the device. The application
|
||||||
// must call tuh_midi_stream_flush to actually have the
|
// must call tuh_midi_stream_flush to actually have the
|
||||||
// data go out.
|
// data go out.
|
||||||
@ -101,19 +117,6 @@ uint32_t tuh_midi_stream_flush( uint8_t dev_addr);
|
|||||||
// it properly.
|
// it properly.
|
||||||
uint32_t tuh_midi_stream_read (uint8_t dev_addr, uint8_t *p_cable_num, uint8_t *p_buffer, uint16_t bufsize);
|
uint32_t tuh_midi_stream_read (uint8_t dev_addr, uint8_t *p_cable_num, uint8_t *p_buffer, uint16_t bufsize);
|
||||||
|
|
||||||
// Read a raw MIDI packet from the connected device
|
|
||||||
// This function does not parse the packet format
|
|
||||||
// Return true if a packet was returned
|
|
||||||
bool tuh_midi_packet_read (uint8_t dev_addr, uint8_t packet[4]);
|
|
||||||
|
|
||||||
uint8_t tuh_midi_get_num_rx_cables(uint8_t dev_addr);
|
|
||||||
uint8_t tuh_midi_get_num_tx_cables(uint8_t dev_addr);
|
|
||||||
#if CFG_MIDI_HOST_DEVSTRINGS
|
|
||||||
uint8_t tuh_midi_get_rx_cable_istrings(uint8_t dev_addr, uint8_t* istrings, uint8_t max_istrings);
|
|
||||||
uint8_t tuh_midi_get_tx_cable_istrings(uint8_t dev_addr, uint8_t* istrings, uint8_t max_istrings);
|
|
||||||
uint8_t tuh_midi_get_all_istrings(uint8_t dev_addr, const uint8_t** istrings);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Callbacks (Weak is optional)
|
// Callbacks (Weak is optional)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user