// TITLE: Main header file for the USB Library
#pragma once
#ifdef __TMS320C28XX__
#define INT_USB INT_USBA // USB Define for C28x.
#define USB_BASE USBA_BASE // USB Define for C28x.
#else
#define INT_USB INT_USB0 // USB Define for CM.
#define USB_BASE USB0_BASE // USB Define for C28x.
#endif
// USB-Request als Byte-struct erspart Alignment-Probleme
typedef struct tUSBRequest{
//! Determines the type and direction of the request.
uint8_t bmRequestType,
//! Identifies the specific request being made.
bRequest,
//! Word-sized field that varies according to the request.
wValueL, wValueH,
//! Word-sized field that varies according to the request; typically used
//! to pass an index or offset.
wIndexL, wIndexH,
//! The number of bytes to transfer if there is a data stage to the
//! request.
wLengthL, wLengthH;
#ifdef __cplusplus
uint16_t wRequest() const {return bRequest<<8|bmRequestType;}
uint16_t wValue() const {return wValueH<<8|wValueL;}
uint16_t wIndex() const {return wIndexH<<8|wIndexL;}
uint16_t wLength() const {return wLengthH<<8|wLengthL;}
void limitLength(uint32_t&l) const {if (l>wLength()) l=wLength();}
void limitLength(volatile uint32_t&l) const {if (l>wLength()) l=wLength();}
#endif
}tUSBRequest;
//*****************************************************************************
//! Generate two-byte, three-byte, and four-byte value for USB descriptor
//*****************************************************************************
#define USB2(v) (v) & 0xff, (v) >> 8
#define USB3(v) (v) & 0xff, (v) >> 8 & 0xff, (v)>> 16 & 0xff
#define USB4(v) (v) & 0xff, (v) >> 8 & 0xff, (v)>> 16 & 0xff, (v)>>24 & 0xff
#if 0
struct tUSBDHIDDevice;
//*****************************************************************************
//
// Function prototype for any standard USB request.
//
//*****************************************************************************
typedef void (* tStdRequest)(tUSBDHIDDevice*pvInstance, tUSBRequest *pUSBRequest);
//*****************************************************************************
//
// Data callback for receiving data from an endpoint.
//
//*****************************************************************************
typedef void (* tInfoCallback)(tUSBDHIDDevice*pvInstance, uint32_t ui32Info);
//*****************************************************************************
//
// Callback made to indicate that an interface alternate setting change has
// occurred.
//
//*****************************************************************************
typedef void (* tInterfaceCallback)(tUSBDHIDDevice*pvInstance, uint8_t ui8InterfaceNum,
uint8_t ui8AlternateSetting);
//*****************************************************************************
//
// Generic interrupt handler callbacks.
//
//*****************************************************************************
typedef void (* tUSBIntHandler)(tUSBDHIDDevice*pvInstance);
//*****************************************************************************
//
// Interrupt handler callbacks that have status information.
//
//*****************************************************************************
typedef void (* tUSBEPIntHandler)(tUSBDHIDDevice*pvInstance, uint32_t ui32Status);
//*****************************************************************************
//
// Generic handler callbacks that are used when the callers needs to call into
// an instance of class.
//
//*****************************************************************************
typedef void (* tUSBDeviceHandler)(tUSBDHIDDevice*pvInstance, uint32_t ui32Request,
void *pvRequestData);
#endif
//*****************************************************************************
//
//! USB event handler functions used during enumeration and operation of the
//! device stack.
//
//*****************************************************************************
struct tCustomHandlers {
//! This callback is made whenever the USB host requests a non-standard
//! descriptor from the device.
virtual bool cbGetDescriptor(tUSBRequest*) {return false;}
//! This callback is made whenever the USB host makes a non-standard
//! request.
virtual bool cbRequestHandler(tUSBRequest*) {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() {}
//! 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) {}
};
//*****************************************************************************
//
// USB descriptor parsing functions found in usbdesc.c
//
//*****************************************************************************
//*****************************************************************************
//
//! The USB_DESC_ANY label is used as a wild card in several of the descriptor
//! parsing APIs to determine whether or not particular search criteria should
//! be ignored.
//
//*****************************************************************************
#define USB_DESC_ANY 0xFFFFFFFF
//*****************************************************************************
//
//! The operating mode required by the USB library client. This type is used
//! by applications which wish to be able to switch between host and device
//! modes by calling the USBStackModeSet() API.
//
//*****************************************************************************
enum tUSBMode{
//! Operate in USB device mode with active monitoring of VBUS and the
//! ID pin must be pulled to a logic high value.
eUSBModeDevice,
//! Operate in USB host mode with active monitoring of VBUS and the ID pin
//! must be pulled to a logic low value.
eUSBModeHost,
//! Operate as an On-The-Go device which requires both VBUS and ID to be
//! connected directly to the USB controller from the USB connector.
eUSBModeOTG,
//! A marker indicating that no USB mode has yet been set by the
//! application.
eUSBModeNone,
//! Force host mode so that the VBUS and ID pins are not used or monitored
//! by the USB controller.
eUSBModeForceHost,
//! Forcing device mode so that the VBUS and ID pins are not used or
//! monitored by the USB controller.
eUSBModeForceDevice,
};
//*****************************************************************************
// A pointer to a USB mode callback function. This function is called by the
// USB library to indicate to the application which operating mode it should
// use, host or device.
//*****************************************************************************
//typedef void (*tUSBModeCallback)(uint32_t ui32Index, tUSBMode iMode);
//*****************************************************************************
//! USB callback function.
//!
//! \param pvCBData is the callback pointer associated with the instance
//! generating the callback. This is a value provided by the client during
//! initialization of the instance making the callback.
//! \param ui32Event is the identifier of the asynchronous event which is being
//! notified to the client.
//! \param ui32MsgParam is an event-specific parameter.
//! \param pvMsgData is an event-specific data pointer.
//!
//! A function pointer provided to the USB layer by the application
//! which will be called to notify it of all asynchronous events relating to
//! data transmission or reception. This callback is used by device class
//! drivers and host pipe functions.
//!
//! \return Returns an event-dependent value.
//
//*****************************************************************************
//typedef uint32_t (* tUSBCallback)(void *pvCBData, uint32_t ui32Event,
// uint32_t ui32MsgParam, void *pvMsgData);
//*****************************************************************************
//
// Error sources reported via USB_EVENT_ERROR.
//
//*****************************************************************************
//! The host received an invalid PID in a transaction.
#define USBERR_HOST_IN_PID_ERROR 0x01000000
//! The host did not receive a response from a device.
#define USBERR_HOST_IN_NOT_COMP 0x00100000
//! The host received a stall on an IN endpoint.
#define USBERR_HOST_IN_STALL 0x00400000
//! The host detected a CRC or bit-stuffing error (isochronous mode).
#define USBERR_HOST_IN_DATA_ERROR 0x00080000
//! The host received NAK on an IN endpoint for longer than the specified
//! timeout period (interrupt, bulk and control modes).
#define USBERR_HOST_IN_NAK_TO 0x00080000
//! The host failed to communicate with a device via an IN endpoint.
#define USBERR_HOST_IN_ERROR 0x00040000
//! The host receive FIFO is full.
#define USBERR_HOST_IN_FIFO_FULL 0x00020000
//
//! The host received NAK on an OUT endpoint for longer than the specified
//! timeout period (bulk, interrupt and control modes).
#define USBERR_HOST_OUT_NAK_TO 0x00000080
//! The host did not receive a response from a device (isochronous mode).
#define USBERR_HOST_OUT_NOT_COMP 0x00000080
//! The host received a stall on an OUT endpoint.
#define USBERR_HOST_OUT_STALL 0x00000020
//! The host failed to communicate with a device via an OUT endpoint.
#define USBERR_HOST_OUT_ERROR 0x00000004
//! The host received NAK on endpoint 0 for longer than the configured
//! timeout.
#define USBERR_HOST_EP0_NAK_TO 0x00000080
//! The host failed to communicate with a device via an endpoint zero.
#define USBERR_HOST_EP0_ERROR 0x00000010
//! The device detected a CRC error in received data.
#define USBERR_DEV_RX_DATA_ERROR 0x00080000
//! The device was unable to receive a packet from the host since the receive
//! FIFO is full.
#define USBERR_DEV_RX_OVERRUN 0x00040000
//! The device receive FIFO is full.
#define USBERR_DEV_RX_FIFO_FULL 0x00020000
#if 0
//! This structure is used to return generic event based information to an
//! application. The following events are currently supported:
//! USB_EVENT_CONNECTED, USB_EVENT_DISCONNECTED, USB_EVENT_POWER_FAULT,
//! USB_EVENT_POWER_FAULT, USB_EVENT_POWER_ENABLE,
//! USB_EVENT_POWER_DISABLE and USB_EVENT_SOF.
//
//*****************************************************************************
struct tEventInfo {
//! One of the USB_EVENT_ values.
uint32_t ui32Event;
//! The caller supplied instance value that is passed to event handlers.
uint32_t ui32Instance;
};
#endif
//*****************************************************************************
// Base identifiers for groups of USB events. These are used by both the
// device class drivers and host layer.
//
// USB_CLASS_EVENT_BASE is the lowest identifier that should be used for
// a class-specific event. Individual event bases are defined for each
// of the supported device class drivers. Events with IDs between
// USB_EVENT_BASE and USB_CLASS_EVENT_BASE are reserved for stack use.
//
//*****************************************************************************
#define USB_EVENT_BASE 0x0000
#define USB_CLASS_EVENT_BASE 0x8000
//*****************************************************************************
//
// Event base identifiers for the various device classes supported in host
// and device modes.
// The first 0x800 values of a range are reserved for the device specific
// messages and the second 0x800 values of a range are used for the host
// specific messages for a given class.
//
//*****************************************************************************
#define USBD_CDC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0)
#define USBD_HID_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x1000)
#define USBD_HID_KEYB_EVENT_BASE \
(USBD_HID_EVENT_BASE + 0x100)
#define USBD_BULK_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x2000)
#define USBD_MSC_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x3000)
#define USBD_AUDIO_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x4000)
#define USBD_DFU_EVENT_BASE (USB_CLASS_EVENT_BASE + 0x5000)
#define USBH_CDC_EVENT_BASE (USBD_CDC_EVENT_BASE + 0x800)
#define USBH_HID_EVENT_BASE (USBD_HID_EVENT_BASE + 0x800)
#define USBH_BULK_EVENT_BASE (USBD_BULK_EVENT_BASE + 0x800)
#define USBH_MSC_EVENT_BASE (USBD_MSC_EVENT_BASE + 0x800)
#define USBH_AUDIO_EVENT_BASE (USBD_AUDIO_EVENT_BASE + 0x800)
//*****************************************************************************
//
// General events supported by device classes and host pipes.
//
//*****************************************************************************
//
//! The device is now attached to a USB host and ready to begin sending
//! and receiving data (used by device classes only).
//
#define USB_EVENT_CONNECTED (USB_EVENT_BASE + 0)
//
//! The device has been disconnected from the USB host (used by device classes
//! only).
//!
//! \note In device mode, the USB_EVENT_DISCONNECTED will not be reported if
//! the MCU's PB1/USB0VBUS pin is connected to a fixed +5 Volts rather than
//! directly to the VBUS pin on the USB connector.
//
#define USB_EVENT_DISCONNECTED (USB_EVENT_BASE + 1)
//
//! Data has been received and is in the buffer provided or is ready to be
//! read from the FIFO. If the \e pvMsgData value is 0 then the
//! \e ui32MsgParam value contains the amount of data in bytes ready to be read
//! from the device. If the \e pvMsgData value is not 0 then \e pvMsgData is
//! a pointer to the data that was read and \e ui32MsgParam is the number of
//! valid bytes in the array pointed to by \e pvMsgData.
//
#define USB_EVENT_RX_AVAILABLE (USB_EVENT_BASE + 2)
//
//! This event is sent by a lower layer to inquire about the amount of
//! unprocessed data buffered in the layers above. It is used in cases
//! where a low level driver needs to ensure that all preceding data has
//! been processed prior to performing some action or making some notification.
//! Clients receiving this event should return the number of bytes of data
//! that are unprocessed or 0 if no outstanding data remains.
//
#define USB_EVENT_DATA_REMAINING \
(USB_EVENT_BASE + 3)
//
//! This event is sent by a lower layer supporting DMA to request a buffer in
//! which the next received packet may be stored. The \e ui32MsgValue
//! parameter indicates the maximum size of packet that can be received in this
//! channel and \e pvMsgData points to storage which should be written with the
//! returned buffer pointer. The return value from the callback should be the
//! size of the buffer allocated (which may be less than the maximum size
//! passed in \e ui32MsgValue if the client knows that fewer bytes are expected
//! to be received) or 0 if no buffer is being returned.
//
#define USB_EVENT_REQUEST_BUFFER \
(USB_EVENT_BASE + 4)
//
//! Data has been sent and acknowledged. If this event is received via the
//! USB buffer callback, the \e ui32MsgValue parameter indicates the number of
//! bytes from the transmit buffer that have been successfully transmitted
//! and acknowledged.
//
#define USB_EVENT_TX_COMPLETE (USB_EVENT_BASE + 5)
//
//! An error has been reported on the channel or pipe. The \e ui32MsgValue
//! parameter indicates the source(s) of the error and is the logical OR
//! combination of "USBERR_" flags defined below.
//
#define USB_EVENT_ERROR (USB_EVENT_BASE + 6)
//
//! The bus has entered suspend state.
//
#define USB_EVENT_SUSPEND (USB_EVENT_BASE + 7)
//
//! The bus has left suspend state.
//
#define USB_EVENT_RESUME (USB_EVENT_BASE + 8)
//
//! A scheduler event has occurred.
//
#define USB_EVENT_SCHEDULER (USB_EVENT_BASE + 9)
//
//! A device or host has detected a stall condition.
//
#define USB_EVENT_STALL (USB_EVENT_BASE + 10)
//
//! The host detected a power fault condition.
//
#define USB_EVENT_POWER_FAULT (USB_EVENT_BASE + 11)
//
//! The controller has detected a A-Side cable and needs power applied This is
//! only generated on OTG parts if automatic power control is disabled.
//
#define USB_EVENT_POWER_ENABLE (USB_EVENT_BASE + 12)
//
//! The controller needs power removed, This is only generated on OTG parts
//! if automatic power control is disabled.
//
#define USB_EVENT_POWER_DISABLE (USB_EVENT_BASE + 13)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the interface number. This
//! event is typically due to the class being included in a composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_IFACE_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old interface number and the second is the new interface number.
//
#define USB_EVENT_COMP_IFACE_CHANGE \
(USB_EVENT_BASE + 14)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the endpoint number. This
//! event is typically due to the class being included in a composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_EP_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old endpoint number and the second is the new endpoint number. The
//! endpoint numbers should be exactly as USB specification defines them and
//! bit 7 set indicates an IN endpoint and bit 7 clear indicates an OUT
//! endpoint.
//
#define USB_EVENT_COMP_EP_CHANGE \
(USB_EVENT_BASE + 15)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the string index number for a
//! string. This event is typically due to the class being included in a
//! composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_STR_CHANGE.
//!
//! The \e pvRequestData is a pointer to a two byte array where the first value
//! is the old string index and the second is the new string index.
//
#define USB_EVENT_COMP_STR_CHANGE \
(USB_EVENT_BASE + 16)
//
//! This define is used with a device class's pfnDeviceHandler handler function
//! to indicate that the USB library has changed the configuration descriptor.
//! This allows the class to make final adjustments to the configuration
//! descriptor. This event is typically due to the class being included in a
//! composite device.
//!
//! The \e pvInstance is a pointer to an instance of the device being accessed.
//!
//! The \e ui32Request is USB_EVENT_COMP_CONFIG.
//!
//! The \e pvRequestData is a pointer to the beginning of the configuration
//! descriptor for the device instance.
//
#define USB_EVENT_COMP_CONFIG (USB_EVENT_BASE + 17)
//
//! An unknown device is now attached to a USB host. This value is only valid
//! for the generic event handler and not other device handlers. It is
//! useful for applications that want to know when an unknown device is
//! connected and what the class is of the unknown device.
//!
//! The \e ui32Instance is the device instance for the unknown device.
//
#define USB_EVENT_UNKNOWN_CONNECTED \
(USB_EVENT_BASE + 18)
//
//! A start of frame event has occurred. This event is disabled by default
//! and must be enabled via a call from the application to USBHCDEventEnable().
//
#define USB_EVENT_SOF (USB_EVENT_BASE + 19)
//typedef uint32_t (* tUSBPacketTransfer)(void *pvHandle, uint8_t *pi8Data,
// uint32_t ui32Length, bool bLast);
//*****************************************************************************
//
//! A function pointer type which describes either a class driver transmit
//! or receive packet available function (both have the same prototype) to the
//! USB buffer object.
//!
//! \param pvHandle is the handle of the device.
//!
//! \return None.
//
//*****************************************************************************
//typedef uint32_t (* tUSBPacketAvailable)(void *pvHandle);
//*****************************************************************************
//
//! The number of bytes of workspace that each USB buffer object requires.
//! This workspace memory is provided to the buffer on USBBufferInit() in
//! the \e pvWorkspace field of the \e tUSBBuffer structure.
//
//*****************************************************************************
//#define USB_BUFFER_WORKSPACE_SIZE 24
Detected encoding: UTF-8 | 0
|