forked for unsupported target
Dependents: stm32-disco-example DISCO-F469NI_BD_SD_Card_Control
Fork of USBHOST by
Diff: USBHostHID/USBHostKeyboard.cpp
- Revision:
- 5:fc157e6bd5a5
- Parent:
- 1:ab240722d7ef
diff -r 1c76b46ad779 -r fc157e6bd5a5 USBHostHID/USBHostKeyboard.cpp --- a/USBHostHID/USBHostKeyboard.cpp Fri Feb 17 12:40:57 2017 +0100 +++ b/USBHostHID/USBHostKeyboard.cpp Wed Apr 26 18:11:37 2017 +0200 @@ -99,7 +99,8 @@ } -bool USBHostKeyboard::connect() { +bool USBHostKeyboard::connect() +{ if (dev_connected) { return true; @@ -112,16 +113,23 @@ break; if (keyboard_device_found) { - int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN); + { + /* As this is done in a specific thread + * this lock is taken to avoid to process the device + * disconnect in usb process during the device registering */ + USBHost::Lock Lock(host); - if (!int_in) - break; + int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN); - USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf); - dev->setName("Keyboard", keyboard_intf); - host->registerDriver(dev, keyboard_intf, this, &USBHostKeyboard::init); + if (!int_in) + break; - int_in->attach(this, &USBHostKeyboard::rxHandler); + USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf); + dev->setName("Keyboard", keyboard_intf); + host->registerDriver(dev, keyboard_intf, this, &USBHostKeyboard::init); + + int_in->attach(this, &USBHostKeyboard::rxHandler); + } host->interruptRead(dev, int_in, report, int_in->getSize(), false); dev_connected = true;