Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h
Dependents: DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory
Fork of USBHOST by
Diff: USBHostHID/USBHostKeyboard.cpp
- Revision:
- 8:3e7a33f81048
- Parent:
- 5:fc157e6bd5a5
--- a/USBHostHID/USBHostKeyboard.cpp Mon Apr 30 05:37:24 2018 +0000 +++ b/USBHostHID/USBHostKeyboard.cpp Sat Jan 04 23:30:59 2020 +0000 @@ -19,71 +19,81 @@ #if USBHOST_KEYBOARD static uint8_t keymap[4][0x39] = { - { 0, 0, 0, 0, 'a', 'b' /*0x05*/, - 'c', 'd', 'e', 'f', 'g' /*0x0a*/, - 'h', 'i', 'j', 'k', 'l'/*0x0f*/, - 'm', 'n', 'o', 'p', 'q'/*0x14*/, - 'r', 's', 't', 'u', 'v'/*0x19*/, - 'w', 'x', 'y', 'z', '1'/*0x1E*/, - '2', '3', '4', '5', '6'/*0x23*/, - '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/ - 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/ - '=', '[', ']', '\\', '#', /*0x32*/ - ';', '\'', 0, ',', '.', /*0x37*/ - '/'}, + { + 0, 0, 0, 0, 'a', 'b' /*0x05*/, + 'c', 'd', 'e', 'f', 'g' /*0x0a*/, + 'h', 'i', 'j', 'k', 'l'/*0x0f*/, + 'm', 'n', 'o', 'p', 'q'/*0x14*/, + 'r', 's', 't', 'u', 'v'/*0x19*/, + 'w', 'x', 'y', 'z', '1'/*0x1E*/, + '2', '3', '4', '5', '6'/*0x23*/, + '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/ + 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/ + '=', '[', ']', '\\', '#', /*0x32*/ + ';', '\'', 0, ',', '.', /*0x37*/ + '/' + }, /* CTRL MODIFIER */ - { 0, 0, 0, 0, 0, 0 /*0x05*/, - 0, 0, 0, 0, 0 /*0x0a*/, - 0, 0, 0, 0, 0/*0x0f*/, - 0, 0, 0, 0, 0/*0x14*/, - 0, 0, 0, 0, 0/*0x19*/, - 0, 0, 0, 0, 0/*0x1E*/, - 0, 0, 0, 0, 0/*0x23*/, - 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ - 0, 0, 0, 0, 0, /*0x2d*/ - 0, 0, 0, 0, 0, /*0x32*/ - 0, 0, 0, 0, 0, /*0x37*/ - 0}, + { + 0, 0, 0, 0, 0, 0 /*0x05*/, + 0, 0, 0, 0, 0 /*0x0a*/, + 0, 0, 0, 0, 0/*0x0f*/, + 0, 0, 0, 0, 0/*0x14*/, + 0, 0, 0, 0, 0/*0x19*/, + 0, 0, 0, 0, 0/*0x1E*/, + 0, 0, 0, 0, 0/*0x23*/, + 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ + 0, 0, 0, 0, 0, /*0x2d*/ + 0, 0, 0, 0, 0, /*0x32*/ + 0, 0, 0, 0, 0, /*0x37*/ + 0 + }, /* SHIFT MODIFIER */ - { 0, 0, 0, 0, 'A', 'B' /*0x05*/, - 'C', 'D', 'E', 'F', 'G' /*0x0a*/, - 'H', 'I', 'J', 'K', 'L'/*0x0f*/, - 'M', 'N', 'O', 'P', 'Q'/*0x14*/, - 'R', 'S', 'T', 'U', 'V'/*0x19*/, - 'W', 'X', 'Y', 'Z', '!'/*0x1E*/, - '@', '#', '$', '%', '^'/*0x23*/, - '&', '*', '(', ')', 0, /*0x28*/ - 0, 0, 0, 0, 0, /*0x2d*/ - '+', '{', '}', '|', '~', /*0x32*/ - ':', '"', 0, '<', '>', /*0x37*/ - '?'}, + { + 0, 0, 0, 0, 'A', 'B' /*0x05*/, + 'C', 'D', 'E', 'F', 'G' /*0x0a*/, + 'H', 'I', 'J', 'K', 'L'/*0x0f*/, + 'M', 'N', 'O', 'P', 'Q'/*0x14*/, + 'R', 'S', 'T', 'U', 'V'/*0x19*/, + 'W', 'X', 'Y', 'Z', '!'/*0x1E*/, + '@', '#', '$', '%', '^'/*0x23*/, + '&', '*', '(', ')', 0, /*0x28*/ + 0, 0, 0, 0, 0, /*0x2d*/ + '+', '{', '}', '|', '~', /*0x32*/ + ':', '"', 0, '<', '>', /*0x37*/ + '?' + }, /* ALT MODIFIER */ - { 0, 0, 0, 0, 0, 0 /*0x05*/, - 0, 0, 0, 0, 0 /*0x0a*/, - 0, 0, 0, 0, 0/*0x0f*/, - 0, 0, 0, 0, 0/*0x14*/, - 0, 0, 0, 0, 0/*0x19*/, - 0, 0, 0, 0, 0/*0x1E*/, - 0, 0, 0, 0, 0/*0x23*/, - 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ - 0, 0, 0, 0, 0, /*0x2d*/ - 0, 0, 0, 0, 0, /*0x32*/ - 0, 0, 0, 0, 0, /*0x37*/ - 0} + { + 0, 0, 0, 0, 0, 0 /*0x05*/, + 0, 0, 0, 0, 0 /*0x0a*/, + 0, 0, 0, 0, 0/*0x0f*/, + 0, 0, 0, 0, 0/*0x14*/, + 0, 0, 0, 0, 0/*0x19*/, + 0, 0, 0, 0, 0/*0x1E*/, + 0, 0, 0, 0, 0/*0x23*/, + 0, 0, 0, 0, 0 /*enter*/, /*0x28*/ + 0, 0, 0, 0, 0, /*0x2d*/ + 0, 0, 0, 0, 0, /*0x32*/ + 0, 0, 0, 0, 0, /*0x37*/ + 0 + } }; -USBHostKeyboard::USBHostKeyboard() { +USBHostKeyboard::USBHostKeyboard() +{ host = USBHost::getHostInst(); init(); } -void USBHostKeyboard::init() { +void USBHostKeyboard::init() +{ dev = NULL; int_in = NULL; report_id = 0; @@ -94,7 +104,8 @@ keyboard_device_found = false; } -bool USBHostKeyboard::connected() { +bool USBHostKeyboard::connected() +{ return dev_connected; } @@ -109,8 +120,9 @@ for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) { if ((dev = host->getDevice(i)) != NULL) { - if (host->enumerate(dev, this)) + if (host->enumerate(dev, this)) { break; + } if (keyboard_device_found) { { @@ -121,8 +133,9 @@ int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN); - if (!int_in) + if (!int_in) { break; + } 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); @@ -141,7 +154,8 @@ return false; } -void USBHostKeyboard::rxHandler() { +void USBHostKeyboard::rxHandler() +{ int len = int_in->getLengthTransferred(); int index = (len == 9) ? 1 : 0; int len_listen = int_in->getSize(); @@ -157,8 +171,9 @@ (*onKeyCode)(report[index + 2], modifier); } } - if (dev && int_in) + if (dev && int_in) { host->interruptRead(dev, int_in, report, len_listen, false); + } } /*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid) @@ -169,9 +184,9 @@ /*virtual*/ bool USBHostKeyboard::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed { if ((keyboard_intf == -1) && - (intf_class == HID_CLASS) && - (intf_subclass == 0x01) && - (intf_protocol == 0x01)) { + (intf_class == HID_CLASS) && + (intf_subclass == 0x01) && + (intf_protocol == 0x01)) { keyboard_intf = intf_nb; return true; }