Added target compiler selections for FRDM-K20D50 which works.

Dependencies:   FATFileSystem

Dependents:   kl25z_Usb_Logger

Fork of F401RE-USBHost by Norimasa Okamoto

Committer:
va009039
Date:
Sat Jan 25 12:51:44 2014 +0000
Revision:
3:a3872f7593e2
fix max packet size

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 3:a3872f7593e2 1 // Simple USBHost for FRDM-KL46Z
va009039 3:a3872f7593e2 2 #pragma once
va009039 3:a3872f7593e2 3 #include "mbed.h"
va009039 3:a3872f7593e2 4 #include "USBHostTypes.h"
va009039 3:a3872f7593e2 5 #include "USBEndpoint.h"
va009039 3:a3872f7593e2 6
va009039 3:a3872f7593e2 7 struct SETUP_PACKET {
va009039 3:a3872f7593e2 8 uint8_t bmRequestType;
va009039 3:a3872f7593e2 9 uint8_t bRequest;
va009039 3:a3872f7593e2 10 uint16_t wValue;
va009039 3:a3872f7593e2 11 uint16_t wIndex;
va009039 3:a3872f7593e2 12 uint16_t wLength;
va009039 3:a3872f7593e2 13 };
va009039 3:a3872f7593e2 14
va009039 3:a3872f7593e2 15 #define GET_CONFIGURATION 8
va009039 3:a3872f7593e2 16
va009039 3:a3872f7593e2 17 // TOK_PID[5:2]
va009039 3:a3872f7593e2 18 #define DATA0 0x03
va009039 3:a3872f7593e2 19 #define DATA1 0x0b
va009039 3:a3872f7593e2 20 #define ACK 0x02
va009039 3:a3872f7593e2 21 #define STALL 0x0e
va009039 3:a3872f7593e2 22 #define NAK 0x0a
va009039 3:a3872f7593e2 23 #define Bus_Timeout 0x00
va009039 3:a3872f7593e2 24 #define Data_Error 0x0f
va009039 3:a3872f7593e2 25
va009039 3:a3872f7593e2 26 enum ODD_EVEN {
va009039 3:a3872f7593e2 27 ODD = 0,
va009039 3:a3872f7593e2 28 EVEN = 1,
va009039 3:a3872f7593e2 29 };
va009039 3:a3872f7593e2 30
va009039 3:a3872f7593e2 31 class Report {
va009039 3:a3872f7593e2 32 public:
va009039 3:a3872f7593e2 33 void clear();
va009039 3:a3872f7593e2 34 void print_errstat();
va009039 3:a3872f7593e2 35 // error count
va009039 3:a3872f7593e2 36 uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR]
va009039 3:a3872f7593e2 37 uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF]
va009039 3:a3872f7593e2 38 uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16]
va009039 3:a3872f7593e2 39 uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8]
va009039 3:a3872f7593e2 40 uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR]
va009039 3:a3872f7593e2 41 uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR]
va009039 3:a3872f7593e2 42 uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR]
va009039 3:a3872f7593e2 43 //
va009039 3:a3872f7593e2 44 uint32_t nak;
va009039 3:a3872f7593e2 45 };
va009039 3:a3872f7593e2 46
va009039 3:a3872f7593e2 47 class Data01 {
va009039 3:a3872f7593e2 48 public:
va009039 3:a3872f7593e2 49 void init();
va009039 3:a3872f7593e2 50 void set(int txrx, int ep, uint8_t _data01);
va009039 3:a3872f7593e2 51 void toggle(int txrx, int ep);
va009039 3:a3872f7593e2 52 uint8_t get(int txrx, int ep);
va009039 3:a3872f7593e2 53 private:
va009039 3:a3872f7593e2 54 uint8_t txrx_data01[2][16];
va009039 3:a3872f7593e2 55 };
va009039 3:a3872f7593e2 56
va009039 3:a3872f7593e2 57 class USBHALHost {
va009039 3:a3872f7593e2 58 public:
va009039 3:a3872f7593e2 59 uint8_t LastStatus;
va009039 3:a3872f7593e2 60 uint8_t prev_LastStatus;
va009039 3:a3872f7593e2 61 Report report;
va009039 3:a3872f7593e2 62
va009039 3:a3872f7593e2 63 protected:
va009039 3:a3872f7593e2 64 USBHALHost();
va009039 3:a3872f7593e2 65 void init();
va009039 3:a3872f7593e2 66 virtual bool enumeration() = 0;
va009039 3:a3872f7593e2 67 bool lowSpeed;
va009039 3:a3872f7593e2 68 int MaxPacketSize0;
va009039 3:a3872f7593e2 69 void setAddr(int addr);
va009039 3:a3872f7593e2 70 void setEndpoint(bool use_retry = false);
va009039 3:a3872f7593e2 71 void token_transfer_init();
va009039 3:a3872f7593e2 72 int token_setup(SETUP_PACKET* setup, uint16_t wLength = 0);
va009039 3:a3872f7593e2 73 int token_in(uint8_t ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10);
va009039 3:a3872f7593e2 74 int token_out(uint8_t ep, const uint8_t* data = NULL, int size = 0);
va009039 3:a3872f7593e2 75 void token_ready();
va009039 3:a3872f7593e2 76 private:
va009039 3:a3872f7593e2 77 static void _usbisr(void);
va009039 3:a3872f7593e2 78 void UsbIrqhandler();
va009039 3:a3872f7593e2 79 __IO bool attach_done;
va009039 3:a3872f7593e2 80 __IO bool token_done;
va009039 3:a3872f7593e2 81 void wait_attach();
va009039 3:a3872f7593e2 82 Data01 data01;
va009039 3:a3872f7593e2 83 ODD_EVEN tx_ptr;
va009039 3:a3872f7593e2 84 ODD_EVEN rx_ptr;
va009039 3:a3872f7593e2 85 static USBHALHost * instHost;
va009039 3:a3872f7593e2 86 };