Usb read

Dependencies:   FATFileSystem

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Tue Jun 10 13:38:41 2014 +0900
Revision:
13:8774c07f12a5
add USBHostC270

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 13:8774c07f12a5 1 /* mbed USBHost Library
va009039 13:8774c07f12a5 2 * Copyright (c) 2006-2013 ARM Limited
va009039 13:8774c07f12a5 3 *
va009039 13:8774c07f12a5 4 * Licensed under the Apache License, Version 2.0 (the "License");
va009039 13:8774c07f12a5 5 * you may not use this file except in compliance with the License.
va009039 13:8774c07f12a5 6 * You may obtain a copy of the License at
va009039 13:8774c07f12a5 7 *
va009039 13:8774c07f12a5 8 * http://www.apache.org/licenses/LICENSE-2.0
va009039 13:8774c07f12a5 9 *
va009039 13:8774c07f12a5 10 * Unless required by applicable law or agreed to in writing, software
va009039 13:8774c07f12a5 11 * distributed under the License is distributed on an "AS IS" BASIS,
va009039 13:8774c07f12a5 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
va009039 13:8774c07f12a5 13 * See the License for the specific language governing permissions and
va009039 13:8774c07f12a5 14 * limitations under the License.
va009039 13:8774c07f12a5 15 */
va009039 13:8774c07f12a5 16
va009039 13:8774c07f12a5 17 #ifndef USBHOSTMOUSE_H
va009039 13:8774c07f12a5 18 #define USBHOSTMOUSE_H
va009039 13:8774c07f12a5 19
va009039 13:8774c07f12a5 20 #include "USBHostConf.h"
va009039 13:8774c07f12a5 21
va009039 13:8774c07f12a5 22 #if USBHOST_MOUSE
va009039 13:8774c07f12a5 23
va009039 13:8774c07f12a5 24 #include "USBHost.h"
va009039 13:8774c07f12a5 25
va009039 13:8774c07f12a5 26 /**
va009039 13:8774c07f12a5 27 * A class to communicate a USB mouse
va009039 13:8774c07f12a5 28 */
va009039 13:8774c07f12a5 29 class USBHostMouse : public IUSBEnumerator {
va009039 13:8774c07f12a5 30 public:
va009039 13:8774c07f12a5 31
va009039 13:8774c07f12a5 32 /**
va009039 13:8774c07f12a5 33 * Constructor
va009039 13:8774c07f12a5 34 */
va009039 13:8774c07f12a5 35 USBHostMouse();
va009039 13:8774c07f12a5 36
va009039 13:8774c07f12a5 37 /**
va009039 13:8774c07f12a5 38 * Try to connect a mouse device
va009039 13:8774c07f12a5 39 *
va009039 13:8774c07f12a5 40 * @return true if connection was successful
va009039 13:8774c07f12a5 41 */
va009039 13:8774c07f12a5 42 bool connect();
va009039 13:8774c07f12a5 43
va009039 13:8774c07f12a5 44 /**
va009039 13:8774c07f12a5 45 * Check if a mouse is connected
va009039 13:8774c07f12a5 46 *
va009039 13:8774c07f12a5 47 * @returns true if a mouse is connected
va009039 13:8774c07f12a5 48 */
va009039 13:8774c07f12a5 49 bool connected();
va009039 13:8774c07f12a5 50
va009039 13:8774c07f12a5 51 /**
va009039 13:8774c07f12a5 52 * Attach a callback called when a mouse event is received
va009039 13:8774c07f12a5 53 *
va009039 13:8774c07f12a5 54 * @param ptr function pointer
va009039 13:8774c07f12a5 55 */
va009039 13:8774c07f12a5 56 inline void attachEvent(void (*ptr)(uint8_t buttons, int8_t x, int8_t y, int8_t z)) {
va009039 13:8774c07f12a5 57 if (ptr != NULL) {
va009039 13:8774c07f12a5 58 onUpdate = ptr;
va009039 13:8774c07f12a5 59 }
va009039 13:8774c07f12a5 60 }
va009039 13:8774c07f12a5 61
va009039 13:8774c07f12a5 62 /**
va009039 13:8774c07f12a5 63 * Attach a callback called when the button state changes
va009039 13:8774c07f12a5 64 *
va009039 13:8774c07f12a5 65 * @param ptr function pointer
va009039 13:8774c07f12a5 66 */
va009039 13:8774c07f12a5 67 inline void attachButtonEvent(void (*ptr)(uint8_t buttons)) {
va009039 13:8774c07f12a5 68 if (ptr != NULL) {
va009039 13:8774c07f12a5 69 onButtonUpdate = ptr;
va009039 13:8774c07f12a5 70 }
va009039 13:8774c07f12a5 71 }
va009039 13:8774c07f12a5 72
va009039 13:8774c07f12a5 73 /**
va009039 13:8774c07f12a5 74 * Attach a callback called when the X axis value changes
va009039 13:8774c07f12a5 75 *
va009039 13:8774c07f12a5 76 * @param ptr function pointer
va009039 13:8774c07f12a5 77 */
va009039 13:8774c07f12a5 78 inline void attachXEvent(void (*ptr)(int8_t x)) {
va009039 13:8774c07f12a5 79 if (ptr != NULL) {
va009039 13:8774c07f12a5 80 onXUpdate = ptr;
va009039 13:8774c07f12a5 81 }
va009039 13:8774c07f12a5 82 }
va009039 13:8774c07f12a5 83
va009039 13:8774c07f12a5 84 /**
va009039 13:8774c07f12a5 85 * Attach a callback called when the Y axis value changes
va009039 13:8774c07f12a5 86 *
va009039 13:8774c07f12a5 87 * @param ptr function pointer
va009039 13:8774c07f12a5 88 */
va009039 13:8774c07f12a5 89 inline void attachYEvent(void (*ptr)(int8_t y)) {
va009039 13:8774c07f12a5 90 if (ptr != NULL) {
va009039 13:8774c07f12a5 91 onYUpdate = ptr;
va009039 13:8774c07f12a5 92 }
va009039 13:8774c07f12a5 93 }
va009039 13:8774c07f12a5 94
va009039 13:8774c07f12a5 95 /**
va009039 13:8774c07f12a5 96 * Attach a callback called when the Z axis value changes (scrolling)
va009039 13:8774c07f12a5 97 *
va009039 13:8774c07f12a5 98 * @param ptr function pointer
va009039 13:8774c07f12a5 99 */
va009039 13:8774c07f12a5 100 inline void attachZEvent(void (*ptr)(int8_t z)) {
va009039 13:8774c07f12a5 101 if (ptr != NULL) {
va009039 13:8774c07f12a5 102 onZUpdate = ptr;
va009039 13:8774c07f12a5 103 }
va009039 13:8774c07f12a5 104 }
va009039 13:8774c07f12a5 105
va009039 13:8774c07f12a5 106 protected:
va009039 13:8774c07f12a5 107 //From IUSBEnumerator
va009039 13:8774c07f12a5 108 virtual void setVidPid(uint16_t vid, uint16_t pid);
va009039 13:8774c07f12a5 109 virtual bool 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 13:8774c07f12a5 110 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
va009039 13:8774c07f12a5 111
va009039 13:8774c07f12a5 112 private:
va009039 13:8774c07f12a5 113 USBHost * host;
va009039 13:8774c07f12a5 114 USBDeviceConnected * dev;
va009039 13:8774c07f12a5 115 USBEndpoint * int_in;
va009039 13:8774c07f12a5 116 uint8_t report[4];
va009039 13:8774c07f12a5 117
va009039 13:8774c07f12a5 118 bool dev_connected;
va009039 13:8774c07f12a5 119 bool mouse_device_found;
va009039 13:8774c07f12a5 120 int mouse_intf;
va009039 13:8774c07f12a5 121
va009039 13:8774c07f12a5 122 uint8_t buttons;
va009039 13:8774c07f12a5 123 int8_t x;
va009039 13:8774c07f12a5 124 int8_t y;
va009039 13:8774c07f12a5 125 int8_t z;
va009039 13:8774c07f12a5 126
va009039 13:8774c07f12a5 127 void rxHandler();
va009039 13:8774c07f12a5 128 void (*onUpdate)(uint8_t buttons, int8_t x, int8_t y, int8_t z);
va009039 13:8774c07f12a5 129 void (*onButtonUpdate)(uint8_t buttons);
va009039 13:8774c07f12a5 130 void (*onXUpdate)(int8_t x);
va009039 13:8774c07f12a5 131 void (*onYUpdate)(int8_t y);
va009039 13:8774c07f12a5 132 void (*onZUpdate)(int8_t z);
va009039 13:8774c07f12a5 133 int report_id;
va009039 13:8774c07f12a5 134 void init();
va009039 13:8774c07f12a5 135 };
va009039 13:8774c07f12a5 136
va009039 13:8774c07f12a5 137 #endif
va009039 13:8774c07f12a5 138
va009039 13:8774c07f12a5 139 #endif