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

// TITLE: Definitions used by HID class devices
#pragma once

enum tHIDState{
    eHIDStateUnconfigured,    // Unconfigured.
    eHIDStateIdle,    // No outstanding transaction remains to be completed.
    eHIDStateWaitData    // Waiting on completion of a send or receive transaction.
};
#if 0
//*****************************************************************************
//! The structure used to track idle time for reports.  An array of these
//! structures is passed to the HID device class driver during USBDHIDInit and
//! is used to track automatic resending of each report (if not disabled by
//! the host).
//*****************************************************************************
struct tHIDReportIdle {
    //! The idle duration for the report expressed in units of 4mS.  0
    //! indicates infinite and informs the class driver not to send the report
    //! unless a state change occurs.
    uint8_t ui8Duration4mS;
    //! The ID of the report which this structure applies to.  This is the
    //! report ID as specified using a ReportID tag in the report descriptor
    //! rather than the index of the report in the HID class descriptor array.
    //! If only a single Input report is supported and, thus, no ReportID tag
    //! is present, this field should be set to 0.
    uint8_t ui8ReportID;
    //! The number of milliseconds before we need to send a copy of a given
    //! report back to the host.  This field is updated by the HID driver and
    //! used to time sending of USBD_HID_EVENT_IDLE_TIMEOUT.
    uint16_t ui16TimeTillNextmS;
    //! The number of milliseconds that have passed since the last time this
    //! report was sent.  The HID class driver needs to track this since
    //! Set_Idle requests are required to take effect as if issued immediately
    //! after the last transmission of the report to which they refer.
    uint32_t ui32TimeSinceReportmS;
};
#endif
//*****************************************************************************
//! The structure used by the application to define operating parameters for
//! the HID device.
//*****************************************************************************
struct tUSBDHIDDevice:public tDeviceInfo{
    // Base address for the USB controller.
  uint32_t ui32USBBase;
    // The device info to interact with the lower level DCD code.
    // The state of the HID receive channel.
  volatile tHIDState iHIDRxState;
    // The state of the HID transmit channel.
  volatile tHIDState iHIDTxState;
    // State of any pending operations that could not be handled immediately
    // upon receipt.
  volatile uint16_t ui16DeferredOpFlags;
    // Size of the HID IN report.
  uint16_t ui16InReportSize;
  uint16_t ui16InReportIndex;
    // Size of the HID OUT report.
  uint16_t ui16OutReportSize;
    // Pointer to the current HID IN report data.
  uint8_t *pui8InReportData;
    // Pointer to the current HID OUT report data.
  uint8_t *pui8OutReportData;
    // The connection status of the device.
  volatile bool bConnected;
    // Whether an IN transaction is in process.
  volatile bool bSendInProgress;
    // An HID request transaction is in process(Endpoint 0).
  bool bGetRequestPending;
    // The IN endpoint number, this is modified in composite devices.
  uint8_t ui8INEndpoint;
    // The OUT endpoint number, this is modified in composite devices.
  uint8_t ui8OUTEndpoint;
    // The bulk class interface number, this is modified in composite devices.
  uint8_t ui8Interface;
    //! A pointer to the first element in an array of structures used to track
    //! idle time for each Input report.  When USBDHIDInit is called, the
    //! ui8Duration4mS and ui8ReportID fields of each of these array members
    //! should be initialized to indicate the default idle timeout for each
    //! input report.  This array must be in RAM since the HID device class
    //! driver will update values in it in response to requests from the host
    //! and to track elapsed time.  The number of elements in the array must
    //! match the number supplied in the ui8NumInputReports field above.
    //
//  tHIDReportIdle *psReportIdle;

    //! A pointer to the callback function which will be called to notify
    //! the application of general events, events related to report transfers
    //! on endpoint zero and events related to reception of Output and Feature
    //! reports via the (optional) interrupt OUT endpoint.
    //
  virtual uint32_t RxCallback(uint32_t,uint32_t, void*) {return 0;}

  void *Init();
  void Term();
//  void *SetRxCBData(void *pvCBData);
//  void *SetTxCBData(void *pvCBData);
  uint32_t ReportWrite(uint8_t *pi8Data, uint32_t ui32Length, bool bLast);
  uint32_t PacketRead(uint8_t *pi8Data, uint32_t ui32Length, bool bLast);
  uint32_t TxPacketAvailable();
  uint32_t RxPacketAvailable();
private:
  virtual void TickHandler(uint32_t);
  bool cbGetDescriptor(tUSBRequest*) override;
  bool cbRequestHandler(tUSBRequest*) override;
  void cbDisconnectHandler() override;
  void cbSuspendHandler() override;
  void cbResumeHandler() override;
  void cbResetHandler() override;
  void cbConfigChange(uint32_t) override;

//  void ClearReportTimer(uint8_t ui8ReportID)const;
//  void ClearIdleTimers()const;
//  void ProcessIdleTimers(uint32_t ms);
//  void SetIdleTimeout(uint8_t ui8ReportID, uint8_t ui8Timeout4mS);
//  uint32_t GetIdleTimeout(uint8_t ui8ReportID)const;
//  int32_t ScheduleReportTransmission();
  bool ProcessDataFromHost(uint32_t);
  bool ProcessDataToHost(uint32_t);
  void HandleEndpoints(uint32_t);
  void HandleDevice(uint32_t, void*);
};

