mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Merge branch 'master' into rollover
* master: Update MIDI driver v0.3.2 # Conflicts: # examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino # examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino # examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino # examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino # usbh_midi.cpp # usbh_midi.h
This commit is contained in:
commit
9162d13f77
7 changed files with 99 additions and 118 deletions
|
@ -51,7 +51,7 @@ env:
|
||||||
- PLATFORMIO_CI_SRC=examples/PSBuzz
|
- PLATFORMIO_CI_SRC=examples/PSBuzz
|
||||||
# - PLATFORMIO_CI_SRC=examples/testusbhostFAT
|
# - PLATFORMIO_CI_SRC=examples/testusbhostFAT
|
||||||
- PLATFORMIO_CI_SRC=examples/USB_desc
|
- PLATFORMIO_CI_SRC=examples/USB_desc
|
||||||
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter
|
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidirectional_converter
|
||||||
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample
|
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample
|
||||||
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter
|
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter
|
||||||
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi
|
- PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* USB-MIDI dump utility
|
* USB-MIDI dump utility
|
||||||
* Copyright (C) 2013-2016 Yuuichi Akagawa
|
* Copyright (C) 2013-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* for use with USB Host Shield 2.0 from Circuitsathome.com
|
* for use with USB Host Shield 2.0 from Circuitsathome.com
|
||||||
* https://github.com/felis/USB_Host_Shield_2.0
|
* https://github.com/felis/USB_Host_Shield_2.0
|
||||||
|
@ -44,10 +44,13 @@ void setup()
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
Usb.Task();
|
Usb.Task();
|
||||||
|
//uint32_t t1 = (uint32_t)micros();
|
||||||
if ( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
if ( Usb.getUsbTaskState() == USB_STATE_RUNNING )
|
||||||
{
|
{
|
||||||
MIDI_poll();
|
MIDI_poll();
|
||||||
}
|
}
|
||||||
|
//delay(1ms)
|
||||||
|
//doDelay(t1, (uint32_t)micros(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Poll USB MIDI Controler and send to serial MIDI
|
// Poll USB MIDI Controler and send to serial MIDI
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* USB-MIDI to Legacy Serial MIDI converter
|
* USB-MIDI to Legacy Serial MIDI converter
|
||||||
* Copyright (C) 2012-2016 Yuuichi Akagawa
|
* Copyright (C) 2012-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
||||||
* by Collin Cunningham - makezine.com, narbotic.com
|
* by Collin Cunningham - makezine.com, narbotic.com
|
||||||
|
@ -55,6 +55,7 @@ void loop()
|
||||||
{
|
{
|
||||||
MIDI_poll();
|
MIDI_poll();
|
||||||
}
|
}
|
||||||
|
//delay(1ms)
|
||||||
doDelay(t1, (uint32_t)micros(), 1000);
|
doDelay(t1, (uint32_t)micros(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* USB-MIDI to Legacy Serial MIDI converter
|
* USB-MIDI to Legacy Serial MIDI converter
|
||||||
* Copyright (C) 2012-2016 Yuuichi Akagawa
|
* Copyright (C) 2012-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
||||||
* by Collin Cunningham - makezine.com, narbotic.com
|
* by Collin Cunningham - makezine.com, narbotic.com
|
||||||
|
@ -57,6 +57,7 @@ void loop()
|
||||||
{
|
{
|
||||||
MIDI_poll();
|
MIDI_poll();
|
||||||
}
|
}
|
||||||
|
//delay(1ms)
|
||||||
doDelay(t1, (uint32_t)micros(), 1000);
|
doDelay(t1, (uint32_t)micros(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* Legacy Serial MIDI and USB Host bidirectional converter
|
* Legacy Serial MIDI and USB Host bidirectional converter
|
||||||
* Copyright (C) 2013-2016 Yuuichi Akagawa
|
* Copyright (C) 2013-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* for use with Arduino MIDI library
|
* for use with Arduino MIDI library
|
||||||
* https://github.com/FortySevenEffects/arduino_midi_library/
|
* https://github.com/FortySevenEffects/arduino_midi_library/
|
||||||
|
@ -49,7 +49,6 @@ void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime);
|
||||||
#define USBH_MIDI_SYSEX_ENABLE
|
#define USBH_MIDI_SYSEX_ENABLE
|
||||||
|
|
||||||
#ifdef USBH_MIDI_SYSEX_ENABLE
|
#ifdef USBH_MIDI_SYSEX_ENABLE
|
||||||
MidiSysEx sysExData;
|
|
||||||
//SysEx:
|
//SysEx:
|
||||||
void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) {
|
void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) {
|
||||||
Midi.SendSysEx(sysexmsg, sizeofsysex);
|
Midi.SendSysEx(sysexmsg, sizeofsysex);
|
||||||
|
@ -93,6 +92,7 @@ void loop()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//delay(1ms)
|
||||||
doDelay(t1, (uint32_t)micros(), 1000);
|
doDelay(t1, (uint32_t)micros(), 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,23 +117,17 @@ void MIDI_poll()
|
||||||
uint8_t *p = recvBuf;
|
uint8_t *p = recvBuf;
|
||||||
while (readPtr < MIDI_EVENT_PACKET_SIZE) {
|
while (readPtr < MIDI_EVENT_PACKET_SIZE) {
|
||||||
if (*p == 0 && *(p + 1) == 0) break; //data end
|
if (*p == 0 && *(p + 1) == 0) break; //data end
|
||||||
MidiSysEx::Status rc = sysExData.set(p);
|
|
||||||
switch (rc) {
|
uint8_t outbuf[3];
|
||||||
case MidiSysEx::nonsysex : //No SysEx message send data to Serial MIDI
|
uint8_t rc = Midi.extractSysExData(p, outbuf);
|
||||||
|
if ( rc == 0 ) {
|
||||||
p++;
|
p++;
|
||||||
size = Midi.lookupMsgSize(*p);
|
size = Midi.lookupMsgSize(*p);
|
||||||
_MIDI_SERIAL_PORT.write(p, size);
|
_MIDI_SERIAL_PORT.write(p, size);
|
||||||
p += 3;
|
p += 3;
|
||||||
break;
|
} else {
|
||||||
case MidiSysEx::done : //SysEx end. send data to Serial MIDI
|
_MIDI_SERIAL_PORT.write(outbuf, rc);
|
||||||
_MIDI_SERIAL_PORT.write(sysExData.get(), sysExData.getSize());
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
case MidiSysEx::overflow : //SysEx buffer over. ignore and flush buffer.
|
|
||||||
sysExData.clear();
|
|
||||||
/* FALLTHROUGH */
|
|
||||||
default:
|
|
||||||
p += 4;
|
p += 4;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
readPtr += 4;
|
readPtr += 4;
|
||||||
}
|
}
|
134
usbh_midi.cpp
134
usbh_midi.cpp
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* USB-MIDI class driver for USB Host Shield 2.0 Library
|
* USB-MIDI class driver for USB Host Shield 2.0 Library
|
||||||
* Copyright (c) 2012-2016 Yuuichi Akagawa
|
* Copyright (c) 2012-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
||||||
* by Collin Cunningham - makezine.com, narbotic.com
|
* by Collin Cunningham - makezine.com, narbotic.com
|
||||||
|
@ -95,9 +95,7 @@ readPtr(0) {
|
||||||
for(uint8_t i=0; i<MIDI_MAX_ENDPOINTS; i++) {
|
for(uint8_t i=0; i<MIDI_MAX_ENDPOINTS; i++) {
|
||||||
epInfo[i].epAddr = 0;
|
epInfo[i].epAddr = 0;
|
||||||
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
epInfo[i].maxPktSize = (i) ? 0 : 8;
|
||||||
epInfo[i].epAttribs = 0;
|
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
||||||
// epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER;
|
|
||||||
epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : 4;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// register in USB subsystem
|
// register in USB subsystem
|
||||||
|
@ -109,7 +107,7 @@ readPtr(0) {
|
||||||
/* Connection initialization of an MIDI Device */
|
/* Connection initialization of an MIDI Device */
|
||||||
uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
{
|
{
|
||||||
uint8_t buf[DESC_BUFF_SIZE];
|
uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)];
|
||||||
USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
|
USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
|
||||||
uint8_t rcode;
|
uint8_t rcode;
|
||||||
UsbDevice *p = NULL;
|
UsbDevice *p = NULL;
|
||||||
|
@ -117,6 +115,15 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
uint8_t num_of_conf; // number of configurations
|
uint8_t num_of_conf; // number of configurations
|
||||||
|
|
||||||
USBTRACE("\rMIDI Init\r\n");
|
USBTRACE("\rMIDI Init\r\n");
|
||||||
|
|
||||||
|
//for reconnect
|
||||||
|
for(uint8_t i=epDataInIndex; i<=epDataOutIndex; i++) {
|
||||||
|
epInfo[i].epAddr = (i==epDataInIndex) ? 0x81 : 0x01;
|
||||||
|
epInfo[i].maxPktSize = 0;
|
||||||
|
epInfo[i].bmSndToggle = 0;
|
||||||
|
epInfo[i].bmRcvToggle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// get memory address of USB device address pool
|
// get memory address of USB device address pool
|
||||||
AddressPool &addrPool = pUsb->GetAddressPool();
|
AddressPool &addrPool = pUsb->GetAddressPool();
|
||||||
|
|
||||||
|
@ -192,15 +199,18 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
USBTRACE(" PID:"), D_PrintHex(pid, 0x80);
|
USBTRACE(" PID:"), D_PrintHex(pid, 0x80);
|
||||||
USBTRACE2(" #Conf:", num_of_conf);
|
USBTRACE2(" #Conf:", num_of_conf);
|
||||||
|
|
||||||
|
isMidiFound = false;
|
||||||
for (uint8_t i=0; i<num_of_conf; i++) {
|
for (uint8_t i=0; i<num_of_conf; i++) {
|
||||||
parseConfigDescr(bAddress, i);
|
rcode = parseConfigDescr(bAddress, i);
|
||||||
|
if( rcode )
|
||||||
|
goto FailGetConfDescr;
|
||||||
if (bNumEP > 1)
|
if (bNumEP > 1)
|
||||||
break;
|
break;
|
||||||
} // for
|
} // for
|
||||||
|
|
||||||
USBTRACE2("\r\nNumEP:", bNumEP);
|
USBTRACE2("\r\nNumEP:", bNumEP);
|
||||||
|
|
||||||
if( bNumEP < 3 ){ //Device not found.
|
if( bNumEP < 2 ){ //Device not found.
|
||||||
rcode = 0xff;
|
rcode = 0xff;
|
||||||
goto FailGetConfDescr;
|
goto FailGetConfDescr;
|
||||||
}
|
}
|
||||||
|
@ -214,7 +224,7 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign epInfo to epinfo pointer
|
// Assign epInfo to epinfo pointer
|
||||||
rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo);
|
rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo);
|
||||||
USBTRACE2("Conf:", bConfNum);
|
USBTRACE2("Conf:", bConfNum);
|
||||||
USBTRACE2("EPin :", (uint8_t)(epInfo[epDataInIndex].epAddr + 0x80));
|
USBTRACE2("EPin :", (uint8_t)(epInfo[epDataInIndex].epAddr + 0x80));
|
||||||
USBTRACE2("EPout:", epInfo[epDataOutIndex].epAddr);
|
USBTRACE2("EPout:", epInfo[epDataOutIndex].epAddr);
|
||||||
|
@ -236,7 +246,7 @@ FailSetConfDescr:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get and parse config descriptor */
|
/* get and parse config descriptor */
|
||||||
void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf )
|
uint8_t USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf )
|
||||||
{
|
{
|
||||||
uint8_t buf[ DESC_BUFF_SIZE ];
|
uint8_t buf[ DESC_BUFF_SIZE ];
|
||||||
uint8_t* buf_ptr = buf;
|
uint8_t* buf_ptr = buf;
|
||||||
|
@ -250,7 +260,7 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf )
|
||||||
// get configuration descriptor (get descriptor size only)
|
// get configuration descriptor (get descriptor size only)
|
||||||
rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf );
|
rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf );
|
||||||
if( rcode ){
|
if( rcode ){
|
||||||
return;
|
return rcode;
|
||||||
}
|
}
|
||||||
total_length = buf[2] | ((int)buf[3] << 8);
|
total_length = buf[2] | ((int)buf[3] << 8);
|
||||||
if( total_length > DESC_BUFF_SIZE ) { //check if total length is larger than buffer
|
if( total_length > DESC_BUFF_SIZE ) { //check if total length is larger than buffer
|
||||||
|
@ -260,7 +270,7 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf )
|
||||||
// get configuration descriptor (all)
|
// get configuration descriptor (all)
|
||||||
rcode = pUsb->getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
rcode = pUsb->getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor
|
||||||
if( rcode ){
|
if( rcode ){
|
||||||
return;
|
return rcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
//parsing descriptors
|
//parsing descriptors
|
||||||
|
@ -313,6 +323,7 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf )
|
||||||
}//switch( descr_type
|
}//switch( descr_type
|
||||||
buf_ptr += descr_length; //advance buffer pointer
|
buf_ptr += descr_length; //advance buffer pointer
|
||||||
}//while( buf_ptr <=...
|
}//while( buf_ptr <=...
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Performs a cleanup after failed Init() attempt */
|
/* Performs a cleanup after failed Init() attempt */
|
||||||
|
@ -340,12 +351,12 @@ uint8_t USBH_MIDI::RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Receive data from MIDI device */
|
/* Receive data from MIDI device */
|
||||||
uint8_t USBH_MIDI::RecvData(uint8_t *outBuf)
|
uint8_t USBH_MIDI::RecvData(uint8_t *outBuf, bool isRaw)
|
||||||
{
|
{
|
||||||
uint8_t rcode = 0; //return code
|
uint8_t rcode = 0; //return code
|
||||||
uint16_t rcvd;
|
uint16_t rcvd;
|
||||||
|
|
||||||
if( bPollEnable == false ) return false;
|
if( bPollEnable == false ) return 0;
|
||||||
|
|
||||||
//Checking unprocessed message in buffer.
|
//Checking unprocessed message in buffer.
|
||||||
if( readPtr != 0 && readPtr < MIDI_EVENT_PACKET_SIZE ){
|
if( readPtr != 0 && readPtr < MIDI_EVENT_PACKET_SIZE ){
|
||||||
|
@ -368,14 +379,22 @@ uint8_t USBH_MIDI::RecvData(uint8_t *outBuf)
|
||||||
}
|
}
|
||||||
|
|
||||||
RecvData_return_from_buffer:
|
RecvData_return_from_buffer:
|
||||||
|
uint8_t m;
|
||||||
|
uint8_t cin = recvBuf[readPtr];
|
||||||
|
if( isRaw == true ) {
|
||||||
|
*(outBuf++) = cin;
|
||||||
|
}
|
||||||
readPtr++;
|
readPtr++;
|
||||||
outBuf[0] = recvBuf[readPtr];
|
*(outBuf++) = m = recvBuf[readPtr++];
|
||||||
readPtr++;
|
*(outBuf++) = recvBuf[readPtr++];
|
||||||
outBuf[1] = recvBuf[readPtr];
|
*(outBuf++) = recvBuf[readPtr++];
|
||||||
readPtr++;
|
return lookupMsgSize(m, cin);
|
||||||
outBuf[2] = recvBuf[readPtr];
|
}
|
||||||
readPtr++;
|
|
||||||
return lookupMsgSize(outBuf[0]);
|
/* Receive raw data from MIDI device */
|
||||||
|
uint8_t USBH_MIDI::RecvRawData(uint8_t *outBuf)
|
||||||
|
{
|
||||||
|
return RecvData(outBuf, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send data to MIDI device */
|
/* Send data to MIDI device */
|
||||||
|
@ -443,10 +462,18 @@ void USBH_MIDI::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr )
|
||||||
/*Return */
|
/*Return */
|
||||||
/* 0 : undefined message */
|
/* 0 : undefined message */
|
||||||
/* 0<: Vaild message size(1-3) */
|
/* 0<: Vaild message size(1-3) */
|
||||||
uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg)
|
uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg, uint8_t cin)
|
||||||
{
|
{
|
||||||
uint8_t msgSize = 0;
|
uint8_t msgSize = 0;
|
||||||
|
|
||||||
|
//SysEx message?
|
||||||
|
cin = cin & 0x0f;
|
||||||
|
if( (cin & 0xc) == 4 ) {
|
||||||
|
if( cin == 4 || cin == 7 ) return 3;
|
||||||
|
if( cin == 6 ) return 2;
|
||||||
|
if( cin == 5 ) return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if( midiMsg < 0xf0 ) midiMsg &= 0xf0;
|
if( midiMsg < 0xf0 ) midiMsg &= 0xf0;
|
||||||
switch(midiMsg) {
|
switch(midiMsg) {
|
||||||
//3 bytes messages
|
//3 bytes messages
|
||||||
|
@ -500,8 +527,8 @@ uint16_t USBH_MIDI::countSysExDataSize(uint8_t *dataptr)
|
||||||
dataptr++;
|
dataptr++;
|
||||||
c++;
|
c++;
|
||||||
|
|
||||||
//Limiter (upto 256 bytes)
|
//Limiter (default: 256 bytes)
|
||||||
if(c > 256){
|
if(c > MIDI_MAX_SYSEX_SIZE){
|
||||||
c = 0;
|
c = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -512,13 +539,15 @@ uint16_t USBH_MIDI::countSysExDataSize(uint8_t *dataptr)
|
||||||
/* Send SysEx message to MIDI device */
|
/* Send SysEx message to MIDI device */
|
||||||
uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable)
|
uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable)
|
||||||
{
|
{
|
||||||
uint8_t buf[64];
|
uint8_t buf[MIDI_EVENT_PACKET_SIZE];
|
||||||
uint8_t rc;
|
uint8_t rc = 0;
|
||||||
uint16_t n = datasize;
|
uint16_t n = datasize;
|
||||||
uint16_t pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size
|
uint16_t pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size
|
||||||
uint8_t wptr = 0;
|
uint8_t wptr = 0;
|
||||||
uint8_t maxpkt = epInfo[epDataInIndex].maxPktSize;
|
uint8_t maxpkt = epInfo[epDataInIndex].maxPktSize;
|
||||||
|
|
||||||
|
if( maxpkt > MIDI_EVENT_PACKET_SIZE ) maxpkt = MIDI_EVENT_PACKET_SIZE;
|
||||||
|
|
||||||
USBTRACE("SendSysEx:\r\t");
|
USBTRACE("SendSysEx:\r\t");
|
||||||
USBTRACE2(" Length:\t", datasize);
|
USBTRACE2(" Length:\t", datasize);
|
||||||
USBTRACE2(" Total pktSize:\t", pktSize);
|
USBTRACE2(" Total pktSize:\t", pktSize);
|
||||||
|
@ -571,60 +600,33 @@ uint8_t USBH_MIDI::SendRawData(uint16_t bytes_send, uint8_t *dataptr)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
uint8_t USBH_MIDI::extractSysExData(uint8_t *p, uint8_t *buf)
|
||||||
// System Exclusive packet data management class
|
|
||||||
//
|
|
||||||
MidiSysEx::MidiSysEx()
|
|
||||||
{
|
{
|
||||||
clear();
|
uint8_t rc = 0;
|
||||||
}
|
|
||||||
|
|
||||||
void MidiSysEx::clear()
|
|
||||||
{
|
|
||||||
pos = 0;
|
|
||||||
buf[0] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MidiSysEx::Status MidiSysEx::set(uint8_t *p)
|
|
||||||
{
|
|
||||||
MidiSysEx::Status rc = MidiSysEx::ok;
|
|
||||||
uint8_t cin = *(p) & 0x0f;
|
uint8_t cin = *(p) & 0x0f;
|
||||||
|
|
||||||
//SysEx message?
|
//SysEx message?
|
||||||
if( (cin & 0xc) != 4 ) return MidiSysEx::nonsysex;
|
if( (cin & 0xc) != 4 ) return rc;
|
||||||
|
|
||||||
switch(cin) {
|
switch(cin) {
|
||||||
case 4:
|
case 4:
|
||||||
case 7:
|
case 7:
|
||||||
if( pos+2 < MIDI_EVENT_PACKET_SIZE ) {
|
*buf++ = *(p+1);
|
||||||
buf[pos++] = *(p+1);
|
*buf++ = *(p+2);
|
||||||
buf[pos++] = *(p+2);
|
*buf++ = *(p+3);
|
||||||
buf[pos++] = *(p+3);
|
rc = 3;
|
||||||
}else{
|
|
||||||
rc = MidiSysEx::overflow;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
if( pos+1 < MIDI_EVENT_PACKET_SIZE ) {
|
|
||||||
buf[pos++] = *(p+1);
|
|
||||||
buf[pos++] = *(p+2);
|
|
||||||
}else{
|
|
||||||
rc = MidiSysEx::overflow;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if( pos < MIDI_EVENT_PACKET_SIZE ) {
|
*buf++ = *(p+1);
|
||||||
buf[pos++] = *(p+1);
|
*buf++ = *(p+2);
|
||||||
}else{
|
rc = 2;
|
||||||
rc = MidiSysEx::overflow;
|
break;
|
||||||
}
|
case 5:
|
||||||
|
*buf++ = *(p+1);
|
||||||
|
rc = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//SysEx end?
|
|
||||||
if((cin & 0x3) != 0) {
|
|
||||||
rc = MidiSysEx::done;
|
|
||||||
}
|
|
||||||
return(rc);
|
return(rc);
|
||||||
}
|
}
|
||||||
|
|
34
usbh_midi.h
34
usbh_midi.h
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
* USB-MIDI class driver for USB Host Shield 2.0 Library
|
* USB-MIDI class driver for USB Host Shield 2.0 Library
|
||||||
* Copyright (c) 2012-2016 Yuuichi Akagawa
|
* Copyright (c) 2012-2017 Yuuichi Akagawa
|
||||||
*
|
*
|
||||||
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
* Idea from LPK25 USB-MIDI to Serial MIDI converter
|
||||||
* by Collin Cunningham - makezine.com, narbotic.com
|
* by Collin Cunningham - makezine.com, narbotic.com
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
#define USB_SUBCLASS_MIDISTREAMING 3
|
#define USB_SUBCLASS_MIDISTREAMING 3
|
||||||
#define DESC_BUFF_SIZE 256
|
#define DESC_BUFF_SIZE 256
|
||||||
#define MIDI_EVENT_PACKET_SIZE 64
|
#define MIDI_EVENT_PACKET_SIZE 64
|
||||||
|
#define MIDI_MAX_SYSEX_SIZE 256
|
||||||
class USBH_MIDI;
|
class USBH_MIDI;
|
||||||
|
|
||||||
class USBH_MIDI : public USBDeviceConfig
|
class USBH_MIDI : public USBDeviceConfig
|
||||||
|
@ -57,7 +58,7 @@ protected:
|
||||||
uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
|
uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
|
||||||
uint8_t readPtr;
|
uint8_t readPtr;
|
||||||
|
|
||||||
void parseConfigDescr(uint8_t addr, uint8_t conf);
|
uint8_t parseConfigDescr(uint8_t addr, uint8_t conf);
|
||||||
uint16_t countSysExDataSize(uint8_t *dataptr);
|
uint16_t countSysExDataSize(uint8_t *dataptr);
|
||||||
#ifdef DEBUG_USB_HOST
|
#ifdef DEBUG_USB_HOST
|
||||||
void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr );
|
void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr );
|
||||||
|
@ -67,10 +68,12 @@ public:
|
||||||
USBH_MIDI(USB *p);
|
USBH_MIDI(USB *p);
|
||||||
// Methods for recieving and sending data
|
// Methods for recieving and sending data
|
||||||
uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr);
|
uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr);
|
||||||
uint8_t RecvData(uint8_t *outBuf);
|
uint8_t RecvData(uint8_t *outBuf, bool isRaw=false);
|
||||||
|
uint8_t RecvRawData(uint8_t *outBuf);
|
||||||
uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0);
|
uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0);
|
||||||
uint8_t lookupMsgSize(uint8_t midiMsg);
|
uint8_t lookupMsgSize(uint8_t midiMsg, uint8_t cin=0);
|
||||||
uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0);
|
uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0);
|
||||||
|
uint8_t extractSysExData(uint8_t *p, uint8_t *buf);
|
||||||
uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr);
|
uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr);
|
||||||
// backward compatibility functions
|
// backward compatibility functions
|
||||||
inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); };
|
inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); };
|
||||||
|
@ -81,27 +84,4 @@ public:
|
||||||
virtual uint8_t Release();
|
virtual uint8_t Release();
|
||||||
virtual uint8_t GetAddress() { return bAddress; };
|
virtual uint8_t GetAddress() { return bAddress; };
|
||||||
};
|
};
|
||||||
|
|
||||||
//
|
|
||||||
// System Exclusive packet data management class
|
|
||||||
//
|
|
||||||
class MidiSysEx {
|
|
||||||
private:
|
|
||||||
uint8_t pos;
|
|
||||||
uint8_t buf[MIDI_EVENT_PACKET_SIZE];
|
|
||||||
public:
|
|
||||||
typedef enum {
|
|
||||||
nonsysex = 0,
|
|
||||||
ok = 1,
|
|
||||||
done = 0xfe,
|
|
||||||
overflow = 0xff
|
|
||||||
} Status;
|
|
||||||
|
|
||||||
MidiSysEx();
|
|
||||||
void clear();
|
|
||||||
MidiSysEx::Status set(uint8_t *p);
|
|
||||||
inline uint8_t *get(){return buf;};
|
|
||||||
inline uint8_t getSize(){return pos;};
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //_USBH_MIDI_H_
|
#endif //_USBH_MIDI_H_
|
||||||
|
|
Loading…
Reference in a new issue