📄 f3xx_usb0_standard_requests.lst
字号:
238 //-----------------------------------------------------------------------------
239 void Set_Feature (void) // This routine will set the EP Halt
240 { // feature for endpoint 1
241 1
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 5
242 1 // Make sure device is configured, SETUP data
243 1 if ((USB0_STATE != DEV_CONFIGURED) ||
244 1 // is all valid and that request is directed at an endpoint
245 1 (SETUP.bmRequestType == IN_DEVICE) ||
246 1 (SETUP.bmRequestType == IN_INTERFACE) ||
247 1 SETUP.wValue.c[MSB] || SETUP.wIndex.c[MSB] ||
248 1 SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB])
249 1 {
250 2 Force_Stall (); // Otherwise send stall to host
251 2 }
252 1
253 1 else
254 1 {
255 2 // Make sure endpoint exists and that halt
256 2 if ( (SETUP.bmRequestType == IN_ENDPOINT)&&
257 2 // endpoint feature is selected
258 2 (SETUP.wValue.c[LSB] == ENDPOINT_HALT) &&
259 2 ((SETUP.wIndex.c[LSB] == IN_EP2) ||
260 2 (SETUP.wIndex.c[LSB] == OUT_EP2) ) )
261 2 {
262 3 if (SETUP.wIndex.c[LSB] == IN_EP2)
263 3 {
264 4 POLL_WRITE_BYTE (INDEX, 2);// Set feature endpoint 1 halt
265 4 POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
266 4 EP_STATUS[2] = EP_HALT;
267 4 }
268 3 }
269 2 else
270 2 {
271 3 Force_Stall (); // Send procedural stall
272 3 }
273 2 }
274 1 POLL_WRITE_BYTE (INDEX, 0);
275 1 if (EP_STATUS[0] != EP_STALL)
276 1 {
277 2 POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
278 2 // Indicate SETUP packet has been
279 2 // serviced
280 2 }
281 1 }
282
283 //-----------------------------------------------------------------------------
284 // Set_Address
285 //-----------------------------------------------------------------------------
286 //
287 // Return Value - None
288 // Parameters - None
289 //
290 // Standard request that should not change in custom HID designs.
291 //
292 //-----------------------------------------------------------------------------
293 void Set_Address (void) // Set new function address
294 {
295 1 // Request must be directed to device
296 1 if ((SETUP.bmRequestType != IN_DEVICE) ||
297 1 // with index and length set to zero.
298 1 SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB]||
299 1 SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB]||
300 1 SETUP.wValue.c[MSB] || (SETUP.wValue.c[LSB] & 0x80))
301 1 {
302 2 Force_Stall (); // Send stall if SETUP data invalid
303 2 }
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 6
304 1
305 1 EP_STATUS[0] = EP_ADDRESS; // Set endpoint zero to update
306 1 // address next status phase
307 1 if (SETUP.wValue.c[LSB] != 0)
308 1 {
309 2 USB0_STATE = DEV_ADDRESS; // Indicate that device state is now
310 2 // address
311 2 }
312 1 else
313 1 {
314 2 USB0_STATE = DEV_DEFAULT; // If new address was 0x00, return
315 2 } // device to default state
316 1 if (EP_STATUS[0] != EP_STALL)
317 1 {
318 2 POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
319 2 // Indicate SETUP packet has
320 2 // been serviced
321 2 }
322 1 }
323
324 //-----------------------------------------------------------------------------
325 // Get_Descriptor
326 //-----------------------------------------------------------------------------
327 //
328 // Return Value - None
329 // Parameters - None
330 //
331 // Standard request that should not change in custom HID designs.
332 //
333 //-----------------------------------------------------------------------------
334 void Get_Descriptor (void) // This routine sets the data pointer
335 { // and size to correct descriptor and
336 1 // sets the endpoint status to transmit
337 1
338 1 switch(SETUP.wValue.c[MSB]) // Determine which type of descriptor
339 1 { // was requested, and set data ptr and
340 2 case DSC_DEVICE: // size accordingly
341 2 DATAPTR = (unsigned char*) &DEVICEDESC;
342 2 DATASIZE = DEVICEDESC.bLength;
343 2 break;
344 2
345 2 case DSC_CONFIG:
346 2 DATAPTR = (unsigned char*) &ConfigDesc;
347 2 // Compiler Specific - The next statement
348 2 // reverses the bytes in the configuration
349 2 // descriptor for the compiler
350 2 DATASIZE = ConfigDesc.wTotalLength.c[MSB] +
351 2 256*ConfigDesc.wTotalLength.c[LSB];
352 2 break;
353 2
354 2 case DSC_STRING:
355 2 DATAPTR = STRINGDESCTABLE[SETUP.wValue.c[LSB]];
356 2 // Can have a maximum of 255 strings
357 2 DATASIZE = *DATAPTR;
358 2 break;
359 2
360 2 case DSC_INTERFACE:
361 2 DATAPTR = (unsigned char*) &InterfaceDesc;
362 2 DATASIZE = InterfaceDesc.bLength;
363 2 break;
364 2
365 2 case DSC_ENDPOINT:
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 7
366 2 if ( (SETUP.wValue.c[LSB] == IN_EP2) )
367 2 {
368 3 if (SETUP.wValue.c[LSB] == IN_EP2)
369 3 {
370 4 DATAPTR = (unsigned char*) &Endpoint1Desc;
371 4 DATASIZE = Endpoint1Desc.bLength;
372 4 }
373 3 else
374 3 {
375 4 DATAPTR = (unsigned char*) &Endpoint2Desc;
376 4 DATASIZE = Endpoint2Desc.bLength;
377 4 }
378 3 }
379 2 else
380 2 {
381 3 Force_Stall();
382 3 }
383 2 break;
384 2
385 2 case DSC_HID: // HID Specific (HID class descriptor)
386 2 DATAPTR = (unsigned char*)&HidDesc;
387 2 DATASIZE = HidDesc.bLength;
388 2 break;
389 2
390 2 case DSC_HID_REPORT: // HID Specific (HID report descriptor)
391 2 DATAPTR = (unsigned char*)&HIDREPORTDESC;
392 2 DATASIZE = HID_REPORT_DESCRIPTOR_SIZE;
393 2 break;
394 2
395 2 default:
396 2 Force_Stall (); // Send Stall if unsupported request
397 2 break;
398 2 }
399 1
400 1 // Verify that the requested descriptor is valid
401 1 if (SETUP.wValue.c[MSB] == DSC_DEVICE ||
402 1 SETUP.wValue.c[MSB] == DSC_CONFIG ||
403 1 SETUP.wValue.c[MSB] == DSC_STRING ||
404 1 SETUP.wValue.c[MSB] == DSC_INTERFACE ||
405 1 SETUP.wValue.c[MSB] == DSC_ENDPOINT)
406 1 {
407 2 if ((SETUP.wLength.c[LSB] < DATASIZE) &&
408 2 (SETUP.wLength.c[MSB] == 0))
409 2 {
410 3 DATASIZE = SETUP.wLength.i; // Send only requested amount of data
411 3 }
412 2 }
413 1 if (EP_STATUS[0] != EP_STALL) // Make sure endpoint not in stall mode
414 1 {
415 2 POLL_WRITE_BYTE (E0CSR, rbSOPRDY);// Service SETUP Packet
416 2 EP_STATUS[0] = EP_TX; // Put endpoint in transmit mode
417 2 DATASENT = 0; // Reset Data Sent counter
418 2 }
419 1 }
420
421 //-----------------------------------------------------------------------------
422 // Get_Configuration
423 //-----------------------------------------------------------------------------
424 //
425 // Return Value - None
426 // Parameters - None
427 //
C51 COMPILER V8.17 F3XX_USB0_STANDARD_REQUESTS 03/18/2009 09:55:18 PAGE 8
428 // Standard request that should not change in custom HID designs.
429 //
430 //-----------------------------------------------------------------------------
431 void Get_Configuration (void) // This routine returns current
432 { // configuration value
433 1 // This request must be directed to the device
434 1 if ( (SETUP.bmRequestType != OUT_DEVICE) ||
435 1 // With value word set to zero
436 1 SETUP.wValue.c[MSB] || SETUP.wValue.c[LSB]||
437 1 // And index set to zero
438 1 SETUP.wIndex.c[MSB] || SETUP.wIndex.c[LSB]||
439 1 // And SETUP length set to one
440 1 SETUP.wLength.c[MSB] || (SETUP.wLength.c[LSB] != 1) )
441 1 {
442 2 Force_Stall (); // Otherwise send a stall to host
443 2 }
444 1
445 1 else
446 1 {
447 2 if (USB0_STATE == DEV_CONFIGURED)// If the device is configured, then
448 2 { // return value 0x01 since this software
449 3 // only supports one configuration
450 3 DATAPTR = (unsigned char*)&ONES_PACKET;
451 3 DATASIZE = 1;
452 3 }
453 2 if (USB0_STATE == DEV_ADDRESS) // If the device is in address state, it
454 2 { // is not configured, so return 0x00
455 3 DATAPTR = (unsigned char*)&ZERO_PACKET;
456 3 DATASIZE = 1;
457 3 }
458 2 }
459 1 if (EP_STATUS[0] != EP_STALL)
460 1 {
461 2 // Set Serviced Out Packet bit
462 2 POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
463 2 EP_STATUS[0] = EP_TX; // Put endpoint into transmit mode
464 2 DATASENT = 0; // Reset Data Sent counter to zero
465 2 }
466 1 }
467
468 //-----------------------------------------------------------------------------
469 // Set_Configuration
470 //-----------------------------------------------------------------------------
471 //
472 // Return Value - None
473 // Parameters - None
474 //
475 // Standard request that should not change in custom HID designs.
476 //
477 //-----------------------------------------------------------------------------
478 void Set_Configuration (void) // This routine allows host to change
479 { // current device configuration value
480 1
481 1 // Device must be addressed before configured
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -