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: F401RE-USBHostMIDI_RecieveExample
Fork of F401RE-USBHost by
USBHost.h
- Committer:
- va009039
- Date:
- 2014-01-21
- Revision:
- 1:c072d9e580b0
- Parent:
- 0:5160ee0c522d
- Child:
- 2:0cdac6bcc534
File content as of revision 1:c072d9e580b0:
// Simple USBHost for FRDM-KL46Z
#include "mbed.h"
#pragma once
struct SETUP_PACKET {
uint8_t bmRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
};
#define SET_ADDRESS 5
#define GET_DESCRIPTOR 6
#define GET_CONFIGURATION 8
#define SET_CONFIGURATION 9
// TOK_PID[5:2]
#define DATA0 0x03
#define DATA1 0x0b
#define ACK 0x02
#define STALL 0x0e
#define NAK 0x0a
#define Bus_Timeout 0x00
#define Data_Error 0x0f
enum ODD_EVEN {
ODD = 0,
EVEN = 1,
};
class USBHost {
public:
static USBHost* getHostInst();
int InterruptRead(uint8_t* data, int size);
int ControlRead(SETUP_PACKET* setup, uint8_t* data, int size);
int ControlWrite(SETUP_PACKET* setup, uint8_t* data = NULL, int size = 0);
int BulkRead(uint8_t* data, int size);
int BulkWrite(const uint8_t* data, int size);
uint8_t LastStatus;
protected:
USBHost();
void init();
void wait_attach();
bool enumeration();
uint8_t ep_int_in;
uint8_t ep_bulk_in;
uint8_t ep_bulk_out;
int MaxPacketSize0;
bool lowSpeed;
int dev_addr;
private:
static void _usbisr(void);
int token_setup(SETUP_PACKET* setup, uint16_t wLength = 0);
int token_in(uint8_t ep, uint8_t* data = NULL, int size = 0);
int token_out(uint8_t ep, const uint8_t* data = NULL, int size = 0);
void token_ready();
void UsbIrqhandler();
__IO bool attach_done;
__IO bool token_done;
ODD_EVEN tx_ptr;
ODD_EVEN rx_ptr;
uint8_t tx_data01[16];
uint8_t rx_data01[16];
static USBHost* inst;
};
