📄 protozlg.c
字号:
/*
//*************************************************************************
//
// ZLGMCU
// www.zlgmcu.com
// File Name: protozlg.C
// Revision: 0.4(2002-07-08)
// Author: Liu Ying Bin
// Use library: USB51S.LIB
// Note: USB51S.LIB不带DMA控制功能
//*************************************************************************
*/
#include <stdio.h>
#include <string.h>
#include <reg51.h> /* special function register declarations */
#include "isr.h"
#include "mainloop.h"
#include "protozlg.h"
extern CONTROL_XFER ControlData;
extern IO_REQUEST idata ioRequest;
extern EPPFLAGS bEPPflags;
extern unsigned char idata EpBuf[];
byte_count byte_cnt;
void get_firmware_version()
{
unsigned char i;
i = 0x30; // firmware version number
single_transmit((unsigned char *)&i, 1);
}
void get_buffer_size()
{
unsigned char i[4];
i[0] = EP2_PACKET_SIZE;
i[1] = 0;
i[2] = 0;
i[3] = 0;
single_transmit((unsigned char *)&i, 4);
}
void read_write_register(void)
{
// unsigned char i;
if(ControlData.DeviceRequest.bmRequestType & (unsigned char)USB_ENDPOINT_DIRECTION_MASK) {
if(ControlData.DeviceRequest.wIndex == GET_FIRMWARE_VERSION &&
ControlData.DeviceRequest.wValue == 0 &&
ControlData.DeviceRequest.wLength == 1)
get_firmware_version();
else
if(ControlData.DeviceRequest.wIndex == GET_BUFFER_SIZE &&
ControlData.DeviceRequest.wValue == 0 &&
ControlData.DeviceRequest.wLength == 4)
get_buffer_size();
else
stall_ep0();
} // if read register
else{
if(ControlData.DeviceRequest.wIndex == SETUP_DMA_REQUEST &&
ControlData.DeviceRequest.wValue == 0 &&
ControlData.DeviceRequest.wLength == 6)
{
if(ControlData.dataBuffer[5]==0x81)
{
byte_cnt.byte.high = ControlData.dataBuffer[4];
byte_cnt.byte.low = ControlData.dataBuffer[3];
if(byte_cnt.word<64)
{
D12_WriteEndpoint(5, byte_cnt.byte.low, EpBuf);
byte_cnt.word=0;
}
else
{
byte_cnt.word=byte_cnt.word-64;
D12_WriteEndpoint(5, 64, EpBuf);
}
}
if(ControlData.dataBuffer[5]==0x82)
{
// i = D12_ReadEndpoint(4, 64, EpBuf);//读空端点2数据
// i = D12_ReadEndpoint(4, 64, EpBuf);
}
single_transmit(0, 0);
}
else
stall_ep0();
} // if write register
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -