Support Isochronous transfer additionally

Dependents:   USBHostC270_example_GR-PEACH USBHostDac_example USBHostDac_Audio_in_out

Fork of USBHost_custom by Renesas

Committer:
mbed_official
Date:
Mon Sep 16 15:36:24 2013 +0100
Revision:
13:b58a2204422f
Parent:
8:93da8ea2708b
Child:
24:868cbfe611a7
Synchronized with git revision 061259c07c5cd9172d2dbfabf1f0edc51604f316

Who changed what in which revision?

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