2018.07.26

Dependencies:   FATFileSystem2 mbed-rtos

Fork of USBHost by mbed official

Committer:
sayzyas
Date:
Thu Jul 26 00:29:30 2018 +0000
Revision:
44:e437b1c7c61e
Parent:
43:78f328f311dc
2018.07.26

Who changed what in which revision?

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