From 3aca1f36f5d453967fb86f9f6198b5e25df8a315 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Thu, 21 Apr 2022 21:53:19 +0900 Subject: [PATCH] Update MIDI driver v1.0.0 --- usbh_midi.cpp | 12 +++++++++--- usbh_midi.h | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/usbh_midi.cpp b/usbh_midi.cpp index e9f3d871..84887eb6 100644 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -258,10 +258,11 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) if (rcode) goto FailSetConfDescr; + bPollEnable = true; + if(pFuncOnInit) pFuncOnInit(); // Call the user function - bPollEnable = true; USBTRACE("Init done.\r\n"); return 0; FailGetDevDescr: @@ -275,10 +276,14 @@ FailSetConfDescr: /* Performs a cleanup after failed Init() attempt */ uint8_t USBH_MIDI::Release() { + if(pFuncOnRelease && bPollEnable) + pFuncOnRelease(); // Call the user function + pUsb->GetAddressPool().FreeAddress(bAddress); bAddress = 0; bPollEnable = false; readPtr = 0; + return 0; } @@ -296,8 +301,9 @@ void USBH_MIDI::setupDeviceSpecific() return; } - // LaunchKey: 0x30-32, 0x35:Mini, 0x7B-0x7D:MK2 - if( ( 0x30 <= pid && pid <= 0x32) || pid == 0x35 || ( 0x7B <= pid && pid <= 0x7D) ) { + // LaunchKey: 0x30-32, 0x35:Mini, 0x7B-0x7D:MK2, 0x0102,0x113-0x122:MiniMk3, 0x134-0x137:MK3 + if( (0x30 <= pid && pid <= 0x32) || pid == 0x35 || (0x7B <= pid && pid <= 0x7D) + || pid == 0x102 || (0x113 <= pid && pid <= 0x122) || (0x134 <= pid && pid <= 0x137) ) { bTransferTypeMask = 2; return; } diff --git a/usbh_midi.h b/usbh_midi.h index c6784d05..f6a937cb 100644 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -28,7 +28,7 @@ #define _USBH_MIDI_H_ #include "Usb.h" -#define USBH_MIDI_VERSION 601 +#define USBH_MIDI_VERSION 10000 #define MIDI_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN(MIDI), bulk_OUT(MIDI) #define USB_SUBCLASS_MIDISTREAMING 3 #define MIDI_EVENT_PACKET_SIZE 64 @@ -137,8 +137,13 @@ public: void attachOnInit(void (*funcOnInit)(void)) { pFuncOnInit = funcOnInit; }; + + void attachOnRelease(void (*funcOnRelease)(void)) { + pFuncOnRelease = funcOnRelease; + }; private: void (*pFuncOnInit)(void) = nullptr; // Pointer to function called in onInit() + void (*pFuncOnRelease)(void) = nullptr; // Pointer to function called in onRelease() }; #endif //_USBH_MIDI_H_