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

📄 f3xx_usb0_descriptor.#3

📁 HID Mouse source code 屬於Silabs C8051F326/F327,可以做一個USB 鼠標
💻 #3
字号:
//-----------------------------------------------------------------------------
// F3xx_USB0_Descriptor.c
//-----------------------------------------------------------------------------
// Copyright 2005 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// Source file for USB firmware. Includes descriptor data.
//
//
// How To Test:    See Readme.txt
//
//
// FID:            3XX000031
// Target:         C8051F32x/C8051F340
// Tool chain:     Keil C51 7.50 / Keil EVAL C51
//                 Silicon Laboratories IDE version 2.6
// Command Line:   See Readme.txt
// Project Name:   F3xx_MouseExample
//
//
// Release 1.3
//    - Changes by PD, GP
//    - Modified Descriptors
//    - Changed name from USB_Descriptor.c
//    - 07 December 2005
// Release 1.0
//    -Initial Revision (DM)
//    -22 NOV 2002
////-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include "F3xx_USB0_Register.h"
#include "F3xx_USB0_InterruptServiceRoutine.h"
#include "F3xx_USB0_Descriptor.h"

//-----------------------------------------------------------------------------
// Descriptor Declarations
//-----------------------------------------------------------------------------

const device_descriptor DEVICEDESC =
{   18,                                 // bLength   0x01,                               // bDescriptorType   0x1001,                             // bcdUSB   0x00,                               // bDeviceClass   0x00,                               // bDeviceSubClass   0x00,                               // bDeviceProtocol   EP0_PACKET_SIZE,                    // bMaxPacketSize0   0xC410,                             // idVendor   0xB981,                             // idProduct   0x0000,                             // bcdDevice   0x01,                               // iManufacturer   0x02,                               // iProduct   0x00,                               // iSerialNumber   0x01                                // bNumConfigurations
}; //end of DEVICEDESC

// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
const hid_configuration_descriptor HIDCONFIGDESC =
{

{ // configuration_descriptor hid_configuration_descriptor
   0x09,                               // Length
   0x02,                               // Type
   0x2200,                             // Totallength (= 9+9+9+7)
   0x01,                               // NumInterfaces
   0x01,                               // bConfigurationValue
   0x00,                               // iConfiguration
   0x80,                               // bmAttributes
   0x20                                // MaxPower (in 2mA units)
},

{ // interface_descriptor hid_interface_descriptor
   0x09,                               // bLength
   0x04,                               // bDescriptorType
   0x00,                               // bInterfaceNumber
   0x00,                               // bAlternateSetting
   0x01,                               // bNumEndpoints
   0x03,                               // bInterfaceClass (3 = HID)
   0x01,                               // bInterfaceSubClass
   0x02,                               // bInterfaceProcotol
   0x00                                // iInterface
},

{ // class_descriptor hid_descriptor
	0x09,	                              // bLength
	0x21,	                              // bDescriptorType
	0x0101,	                           // bcdHID
	0x00,	                              // bCountryCode
	0x01,	                              // bNumDescriptors
	0x22,                               // bDescriptorType
	HID_REPORT_DESCRIPTOR_SIZE_LE       // wItemLength (tot. len. of report
                                       // descriptor)
},

// IN endpoint (mandatory for HID)
{ // endpoint_descriptor hid_endpoint_in_descriptor
   0x07,                               // bLength
   0x05,                               // bDescriptorType
   0x81,                               // bEndpointAddress
   0x03,                               // bmAttributes
   EP1_PACKET_SIZE_LE,                 // MaxPacketSize (LITTLE ENDIAN)
   10                                  // bInterval
},

// OUT endpoint (optional for HID)
{ // endpoint_descriptor hid_endpoint_out_descriptor
   0x07,                               // bLength
   0x05,                               // bDescriptorType
   0x01,                               // bEndpointAddress
   0x03,                               // bmAttributes
   EP2_PACKET_SIZE_LE,                 // MaxPacketSize (LITTLE ENDIAN)
   10                                  // bInterval
}

};

const hid_report_descriptor HIDREPORTDESC =
{
    0x05, 0x01,                        // Usage Page (Generic Desktop)
    0x09, 0x02,                        // Usage (Mouse)
    0xA1, 0x01,                        // Collection (Application)
    0x09, 0x01,                        //   Usage (Pointer)
    0xA1, 0x00,                        //   Collection (Physical)
    0x05, 0x09,                        //     Usage Page (Buttons)
    0x19, 0x01,                        //     Usage Minimum (01)
    0x29, 0x01,                        //     Usage Maximum (01)
    0x15, 0x00,                        //     Logical Minimum (0)
    0x25, 0x01,                        //     Logical Maximum (1)
    0x95, 0x01,                        //     Report Count (1)
    0x75, 0x01,                        //     Report Size (1)
    0x81, 0x02,                        //     Input (Data, Variable, Absolute)
    0x95, 0x01,                        //     Report Count (1)
    0x75, 0x07,                        //     Report Size (7)
    0x81, 0x01,                        //     Input (Constant) for padding
    0x05, 0x01,                        //     Usage Page (Generic Desktop)
    0x09, 0x30,                        //     Usage (X)
    0x09, 0x31,                        //     Usage (Y)
    0x15, 0x81,                        //     Logical Minimum (-127)
    0x25, 0x7F,                        //     Logical Maximum (127)
    0x75, 0x08,                        //     Report Size (8)
    0x95, 0x02,                        //     Report Count (2)
    0x81, 0x06,                        //     Input (Data, Variable, Relative)
    0xC0,                              //   End Collection (Physical)
    0xC0,                               // End Collection (Application)

/*

	0x05,0x01,		//usage page (generic desktop)
	0x09,0x06,		//usage (keyboard)
	0xA1,0x01,		//collection (application)
	0x85,0x01,		//	reportID (0x01)
	0x05,0x07,		//	usage_Page(Keyboard)
	0x19,0xE0,		//	usage_min (224)	
	0x29,0xE7,		//	usage_max (231)	
	0x15,0x00,		//	logical minimum (0)
	0x25,0x01,      //	logical maximum (1)
	0x75,0x01,		//	report size (1)
	0x95,0x08,		//	report count(8)
	0x81,0x02,		//	input (Data, Variable, Absolute)
	0x95,0x01,		//	report count (1)
	0x75,0x08,		//	report size (8)
	0x81,0x07,		//	input (Constant)
	0x95,0x05,		//	report count (5)
	0x75,0x01,		// report size (1)
	0x05,0x08,		// usage page (LEDs)
	0x19,0x01,		// usage minimum (1)
	0x29,0x05,		// usage maximum (5)
	0x91,0x02,		// output (Data, Variable, Absolute)
	0x95,0x01,		// report count (1)
	0x75,0x03,		// report size (3)
	0x91,0x07,      // output (Constant)
	0x95,0x06,      // report count (6)
	0x75,0x08,      // report size (8)
	0x15,0x00,      // logical minimum (0)
	0x25,0x65,      // logical maximum (101)
	0x05,0x07,      // usage page (keyboard)
	0x19,0x00,      // usage minimum (0)
	0x29,0x65,      // usage maximum (101)
	0x81,0x00,      // input (Data, Array)
	0xc0,			// end collection
	0x05,0x01,      // usage page (generic desktop)
	0x09,0x02,      // usage (mouse)
	0xA1,0x01,      // collection (application)
	0x85,0x02,      // reportID (0x02)
	0x09,0x01,		// usage (pointer)
	0xA1,0x00,		// collection (linked) ???
	0x05,0x09,		// usage page (buttons)
	0x19,0x01,		// usage minimum (1)
	0x29,0x03,		// usage maximum (3)
	0x15,0x00,		// logical minimum (0)
	0x25,0x01,		// logical maximum (1)
	0x95,0x03,		// report count (3 bytes)
	0x75,0x01,		// report size (1)
	0x81,0x02,		// input (3 button bits)
	0x95,0x01,		// report count (1)
	0x75,0x05,		// report size (5)
	0x81,0x01,		// input (constant 5 bit padding)
	0x05,0x01,		// usage page (generic desktop)
	0x09,0x30,		// usage (X)
	0x09,0x31,		// usage (Y)
	0x09,0x38,  	// usage (wheel)  ???
	0x15,0x81,		// logical minimum (-127)
	0x25,0x7F,		// logical maximum (127)
	0x75,0x08,		// report size (8)
	0x95,0x03,		// report count (3)
	0x81,0x06,		// input (3 position bytes X & Y & wheel)
	0xC0,       	// end collection
	//Wheel
	0x09,0x38,		//Wheel
	0x95,0x01,		//Wheel data size is 1 byte
	0x81,0x06,		//Variable Data Bit Field whit Relative position
	0x09,0x3c, 		//Motion wakeup
	0x15,0x00,		// 0 no movement
	0x25,0x01,		// 1 movement
	0x75,0x01,		//Wheel report is 1 bit for movement,bit 0 of byte 3
	0x95,0x01,		// 1 report
	0xb1,0x22,		// Variable Data Bit Field with absolute positioning and no preferred state
	0x95,0x07,		//7 reports for reversing,upper 7 bit of byte 3
	0xb1,0x01,		//constant array bit field with absolute positioning
	0xC0        	// end collection,
*/
};

#define STR0LEN 4

code const unsigned char String0Desc [STR0LEN] =
{
   STR0LEN, 0x03, 0x09, 0x04
}; //end of String0Desc

#define STR1LEN sizeof ("SILICON LABORATORIES") * 2

code const unsigned char String1Desc [STR1LEN] =
{
   STR1LEN, 0x03,
   'S', 0,
   'I', 0,
   'L', 0,
   'I', 0,
   'C', 0,
   'O', 0,
   'N', 0,
   ' ', 0,
   'L', 0,
   'A', 0,
   'B', 0,
   'O', 0,
   'R', 0,
   'A', 0,
   'T', 0,
   'O', 0,
   'R', 0,
   'I', 0,
   'E', 0,
   'S', 0
}; //end of String1Desc

#define STR2LEN sizeof ("C8051F320 Development Board") * 2

code const unsigned char String2Desc [STR2LEN] =
{
   STR2LEN, 0x03,
   'C', 0,
   '8', 0,
   '0', 0,
   '5', 0,
   '1', 0,
   'F', 0,
   '3', 0,
   'x', 0,
   'x', 0,
   ' ', 0,
   'D', 0,
   'e', 0,
   'v', 0,
   'e', 0,
   'l', 0,
   'o', 0,
   'p', 0,
   'm', 0,
   'e', 0,
   'n', 0,
   't', 0,
   ' ', 0,
   'B', 0,
   'o', 0,
   'a', 0,
   'r', 0,
   'd', 0
}; //end of String2Desc

unsigned char* const STRINGDESCTABLE [] =
{
   String0Desc,
   String1Desc,
   String2Desc
};

⌨️ 快捷键说明

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