Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FATFileSystem mbed-rtos
Fork of USBHost by
USBHostHub/USBHostHub.h@0:a554658735bf, 2013-03-06 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Mar 06 16:27:14 2013 +0000
- Revision:
- 0:a554658735bf
- Child:
- 3:0f5c32575eb8
first commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| mbed_official | 0:a554658735bf | 1 | /* Copyright (c) 2010-2012 mbed.org, MIT License | 
| mbed_official | 0:a554658735bf | 2 | * | 
| mbed_official | 0:a554658735bf | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software | 
| mbed_official | 0:a554658735bf | 4 | * and associated documentation files (the "Software"), to deal in the Software without | 
| mbed_official | 0:a554658735bf | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, | 
| mbed_official | 0:a554658735bf | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the | 
| mbed_official | 0:a554658735bf | 7 | * Software is furnished to do so, subject to the following conditions: | 
| mbed_official | 0:a554658735bf | 8 | * | 
| mbed_official | 0:a554658735bf | 9 | * The above copyright notice and this permission notice shall be included in all copies or | 
| mbed_official | 0:a554658735bf | 10 | * substantial portions of the Software. | 
| mbed_official | 0:a554658735bf | 11 | * | 
| mbed_official | 0:a554658735bf | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | 
| mbed_official | 0:a554658735bf | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 
| mbed_official | 0:a554658735bf | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | 
| mbed_official | 0:a554658735bf | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
| mbed_official | 0:a554658735bf | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 
| mbed_official | 0:a554658735bf | 17 | */ | 
| mbed_official | 0:a554658735bf | 18 | |
| mbed_official | 0:a554658735bf | 19 | #ifndef USBHOSTHUB_H | 
| mbed_official | 0:a554658735bf | 20 | #define USBHOSTHUB_H | 
| mbed_official | 0:a554658735bf | 21 | |
| mbed_official | 0:a554658735bf | 22 | #include "USBHostConf.h" | 
| mbed_official | 0:a554658735bf | 23 | |
| mbed_official | 0:a554658735bf | 24 | #if MAX_HUB_NB | 
| mbed_official | 0:a554658735bf | 25 | |
| mbed_official | 0:a554658735bf | 26 | #include "USBHostTypes.h" | 
| mbed_official | 0:a554658735bf | 27 | #include "IUSBEnumerator.h" | 
| mbed_official | 0:a554658735bf | 28 | |
| mbed_official | 0:a554658735bf | 29 | class USBHost; | 
| mbed_official | 0:a554658735bf | 30 | class USBDeviceConnected; | 
| mbed_official | 0:a554658735bf | 31 | class USBEndpoint; | 
| mbed_official | 0:a554658735bf | 32 | |
| mbed_official | 0:a554658735bf | 33 | /** | 
| mbed_official | 0:a554658735bf | 34 | * A class to use a USB Hub | 
| mbed_official | 0:a554658735bf | 35 | */ | 
| mbed_official | 0:a554658735bf | 36 | class USBHostHub : public IUSBEnumerator { | 
| mbed_official | 0:a554658735bf | 37 | public: | 
| mbed_official | 0:a554658735bf | 38 | /** | 
| mbed_official | 0:a554658735bf | 39 | * Constructor | 
| mbed_official | 0:a554658735bf | 40 | */ | 
| mbed_official | 0:a554658735bf | 41 | USBHostHub(); | 
| mbed_official | 0:a554658735bf | 42 | |
| mbed_official | 0:a554658735bf | 43 | /** | 
| mbed_official | 0:a554658735bf | 44 | * Check if a USB Hub is connected | 
| mbed_official | 0:a554658735bf | 45 | * | 
| mbed_official | 0:a554658735bf | 46 | * @return true if a serial device is connected | 
| mbed_official | 0:a554658735bf | 47 | */ | 
| mbed_official | 0:a554658735bf | 48 | bool connected(); | 
| mbed_official | 0:a554658735bf | 49 | |
| mbed_official | 0:a554658735bf | 50 | /** | 
| mbed_official | 0:a554658735bf | 51 | * Try to connect device | 
| mbed_official | 0:a554658735bf | 52 | * | 
| mbed_official | 0:a554658735bf | 53 | * @param dev device to connect | 
| mbed_official | 0:a554658735bf | 54 | * @return true if connection was successful | 
| mbed_official | 0:a554658735bf | 55 | */ | 
| mbed_official | 0:a554658735bf | 56 | bool connect(USBDeviceConnected * dev); | 
| mbed_official | 0:a554658735bf | 57 | |
| mbed_official | 0:a554658735bf | 58 | /** | 
| mbed_official | 0:a554658735bf | 59 | * Automatically called by USBHost when a device | 
| mbed_official | 0:a554658735bf | 60 | * has been enumerated by usb_thread | 
| mbed_official | 0:a554658735bf | 61 | * | 
| mbed_official | 0:a554658735bf | 62 | * @param dev device connected | 
| mbed_official | 0:a554658735bf | 63 | */ | 
| mbed_official | 0:a554658735bf | 64 | void deviceConnected(USBDeviceConnected * dev); | 
| mbed_official | 0:a554658735bf | 65 | |
| mbed_official | 0:a554658735bf | 66 | /** | 
| mbed_official | 0:a554658735bf | 67 | * Automatically called by USBHost when a device | 
| mbed_official | 0:a554658735bf | 68 | * has been disconnected from this hub | 
| mbed_official | 0:a554658735bf | 69 | * | 
| mbed_official | 0:a554658735bf | 70 | * @param dev device connected | 
| mbed_official | 0:a554658735bf | 71 | */ | 
| mbed_official | 0:a554658735bf | 72 | void deviceDisconnected(USBDeviceConnected * dev); | 
| mbed_official | 0:a554658735bf | 73 | |
| mbed_official | 0:a554658735bf | 74 | /** | 
| mbed_official | 0:a554658735bf | 75 | * Rest a specific port | 
| mbed_official | 0:a554658735bf | 76 | * | 
| mbed_official | 0:a554658735bf | 77 | * @param port port number | 
| mbed_official | 0:a554658735bf | 78 | */ | 
| mbed_official | 0:a554658735bf | 79 | void portReset(uint8_t port); | 
| mbed_official | 0:a554658735bf | 80 | |
| mbed_official | 0:a554658735bf | 81 | /* | 
| mbed_official | 0:a554658735bf | 82 | * Called by USBHost to set the instance of USBHost | 
| mbed_official | 0:a554658735bf | 83 | * | 
| mbed_official | 0:a554658735bf | 84 | * @param host host instance | 
| mbed_official | 0:a554658735bf | 85 | */ | 
| mbed_official | 0:a554658735bf | 86 | void setHost(USBHost * host); | 
| mbed_official | 0:a554658735bf | 87 | |
| mbed_official | 0:a554658735bf | 88 | /** | 
| mbed_official | 0:a554658735bf | 89 | * Called by USBhost when a hub has been disconnected | 
| mbed_official | 0:a554658735bf | 90 | */ | 
| mbed_official | 0:a554658735bf | 91 | void hubDisconnected(); | 
| mbed_official | 0:a554658735bf | 92 | |
| mbed_official | 0:a554658735bf | 93 | protected: | 
| mbed_official | 0:a554658735bf | 94 | //From IUSBEnumerator | 
| mbed_official | 0:a554658735bf | 95 | virtual void setVidPid(uint16_t vid, uint16_t pid); | 
| mbed_official | 0:a554658735bf | 96 | 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 | 
| mbed_official | 0:a554658735bf | 97 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used | 
| mbed_official | 0:a554658735bf | 98 | |
| mbed_official | 0:a554658735bf | 99 | private: | 
| mbed_official | 0:a554658735bf | 100 | USBHost * host; | 
| mbed_official | 0:a554658735bf | 101 | USBDeviceConnected * dev; | 
| mbed_official | 0:a554658735bf | 102 | bool dev_connected; | 
| mbed_official | 0:a554658735bf | 103 | USBEndpoint * int_in; | 
| mbed_official | 0:a554658735bf | 104 | uint8_t nb_port; | 
| mbed_official | 0:a554658735bf | 105 | uint8_t hub_characteristics; | 
| mbed_official | 0:a554658735bf | 106 | |
| mbed_official | 0:a554658735bf | 107 | void rxHandler(); | 
| mbed_official | 0:a554658735bf | 108 | |
| mbed_official | 0:a554658735bf | 109 | uint8_t buf[sizeof(HubDescriptor)]; | 
| mbed_official | 0:a554658735bf | 110 | |
| mbed_official | 0:a554658735bf | 111 | int hub_intf; | 
| mbed_official | 0:a554658735bf | 112 | bool hub_device_found; | 
| mbed_official | 0:a554658735bf | 113 | |
| mbed_official | 0:a554658735bf | 114 | void setPortFeature(uint32_t feature, uint8_t port); | 
| mbed_official | 0:a554658735bf | 115 | void clearPortFeature(uint32_t feature, uint8_t port); | 
| mbed_official | 0:a554658735bf | 116 | uint32_t getPortStatus(uint8_t port); | 
| mbed_official | 0:a554658735bf | 117 | |
| mbed_official | 0:a554658735bf | 118 | USBDeviceConnected * device_children[MAX_HUB_PORT]; | 
| mbed_official | 0:a554658735bf | 119 | |
| mbed_official | 0:a554658735bf | 120 | void init(); | 
| mbed_official | 0:a554658735bf | 121 | void disconnect(); | 
| mbed_official | 0:a554658735bf | 122 | |
| mbed_official | 0:a554658735bf | 123 | }; | 
| mbed_official | 0:a554658735bf | 124 | |
| mbed_official | 0:a554658735bf | 125 | #endif | 
| mbed_official | 0:a554658735bf | 126 | |
| mbed_official | 0:a554658735bf | 127 | #endif | 
| mbed_official | 0:a554658735bf | 128 | 
