Simple USBHost library for LPC4088. Backward compatibility of official-USBHost.

Dependencies:   FATFileSystem mbed-rtos

EA LPC4088 QSB専用の簡易USBホストライブラリです。
official-USBHostの下位互換で対応プログラムを僅かな修正で動かすことが出来ます。
examples:

Import programLPC4088-USBHostMSD_HelloWorld

Simple USBHost MSD(USB flash drive) for EA LPC4088 QSB test program

Import programLPC4088-BTstack_example

BTstack for EA LPC4088 QSB example program

Import programLPC4088-USBHostC270_example

Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program

Committer:
va009039
Date:
Fri Apr 25 05:18:55 2014 +0000
Revision:
0:148fca6fd246
first commit

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 "USBHostMouse.h"
va009039 0:148fca6fd246 18
va009039 0:148fca6fd246 19 #if USBHOST_MOUSE
va009039 0:148fca6fd246 20
va009039 0:148fca6fd246 21 USBHostMouse::USBHostMouse() {
va009039 0:148fca6fd246 22 host = USBHost::getHostInst();
va009039 0:148fca6fd246 23 init();
va009039 0:148fca6fd246 24 }
va009039 0:148fca6fd246 25
va009039 0:148fca6fd246 26 void USBHostMouse::init() {
va009039 0:148fca6fd246 27 dev = NULL;
va009039 0:148fca6fd246 28 int_in = NULL;
va009039 0:148fca6fd246 29 onUpdate = NULL;
va009039 0:148fca6fd246 30 onButtonUpdate = NULL;
va009039 0:148fca6fd246 31 onXUpdate = NULL;
va009039 0:148fca6fd246 32 onYUpdate = NULL;
va009039 0:148fca6fd246 33 onZUpdate = NULL;
va009039 0:148fca6fd246 34 report_id = 0;
va009039 0:148fca6fd246 35 dev_connected = false;
va009039 0:148fca6fd246 36 mouse_device_found = false;
va009039 0:148fca6fd246 37 mouse_intf = -1;
va009039 0:148fca6fd246 38
va009039 0:148fca6fd246 39 buttons = 0;
va009039 0:148fca6fd246 40 x = 0;
va009039 0:148fca6fd246 41 y = 0;
va009039 0:148fca6fd246 42 z = 0;
va009039 0:148fca6fd246 43 }
va009039 0:148fca6fd246 44
va009039 0:148fca6fd246 45 bool USBHostMouse::connected() {
va009039 0:148fca6fd246 46 return dev_connected;
va009039 0:148fca6fd246 47 }
va009039 0:148fca6fd246 48
va009039 0:148fca6fd246 49 bool USBHostMouse::connect() {
va009039 0:148fca6fd246 50
va009039 0:148fca6fd246 51 if (dev_connected) {
va009039 0:148fca6fd246 52 return true;
va009039 0:148fca6fd246 53 }
va009039 0:148fca6fd246 54
va009039 0:148fca6fd246 55 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
va009039 0:148fca6fd246 56 if ((dev = host->getDevice(i)) != NULL) {
va009039 0:148fca6fd246 57
va009039 0:148fca6fd246 58 if(host->enumerate(dev, this))
va009039 0:148fca6fd246 59 break;
va009039 0:148fca6fd246 60
va009039 0:148fca6fd246 61 if (mouse_device_found) {
va009039 0:148fca6fd246 62
va009039 0:148fca6fd246 63 int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
va009039 0:148fca6fd246 64 if (!int_in)
va009039 0:148fca6fd246 65 break;
va009039 0:148fca6fd246 66
va009039 0:148fca6fd246 67 USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
va009039 0:148fca6fd246 68 dev->setName("Mouse", mouse_intf);
va009039 0:148fca6fd246 69 host->registerDriver(dev, mouse_intf, this, &USBHostMouse::init);
va009039 0:148fca6fd246 70
va009039 0:148fca6fd246 71 int_in->attach(this, &USBHostMouse::rxHandler);
va009039 0:148fca6fd246 72 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
va009039 0:148fca6fd246 73
va009039 0:148fca6fd246 74 dev_connected = true;
va009039 0:148fca6fd246 75 return true;
va009039 0:148fca6fd246 76 }
va009039 0:148fca6fd246 77 }
va009039 0:148fca6fd246 78 }
va009039 0:148fca6fd246 79 init();
va009039 0:148fca6fd246 80 return false;
va009039 0:148fca6fd246 81 }
va009039 0:148fca6fd246 82
va009039 0:148fca6fd246 83 void USBHostMouse::rxHandler() {
va009039 0:148fca6fd246 84 int len_listen = int_in->getSize();
va009039 0:148fca6fd246 85
va009039 0:148fca6fd246 86 if (onUpdate) {
va009039 0:148fca6fd246 87 (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
va009039 0:148fca6fd246 88 }
va009039 0:148fca6fd246 89
va009039 0:148fca6fd246 90 if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
va009039 0:148fca6fd246 91 (*onButtonUpdate)(report[0] & 0x07);
va009039 0:148fca6fd246 92 }
va009039 0:148fca6fd246 93
va009039 0:148fca6fd246 94 if (onXUpdate && (x != report[1])) {
va009039 0:148fca6fd246 95 (*onXUpdate)(report[1]);
va009039 0:148fca6fd246 96 }
va009039 0:148fca6fd246 97
va009039 0:148fca6fd246 98 if (onYUpdate && (y != report[2])) {
va009039 0:148fca6fd246 99 (*onYUpdate)(report[2]);
va009039 0:148fca6fd246 100 }
va009039 0:148fca6fd246 101
va009039 0:148fca6fd246 102 if (onZUpdate && (z != report[3])) {
va009039 0:148fca6fd246 103 (*onZUpdate)(report[3]);
va009039 0:148fca6fd246 104 }
va009039 0:148fca6fd246 105
va009039 0:148fca6fd246 106 // update mouse state
va009039 0:148fca6fd246 107 buttons = report[0] & 0x07;
va009039 0:148fca6fd246 108 x = report[1];
va009039 0:148fca6fd246 109 y = report[2];
va009039 0:148fca6fd246 110 z = report[3];
va009039 0:148fca6fd246 111
va009039 0:148fca6fd246 112 if (dev)
va009039 0:148fca6fd246 113 host->interruptRead(dev, int_in, report, len_listen, false);
va009039 0:148fca6fd246 114 }
va009039 0:148fca6fd246 115
va009039 0:148fca6fd246 116 /*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
va009039 0:148fca6fd246 117 {
va009039 0:148fca6fd246 118 // we don't check VID/PID for mouse driver
va009039 0:148fca6fd246 119 }
va009039 0:148fca6fd246 120
va009039 0:148fca6fd246 121 /*virtual*/ bool USBHostMouse::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 122 {
va009039 0:148fca6fd246 123 if ((mouse_intf == -1) &&
va009039 0:148fca6fd246 124 (intf_class == HID_CLASS) &&
va009039 0:148fca6fd246 125 (intf_subclass == 0x01) &&
va009039 0:148fca6fd246 126 (intf_protocol == 0x02)) {
va009039 0:148fca6fd246 127 mouse_intf = intf_nb;
va009039 0:148fca6fd246 128 return true;
va009039 0:148fca6fd246 129 }
va009039 0:148fca6fd246 130 return false;
va009039 0:148fca6fd246 131 }
va009039 0:148fca6fd246 132
va009039 0:148fca6fd246 133 /*virtual*/ bool USBHostMouse::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used
va009039 0:148fca6fd246 134 {
va009039 0:148fca6fd246 135 if (intf_nb == mouse_intf) {
va009039 0:148fca6fd246 136 if (type == INTERRUPT_ENDPOINT && dir == IN) {
va009039 0:148fca6fd246 137 mouse_device_found = true;
va009039 0:148fca6fd246 138 return true;
va009039 0:148fca6fd246 139 }
va009039 0:148fca6fd246 140 }
va009039 0:148fca6fd246 141 return false;
va009039 0:148fca6fd246 142 }
va009039 0:148fca6fd246 143
va009039 0:148fca6fd246 144 #endif