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.
Dependents: UsbHostMAX3421E_Hello
UsbCore.h@0:84353c479782, 2020-07-12 (annotated)
- Committer:
- hudakz
- Date:
- Sun Jul 12 20:39:26 2020 +0000
- Revision:
- 0:84353c479782
- Child:
- 1:2263e77400e9
MAX3421E-based USB Host Shield Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:84353c479782 | 1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. |
hudakz | 0:84353c479782 | 2 | |
hudakz | 0:84353c479782 | 3 | This program is free software; you can redistribute it and/or modify |
hudakz | 0:84353c479782 | 4 | it under the terms of the GNU General Public License as published by |
hudakz | 0:84353c479782 | 5 | the Free Software Foundation; either version 2 of the License, or |
hudakz | 0:84353c479782 | 6 | (at your option) any later version. |
hudakz | 0:84353c479782 | 7 | |
hudakz | 0:84353c479782 | 8 | This program is distributed in the hope that it will be useful, |
hudakz | 0:84353c479782 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
hudakz | 0:84353c479782 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
hudakz | 0:84353c479782 | 11 | GNU General Public License for more details. |
hudakz | 0:84353c479782 | 12 | |
hudakz | 0:84353c479782 | 13 | You should have received a copy of the GNU General Public License |
hudakz | 0:84353c479782 | 14 | along with this program; if not, write to the Free Software |
hudakz | 0:84353c479782 | 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
hudakz | 0:84353c479782 | 16 | |
hudakz | 0:84353c479782 | 17 | Contact information |
hudakz | 0:84353c479782 | 18 | ------------------- |
hudakz | 0:84353c479782 | 19 | |
hudakz | 0:84353c479782 | 20 | Circuits At Home, LTD |
hudakz | 0:84353c479782 | 21 | Web : http://www.circuitsathome.com |
hudakz | 0:84353c479782 | 22 | e-mail : support@circuitsathome.com |
hudakz | 0:84353c479782 | 23 | */ |
hudakz | 0:84353c479782 | 24 | #ifndef USBCORE_H |
hudakz | 0:84353c479782 | 25 | #define USBCORE_H |
hudakz | 0:84353c479782 | 26 | |
hudakz | 0:84353c479782 | 27 | #include "MAX3421E.h" |
hudakz | 0:84353c479782 | 28 | #include "address.h" |
hudakz | 0:84353c479782 | 29 | |
hudakz | 0:84353c479782 | 30 | //#define USB_METHODS_INLINE |
hudakz | 0:84353c479782 | 31 | /* Common setup data constant combinations */ |
hudakz | 0:84353c479782 | 32 | #define bmREQ_GET_DESCR USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_DEVICE //get descriptor request type |
hudakz | 0:84353c479782 | 33 | #define bmREQ_SET USB_SETUP_HOST_TO_DEVICE | USB_SETUP_TYPE_STANDARD | USB_SETUP_RECIPIENT_DEVICE //set request type for all but 'set feature' and 'set interface' |
hudakz | 0:84353c479782 | 34 | #define bmREQ_CL_GET_INTF USB_SETUP_DEVICE_TO_HOST | USB_SETUP_TYPE_CLASS | USB_SETUP_RECIPIENT_INTERFACE //get interface request type |
hudakz | 0:84353c479782 | 35 | // D7 data transfer direction (0 - host-to-device, 1 - device-to-host) |
hudakz | 0:84353c479782 | 36 | // D6-5 Type (0- standard, 1 - class, 2 - vendor, 3 - reserved) |
hudakz | 0:84353c479782 | 37 | // D4-0 Recipient (0 - device, 1 - interface, 2 - endpoint, 3 - other, 4..31 - reserved) |
hudakz | 0:84353c479782 | 38 | // USB Device Classes |
hudakz | 0:84353c479782 | 39 | #define USB_CLASS_USE_CLASS_INFO 0x00 // Use Class Info in the Interface Descriptors |
hudakz | 0:84353c479782 | 40 | #define USB_CLASS_AUDIO 0x01 // Audio |
hudakz | 0:84353c479782 | 41 | #define USB_CLASS_COM_AND_CDC_CTRL 0x02 // Communications and CDC Control |
hudakz | 0:84353c479782 | 42 | #define USB_CLASS_HID 0x03 // HID |
hudakz | 0:84353c479782 | 43 | #define USB_CLASS_PHYSICAL 0x05 // Physical |
hudakz | 0:84353c479782 | 44 | #define USB_CLASS_IMAGE 0x06 // Image |
hudakz | 0:84353c479782 | 45 | #define USB_CLASS_PRINTER 0x07 // Printer |
hudakz | 0:84353c479782 | 46 | #define USB_CLASS_MASS_STORAGE 0x08 // Mass Storage |
hudakz | 0:84353c479782 | 47 | #define USB_CLASS_HUB 0x09 // Hub |
hudakz | 0:84353c479782 | 48 | #define USB_CLASS_CDC_DATA 0x0a // CDC-Data |
hudakz | 0:84353c479782 | 49 | #define USB_CLASS_SMART_CARD 0x0b // Smart-Card |
hudakz | 0:84353c479782 | 50 | #define USB_CLASS_CONTENT_SECURITY 0x0d // Content Security |
hudakz | 0:84353c479782 | 51 | #define USB_CLASS_VIDEO 0x0e // Video |
hudakz | 0:84353c479782 | 52 | #define USB_CLASS_PERSONAL_HEALTH 0x0f // Personal Healthcare |
hudakz | 0:84353c479782 | 53 | #define USB_CLASS_DIAGNOSTIC_DEVICE 0xdc // Diagnostic Device |
hudakz | 0:84353c479782 | 54 | #define USB_CLASS_WIRELESS_CTRL 0xe0 // Wireless Controller |
hudakz | 0:84353c479782 | 55 | #define USB_CLASS_MISC 0xef // Miscellaneous |
hudakz | 0:84353c479782 | 56 | #define USB_CLASS_APP_SPECIFIC 0xfe // Application Specific |
hudakz | 0:84353c479782 | 57 | #define USB_CLASS_VENDOR_SPECIFIC 0xff // Vendor Specific |
hudakz | 0:84353c479782 | 58 | |
hudakz | 0:84353c479782 | 59 | // Additional Error Codes |
hudakz | 0:84353c479782 | 60 | #define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED 0xD1 |
hudakz | 0:84353c479782 | 61 | #define USB_DEV_CONFIG_ERROR_DEVICE_INIT_INCOMPLETE 0xD2 |
hudakz | 0:84353c479782 | 62 | #define USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS 0xD3 |
hudakz | 0:84353c479782 | 63 | #define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL 0xD4 |
hudakz | 0:84353c479782 | 64 | #define USB_ERROR_HUB_ADDRESS_OVERFLOW 0xD5 |
hudakz | 0:84353c479782 | 65 | #define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL 0xD6 |
hudakz | 0:84353c479782 | 66 | #define USB_ERROR_EPINFO_IS_NULL 0xD7 |
hudakz | 0:84353c479782 | 67 | #define USB_ERROR_INVALID_ARGUMENT 0xD8 |
hudakz | 0:84353c479782 | 68 | #define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE 0xD9 |
hudakz | 0:84353c479782 | 69 | #define USB_ERROR_INVALID_MAX_PKT_SIZE 0xDA |
hudakz | 0:84353c479782 | 70 | #define USB_ERROR_EP_NOT_FOUND_IN_TBL 0xDB |
hudakz | 0:84353c479782 | 71 | #define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET 0xE0 |
hudakz | 0:84353c479782 | 72 | #define USB_ERROR_FailGetDevDescr 0xE1 |
hudakz | 0:84353c479782 | 73 | #define USB_ERROR_FailSetDevTblEntry 0xE2 |
hudakz | 0:84353c479782 | 74 | #define USB_ERROR_FailGetConfDescr 0xE3 |
hudakz | 0:84353c479782 | 75 | #define USB_ERROR_TRANSFER_TIMEOUT 0xFF |
hudakz | 0:84353c479782 | 76 | |
hudakz | 0:84353c479782 | 77 | #define USB_XFER_TIMEOUT 5000 // (5000) USB transfer timeout in milliseconds, per section 9.2.6.1 of USB 2.0 spec |
hudakz | 0:84353c479782 | 78 | #define USB_RETRY_LIMIT 3 // 3 retry limit for a transfer |
hudakz | 0:84353c479782 | 79 | #define USB_SETTLE_DELAY 200 // settle delay in milliseconds |
hudakz | 0:84353c479782 | 80 | #define USB_NUMDEVICES 16 //number of USB devices |
hudakz | 0:84353c479782 | 81 | #define HUB_PORT_RESET_DELAY 20 // hub port reset delay 10 ms recomended, can be up to 20 ms |
hudakz | 0:84353c479782 | 82 | //#define USB_NAK_LIMIT 32000 // NAK limit for a transfer. 0 means NAKs are not counted |
hudakz | 0:84353c479782 | 83 | //#define HUB_MAX_HUBS 7 // maximum number of hubs that can be attached to the host controller |
hudakz | 0:84353c479782 | 84 | /* USB state machine states */ |
hudakz | 0:84353c479782 | 85 | #define USB_STATE_MASK 0xf0 |
hudakz | 0:84353c479782 | 86 | #define USB_STATE_DETACHED 0x10 |
hudakz | 0:84353c479782 | 87 | #define USB_DETACHED_SUBSTATE_INITIALIZE 0x11 |
hudakz | 0:84353c479782 | 88 | #define USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE 0x12 |
hudakz | 0:84353c479782 | 89 | #define USB_DETACHED_SUBSTATE_ILLEGAL 0x13 |
hudakz | 0:84353c479782 | 90 | #define USB_ATTACHED_SUBSTATE_SETTLE 0x20 |
hudakz | 0:84353c479782 | 91 | #define USB_ATTACHED_SUBSTATE_RESET_DEVICE 0x30 |
hudakz | 0:84353c479782 | 92 | #define USB_ATTACHED_SUBSTATE_WAIT_RESET_COMPLETE 0x40 |
hudakz | 0:84353c479782 | 93 | #define USB_ATTACHED_SUBSTATE_WAIT_SOF 0x50 |
hudakz | 0:84353c479782 | 94 | #define USB_ATTACHED_SUBSTATE_WAIT_RESET 0x51 |
hudakz | 0:84353c479782 | 95 | #define USB_ATTACHED_SUBSTATE_GET_DEVICE_DESCRIPTOR_SIZE 0x60 |
hudakz | 0:84353c479782 | 96 | #define USB_STATE_ADDRESSING 0x70 |
hudakz | 0:84353c479782 | 97 | #define USB_STATE_CONFIGURING 0x80 |
hudakz | 0:84353c479782 | 98 | #define USB_STATE_RUNNING 0x90 |
hudakz | 0:84353c479782 | 99 | #define USB_STATE_ERROR 0xa0 |
hudakz | 0:84353c479782 | 100 | |
hudakz | 0:84353c479782 | 101 | |
hudakz | 0:84353c479782 | 102 | class USBDeviceConfig |
hudakz | 0:84353c479782 | 103 | { |
hudakz | 0:84353c479782 | 104 | public: |
hudakz | 0:84353c479782 | 105 | virtual uint8_t Init |
hudakz | 0:84353c479782 | 106 | ( |
hudakz | 0:84353c479782 | 107 | uint8_t parent __attribute__((unused)), |
hudakz | 0:84353c479782 | 108 | uint8_t port __attribute__((unused)), |
hudakz | 0:84353c479782 | 109 | bool lowspeed __attribute__((unused)) |
hudakz | 0:84353c479782 | 110 | ) |
hudakz | 0:84353c479782 | 111 | { |
hudakz | 0:84353c479782 | 112 | return 0; |
hudakz | 0:84353c479782 | 113 | } |
hudakz | 0:84353c479782 | 114 | |
hudakz | 0:84353c479782 | 115 | virtual uint8_t ConfigureDevice |
hudakz | 0:84353c479782 | 116 | ( |
hudakz | 0:84353c479782 | 117 | uint8_t parent __attribute__((unused)), |
hudakz | 0:84353c479782 | 118 | uint8_t port __attribute__((unused)), |
hudakz | 0:84353c479782 | 119 | bool lowspeed __attribute__((unused)) |
hudakz | 0:84353c479782 | 120 | ) |
hudakz | 0:84353c479782 | 121 | { |
hudakz | 0:84353c479782 | 122 | return 0; |
hudakz | 0:84353c479782 | 123 | } |
hudakz | 0:84353c479782 | 124 | |
hudakz | 0:84353c479782 | 125 | virtual uint8_t Release() { return 0; } |
hudakz | 0:84353c479782 | 126 | virtual uint8_t Poll() { return 0; } |
hudakz | 0:84353c479782 | 127 | virtual uint8_t GetAddress() { return 0; } |
hudakz | 0:84353c479782 | 128 | virtual void ResetHubPort(uint8_t port __attribute__((unused))) { return; } |
hudakz | 0:84353c479782 | 129 | |
hudakz | 0:84353c479782 | 130 | // Note used for hubs only! |
hudakz | 0:84353c479782 | 131 | virtual bool VIDPIDOK(uint16_t vid __attribute__((unused)), uint16_t pid __attribute__((unused))) { return false; } |
hudakz | 0:84353c479782 | 132 | virtual bool DEVCLASSOK(uint8_t klass __attribute__((unused))) { return false; } |
hudakz | 0:84353c479782 | 133 | virtual bool DEVSUBCLASSOK(uint8_t subklass __attribute__((unused))) { return true; } |
hudakz | 0:84353c479782 | 134 | }; |
hudakz | 0:84353c479782 | 135 | |
hudakz | 0:84353c479782 | 136 | /* USB Setup Packet Structure */ |
hudakz | 0:84353c479782 | 137 | typedef struct |
hudakz | 0:84353c479782 | 138 | { |
hudakz | 0:84353c479782 | 139 | union |
hudakz | 0:84353c479782 | 140 | { // offset description |
hudakz | 0:84353c479782 | 141 | uint8_t bmRequestType; // 0 Bit-map of request type |
hudakz | 0:84353c479782 | 142 | |
hudakz | 0:84353c479782 | 143 | struct |
hudakz | 0:84353c479782 | 144 | { |
hudakz | 0:84353c479782 | 145 | uint8_t recipient : 5; // Recipient of the request |
hudakz | 0:84353c479782 | 146 | uint8_t type : 2; // Type of request |
hudakz | 0:84353c479782 | 147 | uint8_t direction : 1; // Direction of data X-fer |
hudakz | 0:84353c479782 | 148 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 149 | } |
hudakz | 0:84353c479782 | 150 | ReqType_u; |
hudakz | 0:84353c479782 | 151 | uint8_t bRequest; // 1 Request |
hudakz | 0:84353c479782 | 152 | |
hudakz | 0:84353c479782 | 153 | union |
hudakz | 0:84353c479782 | 154 | { |
hudakz | 0:84353c479782 | 155 | uint16_t wValue; // 2 Depends on bRequest |
hudakz | 0:84353c479782 | 156 | |
hudakz | 0:84353c479782 | 157 | struct |
hudakz | 0:84353c479782 | 158 | { |
hudakz | 0:84353c479782 | 159 | uint8_t wValueLo; |
hudakz | 0:84353c479782 | 160 | uint8_t wValueHi; |
hudakz | 0:84353c479782 | 161 | } __attribute__((packed)); |
hudakz | 0:84353c479782 | 162 | } |
hudakz | 0:84353c479782 | 163 | wVal_u; |
hudakz | 0:84353c479782 | 164 | uint16_t wIndex; // 4 Depends on bRequest |
hudakz | 0:84353c479782 | 165 | uint16_t wLength; // 6 Depends on bRequest |
hudakz | 0:84353c479782 | 166 | } |
hudakz | 0:84353c479782 | 167 | __attribute__((packed)) |
hudakz | 0:84353c479782 | 168 | SETUP_PKT, *PSETUP_PKT; |
hudakz | 0:84353c479782 | 169 | |
hudakz | 0:84353c479782 | 170 | // Base class for incoming data parser |
hudakz | 0:84353c479782 | 171 | class USBReadParser |
hudakz | 0:84353c479782 | 172 | { |
hudakz | 0:84353c479782 | 173 | public: |
hudakz | 0:84353c479782 | 174 | virtual void Parse(const uint16_t len, const uint8_t* pbuf, const uint16_t& offset) = 0; |
hudakz | 0:84353c479782 | 175 | }; |
hudakz | 0:84353c479782 | 176 | |
hudakz | 0:84353c479782 | 177 | class USB : public MAX3421E |
hudakz | 0:84353c479782 | 178 | { |
hudakz | 0:84353c479782 | 179 | AddressPoolImpl<USB_NUMDEVICES> addrPool; |
hudakz | 0:84353c479782 | 180 | USBDeviceConfig* devConfig[USB_NUMDEVICES]; |
hudakz | 0:84353c479782 | 181 | uint8_t bmHubPre; |
hudakz | 0:84353c479782 | 182 | public: |
hudakz | 0:84353c479782 | 183 | USB(PinName mosi, PinName miso, PinName sck, PinName ss, PinName intr); |
hudakz | 0:84353c479782 | 184 | int8_t init(); |
hudakz | 0:84353c479782 | 185 | void SetHubPreMask() { bmHubPre |= bmHUBPRE; } |
hudakz | 0:84353c479782 | 186 | void ResetHubPreMask() { bmHubPre &= (~bmHUBPRE); } |
hudakz | 0:84353c479782 | 187 | AddressPool& GetAddressPool() { return (AddressPool&)addrPool; } |
hudakz | 0:84353c479782 | 188 | uint8_t RegisterDeviceClass(USBDeviceConfig* pdev) |
hudakz | 0:84353c479782 | 189 | { |
hudakz | 0:84353c479782 | 190 | for (uint8_t i = 0; i < USB_NUMDEVICES; i++) { |
hudakz | 0:84353c479782 | 191 | if (!devConfig[i]) { |
hudakz | 0:84353c479782 | 192 | devConfig[i] = pdev; |
hudakz | 0:84353c479782 | 193 | return 0; |
hudakz | 0:84353c479782 | 194 | } |
hudakz | 0:84353c479782 | 195 | } |
hudakz | 0:84353c479782 | 196 | |
hudakz | 0:84353c479782 | 197 | return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS; |
hudakz | 0:84353c479782 | 198 | } |
hudakz | 0:84353c479782 | 199 | |
hudakz | 0:84353c479782 | 200 | void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) { addrPool.ForEachUsbDevice(pfunc); } |
hudakz | 0:84353c479782 | 201 | uint8_t getUsbTaskState(void); |
hudakz | 0:84353c479782 | 202 | void setUsbTaskState(uint8_t state); |
hudakz | 0:84353c479782 | 203 | |
hudakz | 0:84353c479782 | 204 | EpInfo* getEpInfoEntry(uint8_t addr, uint8_t ep); |
hudakz | 0:84353c479782 | 205 | uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo* eprecord_ptr); |
hudakz | 0:84353c479782 | 206 | |
hudakz | 0:84353c479782 | 207 | /* Control requests */ |
hudakz | 0:84353c479782 | 208 | uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr); |
hudakz | 0:84353c479782 | 209 | uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr); |
hudakz | 0:84353c479782 | 210 | |
hudakz | 0:84353c479782 | 211 | uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint8_t conf, USBReadParser* p); |
hudakz | 0:84353c479782 | 212 | |
hudakz | 0:84353c479782 | 213 | uint8_t getStrDescr |
hudakz | 0:84353c479782 | 214 | ( |
hudakz | 0:84353c479782 | 215 | uint8_t addr, |
hudakz | 0:84353c479782 | 216 | uint8_t ep, |
hudakz | 0:84353c479782 | 217 | uint16_t nbytes, |
hudakz | 0:84353c479782 | 218 | uint8_t index, |
hudakz | 0:84353c479782 | 219 | uint16_t langid, |
hudakz | 0:84353c479782 | 220 | uint8_t* dataptr |
hudakz | 0:84353c479782 | 221 | ); |
hudakz | 0:84353c479782 | 222 | uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr); |
hudakz | 0:84353c479782 | 223 | uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value); |
hudakz | 0:84353c479782 | 224 | /**/ |
hudakz | 0:84353c479782 | 225 | uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr, bool direction); |
hudakz | 0:84353c479782 | 226 | uint8_t ctrlStatus(uint8_t ep, bool direction, uint16_t nak_limit); |
hudakz | 0:84353c479782 | 227 | uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t* nbytesptr, uint8_t* data, uint8_t bInterval = 0); |
hudakz | 0:84353c479782 | 228 | uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data); |
hudakz | 0:84353c479782 | 229 | uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit); |
hudakz | 0:84353c479782 | 230 | |
hudakz | 0:84353c479782 | 231 | void task(void); |
hudakz | 0:84353c479782 | 232 | |
hudakz | 0:84353c479782 | 233 | uint8_t defaultAddressing(uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 234 | uint8_t configuring(uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 235 | uint8_t releaseDevice(uint8_t addr); |
hudakz | 0:84353c479782 | 236 | |
hudakz | 0:84353c479782 | 237 | uint8_t ctrlReq |
hudakz | 0:84353c479782 | 238 | ( |
hudakz | 0:84353c479782 | 239 | uint8_t addr, |
hudakz | 0:84353c479782 | 240 | uint8_t ep, |
hudakz | 0:84353c479782 | 241 | uint8_t bmReqType, |
hudakz | 0:84353c479782 | 242 | uint8_t bRequest, |
hudakz | 0:84353c479782 | 243 | uint8_t wValLo, |
hudakz | 0:84353c479782 | 244 | uint8_t wValHi, |
hudakz | 0:84353c479782 | 245 | uint16_t wInd, |
hudakz | 0:84353c479782 | 246 | uint16_t total, |
hudakz | 0:84353c479782 | 247 | uint16_t nbytes, |
hudakz | 0:84353c479782 | 248 | uint8_t* dataptr, |
hudakz | 0:84353c479782 | 249 | USBReadParser* p |
hudakz | 0:84353c479782 | 250 | ); |
hudakz | 0:84353c479782 | 251 | private: |
hudakz | 0:84353c479782 | 252 | uint8_t setAddress(uint8_t addr, uint8_t ep, EpInfo ** ppep, uint16_t* nak_limit); |
hudakz | 0:84353c479782 | 253 | uint8_t outTransfer(EpInfo* pep, uint16_t nak_limit, uint16_t nbytes, uint8_t* data); |
hudakz | 0:84353c479782 | 254 | uint8_t inTransfer(EpInfo* pep, uint16_t nak_limit, uint16_t* nbytesptr, uint8_t* data, uint8_t bInterval = 0); |
hudakz | 0:84353c479782 | 255 | uint8_t attemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed); |
hudakz | 0:84353c479782 | 256 | }; |
hudakz | 0:84353c479782 | 257 | |
hudakz | 0:84353c479782 | 258 | #if 0 //defined(USB_METHODS_INLINE) |
hudakz | 0:84353c479782 | 259 | |
hudakz | 0:84353c479782 | 260 | //get device descriptor |
hudakz | 0:84353c479782 | 261 | inline uint8_t USB::getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr) |
hudakz | 0:84353c479782 | 262 | { |
hudakz | 0:84353c479782 | 263 | return |
hudakz | 0:84353c479782 | 264 | ( |
hudakz | 0:84353c479782 | 265 | ctrlReq |
hudakz | 0:84353c479782 | 266 | ( |
hudakz | 0:84353c479782 | 267 | addr, |
hudakz | 0:84353c479782 | 268 | ep, |
hudakz | 0:84353c479782 | 269 | bmREQ_GET_DESCR, |
hudakz | 0:84353c479782 | 270 | USB_REQUEST_GET_DESCRIPTOR, |
hudakz | 0:84353c479782 | 271 | 0x00, |
hudakz | 0:84353c479782 | 272 | USB_DESCRIPTOR_DEVICE, |
hudakz | 0:84353c479782 | 273 | 0x0000, |
hudakz | 0:84353c479782 | 274 | nbytes, |
hudakz | 0:84353c479782 | 275 | dataptr |
hudakz | 0:84353c479782 | 276 | ) |
hudakz | 0:84353c479782 | 277 | ); |
hudakz | 0:84353c479782 | 278 | } |
hudakz | 0:84353c479782 | 279 | |
hudakz | 0:84353c479782 | 280 | //get configuration descriptor |
hudakz | 0:84353c479782 | 281 | inline uint8_t USB::getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t* dataptr) |
hudakz | 0:84353c479782 | 282 | { |
hudakz | 0:84353c479782 | 283 | return |
hudakz | 0:84353c479782 | 284 | ( |
hudakz | 0:84353c479782 | 285 | ctrlReq |
hudakz | 0:84353c479782 | 286 | ( |
hudakz | 0:84353c479782 | 287 | addr, |
hudakz | 0:84353c479782 | 288 | ep, |
hudakz | 0:84353c479782 | 289 | bmREQ_GET_DESCR, |
hudakz | 0:84353c479782 | 290 | USB_REQUEST_GET_DESCRIPTOR, |
hudakz | 0:84353c479782 | 291 | conf, |
hudakz | 0:84353c479782 | 292 | USB_DESCRIPTOR_CONFIGURATION, |
hudakz | 0:84353c479782 | 293 | 0x0000, |
hudakz | 0:84353c479782 | 294 | nbytes, |
hudakz | 0:84353c479782 | 295 | dataptr |
hudakz | 0:84353c479782 | 296 | ) |
hudakz | 0:84353c479782 | 297 | ); |
hudakz | 0:84353c479782 | 298 | } |
hudakz | 0:84353c479782 | 299 | |
hudakz | 0:84353c479782 | 300 | //get string descriptor |
hudakz | 0:84353c479782 | 301 | inline uint8_t USB::getStrDescr |
hudakz | 0:84353c479782 | 302 | ( |
hudakz | 0:84353c479782 | 303 | uint8_t addr, |
hudakz | 0:84353c479782 | 304 | uint8_t ep, |
hudakz | 0:84353c479782 | 305 | uint16_t nuint8_ts, |
hudakz | 0:84353c479782 | 306 | uint8_t index, |
hudakz | 0:84353c479782 | 307 | uint16_t langid, |
hudakz | 0:84353c479782 | 308 | uint8_t* dataptr |
hudakz | 0:84353c479782 | 309 | ) |
hudakz | 0:84353c479782 | 310 | { |
hudakz | 0:84353c479782 | 311 | return |
hudakz | 0:84353c479782 | 312 | ( |
hudakz | 0:84353c479782 | 313 | ctrlReq |
hudakz | 0:84353c479782 | 314 | ( |
hudakz | 0:84353c479782 | 315 | addr, |
hudakz | 0:84353c479782 | 316 | ep, |
hudakz | 0:84353c479782 | 317 | bmREQ_GET_DESCR, |
hudakz | 0:84353c479782 | 318 | USB_REQUEST_GET_DESCRIPTOR, |
hudakz | 0:84353c479782 | 319 | index, |
hudakz | 0:84353c479782 | 320 | USB_DESCRIPTOR_STRING, |
hudakz | 0:84353c479782 | 321 | langid, |
hudakz | 0:84353c479782 | 322 | nuint8_ts, |
hudakz | 0:84353c479782 | 323 | dataptr |
hudakz | 0:84353c479782 | 324 | ) |
hudakz | 0:84353c479782 | 325 | ); |
hudakz | 0:84353c479782 | 326 | } |
hudakz | 0:84353c479782 | 327 | |
hudakz | 0:84353c479782 | 328 | //set address |
hudakz | 0:84353c479782 | 329 | inline uint8_t USB::setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr) |
hudakz | 0:84353c479782 | 330 | { |
hudakz | 0:84353c479782 | 331 | return(ctrlReq(oldaddr, ep, bmREQ_SET, USB_REQUEST_SET_ADDRESS, newaddr, 0x00, 0x0000, 0x0000, NULL)); |
hudakz | 0:84353c479782 | 332 | } |
hudakz | 0:84353c479782 | 333 | |
hudakz | 0:84353c479782 | 334 | //set configuration |
hudakz | 0:84353c479782 | 335 | inline uint8_t USB::setConf(uint8_t addr, uint8_t ep, uint8_t conf_value) |
hudakz | 0:84353c479782 | 336 | { |
hudakz | 0:84353c479782 | 337 | return(ctrlReq(addr, ep, bmREQ_SET, USB_REQUEST_SET_CONFIGURATION, conf_value, 0x00, 0x0000, 0x0000, NULL)); |
hudakz | 0:84353c479782 | 338 | } |
hudakz | 0:84353c479782 | 339 | #endif // defined(USB_METHODS_INLINE) |
hudakz | 0:84353c479782 | 340 | #endif /* USBCORE_H */ |