Usb read
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHost/USBHALHost_F401RE.h@16:981c3104f6c0, 2014-06-23 (annotated)
- Committer:
- va009039
- Date:
- Mon Jun 23 20:30:04 2014 +0900
- Revision:
- 16:981c3104f6c0
- Parent:
- 11:61843badd06e
- Child:
- 18:61554f238584
add FRDM-K64F.(not tested)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 11:61843badd06e | 1 | // Simple USBHost for Nucleo F401RE |
va009039 | 11:61843badd06e | 2 | #pragma once |
va009039 | 11:61843badd06e | 3 | #include "mbed.h" |
va009039 | 11:61843badd06e | 4 | #include "USBHostTypes.h" |
va009039 | 11:61843badd06e | 5 | #include "USBEndpoint.h" |
va009039 | 11:61843badd06e | 6 | |
va009039 | 11:61843badd06e | 7 | struct SETUP_PACKET { |
va009039 | 11:61843badd06e | 8 | uint8_t bmRequestType; |
va009039 | 11:61843badd06e | 9 | uint8_t bRequest; |
va009039 | 11:61843badd06e | 10 | uint16_t wValue; |
va009039 | 11:61843badd06e | 11 | uint16_t wIndex; |
va009039 | 11:61843badd06e | 12 | uint16_t wLength; |
va009039 | 11:61843badd06e | 13 | }; |
va009039 | 11:61843badd06e | 14 | |
va009039 |
16:981c3104f6c0 | 15 | class HC { |
va009039 |
16:981c3104f6c0 | 16 | static const uint8_t DIR_IN = 1; |
va009039 |
16:981c3104f6c0 | 17 | static const uint8_t DIR_OUT = 0; |
va009039 |
16:981c3104f6c0 | 18 | |
va009039 |
16:981c3104f6c0 | 19 | public: |
va009039 |
16:981c3104f6c0 | 20 | HC(); |
va009039 |
16:981c3104f6c0 | 21 | HC(int ch); |
va009039 |
16:981c3104f6c0 | 22 | ~HC(); |
va009039 |
16:981c3104f6c0 | 23 | HAL_StatusTypeDef Init(uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps); |
va009039 |
16:981c3104f6c0 | 24 | HAL_StatusTypeDef SubmitRequest(uint8_t* pbuff, uint16_t length, bool setup = false); |
va009039 |
16:981c3104f6c0 | 25 | HCD_URBStateTypeDef GetURBState(); |
va009039 |
16:981c3104f6c0 | 26 | HCD_HCStateTypeDef GetState(); |
va009039 |
16:981c3104f6c0 | 27 | uint32_t GetXferCount(); |
va009039 |
16:981c3104f6c0 | 28 | void SetToggle(uint8_t toggle); |
va009039 |
16:981c3104f6c0 | 29 | |
va009039 |
16:981c3104f6c0 | 30 | static uint8_t slot; |
va009039 |
16:981c3104f6c0 | 31 | |
va009039 |
16:981c3104f6c0 | 32 | private: |
va009039 |
16:981c3104f6c0 | 33 | int _ch; |
va009039 |
16:981c3104f6c0 | 34 | uint8_t _ep_addr; |
va009039 |
16:981c3104f6c0 | 35 | uint8_t _ep_type; |
va009039 |
16:981c3104f6c0 | 36 | }; |
va009039 |
16:981c3104f6c0 | 37 | |
va009039 | 11:61843badd06e | 38 | class USBHALHost { |
va009039 | 11:61843badd06e | 39 | public: |
va009039 | 11:61843badd06e | 40 | uint8_t LastStatus; |
va009039 | 11:61843badd06e | 41 | uint8_t prev_LastStatus; |
va009039 | 11:61843badd06e | 42 | |
va009039 | 11:61843badd06e | 43 | protected: |
va009039 | 11:61843badd06e | 44 | USBHALHost(); |
va009039 | 11:61843badd06e | 45 | void init(); |
va009039 | 11:61843badd06e | 46 | virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) = 0; |
va009039 | 11:61843badd06e | 47 | void setAddr(int addr, bool lowSpeed = false){} |
va009039 | 11:61843badd06e | 48 | void setEndpoint(){} |
va009039 | 11:61843badd06e | 49 | void token_transfer_init(){} |
va009039 | 11:61843badd06e | 50 | int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0); |
va009039 |
16:981c3104f6c0 | 51 | int token_iso_in(USBEndpoint* ep, uint8_t* data, int size); |
va009039 |
16:981c3104f6c0 | 52 | void token_ready(){} |
va009039 |
16:981c3104f6c0 | 53 | int multi_token_in(USBEndpoint* ep, uint8_t* data = NULL, size_t total = 0, bool block = true); |
va009039 |
16:981c3104f6c0 | 54 | int multi_token_out(USBEndpoint* ep, const uint8_t* data = NULL, size_t total = 0, bool block = true); |
va009039 |
16:981c3104f6c0 | 55 | |
va009039 |
16:981c3104f6c0 | 56 | private: |
va009039 | 11:61843badd06e | 57 | int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10); |
va009039 | 11:61843badd06e | 58 | int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10); |
va009039 | 11:61843badd06e | 59 | int token_ctl_in(USBEndpoint* ep, uint8_t* data, int size, int retryLimit); |
va009039 | 11:61843badd06e | 60 | int token_int_in(USBEndpoint* ep, uint8_t* data, int size); |
va009039 | 11:61843badd06e | 61 | int token_blk_in(USBEndpoint* ep, uint8_t* data, int size, int retryLimit); |
va009039 | 11:61843badd06e | 62 | int token_ctl_out(USBEndpoint* ep, const uint8_t* data, int size, int retryLimit); |
va009039 | 11:61843badd06e | 63 | int token_int_out(USBEndpoint* ep, const uint8_t* data, int size); |
va009039 | 11:61843badd06e | 64 | int token_blk_out(USBEndpoint* ep, const uint8_t* data, int size, int retryLimit); |
va009039 | 11:61843badd06e | 65 | bool wait_attach(); |
va009039 | 11:61843badd06e | 66 | static USBHALHost * instHost; |
va009039 | 11:61843badd06e | 67 | }; |
va009039 | 11:61843badd06e | 68 |