//*****************************************************************************
//
//! This event indicates that the host is requesting a particular report be
//! returned via endpoint 0, the control endpoint.  The ui32MsgValue parameter
//! contains the requested report type in the high byte and report ID in the
//! low byte (as passed in the wValue field of the USB request structure).
//! The pvMsgData parameter contains a pointer which must be written with the
//! address of the first byte of the requested report.  The callback must
//! return the size in bytes of the report pointed to by *pvMsgData.  The
//! memory returned in response to this event must remain unaltered until
//! USBD_HID_EVENT_REPORT_SENT is sent.
//
//*****************************************************************************
#define USBD_HID_EVENT_GET_REPORT (USBD_HID_EVENT_BASE + 0)

//*****************************************************************************
//
//! This event indicates that a report previously requested via a
//! USBD_HID_EVENT_GET_REPORT has been successfully transmitted to the host.
//! The application may now free or reuse the report memory passed on the
//! previous event.  Although this would seem to be an event that would be
//! passed to the transmit channel callback, it is actually passed to the
//! receive channel callback.  This ensures that all events related to the
//! request and transmission of reports via endpoint zero can be handled in
//! a single function.
//
//*****************************************************************************
#define USBD_HID_EVENT_REPORT_SENT (USBD_HID_EVENT_BASE + 1)

//*****************************************************************************
//
//! This event indicates that the host has sent a Set_Report request to
//! the device and requests that the device provide a buffer into which the
//! report can be written.  The ui32MsgValue parameter contains the received
//! report type in the high byte and report ID in the low byte (as passed in
//! the wValue field of the USB request structure).  The pvMsgData parameter
//! contains the length of buffer requested.  Note that this is the actual
//! length value cast to a "void *" type and not a pointer in this case.
//! The callback must return a pointer to a suitable buffer (cast to the
//! standard "uint32_t" return type for the callback).
//
//*****************************************************************************
#define USBD_HID_EVENT_GET_REPORT_BUFFER (USBD_HID_EVENT_BASE + 2)

//*****************************************************************************
//
//! This event indicates that the host has sent the device a report via
//! endpoint 0, the control endpoint.  The ui32MsgValue field indicates the
//! size of the report and pvMsgData points to the first byte of the report.
//! The report buffer will previously have been returned in response to an
//! earlier USBD_HID_EVENT_GET_REPORT_BUFFER callback.  The HID device class
//! driver will not access the memory pointed to by pvMsgData after this
//! callback is made so the application is free to reuse or free it at this
//! point.
//
//*****************************************************************************
#define USBD_HID_EVENT_SET_REPORT (USBD_HID_EVENT_BASE + 3)

//*****************************************************************************
//
//! This event is sent in response to a Get_Protocol request from the host.
//! The callback should provide the current protocol via the return code,
//! USB_HID_PROTOCOL_BOOT or USB_HID_PROTOCOL_REPORT.
//
//*****************************************************************************
#define USBD_HID_EVENT_GET_PROTOCOL (USBD_HID_EVENT_BASE + 4)

//*****************************************************************************
//
//! This event is sent in response to a Set_Protocol request from the host.
//! The ui32MsgData value will contain the requested protocol,
//! USB_HID_PROTOCOL_BOOT or USB_HID_PROTOCOL_REPORT.
//
//*****************************************************************************
#define USBD_HID_EVENT_SET_PROTOCOL (USBD_HID_EVENT_BASE + 5)

//*****************************************************************************
//
//! This event indicates to an application that a report idle timeout has
//! occurred and requests a pointer to the report that must be sent back to
//! the host.  The ui32MsgData value will contain the requested report ID and
//! pvMsgData contains a pointer that must be written with a pointer to the
//! report data that is to be sent.  The callback must return the number of
//! bytes in the report pointed to by *pvMsgData.
//
//*****************************************************************************
#define USBD_HID_EVENT_IDLE_TIMEOUT (USBD_HID_EVENT_BASE + 6)

Detected encoding: ASCII (7 bit)2