// TITLE: types and definitions used during USB enumeration
#pragma once
//*****************************************************************************
//
// The states for endpoint zero during enumeration.
//
//*****************************************************************************
enum tEP0State{
// The USB device is waiting on a request from the host controller on endpoint zero.
eUSBStateIdle,
// The USB device is sending data back to the host due to an IN request.
eUSBStateTx,
// The USB device is sending the configuration descriptor back to the host due to an IN request.
eUSBStateRx,
// The USB device has completed the IN or OUT request and is now waiting
// for the host to acknowledge the end of the IN/OUT transaction. This
// is the status phase for a USB control transaction.
eUSBStateStatus,
// This endpoint has signaled a stall condition and is waiting for the
// stall to be acknowledged by the host controller.
eUSBStateStall
};
//HACK
//struct tUSBDHIDDevice;
//*****************************************************************************
// The USB controller device information.
//*****************************************************************************
struct tDCDInstance:public tCustomHandlers{
// The current state of endpoint zero.
volatile tEP0State iEP0State;
// The devices current address, this also has a change pending bit in the
// MSB of this value specified by DEV_ADDR_PENDING.
volatile uint8_t ui32DevAddress;
// This holds the current active configuration for this device.
uint8_t ui32Configuration;
// This holds the configuration id that will take effect after a reset.
// uint32_t ui32DefaultConfiguration;
// This holds the current alternate interface for this device.
// uint8_t pui8AltSetting[USB_MAX_INTERFACES_PER_DEVICE];
// This is the pointer to the current data being sent out or received
// on endpoint zero.
uint8_t *pui8EP0Data;
// This is the number of bytes that remain to be sent from or received
// into the g_sUSBDeviceState.pui8EP0Data data buffer.
volatile uint32_t ui32EP0DataRemain;
// Holds the current device status.
uint8_t ui8Status;
// This flag indicates whether or not remote wake up signaling is in
// progress.
bool bRemoteWakeup;
// During remote wake up signaling, this counter is used to track the
// number of milliseconds since the signaling was initiated.
uint8_t ui8RemoteWakeupCount;
// The DMA instance information for this USB controller.
tUSBDMAInstance *psDMAInstance;
// The interrupt number for this instance.
uint32_t ui32IntNum;
// Pointer to the device supplied call back data.
// tUSBDHIDDevice*pvCBData;
};
struct tDeviceInfo;
//extern tDCDInstance g_psDCDInst;
extern tDeviceInfo *g_UsbDevice;
//*****************************************************************************
//
// Device enumeration functions provided by device/usbenum.c and called from
// the interrupt handler in device/usbhandler.c
//
//*****************************************************************************
bool USBDeviceConfig(tDCDInstance *psDevInst/*, const tConfigHeader *psConfig*/);
//bool USBDeviceConfigAlternate(tDCDInstance *psDevInst, const tConfigHeader *psConfig, uint8_t ui8InterfaceNum, uint8_t ui8AlternateSetting);
void USBDCDDeviceInfoInit(tDeviceInfo *psDevice);
//*****************************************************************************
// Macro access function to device information.
//*****************************************************************************
#define DCDGetDMAInstance(psDevInfo) (&(psDevInfo->psDCDInst->sDMAInstance))
//*****************************************************************************
//! This structure is passed to the USB library on a call to USBDCDInit and
//! provides the library with information about the device that the
//! application is implementing. It contains functions pointers for the
//! various USB event handlers and pointers to each of the standard device
//! descriptors.
//*****************************************************************************
struct tDeviceInfo:public tDCDInstance{
//! A pointer to a structure containing pointers to event handler functions
//! provided by the client to support the operation of this device.
// const * psCallbacks;
//! pointer to the descriptors
struct{
const uint8_t *device, *config, *hid, *hidrep;
}desc;
// device: len=18; config: len=word[2], hid: len=9, hidrep: len=word(hid[6])
//
//! A pointer to the string descriptor array for this device. This array
//! must be arranged as follows:
//!
//! - [0] - Standard descriptor containing supported language codes.
//! - [1] - String 1 for the first language listed in descriptor 0.
//! - [2] - String 2 for the first language listed in descriptor 0.
//! - ...
//! - [n] - String n for the first language listed in descriptor 0.
//! - [n+1] - String 1 for the second language listed in descriptor 0.
//! - ...
//! - [2n] - String n for the second language listed in descriptor 0.
//! - [2n+1]- String 1 for the third language listed in descriptor 0.
//! - ...
//! - [3n] - String n for the third language listed in descriptor 0.
//!
//! and so on.
//
const uint8_t * const *ppui8StringDescriptors;
//
//! The total number of descriptors provided in the ppStringDescriptors
//! array.
//
uint32_t ui32NumStringDescriptors;
void Init();
void Term();
void StallEP0();
void RequestDataEP0(uint8_t*,uint32_t);
void SendDataEP0(const uint8_t*,uint32_t);
void SendDataEP0(const uint8_t *data, uint32_t size, const tUSBRequest*rq);
void PowerStatusSet(bool selfpower);
bool RemoteWakeupRequest();
static void USB0DeviceIntHandler();
void DeviceInfoInit();
private:
void ReadAndDispatchRequest();
void DeviceEnumHandler();
static void USBDeviceIntHandlerInternal(uint32_t, uint32_t);
};
Detected encoding: ASCII (7 bit) | 2
|