Fork to update libraries and fix disk_read/disk_write functions

Dependencies:   FATFileSystem mbed-rtos

Dependents:   lpc4088_qsb_usbhost

Fork of LPC4088-USBHost by Norimasa Okamoto

Committer:
embeddedartists
Date:
Fri Apr 24 06:11:09 2015 +0000
Revision:
1:5402b105b911
Parent:
0:148fca6fd246
Updated libraries and had to fix the parameters to disk_read/disk_write

Who changed what in which revision?

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