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