Esempio n. 1
0
//*****************************************************************************
//
//! Handles the ADC interrupt for the touch screen.
//!
//! This function is called when the ADC sequence that samples the touch screen
//! has completed its acquisition.  The touch screen state machine is advanced
//! and the acquired ADC sample is processed appropriately.
//!
//! It is the responsibility of the application using the touch screen driver
//! to ensure that this function is installed in the interrupt vector table for
//! the ADC3 interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenIntHandler(void)
{
    //
    // Clear the ADC sample sequence interrupt.
    //
    HWREG(ADC0_BASE + ADC_O_ISC) = 1 << 3;

    //
    // Determine what to do based on the current state of the state machine.
    //
    switch(g_ulTSState)
    {
        //
        // The new sample is an X axis sample that should be discarded.
        //
        case TS_STATE_SKIP_X:
        {
            //
            // Read and throw away the ADC sample.
            //
            HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Set the analog mode select for the YP pin.
            //
            HWREG(TS_P_BASE + GPIO_O_AMSEL) =
                HWREG(TS_P_BASE + GPIO_O_AMSEL) | TS_YP_PIN;

            //
            // Configure the Y axis touch layer pins as inputs.
            //
            HWREG(TS_P_BASE + GPIO_O_DIR) =
                HWREG(TS_P_BASE + GPIO_O_DIR) & ~TS_YP_PIN;
            if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
            {
                HWREGB(LCD_CONTROL_SET_REG) = LCD_CONTROL_YN;
            }
            else if(g_eDaughterType == DAUGHTER_FPGA)
            {
                HWREGH(LCD_FPGA_CONTROL_SET_REG) = LCD_CONTROL_YN;
            }
            else
            {
                //
                // Default case with no daughter, SDRAM board or any other
                // daughter which doesn't mess with the touchscreen interface.
                //
                HWREG(TS_N_BASE + GPIO_O_DIR) =
                    HWREG(TS_N_BASE + GPIO_O_DIR) & ~TS_YN_PIN;
            }

            //
            // The next sample will be a valid X axis sample.
            //
            g_ulTSState = TS_STATE_READ_X;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is an X axis sample that should be processed.
        //
        case TS_STATE_READ_X:
        {
            //
            // Read the raw ADC sample.
            //
            g_sTouchX = HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Clear the analog mode select for the YP pin.
            //
            HWREG(TS_P_BASE + GPIO_O_AMSEL) =
                HWREG(TS_P_BASE + GPIO_O_AMSEL) & ~TS_YP_PIN;

            //
            // Configure the X and Y axis touch layers as outputs.
            //
            HWREG(TS_P_BASE + GPIO_O_DIR) =
                HWREG(TS_P_BASE + GPIO_O_DIR) | TS_XP_PIN | TS_YP_PIN;

            if((g_eDaughterType != DAUGHTER_SRAM_FLASH) &&
               (g_eDaughterType != DAUGHTER_FPGA))
            {
                HWREG(TS_N_BASE + GPIO_O_DIR) =
                    HWREG(TS_N_BASE + GPIO_O_DIR) | TS_XN_PIN | TS_YN_PIN;
            }

            //
            // Drive the positive side of the Y axis touch layer with VDD and
            // the negative side with GND.  Also, drive both sides of the X
            // axis layer with GND to discharge any residual voltage (so that
            // a no-touch condition can be properly detected).
            //
            if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
            {
                HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
            }
            else if(g_eDaughterType == DAUGHTER_FPGA)
            {
                HWREGH(LCD_FPGA_CONTROL_CLR_REG) = (LCD_CONTROL_XN |
                                                    LCD_CONTROL_YN);
            }
            else
            {
                //
                // Default case - any daughter which doesn't muck with the
                // touchscreen signals.
                //
                HWREG(TS_N_BASE + GPIO_O_DATA +
                      ((TS_XN_PIN | TS_YN_PIN) << 2)) = 0;
            }

            HWREG(TS_P_BASE + GPIO_O_DATA + ((TS_XP_PIN | TS_YP_PIN) << 2)) =
                TS_YP_PIN;

            //
            // Configure the sample sequence to capture the X axis value.
            //
            HWREG(ADC0_BASE + ADC_O_SSMUX3) = ADC_CTL_CH_XP;

            //
            // The next sample will be an invalid Y axis sample.
            //
            g_ulTSState = TS_STATE_SKIP_Y;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is a Y axis sample that should be discarded.
        //
        case TS_STATE_SKIP_Y:
        {
            //
            // Read and throw away the ADC sample.
            //
            HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Set the analog mode select for the XP pin.
            //
            HWREG(TS_P_BASE + GPIO_O_AMSEL) =
                HWREG(TS_P_BASE + GPIO_O_AMSEL) | TS_XP_PIN;

            //
            // Configure the X axis touch layer pins as inputs.
            //
            HWREG(TS_P_BASE + GPIO_O_DIR) =
                HWREG(TS_P_BASE + GPIO_O_DIR) & ~TS_XP_PIN;
            if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
            {
                HWREGB(LCD_CONTROL_SET_REG) = LCD_CONTROL_XN;
            }
            else if(g_eDaughterType == DAUGHTER_FPGA)
            {
                HWREGH(LCD_FPGA_CONTROL_SET_REG) = LCD_CONTROL_XN;
            }
            else
            {
                //
                // Default case - any daughter which doesn't muck with the
                // touchscreen signals.
                //
                HWREG(TS_N_BASE + GPIO_O_DIR) =
                    HWREG(TS_N_BASE + GPIO_O_DIR) & ~TS_XN_PIN;
            }

            //
            // The next sample will be a valid Y axis sample.
            //
            g_ulTSState = TS_STATE_READ_Y;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is a Y axis sample that should be processed.
        //
        case TS_STATE_READ_Y:
        {
            //
            // Read the raw ADC sample.
            //
            g_sTouchY = HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // The next configuration is the same as the initial configuration.
            // Therefore, fall through into the initialization state to avoid
            // duplicating the code.
            //
        }

        //
        // The state machine is in its initial state
        //
        case TS_STATE_INIT:
        {
            //
            // Clear the analog mode select for the XP pin.
            //
            HWREG(TS_P_BASE + GPIO_O_AMSEL) =
                HWREG(TS_P_BASE + GPIO_O_AMSEL) & ~TS_XP_PIN;

            //
            // Configure the X and Y axis touch layers as outputs.
            //
            HWREG(TS_P_BASE + GPIO_O_DIR) =
                HWREG(TS_P_BASE + GPIO_O_DIR) | TS_XP_PIN | TS_YP_PIN;
            if((g_eDaughterType != DAUGHTER_SRAM_FLASH) &&
               (g_eDaughterType != DAUGHTER_FPGA))
            {
                HWREG(TS_N_BASE + GPIO_O_DIR) =
                    HWREG(TS_N_BASE + GPIO_O_DIR) | TS_XN_PIN | TS_YN_PIN;
            }

            //
            // Drive one side of the X axis touch layer with VDD and the other
            // with GND.  Also, drive both sides of the Y axis layer with GND
            // to discharge any residual voltage (so that a no-touch condition
            // can be properly detected).
            //
            HWREG(TS_P_BASE + GPIO_O_DATA + ((TS_XP_PIN | TS_YP_PIN) << 2)) =
                TS_XP_PIN;
            if(g_eDaughterType == DAUGHTER_SRAM_FLASH)
            {
                HWREGB(LCD_CONTROL_CLR_REG) = LCD_CONTROL_XN | LCD_CONTROL_YN;
            }
            else if(g_eDaughterType == DAUGHTER_FPGA)
            {
                HWREGH(LCD_FPGA_CONTROL_CLR_REG) = (LCD_CONTROL_XN |
                                                    LCD_CONTROL_YN);
            }
            else
            {
                //
                // Default case - any daughter which does not muck with the
                // touchscreen signals.
                //
                HWREG(TS_N_BASE + GPIO_O_DATA +
                      ((TS_XN_PIN | TS_YN_PIN) << 2)) = 0;
            }


            //
            // Configure the sample sequence to capture the Y axis value.
            //
            HWREG(ADC0_BASE + ADC_O_SSMUX3) = ADC_CTL_CH_YP;

            //
            // If this is the valid Y sample state, then there is a new X/Y
            // sample pair.  In that case, run the touch screen debouncer.
            //
            if(g_ulTSState == TS_STATE_READ_Y)
            {
                TouchScreenDebouncer();
            }

            //
            // The next sample will be an invalid X axis sample.
            //
            g_ulTSState = TS_STATE_SKIP_X;

            //
            // This state has been handled.
            //
            break;
        }
    }
}
Esempio n. 2
0
//*****************************************************************************
//
//! Handles the ADC interrupt for the touch screen.
//!
//! This function is called when the ADC sequence that samples the touch screen
//! has completed its acquisition.  The touch screen state machine is advanced
//! and the acquired ADC sample is processed appropriately.
//!
//! It is the responsibility of the application using the touch screen driver
//! to ensure that this function is installed in the interrupt vector table for
//! the ADC0 samples sequencer 3 interrupt.
//!
//! \return None.
//
//*****************************************************************************
void
TouchScreenIntHandler(void)
{
    //
    // Clear the ADC sample sequence interrupt.
    //
    HWREG(ADC0_BASE + ADC_O_ISC) = ADC_ISC_IN3;

    //
    // Determine what to do based on the current state of the state machine.
    //
    switch(g_ui32TSState) {
        //
        // The new sample is an X axis sample that should be discarded.
        //
        case TS_STATE_SKIP_X: {
            //
            // Read and throw away the ADC sample.
            //
            HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Set the analog mode select for the YP pin.
            //
            HWREG(TS_YP_BASE + GPIO_O_AMSEL) |= TS_YP_PIN;

            //
            // Configure the Y axis touch layer pins as inputs.
            //
            HWREG(TS_YP_BASE + GPIO_O_DIR) &= ~TS_YP_PIN;
            HWREG(TS_YN_BASE + GPIO_O_DIR) &= ~TS_YN_PIN;

            //
            // The next sample will be a valid X axis sample.
            //
            g_ui32TSState = TS_STATE_READ_X;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is an X axis sample that should be processed.
        //
        case TS_STATE_READ_X: {
            //
            // Read the raw ADC sample.
            //
            g_i16TouchX = HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Clear the analog mode select for the YP pin.
            //
            HWREG(TS_YP_BASE + GPIO_O_AMSEL) &= ~TS_YP_PIN;

            //
            // Configure the X and Y axis touch layers as outputs.
            //
            HWREG(TS_XP_BASE + GPIO_O_DIR) |= TS_XP_PIN;
            HWREG(TS_XN_BASE + GPIO_O_DIR) |= TS_XN_PIN;
            HWREG(TS_YP_BASE + GPIO_O_DIR) |= TS_YP_PIN;
            HWREG(TS_YN_BASE + GPIO_O_DIR) |= TS_YN_PIN;

            //
            // Drive the positive side of the Y axis touch layer with VDD and
            // the negative side with GND.  Also, drive both sides of the X
            // axis layer with GND to discharge any residual voltage (so that
            // a no-touch condition can be properly detected).
            //
            HWREG(TS_XP_BASE + GPIO_O_DATA + (TS_XP_PIN << 2)) = 0;
            HWREG(TS_XN_BASE + GPIO_O_DATA + (TS_XN_PIN << 2)) = 0;
            HWREG(TS_YP_BASE + GPIO_O_DATA + (TS_YP_PIN << 2)) = TS_YP_PIN;
            HWREG(TS_YN_BASE + GPIO_O_DATA + (TS_YN_PIN << 2)) = 0;

            //
            // Configure the sample sequence to capture the X axis value.
            //
            HWREG(ADC0_BASE + ADC_O_SSMUX3) = TS_XP_ADC;

            //
            // The next sample will be an invalid Y axis sample.
            //
            g_ui32TSState = TS_STATE_SKIP_Y;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is a Y axis sample that should be discarded.
        //
        case TS_STATE_SKIP_Y: {
            //
            // Read and throw away the ADC sample.
            //
            HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // Set the analog mode select for the XP pin.
            //
            HWREG(TS_XP_BASE + GPIO_O_AMSEL) |= TS_XP_PIN;

            //
            // Configure the X axis touch layer pins as inputs.
            //
            HWREG(TS_XP_BASE + GPIO_O_DIR) &= ~TS_XP_PIN;
            HWREG(TS_XN_BASE + GPIO_O_DIR) &= ~TS_XN_PIN;

            //
            // The next sample will be a valid Y axis sample.
            //
            g_ui32TSState = TS_STATE_READ_Y;

            //
            // This state has been handled.
            //
            break;
        }

        //
        // The new sample is a Y axis sample that should be processed.
        //
        case TS_STATE_READ_Y: {
            //
            // Read the raw ADC sample.
            //
            g_i16TouchY = HWREG(ADC0_BASE + ADC_O_SSFIFO3);

            //
            // The next configuration is the same as the initial configuration.
            // Therefore, fall through into the initialization state to avoid
            // duplicating the code.
            //
        }

        //
        // The state machine is in its initial state
        //
        case TS_STATE_INIT: {
            //
            // Clear the analog mode select for the XP pin.
            //
            HWREG(TS_XP_BASE + GPIO_O_AMSEL) &= ~TS_XP_PIN;

            //
            // Configure the X and Y axis touch layers as outputs.
            //
            HWREG(TS_XP_BASE + GPIO_O_DIR) |= TS_XP_PIN;
            HWREG(TS_XN_BASE + GPIO_O_DIR) |= TS_XN_PIN;
            HWREG(TS_YP_BASE + GPIO_O_DIR) |= TS_YP_PIN;
            HWREG(TS_YN_BASE + GPIO_O_DIR) |= TS_YN_PIN;

            //
            // Drive one side of the X axis touch layer with VDD and the other
            // with GND.  Also, drive both sides of the Y axis layer with GND
            // to discharge any residual voltage (so that a no-touch condition
            // can be properly detected).
            //
            HWREG(TS_XP_BASE + GPIO_O_DATA + (TS_XP_PIN << 2)) = TS_XP_PIN;
            HWREG(TS_XN_BASE + GPIO_O_DATA + (TS_XN_PIN << 2)) = 0;
            HWREG(TS_YP_BASE + GPIO_O_DATA + (TS_YP_PIN << 2)) = 0;
            HWREG(TS_YN_BASE + GPIO_O_DATA + (TS_YN_PIN << 2)) = 0;

            //
            // Configure the sample sequence to capture the Y axis value.
            //
            HWREG(ADC0_BASE + ADC_O_SSMUX3) = TS_YP_ADC;

            //
            // If this is the valid Y sample state, then there is a new X/Y
            // sample pair.  In that case, run the touch screen debouncer.
            //
            if(g_ui32TSState == TS_STATE_READ_Y) {
                TouchScreenDebouncer();
            }

            //
            // The next sample will be an invalid X axis sample.
            //
            g_ui32TSState = TS_STATE_SKIP_X;

            //
            // This state has been handled.
            //
            break;
        }
    }
}