Simple USBHost WebCam for EA LPC4088 QSB/LPC1768 test program

Dependencies:   LPC4088-USBHost mbed

EA LPC4088 QSB/LPC1768をUSBホストにしてWebカメラからJPEG画像を読み取るテストプログラムです。

The usage is the same as KL46Z-USBHostC270_example.
使い方はKL46Z-USBHostC270_exampleと同じです。
動作確認: Logitech C270,Logitech Q200R(Qcam Orbit AF)
/media/uploads/va009039/lpc4088-c270-480x360.jpg

Committer:
va009039
Date:
Thu Apr 24 05:38:45 2014 +0000
Revision:
0:c972ee42b455
first commit,sync rev.29.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:c972ee42b455 1 /* mbed USBHost Library
va009039 0:c972ee42b455 2 * Copyright (c) 2006-2013 ARM Limited
va009039 0:c972ee42b455 3 *
va009039 0:c972ee42b455 4 * Licensed under the Apache License, Version 2.0 (the "License");
va009039 0:c972ee42b455 5 * you may not use this file except in compliance with the License.
va009039 0:c972ee42b455 6 * You may obtain a copy of the License at
va009039 0:c972ee42b455 7 *
va009039 0:c972ee42b455 8 * http://www.apache.org/licenses/LICENSE-2.0
va009039 0:c972ee42b455 9 *
va009039 0:c972ee42b455 10 * Unless required by applicable law or agreed to in writing, software
va009039 0:c972ee42b455 11 * distributed under the License is distributed on an "AS IS" BASIS,
va009039 0:c972ee42b455 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
va009039 0:c972ee42b455 13 * See the License for the specific language governing permissions and
va009039 0:c972ee42b455 14 * limitations under the License.
va009039 0:c972ee42b455 15 */
va009039 0:c972ee42b455 16
va009039 0:c972ee42b455 17 #include "USBHostMouse.h"
va009039 0:c972ee42b455 18
va009039 0:c972ee42b455 19 #if USBHOST_MOUSE
va009039 0:c972ee42b455 20
va009039 0:c972ee42b455 21 USBHostMouse::USBHostMouse() {
va009039 0:c972ee42b455 22 host = USBHost::getHostInst();
va009039 0:c972ee42b455 23 init();
va009039 0:c972ee42b455 24 }
va009039 0:c972ee42b455 25
va009039 0:c972ee42b455 26 void USBHostMouse::init() {
va009039 0:c972ee42b455 27 dev = NULL;
va009039 0:c972ee42b455 28 int_in = NULL;
va009039 0:c972ee42b455 29 onUpdate = NULL;
va009039 0:c972ee42b455 30 onButtonUpdate = NULL;
va009039 0:c972ee42b455 31 onXUpdate = NULL;
va009039 0:c972ee42b455 32 onYUpdate = NULL;
va009039 0:c972ee42b455 33 onZUpdate = NULL;
va009039 0:c972ee42b455 34 report_id = 0;
va009039 0:c972ee42b455 35 dev_connected = false;
va009039 0:c972ee42b455 36 mouse_device_found = false;
va009039 0:c972ee42b455 37 mouse_intf = -1;
va009039 0:c972ee42b455 38
va009039 0:c972ee42b455 39 buttons = 0;
va009039 0:c972ee42b455 40 x = 0;
va009039 0:c972ee42b455 41 y = 0;
va009039 0:c972ee42b455 42 z = 0;
va009039 0:c972ee42b455 43 }
va009039 0:c972ee42b455 44
va009039 0:c972ee42b455 45 bool USBHostMouse::connected() {
va009039 0:c972ee42b455 46 return dev_connected;
va009039 0:c972ee42b455 47 }
va009039 0:c972ee42b455 48
va009039 0:c972ee42b455 49 bool USBHostMouse::connect() {
va009039 0:c972ee42b455 50
va009039 0:c972ee42b455 51 if (dev_connected) {
va009039 0:c972ee42b455 52 return true;
va009039 0:c972ee42b455 53 }
va009039 0:c972ee42b455 54
va009039 0:c972ee42b455 55 for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) {
va009039 0:c972ee42b455 56 if ((dev = host->getDevice(i)) != NULL) {
va009039 0:c972ee42b455 57
va009039 0:c972ee42b455 58 if(host->enumerate(dev, this))
va009039 0:c972ee42b455 59 break;
va009039 0:c972ee42b455 60
va009039 0:c972ee42b455 61 if (mouse_device_found) {
va009039 0:c972ee42b455 62
va009039 0:c972ee42b455 63 int_in = dev->getEndpoint(mouse_intf, INTERRUPT_ENDPOINT, IN);
va009039 0:c972ee42b455 64 if (!int_in)
va009039 0:c972ee42b455 65 break;
va009039 0:c972ee42b455 66
va009039 0:c972ee42b455 67 USB_INFO("New Mouse device: VID:%04x PID:%04x [dev: %p - intf: %d]", dev->getVid(), dev->getPid(), dev, mouse_intf);
va009039 0:c972ee42b455 68 dev->setName("Mouse", mouse_intf);
va009039 0:c972ee42b455 69 host->registerDriver(dev, mouse_intf, this, &USBHostMouse::init);
va009039 0:c972ee42b455 70
va009039 0:c972ee42b455 71 int_in->attach(this, &USBHostMouse::rxHandler);
va009039 0:c972ee42b455 72 host->interruptRead(dev, int_in, report, int_in->getSize(), false);
va009039 0:c972ee42b455 73
va009039 0:c972ee42b455 74 dev_connected = true;
va009039 0:c972ee42b455 75 return true;
va009039 0:c972ee42b455 76 }
va009039 0:c972ee42b455 77 }
va009039 0:c972ee42b455 78 }
va009039 0:c972ee42b455 79 init();
va009039 0:c972ee42b455 80 return false;
va009039 0:c972ee42b455 81 }
va009039 0:c972ee42b455 82
va009039 0:c972ee42b455 83 void USBHostMouse::rxHandler() {
va009039 0:c972ee42b455 84 int len_listen = int_in->getSize();
va009039 0:c972ee42b455 85
va009039 0:c972ee42b455 86 if (onUpdate) {
va009039 0:c972ee42b455 87 (*onUpdate)(report[0] & 0x07, report[1], report[2], report[3]);
va009039 0:c972ee42b455 88 }
va009039 0:c972ee42b455 89
va009039 0:c972ee42b455 90 if (onButtonUpdate && (buttons != (report[0] & 0x07))) {
va009039 0:c972ee42b455 91 (*onButtonUpdate)(report[0] & 0x07);
va009039 0:c972ee42b455 92 }
va009039 0:c972ee42b455 93
va009039 0:c972ee42b455 94 if (onXUpdate && (x != report[1])) {
va009039 0:c972ee42b455 95 (*onXUpdate)(report[1]);
va009039 0:c972ee42b455 96 }
va009039 0:c972ee42b455 97
va009039 0:c972ee42b455 98 if (onYUpdate && (y != report[2])) {
va009039 0:c972ee42b455 99 (*onYUpdate)(report[2]);
va009039 0:c972ee42b455 100 }
va009039 0:c972ee42b455 101
va009039 0:c972ee42b455 102 if (onZUpdate && (z != report[3])) {
va009039 0:c972ee42b455 103 (*onZUpdate)(report[3]);
va009039 0:c972ee42b455 104 }
va009039 0:c972ee42b455 105
va009039 0:c972ee42b455 106 // update mouse state
va009039 0:c972ee42b455 107 buttons = report[0] & 0x07;
va009039 0:c972ee42b455 108 x = report[1];
va009039 0:c972ee42b455 109 y = report[2];
va009039 0:c972ee42b455 110 z = report[3];
va009039 0:c972ee42b455 111
va009039 0:c972ee42b455 112 if (dev)
va009039 0:c972ee42b455 113 host->interruptRead(dev, int_in, report, len_listen, false);
va009039 0:c972ee42b455 114 }
va009039 0:c972ee42b455 115
va009039 0:c972ee42b455 116 /*virtual*/ void USBHostMouse::setVidPid(uint16_t vid, uint16_t pid)
va009039 0:c972ee42b455 117 {
va009039 0:c972ee42b455 118 // we don't check VID/PID for mouse driver
va009039 0:c972ee42b455 119 }
va009039 0:c972ee42b455 120
va009039 0:c972ee42b455 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:c972ee42b455 122 {
va009039 0:c972ee42b455 123 if ((mouse_intf == -1) &&
va009039 0:c972ee42b455 124 (intf_class == HID_CLASS) &&
va009039 0:c972ee42b455 125 (intf_subclass == 0x01) &&
va009039 0:c972ee42b455 126 (intf_protocol == 0x02)) {
va009039 0:c972ee42b455 127 mouse_intf = intf_nb;
va009039 0:c972ee42b455 128 return true;
va009039 0:c972ee42b455 129 }
va009039 0:c972ee42b455 130 return false;
va009039 0:c972ee42b455 131 }
va009039 0:c972ee42b455 132
va009039 0:c972ee42b455 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:c972ee42b455 134 {
va009039 0:c972ee42b455 135 if (intf_nb == mouse_intf) {
va009039 0:c972ee42b455 136 if (type == INTERRUPT_ENDPOINT && dir == IN) {
va009039 0:c972ee42b455 137 mouse_device_found = true;
va009039 0:c972ee42b455 138 return true;
va009039 0:c972ee42b455 139 }
va009039 0:c972ee42b455 140 }
va009039 0:c972ee42b455 141 return false;
va009039 0:c972ee42b455 142 }
va009039 0:c972ee42b455 143
va009039 0:c972ee42b455 144 #endif