📄 chap9.lst
字号:
165
166 void reserved(void)
167 {
168 stall_ep0();
169 }
170
171 /*
172 //*************************************************************************
173 // USB standard device requests
174 //*************************************************************************
175 */
176
177 void get_status(void)
178 {
C51 COMPILER V7.09 CHAP9 05/11/2005 17:30:28 PAGE 4
179 unsigned char endp, txdat[2];
180 unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
181 unsigned char c;
182
183 if (bRecipient == USB_RECIPIENT_DEVICE) {
184 if(bEPPflags.bits.remote_wakeup == 1)
185 txdat[0] = 3;
186 else
187 txdat[0] = 1;
188 txdat[1]=0;
189 single_transmit(txdat, 2);
190 } else if (bRecipient == USB_RECIPIENT_INTERFACE) {
191 txdat[0]=0;
192 txdat[1]=0;
193 single_transmit(txdat, 2);
194 } else if (bRecipient == USB_RECIPIENT_ENDPOINT) {
195 endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
196 if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
197 c = D12_SelectEndpoint(endp*2 + 1); /* Control-in */
198 else
199 c = D12_SelectEndpoint(endp*2); /* Control-out */
200 if(c & D12_STALL)
201 txdat[0] = 1;
202 else
203 txdat[0] = 0;
204 txdat[1] = 0;
205 single_transmit(txdat, 2);
206 } else
207 stall_ep0();
208 }
209
210 void clear_feature(void)
211 {
212 unsigned char endp;
213 unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
214
215 if (bRecipient == USB_RECIPIENT_DEVICE
216 && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) {
217 DISABLE;
218 bEPPflags.bits.remote_wakeup = 0;
219 ENABLE;
220 single_transmit(0, 0);
221 }
222 else if (bRecipient == USB_RECIPIENT_ENDPOINT
223 && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL) {
224 endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
225 if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
226 /* clear TX stall for IN on EPn. */
227 D12_SetEndpointStatus(endp*2 + 1, 0);
228 else
229 /* clear RX stall for OUT on EPn. */
230 D12_SetEndpointStatus(endp*2, 0);
231 single_transmit(0, 0);
232 } else
233 stall_ep0();
234 }
235
236 void set_feature(void)
237 {
238 unsigned char endp;
239 unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
240
C51 COMPILER V7.09 CHAP9 05/11/2005 17:30:28 PAGE 5
241 if (bRecipient == USB_RECIPIENT_DEVICE
242 && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) {
243 DISABLE;
244 bEPPflags.bits.remote_wakeup = 1;
245 ENABLE;
246 single_transmit(0, 0);
247 }
248 else if (bRecipient == USB_RECIPIENT_ENDPOINT
249 && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL) {
250 endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
251 if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
252 /* clear TX stall for IN on EPn. */
253 D12_SetEndpointStatus(endp*2 + 1, 1);
254 else
255 /* clear RX stall for OUT on EPn. */
256 D12_SetEndpointStatus(endp*2, 1);
257 single_transmit(0, 0);
258 } else
259 stall_ep0();
260 }
261
262 void set_address(void)
263 {
264 D12_SetAddressEnable((unsigned char)(ControlData.DeviceRequest.wValue &
265 DEVICE_ADDRESS_MASK), 1);
266 single_transmit(0, 0);
267 }
268
269 void get_descriptor(void)
270 {
271 unsigned char bDescriptor = MSB(ControlData.DeviceRequest.wValue);
272 unsigned char bLength = MSB(ControlData.DeviceRequest.wLength);
273 char *temp;
274 if (bDescriptor == USB_DEVICE_DESCRIPTOR_TYPE) {
275 temp=(char *)&DeviceDescr;
276 Uart_Printf("%x %x %x %x %x %x %x %x %x",temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]
-,temp[8]);
277 code_transmit((unsigned char *)&DeviceDescr, sizeof(USB_DEVICE_DESCRIPTOR));
278 } else if (bDescriptor == USB_CONFIGURATION_DESCRIPTOR_TYPE) {
279 temp=(char *)&ConfigDescr;
280 Uart_Printf("%x %x %x %x %x %x %x %x %x",temp[0],temp[1],temp[2],temp[3],temp[4],temp[5],temp[6],temp[7]
-,temp[8]);
281 code_transmit((unsigned char *)&Total_Configuration_Descriptor, CONFIG_DESCRIPTOR_LENGTH);
282 } else
283 stall_ep0();
284 }
285 //CONFIG_DESCRIPTOR_LENGTH
286 void get_configuration(void)
287 {
288 unsigned char c = bEPPflags.bits.configuration;
289
290 single_transmit(&c, 1);
291 }
292
293 void set_configuration(void)
294 {
295 if (ControlData.DeviceRequest.wValue == 0) {
296 /* put device in unconfigured state */
297 DISABLE;
298 bEPPflags.bits.configuration = 0;
299 ENABLE;
300 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. *///init_unconfig
C51 COMPILER V7.09 CHAP9 05/11/2005 17:30:28 PAGE 6
301 single_transmit(0, 0);
302
303 } else if (ControlData.DeviceRequest.wValue == 1) {
304 /* Configure device */
305
306 D12_SetEndpointEnable(0); /* Disable all endpoints but EPP0. //init_unconfig*/
307
308 D12_SetEndpointEnable(1); /* Enable generic/iso endpoints. init_config*/
309
310 single_transmit(0, 0);
311
312 DISABLE;
313 bEPPflags.bits.configuration = 1;
314 ENABLE;
315 } else
316 stall_ep0();
317 }
318
319 void get_interface(void)
320 {
321 unsigned char txdat = 0; /* Only/Current interface = 0 */
322 single_transmit(&txdat, 1);
323 }
324
325 void set_interface(void)
326 {
327 if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
328 single_transmit(0, 0);
329 else
330 stall_ep0();
331 }
C51 COMPILATION COMPLETE. 0 WARNING(S), 1 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -