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 ST

Committer:
kenjiArai
Date:
Sat Jan 04 23:30:59 2020 +0000
Revision:
8:3e7a33f81048
Parent:
5:fc157e6bd5a5
updated for STM32F4xx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 1 /* mbed USBHost Library
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 2 * Copyright (c) 2006-2013 ARM Limited
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 3 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 4 * Licensed under the Apache License, Version 2.0 (the "License");
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 5 * you may not use this file except in compliance with the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 6 * You may obtain a copy of the License at
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 7 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 8 * http://www.apache.org/licenses/LICENSE-2.0
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 9 *
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 10 * Unless required by applicable law or agreed to in writing, software
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 11 * distributed under the License is distributed on an "AS IS" BASIS,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 13 * See the License for the specific language governing permissions and
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 14 * limitations under the License.
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 15 */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 16
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 17 #include "USBHostKeyboard.h"
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 18
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 19 #if USBHOST_KEYBOARD
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 20
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 21 static uint8_t keymap[4][0x39] = {
kenjiArai 8:3e7a33f81048 22 {
kenjiArai 8:3e7a33f81048 23 0, 0, 0, 0, 'a', 'b' /*0x05*/,
kenjiArai 8:3e7a33f81048 24 'c', 'd', 'e', 'f', 'g' /*0x0a*/,
kenjiArai 8:3e7a33f81048 25 'h', 'i', 'j', 'k', 'l'/*0x0f*/,
kenjiArai 8:3e7a33f81048 26 'm', 'n', 'o', 'p', 'q'/*0x14*/,
kenjiArai 8:3e7a33f81048 27 'r', 's', 't', 'u', 'v'/*0x19*/,
kenjiArai 8:3e7a33f81048 28 'w', 'x', 'y', 'z', '1'/*0x1E*/,
kenjiArai 8:3e7a33f81048 29 '2', '3', '4', '5', '6'/*0x23*/,
kenjiArai 8:3e7a33f81048 30 '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/
kenjiArai 8:3e7a33f81048 31 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/
kenjiArai 8:3e7a33f81048 32 '=', '[', ']', '\\', '#', /*0x32*/
kenjiArai 8:3e7a33f81048 33 ';', '\'', 0, ',', '.', /*0x37*/
kenjiArai 8:3e7a33f81048 34 '/'
kenjiArai 8:3e7a33f81048 35 },
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 /* CTRL MODIFIER */
kenjiArai 8:3e7a33f81048 38 {
kenjiArai 8:3e7a33f81048 39 0, 0, 0, 0, 0, 0 /*0x05*/,
kenjiArai 8:3e7a33f81048 40 0, 0, 0, 0, 0 /*0x0a*/,
kenjiArai 8:3e7a33f81048 41 0, 0, 0, 0, 0/*0x0f*/,
kenjiArai 8:3e7a33f81048 42 0, 0, 0, 0, 0/*0x14*/,
kenjiArai 8:3e7a33f81048 43 0, 0, 0, 0, 0/*0x19*/,
kenjiArai 8:3e7a33f81048 44 0, 0, 0, 0, 0/*0x1E*/,
kenjiArai 8:3e7a33f81048 45 0, 0, 0, 0, 0/*0x23*/,
kenjiArai 8:3e7a33f81048 46 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
kenjiArai 8:3e7a33f81048 47 0, 0, 0, 0, 0, /*0x2d*/
kenjiArai 8:3e7a33f81048 48 0, 0, 0, 0, 0, /*0x32*/
kenjiArai 8:3e7a33f81048 49 0, 0, 0, 0, 0, /*0x37*/
kenjiArai 8:3e7a33f81048 50 0
kenjiArai 8:3e7a33f81048 51 },
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 52
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 53 /* SHIFT MODIFIER */
kenjiArai 8:3e7a33f81048 54 {
kenjiArai 8:3e7a33f81048 55 0, 0, 0, 0, 'A', 'B' /*0x05*/,
kenjiArai 8:3e7a33f81048 56 'C', 'D', 'E', 'F', 'G' /*0x0a*/,
kenjiArai 8:3e7a33f81048 57 'H', 'I', 'J', 'K', 'L'/*0x0f*/,
kenjiArai 8:3e7a33f81048 58 'M', 'N', 'O', 'P', 'Q'/*0x14*/,
kenjiArai 8:3e7a33f81048 59 'R', 'S', 'T', 'U', 'V'/*0x19*/,
kenjiArai 8:3e7a33f81048 60 'W', 'X', 'Y', 'Z', '!'/*0x1E*/,
kenjiArai 8:3e7a33f81048 61 '@', '#', '$', '%', '^'/*0x23*/,
kenjiArai 8:3e7a33f81048 62 '&', '*', '(', ')', 0, /*0x28*/
kenjiArai 8:3e7a33f81048 63 0, 0, 0, 0, 0, /*0x2d*/
kenjiArai 8:3e7a33f81048 64 '+', '{', '}', '|', '~', /*0x32*/
kenjiArai 8:3e7a33f81048 65 ':', '"', 0, '<', '>', /*0x37*/
kenjiArai 8:3e7a33f81048 66 '?'
kenjiArai 8:3e7a33f81048 67 },
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 68
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 69 /* ALT MODIFIER */
kenjiArai 8:3e7a33f81048 70 {
kenjiArai 8:3e7a33f81048 71 0, 0, 0, 0, 0, 0 /*0x05*/,
kenjiArai 8:3e7a33f81048 72 0, 0, 0, 0, 0 /*0x0a*/,
kenjiArai 8:3e7a33f81048 73 0, 0, 0, 0, 0/*0x0f*/,
kenjiArai 8:3e7a33f81048 74 0, 0, 0, 0, 0/*0x14*/,
kenjiArai 8:3e7a33f81048 75 0, 0, 0, 0, 0/*0x19*/,
kenjiArai 8:3e7a33f81048 76 0, 0, 0, 0, 0/*0x1E*/,
kenjiArai 8:3e7a33f81048 77 0, 0, 0, 0, 0/*0x23*/,
kenjiArai 8:3e7a33f81048 78 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
kenjiArai 8:3e7a33f81048 79 0, 0, 0, 0, 0, /*0x2d*/
kenjiArai 8:3e7a33f81048 80 0, 0, 0, 0, 0, /*0x32*/
kenjiArai 8:3e7a33f81048 81 0, 0, 0, 0, 0, /*0x37*/
kenjiArai 8:3e7a33f81048 82 0
kenjiArai 8:3e7a33f81048 83 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 84
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 85 };
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 86
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 87
kenjiArai 8:3e7a33f81048 88 USBHostKeyboard::USBHostKeyboard()
kenjiArai 8:3e7a33f81048 89 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 90 host = USBHost::getHostInst();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 91 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 92 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 93
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 94
kenjiArai 8:3e7a33f81048 95 void USBHostKeyboard::init()
kenjiArai 8:3e7a33f81048 96 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 97 dev = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 98 int_in = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 99 report_id = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 100 onKey = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 101 onKeyCode = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 102 dev_connected = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 103 keyboard_intf = -1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 104 keyboard_device_found = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 105 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 106
kenjiArai 8:3e7a33f81048 107 bool USBHostKeyboard::connected()
kenjiArai 8:3e7a33f81048 108 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 109 return dev_connected;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 110 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 111
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 112
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 113 bool USBHostKeyboard::connect()
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 114 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 115
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 116 if (dev_connected) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 117 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 118 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 119
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 120 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 121 if ((dev = host->getDevice(i)) != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 122
kenjiArai 8:3e7a33f81048 123 if (host->enumerate(dev, this)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 124 break;
kenjiArai 8:3e7a33f81048 125 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 126
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 127 if (keyboard_device_found) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 128 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 129 /* As this is done in a specific thread
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 130 * this lock is taken to avoid to process the device
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 131 * disconnect in usb process during the device registering */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 132 USBHost::Lock Lock(host);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 133
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 134 int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 135
kenjiArai 8:3e7a33f81048 136 if (!int_in) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 137 break;
kenjiArai 8:3e7a33f81048 138 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 139
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 140 USB_INFO("New Keyboard device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, keyboard_intf);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 141 dev->setName("Keyboard", keyboard_intf);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 142 host->registerDriver(dev, keyboard_intf, this, &USBHostKeyboard::init);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 143
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 144 int_in->attach(this, &USBHostKeyboard::rxHandler);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 145 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 146 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 147
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 148 dev_connected = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 149 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 150 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 151 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 152 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 153 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 154 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 155 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 156
kenjiArai 8:3e7a33f81048 157 void USBHostKeyboard::rxHandler()
kenjiArai 8:3e7a33f81048 158 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 159 int len = int_in->getLengthTransferred();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 160 int index = (len == 9) ? 1 : 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 161 int len_listen = int_in->getSize();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 162 uint8_t key = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 163 if (len == 8 || len == 9) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 164 uint8_t modifier = (report[index] == 4) ? 3 : report[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 165 len_listen = len;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 166 key = keymap[modifier][report[index + 2]];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 167 if (key && onKey) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 168 (*onKey)(key);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 169 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 170 if ((report[index + 2] || modifier) && onKeyCode) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 171 (*onKeyCode)(report[index + 2], modifier);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 172 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 173 }
kenjiArai 8:3e7a33f81048 174 if (dev && int_in) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 175 host->interruptRead(dev, int_in, report, len_listen, false);
kenjiArai 8:3e7a33f81048 176 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 177 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 178
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 179 /*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 180 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 181 // we don't check VID/PID for keyboard driver
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 182 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 183
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 184 /*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
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 185 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 186 if ((keyboard_intf == -1) &&
kenjiArai 8:3e7a33f81048 187 (intf_class == HID_CLASS) &&
kenjiArai 8:3e7a33f81048 188 (intf_subclass == 0x01) &&
kenjiArai 8:3e7a33f81048 189 (intf_protocol == 0x01)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 190 keyboard_intf = intf_nb;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 191 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 192 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 193 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 194 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 195
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 196 /*virtual*/ bool USBHostKeyboard::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 197 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 198 if (intf_nb == keyboard_intf) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 199 if (type == INTERRUPT_ENDPOINT && dir == IN) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 200 keyboard_device_found = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 201 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 202 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 203 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 204 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 205 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 206
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 207 #endif