📄 periph.c
字号:
#pragma NOIV
#include <ezusb.h>
#include <ezregs.h>
#include <intrins.h>
#include <fx.h>
extern BOOL GotSUD; // Received setup data flag
extern BOOL Sleep;
extern BOOL Rwuen;
extern BOOL Selfpwr;
//+++++++++++++++++
#define P0 OUTA
#define P1 OUTB
#define P3 OUTD
//+++++++++++++++++
BYTE Configuration; // Current configuration
BYTE AlternateSetting; // Alternate settings
BYTE suspCount;
BYTE InReportBytes;
void *dscr_ptr;
//-----------------------------------------------------------------------------
// Task Dispatcher hooks
// The following hooks are called by the task dispatcher.
//-----------------------------------------------------------------------------
void TD_Init(void) // Called once at startup
{
PORTACFG = 0x00;
OEA = 0xFF;
PORTBCFG = 0x00;
OEB = 0xFF;
OED = 0xFF;
IN07VAL |= bmEP2 ;
OUT07VAL |= bmEP2;
OUT07IEN |= bmEP2;
IN07IEN |= bmEP2;
suspCount = 1;
OEA = 0xFF;
Rwuen = TRUE; // Enable remote-wakeup
}
void TD_Poll(void) // Called repeatedly while the device is idle
{
}
BOOL TD_Suspend(void) // Called before the device goes into suspend mode
{
return(TRUE);
}
BOOL TD_Resume(void) // Called after the device resumes
{
return(TRUE);
}
//-----------------------------------------------------------------------------
// Device Request hooks
// The following hooks are called by the end point 0 device request parser.
//-----------------------------------------------------------------------------
BOOL DR_GetDescriptor(void)
{
return(TRUE);
}
BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
{
Configuration = SETUPDAT[2];
return(TRUE); // Handled by user code
}
BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
{
IN0BUF[0] = Configuration;
EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
return(TRUE); // Handled by user code
}
BOOL DR_SetInterface(void) // Called when a Set Interface command is received
{
AlternateSetting = SETUPDAT[2];
return(TRUE); // Handled by user code
}
BOOL DR_GetInterface(void) // Called when a Set Interface command is received
{
IN0BUF[0] = AlternateSetting;
EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
return(TRUE); // Handled by user code
}
BOOL DR_GetStatus(void)
{
return(TRUE);
}
BOOL DR_ClearFeature(void)
{
return(TRUE);
}
BOOL DR_SetFeature(void)
{
return(TRUE);
}
#define EZUSB_UNARM_EP(ep_id) EPIO[ep_id].cntrl = bmEPBUSY
BOOL DR_VendorCmnd(void)
{
return(TRUE);
}
//-----------------------------------------------------------------------------
// USB Interrupt Handlers
// The following functions are called by the USB interrupt jump table.
//-----------------------------------------------------------------------------
void ISR_Sudav(void) interrupt 0
{
GotSUD = TRUE; // Set flag
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUDAV; // Clear SUDAV IRQ
}
void ISR_Sutok(void) interrupt 0
{
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUTOK; // Clear SUTOK IRQ
}
void ISR_Sof(void) interrupt 0
{
EZUSB_IRQ_CLEAR();
USBIRQ = bmSOF; // Clear SOF IRQ
}
void ISR_Ures(void) interrupt 0
{
REPORTDSCR *rdp;
dscr_ptr = (REPORTDSCR xdata *) pReportDscr;
rdp = dscr_ptr;
InReportBytes = rdp -> Report_Count_In_Value;
EPIO[IN2BUF_ID].bytes = InReportBytes;
EPIO[OUT2BUF_ID].bytes = 64;
EZUSB_IRQ_CLEAR();
USBIRQ = bmURES; // Clear URES IRQ
}
void ISR_IBN(void) interrupt 0
{
}
void ISR_Susp(void) interrupt 0
{
Sleep = TRUE;
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUSP;
}
void ISR_Ep0in(void) interrupt 0
{
}
void ISR_Ep0out(void) interrupt 0
{
}
void ISR_Ep1in(void) interrupt 0
{
}
void ISR_Ep1out(void) interrupt 0
{
}
void ISR_Ep2in(void) interrupt 0
{
IN2BC = InReportBytes;
EZUSB_IRQ_CLEAR();
IN07IRQ = bmEP2;
}
void ISR_Ep2out(void) interrupt 0
{
int i;
if (EPIO[IN2BUF_ID].cntrl & bmEPBUSY)
{
TOGCTL = 0x08 | IN2BUF_ID;
WRITEDELAY();
if (TOGCTL & 0x80)
TOGCTL |= 0x20;
else
TOGCTL |= 0x40;
}
for (i=0; i < OUT2BC; i++)
{
P0=OUT2BUF[0];
P1=OUT2BUF[1]; //-------------------------------------------------
P3=OUT2BUF[2];
}
OUT2BC = 0;
EZUSB_IRQ_CLEAR();
OUT07IRQ = bmEP2;
}
void ISR_Ep3in(void) interrupt 0
{
}
void ISR_Ep3out(void) interrupt 0
{
}
void ISR_Ep4in(void) interrupt 0
{
}
void ISR_Ep4out(void) interrupt 0
{
}
void ISR_Ep5in(void) interrupt 0
{
}
void ISR_Ep5out(void) interrupt 0
{
}
void ISR_Ep6in(void) interrupt 0
{
}
void ISR_Ep6out(void) interrupt 0
{
}
void ISR_Ep7in(void) interrupt 0
{
}
void ISR_Ep7out(void) interrupt 0
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -