2025-02-12 11:39:26 +07:00
|
|
|
/*
|
2022-08-12 11:06:36 -07:00
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2019 Ha Thach (tinyusb.org)
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* This file is part of the TinyUSB stack.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _TUSB_MIDI_HOST_H_
|
|
|
|
#define _TUSB_MIDI_HOST_H_
|
|
|
|
|
|
|
|
#include "class/audio/audio.h"
|
|
|
|
#include "midi.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Class Driver Configuration
|
|
|
|
//--------------------------------------------------------------------+
|
2025-02-12 22:16:08 +07:00
|
|
|
#ifndef CFG_TUH_MAX_CABLES
|
|
|
|
#define CFG_TUH_MAX_CABLES 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CFG_TUH_MIDI_RX_BUFSIZE
|
2025-02-13 15:52:30 +07:00
|
|
|
#define CFG_TUH_MIDI_RX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
2025-02-12 22:16:08 +07:00
|
|
|
#endif
|
2022-08-12 11:06:36 -07:00
|
|
|
|
2025-02-12 22:16:08 +07:00
|
|
|
#ifndef CFG_TUH_MIDI_TX_BUFSIZE
|
2025-02-13 15:52:30 +07:00
|
|
|
#define CFG_TUH_MIDI_TX_BUFSIZE TUH_EPSIZE_BULK_MPS
|
2022-08-12 11:06:36 -07:00
|
|
|
#endif
|
|
|
|
|
2025-02-12 22:16:08 +07:00
|
|
|
#ifndef CFG_TUH_MIDI_EP_BUFSIZE
|
2025-02-13 15:52:30 +07:00
|
|
|
#define CFG_TUH_MIDI_EP_BUFSIZE TUH_EPSIZE_BULK_MPS
|
2022-08-12 11:06:36 -07:00
|
|
|
#endif
|
|
|
|
|
2025-02-12 22:16:08 +07:00
|
|
|
#ifndef CFG_MIDI_HOST_DEVSTRINGS
|
|
|
|
#define CFG_MIDI_HOST_DEVSTRINGS 0
|
|
|
|
#endif
|
2022-08-12 11:06:36 -07:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Application API (Single Interface)
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
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
|
|
|
|
uint8_t tuh_midih_get_num_rx_cables (uint8_t dev_addr);
|
|
|
|
|
|
|
|
// request available data from the device. tuh_midi_message_received_cb() will
|
|
|
|
// be called if the device has any data to send. Otherwise, the device will
|
|
|
|
// respond NAK. This function blocks until the transfer completes or the
|
|
|
|
// devices sends NAK.
|
|
|
|
// This function will return false if the hardware is busy.
|
|
|
|
bool tuh_midi_read_poll( uint8_t dev_addr );
|
|
|
|
|
|
|
|
// Queue a packet to the device. The application
|
|
|
|
// must call tuh_midi_stream_flush to actually have the
|
|
|
|
// data go out. It is up to the application to properly
|
|
|
|
// format this packet; this function does not check.
|
|
|
|
// Returns true if the packet was successfully queued.
|
|
|
|
bool tuh_midi_packet_write (uint8_t dev_addr, uint8_t const packet[4]);
|
|
|
|
|
|
|
|
// Queue a message to the device. The application
|
|
|
|
// must call tuh_midi_stream_flush to actually have the
|
|
|
|
// data go out.
|
|
|
|
uint32_t tuh_midi_stream_write (uint8_t dev_addr, uint8_t cable_num, uint8_t const* p_buffer, uint32_t bufsize);
|
|
|
|
|
|
|
|
// Send any queued packets to the device if the host hardware is able to do it
|
|
|
|
// Returns the number of bytes flushed to the host hardware or 0 if
|
|
|
|
// the host hardware is busy or there is nothing in queue to send.
|
|
|
|
uint32_t tuh_midi_stream_flush( uint8_t dev_addr);
|
|
|
|
|
|
|
|
// Get the MIDI stream from the device. Set the value pointed
|
|
|
|
// to by p_cable_num to the MIDI cable number intended to receive it.
|
|
|
|
// The MIDI stream will be stored in the buffer pointed to by p_buffer.
|
|
|
|
// Return the number of bytes added to the buffer.
|
|
|
|
// Note that this function ignores the CIN field of the MIDI packet
|
|
|
|
// because a number of commercial devices out there do not encode
|
|
|
|
// it properly.
|
|
|
|
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)
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
|
|
|
|
// Invoked when device with MIDI interface is mounted.
|
2025-02-12 11:39:26 +07:00
|
|
|
// If the MIDI host application requires MIDI IN, it should request an
|
2022-08-12 11:06:36 -07:00
|
|
|
// IN transfer here. The device will likely NAK this transfer. How the driver
|
|
|
|
// handles the NAK is hardware dependent.
|
|
|
|
TU_ATTR_WEAK void tuh_midi_mount_cb(uint8_t dev_addr, uint8_t in_ep, uint8_t out_ep, uint8_t num_cables_rx, uint16_t num_cables_tx);
|
|
|
|
|
|
|
|
// Invoked when device with MIDI interface is un-mounted
|
|
|
|
// For now, the instance parameter is always 0 and can be ignored
|
|
|
|
TU_ATTR_WEAK void tuh_midi_umount_cb(uint8_t dev_addr, uint8_t instance);
|
|
|
|
|
|
|
|
TU_ATTR_WEAK void tuh_midi_rx_cb(uint8_t dev_addr, uint32_t num_packets);
|
|
|
|
TU_ATTR_WEAK void tuh_midi_tx_cb(uint8_t dev_addr);
|
2025-02-13 15:52:30 +07:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Internal Class Driver API
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
bool midih_init (void);
|
|
|
|
bool midih_deinit (void);
|
|
|
|
bool midih_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len);
|
|
|
|
bool midih_set_config (uint8_t dev_addr, uint8_t itf_num);
|
|
|
|
bool midih_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
|
|
|
void midih_close (uint8_t dev_addr);
|
|
|
|
|
2022-08-12 11:06:36 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _TUSB_MIDI_HOST_H_ */
|