// TITLE: types and definitions used during USB enumeration
#pragma once
//#include <stdint.h> // uint32_t
//#include <inc/hw_types.h> // uint8_t
#include "usbdma.h" //tUSBDMAInstance
#include "usblib.h" //usb::tRequest
namespace usb{
// 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
};
// The USB controller device information
struct tDevice {
//! USB event handler functions used during enumeration and operation of the
//! device stack.
//! This callback is made whenever the USB host requests a descriptor from the device.
virtual bool cbGetDescriptor(const tRequest&) {return false;}
//! This callback is made whenever the USB host makes a request.
virtual bool cbRequestHandler(const tRequest&) {return false;}
//! This callback is made in response to a SetInterface request from the host.
virtual void cbInterfaceChange(uint8_t InterfaceNum, uint8_t AlternateSetting) {}
//! This callback is made in response to a SetConfiguration request from the host.
virtual void cbConfigChange(uint32_t ui32Info) {}
//! This callback is made when data has been received following to a call
//! to USBDCDRequestDataEP0.
virtual void cbDataReceived(uint32_t ui32Info) {}
//! This callback is made when data has been transmitted following a call
//! to USBDCDSendDataEP0.
// virtual void cbDataSent(uint32_t ui32Info) {}
//! This callback is made when a USB reset is detected.
virtual void cbResetHandler() {}
//! This callback is made when the bus has been inactive long enough to
//! trigger a suspend condition.
// virtual void cbSuspendHandler() {}
//! This is called when resume signaling is detected.
// virtual void cbResumeHandler() {}
//! This callback is made when the device is disconnected from the USB bus.
virtual void cbDisconnectHandler() {cbResetHandler();}
//! This callback is made to inform the device of activity on all endpoints
//! other than endpoint zero.
virtual void cbEndpointHandler(uint32_t) {}
//! This generic handler is provided to allow requests based on
//! a given instance to be passed into a device. This is commonly used
//! by a top level composite device that is using multiple instances of
//! a class.
// virtual void cbDeviceHandler(uint32_t Request, void *pvRequestData) {}
virtual ~tDevice() {} // Fünferregel
// 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;
// Holds the current device status.
uint8_t ui8Status;
// 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 unsigned ui32EP0DataRemain;
// 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;
// descriptors for HID
struct{
const uint8_t *device, *config, *hid, *hidrep;
}desc;
// device: len=18; config: len=word[2], hid: len=9, hidrep: len=word(hid[6])
const uint8_t * const *ppui8StringDescriptors;
bool Init();
void Term();
void StallEP0();
void RequestDataEP0(uint8_t*,uint32_t);
void SendDataEP0(const uint8_t*,unsigned);
void SendDataEP0(const uint8_t*,unsigned, const tRequest&);
void PowerStatusSet(bool selfpower) {if (selfpower) ui8Status|=1; else ui8Status &= ~1;}
bool RemoteWakeupRequest();
static void USB0DeviceIntHandler();
private:
void ReadAndDispatchRequest();
void DeviceEnumHandler();
void IntHandlerInternal(uint32_t, uint32_t);
// void ResumeTickHandler();
// bool Config();
// void InfoInit();
void EnumResetHandler();
void EP0StateTx();
};
}
//*****************************************************************************
// Macro access function to device information.
//*****************************************************************************
#define DCDGetDMAInstance(p) (&(p)->sDMAInstance)
Vorgefundene Kodierung: UTF-8 | 0
|