Usb read
Dependencies: FATFileSystem
Fork of F401RE-USBHost by
USBHost/USBHALHost_KL46Z.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 FRDM-KL46Z |
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 | 11:61843badd06e | 15 | #define GET_CONFIGURATION 8 |
va009039 | 11:61843badd06e | 16 | |
va009039 | 11:61843badd06e | 17 | // TOK_PID[5:2] |
va009039 | 11:61843badd06e | 18 | #define Bus_Timeout 0x00 |
va009039 | 11:61843badd06e | 19 | #define Data_Error 0x0f |
va009039 | 11:61843badd06e | 20 | |
va009039 | 11:61843badd06e | 21 | enum ODD_EVEN { |
va009039 | 11:61843badd06e | 22 | ODD = 0, |
va009039 | 11:61843badd06e | 23 | EVEN = 1, |
va009039 | 11:61843badd06e | 24 | }; |
va009039 | 11:61843badd06e | 25 | |
va009039 | 11:61843badd06e | 26 | class Report { |
va009039 | 11:61843badd06e | 27 | public: |
va009039 | 11:61843badd06e | 28 | void clear(); |
va009039 | 11:61843badd06e | 29 | void print_errstat(); |
va009039 | 11:61843badd06e | 30 | // error count |
va009039 | 11:61843badd06e | 31 | uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR] |
va009039 | 11:61843badd06e | 32 | uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF] |
va009039 | 11:61843badd06e | 33 | uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16] |
va009039 | 11:61843badd06e | 34 | uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8] |
va009039 | 11:61843badd06e | 35 | uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR] |
va009039 | 11:61843badd06e | 36 | uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR] |
va009039 | 11:61843badd06e | 37 | uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR] |
va009039 | 11:61843badd06e | 38 | // |
va009039 | 11:61843badd06e | 39 | uint32_t nak; |
va009039 | 11:61843badd06e | 40 | uint32_t stall; |
va009039 | 11:61843badd06e | 41 | }; |
va009039 | 11:61843badd06e | 42 | |
va009039 | 11:61843badd06e | 43 | class USBHALHost { |
va009039 | 11:61843badd06e | 44 | public: |
va009039 | 11:61843badd06e | 45 | uint8_t LastStatus; |
va009039 | 11:61843badd06e | 46 | uint8_t prev_LastStatus; |
va009039 | 11:61843badd06e | 47 | Report report; |
va009039 | 11:61843badd06e | 48 | |
va009039 | 11:61843badd06e | 49 | protected: |
va009039 | 11:61843badd06e | 50 | USBHALHost(); |
va009039 | 11:61843badd06e | 51 | void init(); |
va009039 | 11:61843badd06e | 52 | virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) = 0; |
va009039 | 11:61843badd06e | 53 | void setAddr(int addr, bool lowSpeed = false); |
va009039 | 11:61843badd06e | 54 | void setEndpoint(); |
va009039 | 11:61843badd06e | 55 | void token_transfer_init(); |
va009039 | 11:61843badd06e | 56 | int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0); |
va009039 |
16:981c3104f6c0 | 57 | int multi_token_in(USBEndpoint* ep, uint8_t* data = NULL, size_t total = 0, bool block = true); |
va009039 |
16:981c3104f6c0 | 58 | int multi_token_out(USBEndpoint* ep, const uint8_t* data = NULL, size_t total = 0, bool block = true); |
va009039 |
16:981c3104f6c0 | 59 | int token_iso_in(USBEndpoint* ep, uint8_t* data, int size); |
va009039 |
16:981c3104f6c0 | 60 | void token_ready(); |
va009039 |
16:981c3104f6c0 | 61 | |
va009039 |
16:981c3104f6c0 | 62 | private: |
va009039 | 11:61843badd06e | 63 | int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10); |
va009039 | 11:61843badd06e | 64 | int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10); |
va009039 | 11:61843badd06e | 65 | static void _usbisr(void); |
va009039 | 11:61843badd06e | 66 | void UsbIrqhandler(); |
va009039 | 11:61843badd06e | 67 | __IO bool attach_done; |
va009039 | 11:61843badd06e | 68 | __IO bool token_done; |
va009039 | 11:61843badd06e | 69 | bool wait_attach(); |
va009039 | 11:61843badd06e | 70 | bool root_lowSpeed; |
va009039 | 11:61843badd06e | 71 | ODD_EVEN tx_ptr; |
va009039 | 11:61843badd06e | 72 | ODD_EVEN rx_ptr; |
va009039 | 11:61843badd06e | 73 | static USBHALHost * instHost; |
va009039 | 11:61843badd06e | 74 | }; |