USBHOST lib for STM

Dependents:   Nucleo_usbhost door-access-controller-dev

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Wed Feb 15 10:49:44 2017 +0100
Revision:
1:ab240722d7ef
update to mbed 5.3.5

Who changed what in which revision?

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