Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
midi tx sends stuff, but the framing is wrong or something. tx events…
… are transpiring when an rx transaction is occured, every endpoint request throws an error. rx data seems fine though.
- Loading branch information
|
|
@@ -69,7 +69,7 @@ void op_midi_out_note_init(void* mem) { |
|
|
op->in_val[1] = &(op->num); |
|
|
op->in_val[2] = &(op->vel); |
|
|
|
|
|
op->chan = op_from_int(-1); |
|
|
op->chan = OP_ONE; |
|
|
op->num = 0; |
|
|
op->vel = 0; |
|
|
|
|
|
@@ -152,13 +152,21 @@ static void op_midi_out_note_handler(op_midi_t* op_midi, u32 data) { |
|
|
inline void midi_out_note_send_packet( op_midi_out_note_t* mout ) { |
|
|
u8 pack[3]; |
|
|
if(mout->vel == 0) { |
|
|
// note on/off |
|
|
pack[0] = 0x80; |
|
|
} else { |
|
|
pack[0] = 0x90; |
|
|
} |
|
|
pack[0] |= (u8)(mout->chan & 0x0f); |
|
|
pack[1] = (u8)(mout->num); |
|
|
pack[2] = (u8)(mout->vel); |
|
|
|
|
|
print_dbg("\r\n midi_out_note_send_packet; data: "); |
|
|
print_dbg_char_hex(pack[0]); print_dbg(" "); |
|
|
print_dbg_char_hex(pack[1]); print_dbg(" "); |
|
|
print_dbg_char_hex(pack[2]); print_dbg(" "); |
|
|
|
|
|
|
|
|
|
|
|
midi_write(pack, 3); |
|
|
|
|
|
|
|
|
@@ -130,7 +130,7 @@ static void midi_rx_done( usb_add_t add, |
|
|
uhd_trans_status_t stat, |
|
|
iram_size_t nb) { |
|
|
int i; |
|
|
|
|
|
rxBusy = 0; |
|
|
if(nb > 0) { |
|
|
print_dbg("\r\n midi rx; status: 0x"); |
|
|
print_dbg_hex((u32)stat); |
|
|
@@ -141,8 +141,7 @@ static void midi_rx_done( usb_add_t add, |
|
|
print_dbg_char_hex(rxBuf[i]); |
|
|
print_dbg(" "); |
|
|
} |
|
|
// the first byte is weird.. |
|
|
|
|
|
// ignoring 1st byte, virtual cable select |
|
|
rxBytes = nb - 1; |
|
|
midi_parse(); |
|
|
} |
|
|
@@ -177,22 +176,31 @@ extern void midi_read(void) { |
|
|
} |
|
|
|
|
|
// write to MIDI device |
|
|
extern void midi_write(u8* data, u32 bytes) { |
|
|
static u8* pbuf = &(txBuf[1]); |
|
|
extern void midi_write(const u8* data, u32 bytes) { |
|
|
u8* pbuf = &(txBuf[1]); |
|
|
int i; |
|
|
|
|
|
// copy to buffer |
|
|
for(i=0; i<bytes; ++i){ |
|
|
*pbuf++ = data[i]; |
|
|
} |
|
|
|
|
|
// would set virtual cable index here... |
|
|
// high nib of 1st byte = virtual cable, leaving 0 |
|
|
// low nib = 4b com code, duplicated from status byte |
|
|
txBuf[0] = (u8) (data[0] >> 4); |
|
|
/// try cable idx 1 |
|
|
txBuf[0] |= 0x10; |
|
|
|
|
|
print_dbg("\r\n midi tx; data: "); |
|
|
for(i=0; i<(bytes+1); i++) { |
|
|
print_dbg_char_hex(txBuf[i]); |
|
|
print_dbg(" "); |
|
|
} |
|
|
|
|
|
|
|
|
print_dbg("\r\n midi_write..."); |
|
|
txBusy = true; |
|
|
if (!uhi_midi_out_run(txBuf, bytes, &midi_tx_done)) { |
|
|
if (!uhi_midi_out_run(txBuf, bytes+1, &midi_tx_done)) { |
|
|
// hm, every uhd enpoint run always returns unspecified error... |
|
|
// print_dbg("\r\n midi tx endpoint error"); |
|
|
} |
|
|
|
|
|
@@ -10,7 +10,7 @@ extern u8 midiConnect; |
|
|
extern void midi_read(void); |
|
|
|
|
|
// write to MIDI device |
|
|
extern void midi_write(u8* data, u32 bytes); |
|
|
extern void midi_write(const u8* data, u32 bytes); |
|
|
|
|
|
// MIDI device was plugged or unplugged |
|
|
extern void midi_change(uhc_device_t* dev, u8 plug); |
|
|
|
|
|
@@ -248,21 +248,47 @@ void uhi_midi_uninstall(uhc_device_t* dev) { |
|
|
|
|
|
bool uhi_midi_in_run(uint8_t * buf, iram_size_t buf_size, |
|
|
uhd_callback_trans_t callback) { |
|
|
return uhd_ep_run(uhi_midi_dev.dev->address, |
|
|
uhi_midi_dev.ep_in, false, buf, buf_size, |
|
|
UHI_MIDI_TIMEOUT, callback); |
|
|
|
|
|
print_dbg("\r\n attempting to run midi input endpoint ; dev address: 0x"); |
|
|
print_dbg_hex((u32) (uhi_midi_dev.dev->address) ); |
|
|
print_dbg(" , endpoint number: "); |
|
|
print_dbg_ulong((u32) (uhi_midi_dev.ep_in) ); |
|
|
|
|
|
|
|
|
return uhd_ep_run( |
|
|
uhi_midi_dev.dev->address, |
|
|
uhi_midi_dev.ep_in, |
|
|
// false, // shortpacket... |
|
|
//// TEST: |
|
|
true, |
|
|
buf, buf_size, |
|
|
UHI_MIDI_TIMEOUT, |
|
|
callback); |
|
|
} |
|
|
|
|
|
bool uhi_midi_out_run(uint8_t * buf, iram_size_t buf_size, |
|
|
uhd_callback_trans_t callback) { |
|
|
|
|
|
print_dbg("\r\n attempting to run midi output endpoint. dev address: 0x"); |
|
|
/* |
|
|
from uhd.h |
|
|
|
|
|
* \warning About \a b_shortpacket, for OUT endpoint it means that |
|
|
* a short packet or a Zero Length Packet must be sent to the USB line |
|
|
* to properly close the usb transfer at the end of the data transfer. |
|
|
* For Bulk and Interrupt IN endpoint, it will automatically stop the transfer |
|
|
* at the end of the data transfer (received short packet). |
|
|
* |
|
|
*/ |
|
|
print_dbg("\r\n attempting to run midi output endpoint ; dev address: 0x"); |
|
|
print_dbg_hex((u32) (uhi_midi_dev.dev->address) ); |
|
|
print_dbg("endpoint number: "); |
|
|
print_dbg(" , endpoint number: "); |
|
|
print_dbg_ulong((u32) (uhi_midi_dev.ep_out) ); |
|
|
|
|
|
return uhd_ep_run(uhi_midi_dev.dev->address, |
|
|
uhi_midi_dev.ep_out, true, buf, buf_size, |
|
|
UHI_MIDI_TIMEOUT, callback); |
|
|
return uhd_ep_run( |
|
|
uhi_midi_dev.dev->address, |
|
|
uhi_midi_dev.ep_out, |
|
|
true, // automatic shortpacket for buf < wlen |
|
|
buf, buf_size, |
|
|
UHI_MIDI_TIMEOUT, |
|
|
callback); |
|
|
} |
|
|
|