Source file: /~heha/ewa/Motor/Maxmaus5.zip/usblib/usbdevice.h

// TITLE: types and definitions used during USB enumeration
#pragma once
#include "usblib.h"	//tCustomHandlers
#include "usblibpriv.h"	//tUSBDMAInstance

//*****************************************************************************
//
// 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 tDeviceInfo: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;
  // Holds the current device status.
  uint8_t ui8Status;
  // This flag indicates whether or not remote wake up signaling is in
  // progress.
  bool bRemoteWakeup;
    // 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;
    // 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;
  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();
  void IntHandlerInternal(uint32_t, uint32_t);
  void ResumeTickHandler();
  bool Config();
  void InfoInit();
  void EnumResetHandler();
  void EP0StateTx();
};

//extern tDeviceInfo *g_UsbDevice;

//*****************************************************************************
// Macro access function to device information.
//*****************************************************************************
#define DCDGetDMAInstance(p)    (&(p)->sDMAInstance)
Detected encoding: ASCII (7 bit)2