-
-
Save shima-529/567fe38991289e13c81e69f8d7a22ea1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void usb_device_init(void); | |
void usb_device_isr(void) __interrupt(8); | |
#ifdef USE_USB_DEFINE_ | |
/***** USB Protocol Macros *****/ | |
// bRequest Definitions (in SETUP packet) | |
#define GET_STATUS 0 | |
#define CLEAR_FEATURE 1 | |
#define SET_FEATURE 3 | |
#define SET_ADDRESS 5 | |
#define GET_DESCRIPTOR 6 | |
#define SET_DESCRIPTOR 7 | |
#define GET_CONFIGURATION 8 | |
#define SET_CONFIGURATION 9 | |
#define GET_INTERFACE 10 | |
#define SET_INTERFACE 11 | |
#define SYNCH_FRAME 12 | |
// SETUP Packet TypeDef | |
typedef union { | |
unsigned char raw[8]; | |
struct { | |
unsigned char bmRequestType; | |
unsigned char bRequest; | |
unsigned int wValue; | |
unsigned int wIndex; | |
unsigned int wLength; | |
}; | |
} USBSetupPacket; | |
// Standard Descriptor Type | |
#define DEVICE_DESCRIPTOR 1 | |
#define CONFIGURATION_DESCRIPTOR 2 | |
#define STRING_DESCRIPTOR 3 | |
#define INTERFACE_DESCRIPTOR 4 | |
#define ENDPOINT_DESCRIPTOR 5 | |
/***** Register Bit Macros *****/ | |
// Utilities | |
#define BIT(n) (1 << (n)) | |
#define BSHIFT(x, n) ((x) << (n)) | |
/* UEPn_CTRL */ | |
// NOTE: This reg should not be OR'ed or AND'ed. | |
#define bUEP_R_TOG BIT(7) | |
#define bUEP_T_TOG BIT(6) | |
#define bUEP_R_RES_ACK BSHIFT(0, 2) | |
#define bUEP_R_RES_NOTHING BSHIFT(1, 2) | |
#define bUEP_R_RES_NAK BSHIFT(2, 2) | |
#define bUEP_R_RES_STALL BSHIFT(3, 2) | |
#define bUEP_T_RES_ACK BSHIFT(0, 0) | |
#define bUEP_T_RES_NOTHING BSHIFT(1, 0) | |
#define bUEP_T_RES_NAK BSHIFT(2, 0) | |
#define bUEP_T_RES_STALL BSHIFT(3, 0) | |
/* USB_INT_FG */ | |
#define U_IS_NAK BIT(7) | |
#define U_TOG_OK BIT(6) | |
#define U_SIE_FREE BIT(5) | |
#define UIF_FIFO_OV BIT(4) | |
#define UIF_HST_SOF BIT(3) | |
#define UIF_SUSPEND BIT(2) | |
#define UIF_TRANSFER BIT(1) | |
#define UIF_DETECT BIT(0) | |
#define UIF_BUS_RESET BIT(0) | |
/* USB_INT_ST */ | |
#define bUIS_IS_NAK BIT(7) | |
#define bUIS_TOG_OK BIT(6) | |
#define bUIS_TOKEN BSHIFT(3, 4) | |
#define bUIS_TOKEN_OUT BSHIFT(0, 4) | |
#define bUIS_TOKEN_SOF BSHIFT(1, 4) | |
#define bUIS_TOKEN_IN BSHIFT(2, 4) | |
#define bUIS_TOKEN_SETUP BSHIFT(3, 4) | |
#define MASK_UIS_ENDP BSHIFT(0xF, 0) | |
#define MASK_UIS_H_RES BSHIFT(0xF, 0) | |
#endif // USE_USB_DEFINE_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment