Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768
Dependents: F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld
Fork of KL46Z-USBHost by
USBHALHost_KL46Z.h
00001 #pragma once 00002 #include "mbed.h" 00003 #include "USBHostTypes.h" 00004 #include "USBEndpoint.h" 00005 00006 #define GET_CONFIGURATION 8 00007 00008 // TOK_PID[5:2] 00009 #define Bus_Timeout 0x00 00010 #define Data_Error 0x0f 00011 00012 enum ODD_EVEN { 00013 ODD = 0, 00014 EVEN = 1, 00015 }; 00016 00017 class Report { 00018 public: 00019 void clear(); 00020 void print_errstat(); 00021 // error count 00022 uint32_t errstat_piderr; // USBx_ERRSTAT[PIDERR] 00023 uint32_t errstat_crc5eof;// USBx_ERRSTAT[CRC5EOF] 00024 uint32_t errstat_crc16; // USBx_ERRSTAT[CRC16] 00025 uint32_t errstat_dfn8; // USBx_ERRSTAT[DFN8] 00026 uint32_t errstat_btoerr; // USBx_ERRSTAT[BTOERR] 00027 uint32_t errstat_dmaerr; // USBx_ERRSTAT[DMAERR] 00028 uint32_t errstat_bsterr; // USBx_ERRSTAT[BTSERR] 00029 // 00030 uint32_t nak; 00031 uint32_t stall; 00032 }; 00033 00034 class USBHALHost { 00035 public: 00036 uint8_t LastStatus; 00037 uint8_t prev_LastStatus; 00038 Report report; 00039 00040 protected: 00041 USBHALHost(); 00042 void init(); 00043 virtual bool addDevice(USBDeviceConnected* parent, int port, bool lowSpeed) = 0; 00044 int token_setup(USBEndpoint* ep, SETUP_PACKET* setup, uint16_t wLength = 0); 00045 int multi_token_in(USBEndpoint* ep, uint8_t* data = NULL, size_t total = 0, bool block = true); 00046 int multi_token_out(USBEndpoint* ep, const uint8_t* data = NULL, size_t total = 0); 00047 void multi_token_inNB(USBEndpoint* ep, uint8_t* data, int size); 00048 USB_TYPE multi_token_inNB_result(USBEndpoint* ep); 00049 void setToggle(USBEndpoint* ep, uint8_t toggle); 00050 int token_iso_in(USBEndpoint* ep, uint8_t* data, int size); 00051 00052 private: 00053 void setAddr(int addr, bool lowSpeed = false); 00054 void setEndpoint(); 00055 void token_transfer_init(); 00056 void token_ready(); 00057 int token_in(USBEndpoint* ep, uint8_t* data = NULL, int size = 0, int retryLimit = 10); 00058 int token_out(USBEndpoint* ep, const uint8_t* data = NULL, int size = 0, int retryLimit = 10); 00059 static void _usbisr(void); 00060 void UsbIrqhandler(); 00061 __IO bool attach_done; 00062 __IO bool token_done; 00063 bool wait_attach(); 00064 bool root_lowSpeed; 00065 ODD_EVEN tx_ptr; 00066 ODD_EVEN rx_ptr; 00067 static USBHALHost * instHost; 00068 };
Generated on Wed Jul 13 2022 05:41:27 by 1.7.2