Changeset 54787 in vbox
- Timestamp:
- Mar 16, 2015 3:06:25 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Input/PS2M.cpp
r54735 r54787 183 183 /* Auxiliary device operational state. */ 184 184 typedef enum { 185 AUX_STATE_SCALING = RT_BIT(4), /* 2:1 scaling in effect. */ 186 AUX_STATE_ENABLED = RT_BIT(5), /* Reporting enabled in stream mode. */ 187 AUX_STATE_REMOTE = RT_BIT(6) /* Remote mode (reports on request). */ 185 AUX_STATE_RATE_ERR = RT_BIT(0), /* Invalid rate received. */ 186 AUX_STATE_RES_ERR = RT_BIT(1), /* Invalid resolution received. */ 187 AUX_STATE_SCALING = RT_BIT(4), /* 2:1 scaling in effect. */ 188 AUX_STATE_ENABLED = RT_BIT(5), /* Reporting enabled in stream mode. */ 189 AUX_STATE_REMOTE = RT_BIT(6) /* Remote mode (reports on request). */ 188 190 } PS2M_STATE; 191 192 /* Externally visible state bits. */ 193 #define AUX_STATE_EXTERNAL (AUX_STATE_SCALING | AUX_STATE_ENABLED | AUX_STATE_REMOTE) 189 194 190 195 /* Protocols supported by the PS/2 mouse. */ … … 441 446 static void ps2mSetRate(PPS2M pThis, uint8_t rate) 442 447 { 448 Assert(rate); 443 449 pThis->uThrottleDelay = rate ? 1000 / rate : 0; 444 450 pThis->u8SampleRate = rate; … … 553 559 554 560 561 /* Determine whether a reporting rate is one of the valid ones. */ 562 bool ps2mIsRateSupported(uint8_t rate) 563 { 564 static uint8_t aValidRates[] = { 10, 20, 40, 60, 80, 100, 200 }; 565 int i; 566 bool fValid = false; 567 568 for (i = 0; i < RT_ELEMENTS(aValidRates); ++i) 569 if (aValidRates[i] == rate) 570 { 571 fValid = true; 572 break; 573 } 574 575 return fValid; 576 } 577 555 578 /** 556 579 * Receive and process a byte sent by the keyboard controller. … … 606 629 case ACMD_REQ_STATUS: 607 630 /* Report current status, sample rate, and resolution. */ 608 u8Val = pThis->u8State| (pThis->fCurrB & PS2M_STD_BTN_MASK);631 u8Val = (pThis->u8State & AUX_STATE_EXTERNAL) | (pThis->fCurrB & PS2M_STD_BTN_MASK); 609 632 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 610 633 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val); … … 696 719 { 697 720 case ACMD_SET_RES: 698 //@todo reject unsupported resolutions 699 pThis->u8Resolution = cmd; 700 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 701 pThis->u8CurrCmd = 0; 721 if (cmd < 4) /* Valid resolutions are 0-3. */ 722 { 723 pThis->u8Resolution = cmd; 724 pThis->u8State &= ~AUX_STATE_RES_ERR; 725 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 726 pThis->u8CurrCmd = 0; 727 } 728 else 729 { 730 /* Bad resolution. Reply with Resend or Error. */ 731 if (pThis->u8State & AUX_STATE_RES_ERR) 732 { 733 pThis->u8State &= ~AUX_STATE_RES_ERR; 734 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR); 735 pThis->u8CurrCmd = 0; 736 } 737 else 738 { 739 pThis->u8State |= AUX_STATE_RES_ERR; 740 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND); 741 /* NB: Current command remains unchanged. */ 742 } 743 } 702 744 break; 703 745 case ACMD_SET_SAMP_RATE: 704 //@todo reject unsupported rates 705 ps2mSetRate(pThis, cmd); 706 ps2mRateProtocolKnock(pThis, cmd); 707 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 708 pThis->u8CurrCmd = 0; 746 if (ps2mIsRateSupported(cmd)) 747 { 748 pThis->u8State &= ~AUX_STATE_RATE_ERR; 749 ps2mSetRate(pThis, cmd); 750 ps2mRateProtocolKnock(pThis, cmd); 751 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK); 752 pThis->u8CurrCmd = 0; 753 } 754 else 755 { 756 /* Bad rate. Reply with Resend or Error. */ 757 if (pThis->u8State & AUX_STATE_RATE_ERR) 758 { 759 pThis->u8State &= ~AUX_STATE_RATE_ERR; 760 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ERROR); 761 pThis->u8CurrCmd = 0; 762 } 763 else 764 { 765 pThis->u8State |= AUX_STATE_RATE_ERR; 766 ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_RESEND); 767 /* NB: Current command remains unchanged. */ 768 } 769 } 709 770 break; 710 771 default: … … 1082 1143 /* Load the basic auxiliary device state. */ 1083 1144 pThis->u8State = u8State; 1084 pThis->u8SampleRate = u8Rate ;1145 pThis->u8SampleRate = u8Rate ? u8Rate : 40; /* In case it wasn't saved right. */ 1085 1146 pThis->enmProtocol = (PS2M_PROTO)u8Proto; 1086 1147
Note:
See TracChangeset
for help on using the changeset viewer.