📄 subp.lst
字号:
421 4 break;
422 4
423 4 //---------------------------------------------------------------------
424 4 // Specific Class Requests (HID)
425 4 //---------------------------------------------------------------------
426 4 case CLASS_REQUEST:
427 4 switch (dReq.bRequest) // Parse bRequest
C51 COMPILER V7.20 SUBP 01/30/2007 16:37:15 PAGE 8
428 4 {
429 5 case GET_IDLE:
430 5 SL811Write(EP0A_Slave_Buf,Slave_IdleRate); // load current idle rate value
431 5 EP0A_IN_Arm(EP0A_Slave_Buf,1,1); // send 1 unsigned char data back to host
432 5 len_req = 0;
433 5 break;
434 5
435 5 case GET_PROTOCOL:
436 5 SL811Write(EP0A_Slave_Buf,Slave_Protocol); // load current protocol state
437 5 EP0A_IN_Arm(EP0A_Slave_Buf,1,1); // send 1 unsigned char data back to host
438 5 len_req = 0;
439 5 break;
440 5
441 5 case SET_IDLE:
442 5 Slave_IdleRate = ( unsigned char)dReq.wValue; // update Idle Rate (upper unsigned char of wVa
-lue)
443 5 EP0A_IN_Arm(0,0,1); // IN status stage
444 5 break;
445 5
446 5 case SET_PROTOCOL:
447 5 Slave_Protocol = dReq.wValue>>8; // update protocol value, 0=Boot, 1=report
448 5 EP0A_IN_Arm(0,0,1); // IN status stage
449 5 break;
450 5
451 5 default:
452 5 SL811Write(EP0BControl,SEND_STALL); // Stall all unsupported requests
453 5 break;
454 5 }
455 4 break;
456 4
457 4 //---------------------------------------------------------------------
458 4 // Specific Vendor Requests
459 4 //---------------------------------------------------------------------
460 4 case VENDOR_REQUEST:
461 4 SL811Write(EP0AControl,SEND_STALL); // Stall all unsupported requests
462 4 break;
463 4
464 4 //---------------------------------------------------------------------
465 4 // Unsupported Requests
466 4 //---------------------------------------------------------------------
467 4 default:
468 4 SL811Write(EP0AControl,SEND_STALL); // Stall all unsupported requests
469 4 break;
470 4 }
471 3
472 3 } // if(statuse&EP_setup)
473 2
474 2 //================================================================
475 2 // IN/OUT token received from host
476 2 //================================================================
477 2
478 2 else
479 2 {
480 3 //---------------------------------
481 3 // IN's ACKed
482 3 //---------------------------------
483 3 if(SL811Read(EP0AControl)&DIRECTION)
484 3 {
485 4 if(dev_first==0) // happens on the first get device descp
486 4 { // the host terminate IN transfer prematurely
487 5 len_req = 0; // (if EP0 maxpktsize is only 8 unsigned chars)
488 5 dev_first = 1; // reset len_req, end with OUT status stage
C51 COMPILER V7.20 SUBP 01/30/2007 16:37:15 PAGE 9
489 5 }
490 4
491 4 //--------------------------------------
492 4 // Continue with next IN if needed
493 4 //--------------------------------------
494 4 if(len_req)
495 4 {
496 5 data_seq = (((SL811Read(EP0AControl)&DATAX)==0) ? 1:0); // toggle DATA sequence
497 5 len_xfr = (len_req>=EP0_LEN) ? EP0_LEN:( unsigned char)len_req; // get transfer length for EP0
498 5
499 5 if(!IN_NULL) // point to correct buffer location
500 5 {
501 6 EP0A_IN_Arm(EP0A_Slave_Buf+in_buffer_idx, len_xfr, data_seq);
502 6 }
503 5 else
504 5 {EP0A_IN_Arm(0,0,data_seq);} // transfer zero Null packet
505 5
506 5 in_buffer_idx += len_xfr; // update buffer location
507 5 len_req -= len_xfr; // update remaining data length
508 5
509 5 if(len_req==0 && len_xfr==EP0_LEN && !IN_EXACT) // handles null packet of data length
510 5 { // to host is multiple of EP0_LEN, and
511 6 len_req = 1; // only if host request more than this
512 6 IN_NULL = TRUE; // value of length, otherwise, the extra
513 6 } // null pkt is not require.
514 5 }
515 4
516 4 //--------------------------------------
517 4 // Arm Status Stage OUT or new SETUP
518 4 //--------------------------------------
519 4 else// Arm status OUT or next SETUP requests
520 4 {
521 5 EP0A_OUT_Arm(EP0_LEN); // i.e. end of IN status stage.
522 5 }
523 4 }
524 3
525 3 //---------------------------------
526 3 // OUT's ACKed
527 3 //---------------------------------
528 3 else
529 3 {
530 4 if( byte_rx==0) // zero data packet received
531 4 {
532 5 EP0A_OUT_Arm(EP0_LEN); // get ready for next SETUP token
533 5 // if(( unsigned char)dReq.wValue == HID_REPORT) // end of a report descp, indicate
534 5 // {
535 5 // enum_done = 1; // end of complete enumeration
536 5 // P3 &= ~ACTIVE_LED; // Turn on Active LED
537 5 //P35_LED=0;
538 5 // }
539 5 }
540 4 }
541 3
542 3 }
543 2 }
544 1 //----------------------------------------------------------------------------------------
545 1 // End of ACK received
546 1 //----------------------------------------------------------------------------------------
547 1
548 1 //----------------------------------------------------------------------------------------
549 1 // If a STALL was sent out by device, it will still interrupt, but
550 1 // STALL bit in status register does not reflect this when in slave mode.
C51 COMPILER V7.20 SUBP 01/30/2007 16:37:15 PAGE 10
551 1 //----------------------------------------------------------------------------------------
552 1 else if( SL811Read(EP0AControl)&0x20 ) // check for previous stall sent
553 1 EP0A_OUT_Arm(EP0_LEN); // get ready for next SETUP token
554 1
555 1
556 1 // return;
557 1 }
558
559 //*****************************************************************************************
560 // EP0's IN Token Arming (using Set A)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -