diff --git a/Makefile b/Makefile index 94220c3..dc64347 100644 --- a/Makefile +++ b/Makefile @@ -137,6 +137,7 @@ SRC = main.c \ $(USBD_COMPOSITE)/App/usbd_cdc_acm_if.c \ $(USBD_COMPOSITE)/App/usbd_desc.c \ $(USBD_COMPOSITE)/App/usbd_msc_if.c \ + $(USBD_COMPOSITE)/App/usbd_midi_if.c \ $(wildcard $(USBD_COMPOSITE)/Class/CDC_ACM/Src/*.c) \ $(wildcard $(USBD_COMPOSITE)/Class/COMPOSITE/Src/*.c) \ $(wildcard $(USBD_COMPOSITE)/Class/MSC/Src/*.c) \ diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.c b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.c index 4fbad93..78ad3f9 100644 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.c +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.c @@ -34,7 +34,7 @@ static int8_t MIDI_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length){ static int8_t MIDI_Receive(uint8_t *pbuf, uint32_t *Len){ Caw_printf("midi receive\n\r"); - uint32_t len = *Len; + // uint32_t len = *Len; // handle len worth of bytes in pbuf // just print to Caw for now @@ -50,22 +50,22 @@ static int8_t MIDI_TransmitCplt(uint8_t *Buf, uint32_t *Len, uint8_t epnum){ -uint8_t USBD_MIDI_GetDeviceState(USBD_HandleTypeDef *pdev){ - return pdev->dev_state; +uint8_t USBD_MIDI_GetDeviceState(void){ + return hUsbDevice.dev_state; } -uint8_t USBD_MIDI_GetState(USBD_HandleTypeDef *pdev){ - USBD_MIDI_HandleTypeDef *hmidi = (USBD_MIDI_HandleTypeDef*)pdev->pClassData_MIDI; +uint8_t USBD_MIDI_GetState(void){ + USBD_MIDI_HandleTypeDef *hmidi = hUsbDevice.pClassData_MIDI; return hmidi->state; } -uint8_t USBD_MIDI_SendReport(USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len){ - USBD_MIDI_HandleTypeDef *hmidi = (USBD_MIDI_HandleTypeDef*)pdev->pClassData_MIDI; +uint8_t USBD_MIDI_SendReport(uint8_t *report, uint16_t len){ + USBD_MIDI_HandleTypeDef *hmidi = hUsbDevice.pClassData_MIDI; - if (pdev->dev_state == USBD_STATE_CONFIGURED){ + if (hUsbDevice.dev_state == USBD_STATE_CONFIGURED){ if(hmidi->state == MIDI_IDLE){ hmidi->state = MIDI_BUSY; - USBD_LL_Transmit (pdev, MIDI_EPIN_ADDR, report, len); + USBD_LL_Transmit (&hUsbDevice, MIDI_IN_EP, report, len); } } return USBD_OK; diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.h b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.h index e67ede1..93eaa8e 100644 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.h +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/App/usbd_midi_if.h @@ -4,6 +4,6 @@ extern USBD_MIDI_ItfTypeDef USBD_MIDI_fops; -uint8_t USBD_MIDI_GetDeviceState(USBD_HandleTypeDef *pdev); -uint8_t USBD_MIDI_GetState(USBD_HandleTypeDef *pdev); -uint8_t USBD_MIDI_SendReport (USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len); +uint8_t USBD_MIDI_GetDeviceState(void); +uint8_t USBD_MIDI_GetState(void); +uint8_t USBD_MIDI_SendReport(uint8_t *report, uint16_t len); diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Src/usbd_composite.c b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Src/usbd_composite.c index 8f908ab..f0792c7 100755 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Src/usbd_composite.c +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/COMPOSITE/Src/usbd_composite.c @@ -471,7 +471,7 @@ static uint8_t USBD_COMPOSITE_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum) } #endif #if (USBD_USE_MIDI == 1) - if (epnum == (MIDI_EPIN_ADDR & 0x7F)) + if (epnum == (MIDI_IN_EP & 0x7F)) { USBD_MIDI.DataIn(pdev, epnum); } @@ -762,7 +762,7 @@ static uint8_t USBD_COMPOSITE_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum) } #endif #if (USBD_USE_MIDI == 1) - if (epnum == MIDI_EPOUT_ADDR) + if (epnum == MIDI_OUT_EP) { USBD_MIDI.DataOut(pdev, epnum); } diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Inc/usbd_midi.h b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Inc/usbd_midi.h index a954bb0..4a24bc5 100644 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Inc/usbd_midi.h +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Inc/usbd_midi.h @@ -8,10 +8,10 @@ #define MIDI_IN_PORTS_NUM 0x01 #define MIDI_OUT_PORTS_NUM 0x01 -#define MIDI_EPIN_ADDR 0x81 +// #define MIDI_EPIN_ADDR 0x81 #define MIDI_EPIN_SIZE 0x40 -#define MIDI_EPOUT_ADDR 0x01 +// #define MIDI_EPOUT_ADDR 0x01 #define MIDI_EPOUT_SIZE 0x40 #define USB_MIDI_CLASS_DESC_SHIFT 18 diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Src/usbd_midi.c b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Src/usbd_midi.c index 770e187..be5a2d7 100644 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Src/usbd_midi.c +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Class/MIDI/Src/usbd_midi.c @@ -525,19 +525,19 @@ static uint8_t USBD_MIDI_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx){ pdev->pClassData_MIDI = (void*)hmidi; USBD_LL_OpenEP(pdev, - MIDI_EPIN_ADDR, + MIDI_IN_EP, USBD_EP_TYPE_INTR, MIDI_EPIN_SIZE); - pdev->ep_out[MIDI_EPIN_ADDR & 0xFU].is_used = 1U; + pdev->ep_out[MIDI_IN_EP & 0xFU].is_used = 1U; USBD_LL_OpenEP(pdev, - MIDI_EPOUT_ADDR, + MIDI_OUT_EP, USBD_EP_TYPE_INTR, MIDI_EPOUT_SIZE); - pdev->ep_in[MIDI_EPOUT_ADDR & 0xFU].is_used = 1U; + pdev->ep_in[MIDI_OUT_EP & 0xFU].is_used = 1U; USBD_LL_PrepareReceive(pdev, - MIDI_EPOUT_ADDR, + MIDI_OUT_EP, hmidi->RxBuffer, MIDI_EPOUT_SIZE); return ret; @@ -546,11 +546,11 @@ static uint8_t USBD_MIDI_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx){ static uint8_t USBD_MIDI_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx){ /* Close MIDI EPs */ // USBD_LL_CloseEP(pdev, MIDI_EPIN_SIZE); - USBD_LL_CloseEP(pdev, MIDI_EPIN_ADDR); - pdev->ep_in[MIDI_EPIN_ADDR & 0xFU].is_used = 0U; + USBD_LL_CloseEP(pdev, MIDI_IN_EP); + pdev->ep_in[MIDI_IN_EP & 0xFU].is_used = 0U; - USBD_LL_CloseEP(pdev, MIDI_EPOUT_ADDR); - pdev->ep_in[MIDI_EPOUT_ADDR & 0xFU].is_used = 0U; + USBD_LL_CloseEP(pdev, MIDI_OUT_EP); + pdev->ep_in[MIDI_OUT_EP & 0xFU].is_used = 0U; /* FRee allocated memory */ if(pdev->pClassData_MIDI != NULL){ @@ -630,7 +630,7 @@ static uint8_t USBD_MIDI_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum){ } static uint8_t USBD_MIDI_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum){ - if (epnum != (MIDI_EPOUT_ADDR & 0x0F)) return USBD_FAIL; + if (epnum != (MIDI_OUT_EP & 0x0F)) return USBD_FAIL; USBD_MIDI_HandleTypeDef *hmidi = (USBD_MIDI_HandleTypeDef*)pdev->pClassData_MIDI; hmidi->RxLength = USBD_LL_GetRxDataSize(pdev, epnum); @@ -638,7 +638,7 @@ static uint8_t USBD_MIDI_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum){ ((USBD_MIDI_ItfTypeDef*)pdev->pUserData_MIDI)->Receive(hmidi->RxBuffer, &hmidi->RxLength); USBD_LL_PrepareReceive(pdev, - MIDI_EPOUT_ADDR, + MIDI_OUT_EP, hmidi->RxBuffer, MIDI_EPOUT_SIZE); diff --git a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target/usbd_conf.c b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target/usbd_conf.c index 35b6421..322a31b 100755 --- a/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target/usbd_conf.c +++ b/Middlewares/Third_Party/AL94_USB_Composite/COMPOSITE/Target/usbd_conf.c @@ -489,7 +489,7 @@ USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev) HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (PRNT_IN_EP & 0x7F), 128); #endif #if (USBD_USE_MIDI == 1) - HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MIDI_EPIN_ADDR & 0x7F), 128); + HAL_PCDEx_SetTxFiFoInBytes(hpcd_USB_OTG_PTR, (MIDI_IN_EP & 0x7F), 128); #endif #if (USBD_USE_CDC_ACM == 1) for (uint8_t i = 0; i < USBD_CDC_ACM_COUNT; i++) diff --git a/crow.dfu b/crow.dfu index 711d373..c6252df 100644 Binary files a/crow.dfu and b/crow.dfu differ diff --git a/main.c b/main.c index c634406..c467163 100755 --- a/main.c +++ b/main.c @@ -25,6 +25,7 @@ // new USB composite device setup #include "lib/usb_otg.h" #include "usb_device.h" +#include "usbd_midi_if.h" #include "lib/midi.h" // #include "lib/mhost.h" @@ -130,6 +131,27 @@ int main(void) char* crow_msg = "print('hi')\n\r"; USBHost_Send((unsigned char*)crow_msg, strlen(crow_msg)); // Caw_printf("hi\n\r"); + + // the midiparser lib probably wraps this + // 144 60 127 - turn ON note #60 on MIDI channel 1 with a velocity of 127 + uint8_t cable = 0; + uint8_t code = 0x9; // note-on message (see usb-midi pdf doc) + uint8_t message = 0x9; // note-on + uint8_t channel = 0; + uint8_t note = 60; + uint8_t velocity = 127; + + uint8_t reportBuffer[4] = { + // cable - represents physical/virtual port number (0 - 15) of the device + // code - in general cases is equal to midi message + (cable << 4) | code, + (message << 4) | channel, + note, + velocity, + }; + // while (USBD_MIDI_GetState() != MIDI_IDLE) {}; + USBD_MIDI_SendReport(reportBuffer, 4); + Caw_printf(".\n\r"); } U_PrintNow();