USBHost library with fixes

Dependencies:   mbed-rtos FATFileSystem

Dependents:   mbedica

Committer:
zrussell3
Date:
Thu Dec 13 19:24:21 2018 +0000
Revision:
0:b176d95bb38f
Modified USBHost library to fix modifier input

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zrussell3 0:b176d95bb38f 1 /* mbed USBHost Library
zrussell3 0:b176d95bb38f 2 * Copyright (c) 2006-2013 ARM Limited
zrussell3 0:b176d95bb38f 3 *
zrussell3 0:b176d95bb38f 4 * Licensed under the Apache License, Version 2.0 (the "License");
zrussell3 0:b176d95bb38f 5 * you may not use this file except in compliance with the License.
zrussell3 0:b176d95bb38f 6 * You may obtain a copy of the License at
zrussell3 0:b176d95bb38f 7 *
zrussell3 0:b176d95bb38f 8 * http://www.apache.org/licenses/LICENSE-2.0
zrussell3 0:b176d95bb38f 9 *
zrussell3 0:b176d95bb38f 10 * Unless required by applicable law or agreed to in writing, software
zrussell3 0:b176d95bb38f 11 * distributed under the License is distributed on an "AS IS" BASIS,
zrussell3 0:b176d95bb38f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
zrussell3 0:b176d95bb38f 13 * See the License for the specific language governing permissions and
zrussell3 0:b176d95bb38f 14 * limitations under the License.
zrussell3 0:b176d95bb38f 15 */
zrussell3 0:b176d95bb38f 16
zrussell3 0:b176d95bb38f 17 #ifndef USBHOSTHUB_H
zrussell3 0:b176d95bb38f 18 #define USBHOSTHUB_H
zrussell3 0:b176d95bb38f 19
zrussell3 0:b176d95bb38f 20 #include "USBHostConf.h"
zrussell3 0:b176d95bb38f 21
zrussell3 0:b176d95bb38f 22 #if MAX_HUB_NB
zrussell3 0:b176d95bb38f 23
zrussell3 0:b176d95bb38f 24 #include "USBHostTypes.h"
zrussell3 0:b176d95bb38f 25 #include "IUSBEnumerator.h"
zrussell3 0:b176d95bb38f 26
zrussell3 0:b176d95bb38f 27 class USBHost;
zrussell3 0:b176d95bb38f 28 class USBDeviceConnected;
zrussell3 0:b176d95bb38f 29 class USBEndpoint;
zrussell3 0:b176d95bb38f 30
zrussell3 0:b176d95bb38f 31 /**
zrussell3 0:b176d95bb38f 32 * A class to use a USB Hub
zrussell3 0:b176d95bb38f 33 */
zrussell3 0:b176d95bb38f 34 class USBHostHub : public IUSBEnumerator {
zrussell3 0:b176d95bb38f 35 public:
zrussell3 0:b176d95bb38f 36 /**
zrussell3 0:b176d95bb38f 37 * Constructor
zrussell3 0:b176d95bb38f 38 */
zrussell3 0:b176d95bb38f 39 USBHostHub();
zrussell3 0:b176d95bb38f 40
zrussell3 0:b176d95bb38f 41 /**
zrussell3 0:b176d95bb38f 42 * Check if a USB Hub is connected
zrussell3 0:b176d95bb38f 43 *
zrussell3 0:b176d95bb38f 44 * @return true if a serial device is connected
zrussell3 0:b176d95bb38f 45 */
zrussell3 0:b176d95bb38f 46 bool connected();
zrussell3 0:b176d95bb38f 47
zrussell3 0:b176d95bb38f 48 /**
zrussell3 0:b176d95bb38f 49 * Try to connect device
zrussell3 0:b176d95bb38f 50 *
zrussell3 0:b176d95bb38f 51 * @param dev device to connect
zrussell3 0:b176d95bb38f 52 * @return true if connection was successful
zrussell3 0:b176d95bb38f 53 */
zrussell3 0:b176d95bb38f 54 bool connect(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 55
zrussell3 0:b176d95bb38f 56 /**
zrussell3 0:b176d95bb38f 57 * Automatically called by USBHost when a device
zrussell3 0:b176d95bb38f 58 * has been enumerated by usb_thread
zrussell3 0:b176d95bb38f 59 *
zrussell3 0:b176d95bb38f 60 * @param dev device connected
zrussell3 0:b176d95bb38f 61 */
zrussell3 0:b176d95bb38f 62 void deviceConnected(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 63
zrussell3 0:b176d95bb38f 64 /**
zrussell3 0:b176d95bb38f 65 * Automatically called by USBHost when a device
zrussell3 0:b176d95bb38f 66 * has been disconnected from this hub
zrussell3 0:b176d95bb38f 67 *
zrussell3 0:b176d95bb38f 68 * @param dev device disconnected
zrussell3 0:b176d95bb38f 69 */
zrussell3 0:b176d95bb38f 70 void deviceDisconnected(USBDeviceConnected * dev);
zrussell3 0:b176d95bb38f 71
zrussell3 0:b176d95bb38f 72 /**
zrussell3 0:b176d95bb38f 73 * Rest a specific port
zrussell3 0:b176d95bb38f 74 *
zrussell3 0:b176d95bb38f 75 * @param port port number
zrussell3 0:b176d95bb38f 76 */
zrussell3 0:b176d95bb38f 77 void portReset(uint8_t port);
zrussell3 0:b176d95bb38f 78
zrussell3 0:b176d95bb38f 79 /*
zrussell3 0:b176d95bb38f 80 * Called by USBHost to set the instance of USBHost
zrussell3 0:b176d95bb38f 81 *
zrussell3 0:b176d95bb38f 82 * @param host host instance
zrussell3 0:b176d95bb38f 83 */
zrussell3 0:b176d95bb38f 84 void setHost(USBHost * host);
zrussell3 0:b176d95bb38f 85
zrussell3 0:b176d95bb38f 86 /**
zrussell3 0:b176d95bb38f 87 * Called by USBhost when a hub has been disconnected
zrussell3 0:b176d95bb38f 88 */
zrussell3 0:b176d95bb38f 89 void hubDisconnected();
zrussell3 0:b176d95bb38f 90
zrussell3 0:b176d95bb38f 91 protected:
zrussell3 0:b176d95bb38f 92 //From IUSBEnumerator
zrussell3 0:b176d95bb38f 93 virtual void setVidPid(uint16_t vid, uint16_t pid);
zrussell3 0:b176d95bb38f 94 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
zrussell3 0:b176d95bb38f 95 virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used
zrussell3 0:b176d95bb38f 96
zrussell3 0:b176d95bb38f 97 private:
zrussell3 0:b176d95bb38f 98 USBHost * host;
zrussell3 0:b176d95bb38f 99 USBDeviceConnected * dev;
zrussell3 0:b176d95bb38f 100 bool dev_connected;
zrussell3 0:b176d95bb38f 101 USBEndpoint * int_in;
zrussell3 0:b176d95bb38f 102 uint8_t nb_port;
zrussell3 0:b176d95bb38f 103 uint8_t hub_characteristics;
zrussell3 0:b176d95bb38f 104
zrussell3 0:b176d95bb38f 105 void rxHandler();
zrussell3 0:b176d95bb38f 106
zrussell3 0:b176d95bb38f 107 uint8_t buf[sizeof(HubDescriptor)];
zrussell3 0:b176d95bb38f 108
zrussell3 0:b176d95bb38f 109 int hub_intf;
zrussell3 0:b176d95bb38f 110 bool hub_device_found;
zrussell3 0:b176d95bb38f 111
zrussell3 0:b176d95bb38f 112 void setPortFeature(uint32_t feature, uint8_t port);
zrussell3 0:b176d95bb38f 113 void clearPortFeature(uint32_t feature, uint8_t port);
zrussell3 0:b176d95bb38f 114 uint32_t getPortStatus(uint8_t port);
zrussell3 0:b176d95bb38f 115
zrussell3 0:b176d95bb38f 116 USBDeviceConnected * device_children[MAX_HUB_PORT];
zrussell3 0:b176d95bb38f 117
zrussell3 0:b176d95bb38f 118 void init();
zrussell3 0:b176d95bb38f 119 void disconnect();
zrussell3 0:b176d95bb38f 120
zrussell3 0:b176d95bb38f 121 };
zrussell3 0:b176d95bb38f 122
zrussell3 0:b176d95bb38f 123 #endif
zrussell3 0:b176d95bb38f 124
zrussell3 0:b176d95bb38f 125 #endif