📄 f3xx_usb0_interruptserviceroutine.h
字号:
/** @file
* Header for USB ISR functionality (SiLabs).
* @addtogroup usb_code
* @{
*/
#ifndef USB_ISR_H__
#define USB_ISR_H__
#include <stdint.h>
#include <stdbool.h>
extern uint8_t USB0_STATE;
extern bool ep1_sent, ep2_sent, ep3_sent;
//#define _USB_LOW_SPEED_ // Change this comment to make
// Full/Low speed
//-----------------------------------------------------------------------------
// WORD type definition, for KEIL Compiler
//-----------------------------------------------------------------------------
#ifndef _WORD_DEF_ // Compiler Specific, written
// for Little Endian
#define _WORD_DEF_
typedef union {
uint16_t i;
uint8_t c[2];
} WORD;
#define cLSB 1 // All words sent to and received
//from the host are
#define cMSB 0 // little endian, this is switched
// by software when neccessary.
// These sections of code have been
// marked with "Compiler Specific"
// as above for easier modification
#endif /* _WORD_DEF_ */
//-----------------------------------------------------------------------------
// Define Endpoint Packet Sizes
//-----------------------------------------------------------------------------
#ifdef _USB_LOW_SPEED_
#define EP0_PACKET_SIZE 0x08 // This value can be 8,16,32,64
// depending on device speed, see
// USB spec
#else
#define EP0_PACKET_SIZE 0x40
#endif /* _USB_LOW_SPEED_ */
#define EP1_PACKET_SIZE 0x000A // Can range 0 - 1024 depending on data
// and transfer type
#define EP1_PACKET_SIZE_LE 0x0A00 // IMPORTANT- this should be
// Little-Endian version of
// EP1_PACKET_SIZE
#define EP2_PACKET_SIZE 0x000A // Can range 0 - 1024 depending on data
// and transfer type
#define EP2_PACKET_SIZE_LE 0x0A00 // IMPORTANT- this should be
// Little-Endian version of
// EP2_PACKET_SIZE
//-----------------------------------------------------------------------------
// Standard Descriptor Types
//-----------------------------------------------------------------------------
#define DSC_DEVICE 0x01 // Device Descriptor
#define DSC_CONFIG 0x02 // Configuration Descriptor
#define DSC_STRING 0x03 // String Descriptor
#define DSC_INTERFACE 0x04 // Interface Descriptor
#define DSC_ENDPOINT 0x05 // Endpoint Descriptor
//-----------------------------------------------------------------------------
// HID Descriptor Types
//-----------------------------------------------------------------------------
#define DSC_HID 0x21 // HID Class Descriptor
#define DSC_HID_REPORT 0x22 // HID Report Descriptor
//-----------------------------------------------------------------------------
// Standard Request Codes
//-----------------------------------------------------------------------------
#define GET_STATUS 0x00 // Code for Get Status
#define CLEAR_FEATURE 0x01 // Code for Clear Feature
#define SET_FEATURE 0x03 // Code for Set Feature
#define SET_ADDRESS 0x05 // Code for Set Address
#define GET_DESCRIPTOR 0x06 // Code for Get Descriptor
#define SET_DESCRIPTOR 0x07 // Code for Set Descriptor(not used)
#define GET_CONFIGURATION 0x08 // Code for Get Configuration
#define SET_CONFIGURATION 0x09 // Code for Set Configuration
#define GET_INTERFACE 0x0A // Code for Get Interface
#define SET_INTERFACE 0x0B // Code for Set Interface
#define SYNCH_FRAME 0x0C // Code for Synch Frame(not used)
//-----------------------------------------------------------------------------
// HID Request Codes
//-----------------------------------------------------------------------------
#define GET_REPORT 0x01 // Code for Get Report
#define GET_IDLE 0x02 // Code for Get Idle
#define GET_PROTOCOL 0x03 // Code for Get Protocol
#define SET_REPORT 0x09 // Code for Set Report
#define SET_IDLE 0x0A // Code for Set Idle
#define SET_PROTOCOL 0x0B // Code for Set Protocol
//-----------------------------------------------------------------------------
// Define device states
//-----------------------------------------------------------------------------
#define DEV_ATTACHED 0x00 // Device is in Attached State
#define DEV_POWERED 0x01 // Device is in Powered State
#define DEV_DEFAULT 0x02 // Device is in Default State
#define DEV_ADDRESS 0x03 // Device is in Addressed State
#define DEV_CONFIGURED 0x04 // Device is in Configured State
#define DEV_SUSPENDED 0x05 // Device is in Suspended State
//-----------------------------------------------------------------------------
// Define bmRequestType bitmaps
//-----------------------------------------------------------------------------
#define IN_DEVICE 0x00 // Request made to device,
// direction is IN
#define OUT_DEVICE 0x80 // Request made to device,
// direction is OUT
#define IN_INTERFACE 0x01 // Request made to interface,
// direction is IN
#define OUT_INTERFACE 0x81 // Request made to interface,
// direction is OUT
#define IN_ENDPOINT 0x02 // Request made to endpoint,
// direction is IN
#define OUT_ENDPOINT 0x82 // Request made to endpoint,
// direction is OUT
//-----------------------------------------------------------------------------
// Define wIndex bitmaps
//-----------------------------------------------------------------------------
#define IN_EP1 0x81 // Index values used by Set and Clear
// feature
#define OUT_EP1 0x01 // commands for Endpoint_Halt
#define IN_EP2 0x82
#define OUT_EP2 0x02
//-----------------------------------------------------------------------------
// Define wValue bitmaps for Standard Feature Selectors
//-----------------------------------------------------------------------------
#define DEVICE_REMOTE_WAKEUP 0x01 // Remote wakeup feature(not used)
#define ENDPOINT_HALT 0x00 // Endpoint_Halt feature selector
//-----------------------------------------------------------------------------
// Define Endpoint States
//-----------------------------------------------------------------------------
#define EP_IDLE 0x00 // This signifies Endpoint Idle State
#define EP_TX 0x01 // Endpoint Transmit State
#define EP_RX 0x02 // Endpoint Receive State
#define EP_HALT 0x03 // Endpoint Halt State (return stalls)
#define EP_STALL 0x04 // Endpoint Stall (send procedural stall
// next status phase)
#define EP_ADDRESS 0x05 // Endpoint Address (change FADDR during
// next status phase)
#define EP_GetReport 0x06 // Special Control Endpoint State for
// GetReport HID Request
#define EP_SetReport 0x07 // Special Control Endpoint State for
// SetReport HID Request
//-----------------------------------------------------------------------------
// SETUP Packet Type Definition
//-----------------------------------------------------------------------------
typedef struct
{
uint8_t bmRequestType; // Request recipient, type, and dir.
uint8_t bRequest; // Specific standard request number
WORD wValue; // varies according to request
WORD wIndex; // varies according to request
WORD wLength; // Number of bytes to transfer
} setup_buffer;
//-----------------------------------------------------------------------------
// Function prototypes
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// USB Routines
//-----------------------------------------------------------------------------
void Force_Stall(void); // Forces a procedural stall on Endpoint 0
//-----------------------------------------------------------------------------
// Standard Requests
//-----------------------------------------------------------------------------
void Get_Status(void); // These are called for each specific standard request
void Clear_Feature(void);
void Set_Feature(void);
void Set_Address(void);
void Get_Descriptor(void);
void Get_Configuration(void);
void Set_Configuration(void);
void Get_Interface(void);
void Set_Interface(void);
//-----------------------------------------------------------------------------
// HID Specific Requests
//-----------------------------------------------------------------------------
void Get_Report(void);
void Set_Report(void);
void Get_Idle(void);
void Set_Idle(void);
void Get_Protocol(void);
void Set_Protocol(void);
//-----------------------------------------------------------------------------
// Local Function Definitions
//-----------------------------------------------------------------------------
void Usb_Resume(void); // resumes USB operation
void Usb_Reset(void); // Called after USB bus reset
void Handle_Control(void); // Handle SETUP packet on EP 0
void Handle_In(uint8_t); // used by SetConfiguration in
// USB_STD_REQ to initialize
// ReadyToTransfer
void Handle_Out1(void); // Handle out packet on EP 1
void Usb_Suspend(void); // This routine called when
// suspend signalling on bus
void Fifo_Read(uint8_t, uint16_t, uint8_t*);
// Used for multiple byte reads
// of Endpoint fifos
void Fifo_Write_Foreground(uint8_t, uint16_t, uint8_t*);
// Used for multiple byte writes
// of Endpoint fifos in foreground
void Fifo_Write_InterruptServiceRoutine(uint8_t, uint16_t, uint8_t*);
// Used for multiple byte
// writes of Endpoint fifos
#endif /* USB_ISR_H__ */
/** @} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -