📄 chap_9.lst
字号:
C51 COMPILER V6.12 CHAP_9 07/30/2003 21:27:45 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE CHAP_9
OBJECT MODULE PLACED IN .\CHAP_9.OBJ
COMPILER INVOKED BY: f:\Keil\C51\BIN\C51.EXE .\CHAP_9.C LARGE DEBUG OBJECTEXTEND
stmt level source
1 ////CHAP9.C
2 #include "common.h"
3 #include "chap_9.h"
4 #include "mainloop.h"
5 #include "D12CI.h"
6 #include "usb100.h"
7 #include "protodma.h"
8 #include "disp.h"
9
10 extern EPPFLAGS bEPPflags;
11
12 CONTROL_XFER ControlData;
13 uchar setupcounter;
14
15 code HID_REPORT_DESCRIPTOR MyReportDescriptor[] = { /*添加的report*/
16 0x05, 0x01, // Usage Page (Generic Desktop),
17 0x09, 0x06, // Usage (Keyboard),
18 0xA1, 0x01, // Collection (Application),
19 0x05, 0x07, // Usage Page (Key Codes);
20 0x19, 0xE0, // Usage Minimum (224),
21 0x29, 0xE7, // Usage Maximum (231),
22 0x15, 0x00, // Logical Minimum (0),
23 0x25, 0x01, // Logical Maximum (1),
24 0x75, 0x01, // Report Size (1),
25 0x95, 0x08, // Report Count (8),
26 0x81, 0x02, // Input (Data, Variable, Absolute),;Modifier byte
27 0x95, 0x01, // Report Count (1),
28 0x75, 0x08, // Report Size (8),
29 0x81, 0x01, // Input (Constant), ;Reserved byte
30 0x95, 0x05, // Report Count (5),
31 0x75, 0x01, // Report Size (1),
32 0x05, 0x08, // Usage Page (Page# for LEDs),
33 0x19, 0x01, // Usage Minimum (1),
34 0x29, 0x05, // Usage Maximum (5),
35 0x91, 0x02, // Output (Data, Variable, Absolute), ;LED report
36 0x95, 0x01, // Report Count (1),
37 0x75, 0x03, // Report Size (3),
38 0x91, 0x01, // Output (Constant), ;LED report padding
39 0x95, 0x06, // Report Count (6),
40 0x75, 0x08, // Report Size (8),
41 0x15, 0x00, // Logical Minimum (0),
42 0x25, 0x65, // Logical Maximum(101),
43 0x05, 0x07, // Usage Page (Key Codes),
44 0x19, 0x00, // Usage Minimum (0),
45 0x29, 0x65, // Usage Maximum (101),
46 0x81, 0x00, // Input (Data, Array), ;Key arrays (6 bytes)
47 0xC0 // End Collection
48 };
49
50 code USB_DEVICE_DESCRIPTOR DeviceDescr =
51 {
52 sizeof(USB_DEVICE_DESCRIPTOR),
53 USB_DEVICE_DESCRIPTOR_TYPE,
54 SWAP(0x0110),
55 0,//USB_CLASS_CODE_TEST_CLASS_DEVICE,
C51 COMPILER V6.12 CHAP_9 07/30/2003 21:27:45 PAGE 2
56 0, 0,
57 EP0_PACKET_SIZE,
58 SWAP(0x0471),
59 SWAP(0x0011),//
60 SWAP(0x0100),
61 1, 2, 0,
62 1
63 };
64
65 code USB_CONFIGURATION_DESCRIPTOR ConfigDescr =
66 {
67 sizeof(USB_CONFIGURATION_DESCRIPTOR),
68 USB_CONFIGURATION_DESCRIPTOR_TYPE,
69 SWAP(CONFIG_DESCRIPTOR_LENGTH),
70 1,
71 1,
72 0,
73 0x80,//0x60,//
74 0x80//0x32
75 };
76
77 code USB_INTERFACE_DESCRIPTOR InterfaceDescr =
78 {
79 sizeof(USB_INTERFACE_DESCRIPTOR),
80 USB_INTERFACE_DESCRIPTOR_TYPE,
81 0,
82 0,
83 NUM_ENDPOINTS,
84 3,
85 1,
86 1,
87 //USB_CLASS_CODE_TEST_CLASS_DEVICE,
88 //USB_SUBCLASS_CODE_TEST_CLASS_D12,
89 //USB_PROTOCOL_CODE_TEST_CLASS_D12,
90 0
91 };
92
93 //
94 // The HID descriptor has some basic device info and tells how long the report
95 // descriptor is.
96 //
97
98 code USB_HID_DESCRIPTOR ClassDescriptor = { /*添加的class descriptor*/
99 0x09, // length of HID descriptor
100 0x21, // descriptor type == HID
101 SWAP(0x0100), // hid spec release
102 0x00, // country code == Not Specified
103 0x01, // number of HID class descriptors
104 0x22, // report descriptor type
105 SWAP(sizeof(MyReportDescriptor)) // total length of report descriptor
106 };
107
108 code USB_ENDPOINT_DESCRIPTOR EP1_TXDescr =
109 {
110 sizeof(USB_ENDPOINT_DESCRIPTOR),
111 USB_ENDPOINT_DESCRIPTOR_TYPE,
112 0x81,
113 USB_ENDPOINT_TYPE_INTERRUPT,
114 SWAP(EP1_PACKET_SIZE),
115 10
116 };
117
C51 COMPILER V6.12 CHAP_9 07/30/2003 21:27:45 PAGE 3
118 code USB_ENDPOINT_DESCRIPTOR EP1_RXDescr =
119 {
120 sizeof(USB_ENDPOINT_DESCRIPTOR),
121 USB_ENDPOINT_DESCRIPTOR_TYPE,
122 0x1,
123 USB_ENDPOINT_TYPE_INTERRUPT,
124 SWAP(EP1_PACKET_SIZE),
125 10
126 };
127
128 code USB_ENDPOINT_DESCRIPTOR EP2_TXDescr =
129 {
130 sizeof(USB_ENDPOINT_DESCRIPTOR),
131 USB_ENDPOINT_DESCRIPTOR_TYPE,
132 0x82,
133 USB_ENDPOINT_TYPE_BULK,
134 SWAP(EP2_PACKET_SIZE),
135 10
136 };
137
138 code USB_ENDPOINT_DESCRIPTOR EP2_RXDescr =
139 {
140 sizeof(USB_ENDPOINT_DESCRIPTOR),
141 USB_ENDPOINT_DESCRIPTOR_TYPE,
142 0x2,
143 USB_ENDPOINT_TYPE_BULK,
144 SWAP(EP2_PACKET_SIZE),
145 10
146 };
147
148 code void(* StandardDeviceRequest[])(void)=
149 {
150 get_status,
151 clear_feature,
152 reserved,
153 set_feature,
154 reserved,
155 set_address,
156 get_descriptor,
157 reserved,
158 get_configuration,
159 set_configuration,
160 get_interface,
161 set_interface,
162 reserved,
163 reserved,
164 reserved,
165 reserved
166 };
167
168 extern code void(*VendorDeviceRequest[])(void);
169
170 void stall_ep0(void)
171 {
172 1 D12_SetEndpointStatus(0, 1);
173 1 D12_SetEndpointStatus(1, 1);
174 1 }
175
176 void reserved(void)
177 {
178 1 stall_ep0();
179 1 }
C51 COMPILER V6.12 CHAP_9 07/30/2003 21:27:45 PAGE 4
180
181 void control_handler()
182 {
183 1 uchar type,req;
184 1 type = ControlData.DeviceRequest.bmRequestType&USB_REQUEST_TYPE_MASK;
185 1 req = ControlData.DeviceRequest.bRequest&USB_REQUEST_MASK;
186 1 if(type==USB_STANDARD_REQUEST)
187 1 (*StandardDeviceRequest[req])();
188 1 else if(type==USB_VENDOR_REQUEST)
189 1 (*VendorDeviceRequest[req])();
190 1 else
191 1 stall_ep0();
192 1 }
193
194 void init_unconfig(void)
195 {
196 1 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. */
197 1 }
198
199 void init_config(void)
200 {
201 1 D12_SetEndpointEnable(1);
202 1 }
203 void single_transmit(uchar * buf,uchar len)
204 {
205 1 if(len<=EP0_PACKET_SIZE){
206 2 D12_WriteEndpoint(1,len,buf);
207 2 }
208 1 }
209 void code_transmit(uchar code * pRomData,ushort len)
210 {
211 1 ControlData.wCount = 0;
212 1 if(ControlData.wLength>len)
213 1 ControlData.wLength = len;
214 1 ControlData.pData = pRomData;
215 1 if(ControlData.wLength >= EP0_PACKET_SIZE)
216 1 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -