📄 user_lib.c
字号:
/**************** (c) 2000 STMicroelectronics **********************
PROJECT : USB - ST7 FULL SPEED
VERSION : v 0.96
CREATION DATE : 01/12/2000
AUTHOR : MICROCONTROLLER DIVISION / ST Rousset
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
MODIFICATIONS :
******************************************************************************/
#include "mcu_conf.h"
#include "usb_def.h"
#include "usb_reg.h"
#include "usb_Lib.h"
#include "descript.h"
#include "User_lib.h"
#include "appli.h"
#include "MConfig.h"
#include "HID_usb.h"
#pragma DATA_SEG CLASS_RAM
extern unsigned char Current_Operation;
#define RBC_OP_IDLE 0x00
#pragma DATA_SEG CRD_MESSAGE_BUFFER
extern unsigned char UsbMessageBuffer[200];
#pragma CODE_SEG USER_USB_ROM
#pragma DATA_SEG DEFAULT_RAM
unsigned int Reset_point;
unsigned int Set_Label()
{
asm {
LD Y, S
LD A, (0x101, Y)
LD X, A
LD A, (0x102, Y)
}
}
#pragma NO_ENTRY
void Jmp_Label(unsigned int pc)
{
asm {
RSP
LD _LEX, X
LD _LEX:1, A
JP [_LEX.w]
}
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Set_Configuration
INPUT/OUTPUT : None
DESCRIPTION : Assign configuration value sent by Host & reset Stalled EPs.
-----------------------------------------------------------------------------*/
char USER_USB_Set_Configuration(void)
{
// Valid request in ADDRESS_STATE and CONFIGURED_STATE
if (vUSB_Configuration == 0) { // Device is Unconfigured
USB_SetTxEP1Status(EP_DISABLE);
USB_SetRxEP2Status(EP_DISABLE);
}
else { // Device is now configured, you can start your USB Application
BOT_Init();
Crd_Initiate(); // @jin0817
USB_SetTxEP1Status(EP_NAK);
}
return REQ_SUCCESS; // If the configuration is not one of the expected, you can answer an ERROR
// The Library check that vUSB_Configuration is not higher than MAX_NUM_CONFIG
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Set_Interface
INPUT/OUTPUT : None
DESCRIPTION : Change Interface Value
-----------------------------------------------------------------------------*/
char USER_USB_Set_Interface(void)
{
char Interface = sUSB_vSetup.USBwIndex0;
char Alt = sUSB_vSetup.USBwValue0; // the alternate setting number.
// if (Interface == 0 && Alt == 0)
return REQ_SUCCESS;
// @jin0817 else
// return REQ_ERROR;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Get_Interface
INPUT/OUTPUT : None
DESCRIPTION : Change Alternative Interface Setting
-----------------------------------------------------------------------------*/
char USER_USB_Get_Interface(void) // return the alternate setting number.
{
char Interface = sUSB_vSetup.USBwIndex0;
return 0;
}
extern char Startup_VAR;
void USER_USB_Reset()
{
CNT2RXR = 64;
if (Startup_VAR & 0x10)
{
Startup_VAR &= ~0x10;
Jmp_Label(Reset_point);
}
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USB_Status_In
INPUT/OUTPUT : None
DESCRIPTION : Application post process after status IN stage
(if a request need to be executed after a Status_In, for example SET_ADDRESS)
-----------------------------------------------------------------------------*/
void USER_USB_Status_In(void)
{
if (( sUSB_vSetup.USBbmRequestType ==( REQ_TYPE_CLASS | RECIPIENT_INTERFACE ) )&& ( sUSB_vSetup.USBbRequest == SET_REPORT )) {
Set_bTxOutCompleteFlag;
Reset_bDataReadyFlag;
}
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USB_Status_Out
INPUT/OUTPUT : None
DESCRIPTION : Application post process after status OUT stage
-----------------------------------------------------------------------------*/
void USER_USB_Status_Out()
{
if (( sUSB_vSetup.USBbmRequestType == ( REQ_TYPE_CLASS | RECIPIENT_INTERFACE | 0x80 ) ) && (sUSB_vSetup.USBbRequest != GET_REPORT) ) {
} //@jin Set flag after Data In
}
void USER_USB_SOF()
{
asm NOP;
}
void USER_USB_Suspend(){
USBCTLR |= 0x02; // Force SUSPEND mode
My_Suspend();
asm HALT;
}
void USER_USB_ESuspend(){
USBCTLR &= ~0x02; // Clear SUSPEND mode
My_EndSuspend();
}
void USER_USB_WakeUp()
{
asm NOP;
}
#pragma INTO_ROM
const unsigned char CardNotReady[2] = { 1, 0 };
char USER_USB_Setup()
{
extern unsigned char Max_Lun;
extern const char Appli_ReportDescriptor[94];
switch (sUSB_vSetup.USBbmRequestType) {
case REQ_TYPE_STANDARD | RECIPIENT_INTERFACE | 0x80 :
if (sUSB_vSetup.USBbRequest != GET_DESCRIPTOR) // GET_DESCRIPTOR for HID devices
break;
if (sUSB_vSetup.USBwValue1 != 0x22) // HID Descriptor
break;
vUSB_length = sizeof(Appli_ReportDescriptor); // Length of the HID Descriptor
vUSB_DataToSend = Appli_ReportDescriptor;
return REQ_SUCCESS;
case REQ_TYPE_CLASS | RECIPIENT_INTERFACE:
if (sUSB_vSetup.USBwIndex == 1 ) { // for interface1 HID Interface
if (sUSB_vSetup.USBbRequest != SET_REPORT) // GET_DESCRIPTOR for HID devices
break;
if (sUSB_vSetup.USBwValue1 != OUTPUT_REPORT ) //
break;
vUSB_offset = 0;
if ( bTxInCompleteFlag ) {
vUSB_length = sUSB_vSetup.USBwLength;
vUSB_DataToSend = UsbMessageBuffer;
Reset_bTxInCompleteFlag;
}
else {
vUSB_length = 2;
vUSB_DataToSend = CardNotReady; // receive data if databuffer free
}
}
else { // FOR MASS STORAGE INTERFACE
if (sUSB_vSetup.USBbRequest != 0xFF) // Interface Reset for BOT devices
break;
if (sUSB_vSetup.Flag & (NON0_wValue | NON0_wIndex1 | NON0_wLength))
break;
BOT_Reset();
}
return REQ_SUCCESS;
case REQ_TYPE_CLASS | RECIPIENT_INTERFACE | 0x80:
if (sUSB_vSetup.USBwIndex == 0 ) { // for interface0 MASS STORAGE INTERFACE
if (sUSB_vSetup.USBbRequest != 0xFE) // GetMaxLUN for BOT devices
break;
if ((sUSB_vSetup.Flag & (NON0_wValue | NON0_wIndex1 | ONE_wLength)) != ONE_wLength)
break;
sUSB_vSetup.USBwValue0 = Max_Lun;
vUSB_length = 1;
vUSB_DataToSend = &sUSB_vSetup.USBwValue0;
}
else { // FOR HID INTERFACE
if (sUSB_vSetup.USBbRequest != GET_REPORT) // GET_DESCRIPTOR for HID devices
break;
if (sUSB_vSetup.USBwValue1 != FEATURE_REPORT ) //
break;
vUSB_offset = 0;
if ( bDataReadyFlag ) {
vUSB_length = UsbMessageBuffer[RecDataLength] + 2;
vUSB_DataToSend = UsbMessageBuffer;
Set_bTxInCompleteFlag;
}
else {
vUSB_length = 2;
vUSB_DataToSend = CardNotReady;
}
return REQ_SUCCESS;
}
default:
break;
}
RequestError();
return REQ_ERROR;
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Set_Feature_Int
INPUT/OUTPUT : None
DESCRIPTION : Set or enable a specific feature for the specified recipient.
-----------------------------------------------------------------------------*/
void USER_USB_Set_Feature_Int(void)
{
RequestError(); // Inappropriate Request. Recipient does not exist.
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Clear_Feature_Int
INPUT/OUTPUT : None
DESCRIPTION : Set or enable a specific feature for the specified recipient.
-----------------------------------------------------------------------------*/
void USER_USB_Clear_Feature_Int(void)
{
RequestError(); // Inappropriate Request. Recipient does not exist.
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Set_Feature_EP
INPUT/OUTPUT : None
DESCRIPTION : Set or enable a specific feature for the specified recipient.
-----------------------------------------------------------------------------*/
void USER_USB_Set_Feature_EP(void)
{
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Clear_Feature_EP
INPUT/OUTPUT : None
DESCRIPTION : Set or enable a specific feature for the specified recipient.
-----------------------------------------------------------------------------*/
void USER_USB_Clear_Feature_EP(void)
{
extern void BOT_Clear_Feature_EP(void); // See BOT.c
BOT_Clear_Feature_EP();
}
/*-----------------------------------------------------------------------------
ROUTINE NAME : USER_USB_Copydata
INPUT/OUTPUT : Length is number of bytes to be copied. vUSB_offset is the offset
of your data buffer
DESCRIPTION :
-----------------------------------------------------------------------------*/
void USER_USB_CopydataIN(unsigned char Length)
{
/* asm {
LD X, A
DEC X
cpIN: LD A, ([vUSB_DataToSend.w],X)
LD (EP0_IN, X), A
DEC X
JRPL cpIN
}
*/
char x;
for ( x=0;Length;x++, Length-- )
{
EP0_IN[x] = *vUSB_DataToSend++;
}
}
void USER_USB_CopydataOUT(unsigned char Length)
{
/* asm {
LD X, A
DEC X
cpOUT: LD A, (EP0_OUT, X)
LD ([vUSB_DataToSend.w],X), A
DEC X
JRPL cpOUT
}
*/
char x;
for (x=0; Length; x++, Length-- )
{
*vUSB_DataToSend++ = EP0_OUT[x];
}
}
/**************** (c) 2000 STMicroelectronics **********************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -