Skip to content

Commit

Permalink
stm32/usb: rework checking if usb connection is active
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Feb 17, 2021
1 parent e185173 commit d67bcd9
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/board/stm32/usb/midi/USB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ namespace
USBD_HandleTypeDef hUsbDeviceFS;
volatile bool TxDone;
volatile uint8_t rxBuffer[RX_BUFFER_SIZE_USB];
volatile bool initialized;

//rxBuffer is overriden every time RxCallback is called
//save results in ring buffer and remove them as needed in readMIDI
Expand All @@ -51,16 +50,14 @@ namespace
USBD_LL_OpenEP(pdev, MIDI_STREAM_IN_EPADDR, USB_EP_TYPE_BULK, TX_BUFFER_SIZE_USB);
USBD_LL_OpenEP(pdev, MIDI_STREAM_OUT_EPADDR, USB_EP_TYPE_BULK, RX_BUFFER_SIZE_USB);
USBD_LL_PrepareReceive(pdev, MIDI_STREAM_OUT_EPADDR, (uint8_t*)(rxBuffer), RX_BUFFER_SIZE_USB);
TxDone = true;
initialized = true;
TxDone = true;
return 0;
}

uint8_t deInitCallback(USBD_HandleTypeDef* pdev, uint8_t cfgidx)
{
USBD_LL_CloseEP(pdev, MIDI_STREAM_IN_EPADDR);
USBD_LL_CloseEP(pdev, MIDI_STREAM_OUT_EPADDR);
initialized = false;
return 0;
}

Expand Down Expand Up @@ -187,7 +184,7 @@ namespace Board
{
bool isUSBconnected()
{
return initialized;
return (hUsbDeviceFS.dev_state == USBD_STATE_CONFIGURED);
}

bool readMIDI(MIDI::USBMIDIpacket_t& USBMIDIpacket)
Expand Down Expand Up @@ -218,7 +215,7 @@ namespace Board

bool writeMIDI(MIDI::USBMIDIpacket_t& USBMIDIpacket)
{
if (!initialized)
if (!isUSBconnected())
return false;

while (!TxDone)
Expand Down

0 comments on commit d67bcd9

Please sign in to comment.