VirtualBox

Changeset 54787 in vbox


Ignore:
Timestamp:
Mar 16, 2015 3:06:25 PM (10 years ago)
Author:
vboxsync
Message:

PS2: A couple of todos plus better handling of incorrectly saved reporting rate.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Input/PS2M.cpp

    r54735 r54787  
    183183/* Auxiliary device operational state. */
    184184typedef 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). */
    188190} PS2M_STATE;
     191
     192/* Externally visible state bits. */
     193#define AUX_STATE_EXTERNAL  (AUX_STATE_SCALING | AUX_STATE_ENABLED | AUX_STATE_REMOTE)
    189194
    190195/* Protocols supported by the PS/2 mouse. */
     
    441446static void ps2mSetRate(PPS2M pThis, uint8_t rate)
    442447{
     448    Assert(rate);
    443449    pThis->uThrottleDelay = rate ? 1000 / rate : 0;
    444450    pThis->u8SampleRate = rate;
     
    553559
    554560
     561/* Determine whether a reporting rate is one of the valid ones. */
     562bool 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
    555578/**
    556579 * Receive and process a byte sent by the keyboard controller.
     
    606629        case ACMD_REQ_STATUS:
    607630            /* 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);
    609632            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, ARSP_ACK);
    610633            ps2kInsertQueue((GeneriQ *)&pThis->cmdQ, u8Val);
     
    696719            {
    697720                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                    }
    702744                    break;
    703745                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                    }
    709770                    break;
    710771                default:
     
    10821143    /* Load the basic auxiliary device state. */
    10831144    pThis->u8State      = u8State;
    1084     pThis->u8SampleRate = u8Rate;
     1145    pThis->u8SampleRate = u8Rate ? u8Rate : 40; /* In case it wasn't saved right. */
    10851146    pThis->enmProtocol  = (PS2M_PROTO)u8Proto;
    10861147
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette