3030#include "bsp/board_api.h"
3131#include "tusb.h"
3232
33- #if CFG_TUH_MIDI
34-
3533//--------------------------------------------------------------------+
3634// STATIC GLOBALS DECLARATION
3735//--------------------------------------------------------------------+
38- static uint8_t midi_dev_addr = 0 ;
3936
4037//--------------------------------------------------------------------+
4138// MACRO CONSTANT TYPEDEF PROTOTYPES
@@ -65,8 +62,6 @@ int main(void) {
6562 return 0 ;
6663}
6764
68- #endif
69-
7065//--------------------------------------------------------------------+
7166// Blinking Task
7267//--------------------------------------------------------------------+
@@ -88,53 +83,40 @@ void led_blinking_task(void) {
8883// MIDI host receive task
8984//--------------------------------------------------------------------+
9085void midi_host_rx_task (void ) {
91- // device must be attached and have at least one endpoint ready to receive a message
92- if (!midi_dev_addr || !tuh_midi_mounted (midi_dev_addr )) {
93- return ;
94- }
95- if (tuh_midi_get_num_rx_cables (midi_dev_addr ) < 1 ) {
96- return ;
97- }
86+ // nothing to do, we just print out received data in callback
9887}
9988
10089//--------------------------------------------------------------------+
10190// TinyUSB Callbacks
10291//--------------------------------------------------------------------+
10392
10493// Invoked when device with MIDI interface is mounted.
105- void tuh_midi_mount_cb (uint8_t dev_addr , uint8_t num_cables_rx , uint16_t num_cables_tx ) {
106- (void ) num_cables_rx ;
107- (void ) num_cables_tx ;
108- midi_dev_addr = dev_addr ;
109- TU_LOG1 ("MIDI device address = %u, Number of RX cables = %u, Number of TX cables = %u\r\n" ,
110- dev_addr , num_cables_rx , num_cables_tx );
94+ void tuh_midi_mount_cb (uint8_t idx , uint8_t num_cables_rx , uint16_t num_cables_tx ) {
95+ printf ("MIDI Interface Index = %u, Number of RX cables = %u, Number of TX cables = %u\r\n" ,
96+ idx , num_cables_rx , num_cables_tx );
11197}
11298
11399// Invoked when device with hid interface is un-mounted
114- void tuh_midi_umount_cb (uint8_t dev_addr ) {
115- (void ) dev_addr ;
116- midi_dev_addr = 0 ;
117- TU_LOG1 ("MIDI device address = %d is unmounted\r\n" , dev_addr );
100+ void tuh_midi_umount_cb (uint8_t idx ) {
101+ printf ("MIDI Interface Index = %u is unmounted\r\n" , idx );
118102}
119103
120- void tuh_midi_rx_cb (uint8_t dev_addr , uint32_t num_packets ) {
121- if (midi_dev_addr != dev_addr ) {
122- return ;
123- }
124-
104+ void tuh_midi_rx_cb (uint8_t idx , uint32_t num_packets ) {
125105 if (num_packets == 0 ) {
126106 return ;
127107 }
128108
129109 uint8_t cable_num ;
130110 uint8_t buffer [48 ];
131- uint32_t bytes_read = tuh_midi_stream_read (dev_addr , & cable_num , buffer , sizeof (buffer ));
132- (void ) bytes_read ;
111+ uint32_t bytes_read = tuh_midi_stream_read (idx , & cable_num , buffer , sizeof (buffer ));
133112
134- TU_LOG1 ("Read bytes %lu cable %u" , bytes_read , cable_num );
135- TU_LOG1_MEM (buffer , bytes_read , 2 );
113+ printf ("Cable %u rx %lu bytes: " , cable_num , bytes_read );
114+ for (uint32_t i = 0 ; i < bytes_read ; i ++ ) {
115+ printf ("%02X " , buffer [i ]);
116+ }
117+ printf ("\r\n" );
136118}
137119
138- void tuh_midi_tx_cb (uint8_t dev_addr ) {
139- (void ) dev_addr ;
120+ void tuh_midi_tx_cb (uint8_t idx ) {
121+ (void ) idx ;
140122}
0 commit comments