⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 44b0板上的usb固件及上位机程序
💻 C
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "ARMHAL.h"
#include "D12CI.h"
#include "isr.h"
#include "USB.h"
#include "stdio.h"

extern EPPFLAGS bEPPflags;
extern CONTROL_XFER ControlData;
extern U8 GenEpBuf[200];

U8 DeviceDescriptor[SIZEOF_DEVICE_DESCRIPTOR] = {
	SIZEOF_DEVICE_DESCRIPTOR,	// Length of this descriptor (12h bytes)
	DESC_TYPE_DEVICE,		// Type code of this descriptor (01h)
	0x10,0x01,			// Release of USB spec (Rev 1.1)
	0x00,				// Device's base class code-vendor specific
	0x00,				// Device's sub class code
	0x00,				// Device's protocol type code
	EP0_MAX_PACKET_SIZE,		// End porint 0's max packet size = 16
	VID_L, VID_H,			// Vendor ID for device
	PID_L, PID_H,			// Product ID for device
	0x00, 0x00,			// Revision levle of device, Rev=1.0
	/*0x01*/0x00,				// Index of manufacturer name string desc
	/*0x02*/0x00,				// Index of product name string desc
	0x00,				// Serial Number string descriptro index (None)
	0x01				// Number of configurations supported
};

U8 ConfigurationDescriptorGroup[SIZEOF_CONFIG_DESC_GROUP] = {
	// Configuration Descriptor, size = 0x09
	SIZEOF_CONFIG_DESCRIPTOR,	// bLength
	DESC_TYPE_CONFIG,		// bDescriptorType
	SIZEOF_CONFIG_DESC_GROUP, 0x00,	// wTotalLength
	0x01,				// bNumInterfaces
	0x01,				// bConfigurationValue
	0x00,				// Index of string descriptor (None)
	CFG_DESC_ATTR_SELF_POWERED,	// bmAttributes, self-powered
	0x32,				// Max. Power Consumption at 2mA unit
	// Interface Descriptor, size = 0x09
	SIZEOF_INTERFACE_DESCRIPTOR,	// bLength
	DESC_TYPE_INTERFACE,		// bDescriptorType
	0x00,				// bInterfaceNumber
	0x00,				// bAlternateSetting
	2,				// bNumEndpoints
	0x03,				// bInterfaceClass - vendor-specific
	0,				// bInterfaceSubClass
	0,				// bInterfaceProtocol
	0x00,				// iInterface
	// HID Class Descriptor
	SIZEOF_HID_DESCRIPTOR,		// Descriptor length (9 bytes)
	DESC_TYPE_HID,			// Descriptor type (HID 21h)
	0x10, 0x01,			// HID class release number (1.10)
	0x00,				// Localized country code (None)
	0x01,				// Number of HID class descriptor of follow (1)
	0x22,				// Report descriptor type (HID)
	SIZEOF_REPORT_DESCRIPTOR, 0x00,	// Total Length of report descriptor
	// Endpoint Descriptor, size = 0x07
	SIZEOF_ENDPOINT_DESCRIPTOR,	// bLength
	DESC_TYPE_ENDPOINT,		// bDescriptorType
	0x81,				// bEndpointAddress; bit7=1 for IN, bits 3-0 =1 for endpoint number
	EP_DESC_ATTR_TYPE_INT,		// bmAttributes, interrupt transer
	0x10, 0x00,			// wMaxPacketSize, 16 bytes
	0x05,				// bInterval
	// Endpoint Descriptor, size = 0x07
	SIZEOF_ENDPOINT_DESCRIPTOR,	// bLength
	DESC_TYPE_ENDPOINT,		// bDescriptorType
	0x01,				// bEndpointAddress; bit7=0 for OUT, bits 3-0 =1 for endpoint number
	EP_DESC_ATTR_TYPE_INT,		// bmAttributes, interrupt transer
	0x10, 0x00,			// wMaxPacketSize, 16 bytes
	0x05				// bInterval
};
U8 HidDescriptor[SIZEOF_HID_DESCRIPTOR] = {
		// HID Class Descriptor
	SIZEOF_HID_DESCRIPTOR,		// Descriptor length (9 bytes)
	DESC_TYPE_HID,			// Descriptor type (HID 21h)
	0x10, 0x01,			// HID class release number (1.00)
	0x00,				// Localized country code (None)
	0x01,				// Number of HID class descriptor of follow (1)
	0x22,				// Report descriptor type (HID)
	SIZEOF_REPORT_DESCRIPTOR, 0x00	// Total Length of report descriptor	
};

U8 HidReport[SIZEOF_REPORT_DESCRIPTOR] = {
	0x06, 0x00, 0xff,	// usage page (Vendor Defined)
	0x09, 0x01,		// usage (I/O Device)
	0xa1, 0x01,		// Collection (Application)
	0x19, 0x01,		// Usage_Minimum
	0x29, 0x08,		// Usage_Maximum
	0x15, 0x00,		// logical minimum (0)
	0x25, 0x7f,		// logical maximum (0xff)
	0x75, 0x08,		// report size (8)
	0x95, 0x08,		// report count
	0x81, 0x02,		// Input (Data, Var, Abs)
	0x19, 0x01,		// Usage_Minimum
	0x29, 0x08,		// Usage_Maximum
	0x91, 0x02,		// Output (Data, Var, Abs)
	0xc0
};
	
void InitD12(void);

void Main(void)
{

	U8 i;
	rSYSCFG=CACHECFG;   // Using 8KB Cache//

	Port_Init();
	Led_Display(0);
	
	rPCONG = 0x00ff;	// EINT7~0
	rPUPG = 0x0;		// pull up enable
	

	for(i=0; i<200; i++)
		GenEpBuf[i] = i + 0x10;
	// Initialize PDIUSBD12
	InitD12();

	do
	{
		fn_usb_isr();
		if( (bEPPflags.bits.setup_packet==1) )
		{
			bEPPflags.bits.setup_packet = 0;
			ControlHandler();
		}
		if( bEPPflags.bits.ep1_rxdone==1 )
		{
			bEPPflags.bits.ep1_rxdone = 0;
			Led_Display(GenEpBuf[0]);
		}
		
	} while(1);
}

// Initialize PDIUSBD12
void InitD12(void)
{
	bEPPflags.bits.timer = 0;
	bEPPflags.bits.bus_reset = 0;
	bEPPflags.bits.suspend = 0;
	bEPPflags.bits.setup_packet = 0;
	bEPPflags.bits.remote_wakeup = 0;
	bEPPflags.bits.in_isr = 0;
	bEPPflags.bits.control_state = 0;
	bEPPflags.bits.configuration = 0;
	bEPPflags.bits.verbose = 0;
	
	D12_SetMode(0x0e, 0x01);
	Delay(20000);
	D12_SetMode(0x1e, 0x01);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -