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:
frq08711@LMECWL0871.LME.ST.COM
Date:
Wed Apr 26 18:11:37 2017 +0200
Revision:
5:fc157e6bd5a5
Parent:
1:ab240722d7ef
Child:
8:3e7a33f81048
update for hub support

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] = {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 22 { 0, 0, 0, 0, 'a', 'b' /*0x05*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 23 'c', 'd', 'e', 'f', 'g' /*0x0a*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 24 'h', 'i', 'j', 'k', 'l'/*0x0f*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 25 'm', 'n', 'o', 'p', 'q'/*0x14*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 26 'r', 's', 't', 'u', 'v'/*0x19*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 27 'w', 'x', 'y', 'z', '1'/*0x1E*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 28 '2', '3', '4', '5', '6'/*0x23*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 29 '7', '8', '9', '0', 0x0A /*enter*/, /*0x28*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 30 0x1B /*escape*/, 0x08 /*backspace*/, 0x09/*tab*/, 0x20/*space*/, '-', /*0x2d*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 31 '=', '[', ']', '\\', '#', /*0x32*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 32 ';', '\'', 0, ',', '.', /*0x37*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 33 '/'},
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 34
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 35 /* CTRL MODIFIER */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 36 { 0, 0, 0, 0, 0, 0 /*0x05*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 37 0, 0, 0, 0, 0 /*0x0a*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 38 0, 0, 0, 0, 0/*0x0f*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 39 0, 0, 0, 0, 0/*0x14*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 40 0, 0, 0, 0, 0/*0x19*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 41 0, 0, 0, 0, 0/*0x1E*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 42 0, 0, 0, 0, 0/*0x23*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 43 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 44 0, 0, 0, 0, 0, /*0x2d*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 45 0, 0, 0, 0, 0, /*0x32*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 46 0, 0, 0, 0, 0, /*0x37*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 47 0},
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 48
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 49 /* SHIFT MODIFIER */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 50 { 0, 0, 0, 0, 'A', 'B' /*0x05*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 51 'C', 'D', 'E', 'F', 'G' /*0x0a*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 52 'H', 'I', 'J', 'K', 'L'/*0x0f*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 53 'M', 'N', 'O', 'P', 'Q'/*0x14*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 54 'R', 'S', 'T', 'U', 'V'/*0x19*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 55 'W', 'X', 'Y', 'Z', '!'/*0x1E*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 56 '@', '#', '$', '%', '^'/*0x23*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 57 '&', '*', '(', ')', 0, /*0x28*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 58 0, 0, 0, 0, 0, /*0x2d*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 59 '+', '{', '}', '|', '~', /*0x32*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 60 ':', '"', 0, '<', '>', /*0x37*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 61 '?'},
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 62
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 63 /* ALT MODIFIER */
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 64 { 0, 0, 0, 0, 0, 0 /*0x05*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 65 0, 0, 0, 0, 0 /*0x0a*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 66 0, 0, 0, 0, 0/*0x0f*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 67 0, 0, 0, 0, 0/*0x14*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 68 0, 0, 0, 0, 0/*0x19*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 69 0, 0, 0, 0, 0/*0x1E*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 70 0, 0, 0, 0, 0/*0x23*/,
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 71 0, 0, 0, 0, 0 /*enter*/, /*0x28*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 72 0, 0, 0, 0, 0, /*0x2d*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 73 0, 0, 0, 0, 0, /*0x32*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 74 0, 0, 0, 0, 0, /*0x37*/
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 75 0}
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 76
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 77 };
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 78
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 79
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 80 USBHostKeyboard::USBHostKeyboard() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 81 host = USBHost::getHostInst();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 82 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 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 void USBHostKeyboard::init() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 87 dev = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 88 int_in = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 89 report_id = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 90 onKey = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 91 onKeyCode = NULL;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 92 dev_connected = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 93 keyboard_intf = -1;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 94 keyboard_device_found = false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 95 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 96
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 97 bool USBHostKeyboard::connected() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 98 return dev_connected;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 99 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 100
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 101
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 102 bool USBHostKeyboard::connect()
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 103 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 104
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 105 if (dev_connected) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 106 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 107 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 108
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 109 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 110 if ((dev = host->getDevice(i)) != NULL) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 111
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 112 if (host->enumerate(dev, this))
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 113 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 114
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 115 if (keyboard_device_found) {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 116 {
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 117 /* As this is done in a specific thread
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 118 * this lock is taken to avoid to process the device
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 119 * disconnect in usb process during the device registering */
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 120 USBHost::Lock Lock(host);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 121
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 122 int_in = dev->getEndpoint(keyboard_intf, INTERRUPT_ENDPOINT, IN);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 123
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 124 if (!int_in)
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 125 break;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 126
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 127 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 128 dev->setName("Keyboard", keyboard_intf);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 129 host->registerDriver(dev, keyboard_intf, this, &USBHostKeyboard::init);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 130
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 131 int_in->attach(this, &USBHostKeyboard::rxHandler);
frq08711@LMECWL0871.LME.ST.COM 5:fc157e6bd5a5 132 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 133 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 134
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 135 dev_connected = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 136 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 137 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 138 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 139 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 140 init();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 141 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 142 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 143
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 144 void USBHostKeyboard::rxHandler() {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 145 int len = int_in->getLengthTransferred();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 146 int index = (len == 9) ? 1 : 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 147 int len_listen = int_in->getSize();
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 148 uint8_t key = 0;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 149 if (len == 8 || len == 9) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 150 uint8_t modifier = (report[index] == 4) ? 3 : report[index];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 151 len_listen = len;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 152 key = keymap[modifier][report[index + 2]];
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 153 if (key && onKey) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 154 (*onKey)(key);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 155 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 156 if ((report[index + 2] || modifier) && onKeyCode) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 157 (*onKeyCode)(report[index + 2], modifier);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 158 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 159 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 160 if (dev && int_in)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 161 host->interruptRead(dev, int_in, report, len_listen, false);
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 162 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 163
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 164 /*virtual*/ void USBHostKeyboard::setVidPid(uint16_t vid, uint16_t pid)
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 165 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 166 // we don't check VID/PID for keyboard driver
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 167 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 168
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 169 /*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 170 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 171 if ((keyboard_intf == -1) &&
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 172 (intf_class == HID_CLASS) &&
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 173 (intf_subclass == 0x01) &&
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 174 (intf_protocol == 0x01)) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 175 keyboard_intf = intf_nb;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 176 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 177 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 178 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 179 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 180
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 181 /*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 182 {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 183 if (intf_nb == keyboard_intf) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 184 if (type == INTERRUPT_ENDPOINT && dir == IN) {
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 185 keyboard_device_found = true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 186 return true;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 187 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 188 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 189 return false;
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 190 }
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 191
frq08711@LMECWL0871.LME.ST.COM 1:ab240722d7ef 192 #endif