Esempio n. 1
0
int main(void)
{
    tRectangle sRect;
    unsigned int i = 0;
    unsigned char *src = (unsigned char *) palette_32b;
    unsigned char *dest = (unsigned char *) (g_pucBuffer+4);

    MMUConfigAndEnable();

    //
    //Enable USB module clock
    //
    USB0ModuleClkConfig();
    //
    //Enable DM timer 3 module clock
    //
    DMTimer3ModuleClkConfig();
    //
    //Enbale touch screen module colock
    //
    TSCADCModuleClkConfig();
    //
    //Enable touch screen ADC pinmux
    //
    TSCADCPinMuxSetUp();
    //
    //Enbale USB interrupts
    //
    USBInterruptEnable();
    //
    //Switch ON LCD back light
    //
    LCDBackLightEnable();
    //
    //UDP Pin control
    //
    UPDNPinControl();

    //
    //Delay timer setup
    //
    DelayTimerSetup();

    //
    //Configures raster to display image
    //
    SetUpLCD();
    //
    //Register touch scren interrupt
    //
    TouchIntRegister();

    IntSystemEnable(SYS_INT_TINT3);
    IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_ADC_TSC_GENINT);
    IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ);

    RasterDMAFBConfig(SOC_LCDC_0_REGS,
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 -
                      PALETTE_OFFSET, FRAME_BUFFER_0);

    RasterDMAFBConfig(SOC_LCDC_0_REGS,
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
                      (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 -
                      PALETTE_OFFSET, FRAME_BUFFER_1);

    src = (unsigned char *) palette_32b;
    dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET);

    // Copy palette info into buffer
    for( i = PALETTE_OFFSET; i < (PALETTE_SIZE+PALETTE_OFFSET); i++)
    {
        *dest++ = *src++;
    }

    GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT);

    // Initialize a drawing context.
    GrContextInit(&g_sContext, &g_s35_480x272x24Display);

    /* enable End of frame interrupt */
    RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

    /* enable raster */
    RasterEnable(SOC_LCDC_0_REGS);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 23;
    GrContextForegroundSet(&g_sContext, ClrDarkBlue);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, &g_sFontCm20);
    GrStringDrawCentered(&g_sContext, "usb-dev-mouse", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 10, 0);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 25;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2;
    GrContextForegroundSet(&g_sContext, ClrDarkGray);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrRed);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Draw the buttons in their initial (unpressed)state.
    //
    UpdateDisplay(g_ucButtons, true);

    //
    //Initialize touch screen
    //
    TouchInit();
    //
    //Touch screen Interrupt enbale
    //
    TouchIntEnable();
    //
    //Touch Screen Enable
    //
    TouchEnable();
    //
    // Initialize the mouse
    //
    USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice);

    //
    // Drop into the main loop.
    //
    while(1)
    {
        //
        // Wait for USB configuration to complete.
        //
        while(!bConnected)
        {
        }

        //
        //Wait till someone touches the screen
        //
        while(!g_iTouch)
        {
            g_iTouch = TouchDetect();
        }

        //
        //Loop here as long as someone moving the finger/stylus on the touch screen
        //
        do
        {
            //
            //If so, read the x and Y vlaue and give it to touch handler
            //
            TouchCoOrdGet(&g_lScreenX, &g_lScreenY);
            //
            //Call touch handler
            //
            TouchHandler();

        }while(TouchDetect());
        //
        //Touch is released
        //
        g_released = 1;
        //
        //Reset the button status
        //
        g_ucButtons = 0;
        //
        //Call the touch handler to update the release status
        //
        TouchHandler();
        //
        //Reset the touch flag
        //
        g_iTouch = 0;
    }

}
/*
** Initializes the touch screen
*/
void InitTouchScreen(LcdTouch_t* structure)
{
	structure->TouchScreen_Type = TouchScreen_Type_Int;

	unsigned int i;
	/*	TSC clock config	*/
	TSCADCModuleClkConfig();
	/*	TSC pin mux	*/
	pin_mux_adc_all();

	TouchIntRegister();

	/*	Timer3 Clock config	*/
	//DMTimer3ModuleClkConfig(TimerClkSource_CLK_M_OSC);

    /* configures ADC to 3Mhz */
    TSCADCConfigureAFEClock(SOC_ADC_TSC_0_REGS, 24000000, 1000000);

    /* Enable Transistor bias */
    TSCADCTSTransistorConfig(SOC_ADC_TSC_0_REGS, TSCADC_TRANSISTOR_ENABLE);

    /* Map hardware event to Pen Touch IRQ */
    TSCADCHWEventMapSet(SOC_ADC_TSC_0_REGS, TSCADC_PEN_TOUCH);

    /* Set 4 Wire or 5 wire touch screen  mode */
    TSCADCTSModeConfig(SOC_ADC_TSC_0_REGS, TSCADC_FOUR_WIRE_MODE);

    TSCADCStepIDTagConfig(SOC_ADC_TSC_0_REGS, 1);

    /* Disable Write Protection of Step Configuration regs*/
    TSCADCStepConfigProtectionDisable(SOC_ADC_TSC_0_REGS);

    /* Configure ADC to Single ended operation mode */
    TSCADCIdleStepOperationModeControl(SOC_ADC_TSC_0_REGS,
                                    TSCADC_SINGLE_ENDED_OPER_MODE);

    /* Configure reference volatage and input to idlestep */
    TSCADCIdleStepConfig(SOC_ADC_TSC_0_REGS, TSCADC_NEGATIVE_REF_VSSA,
                         TSCADC_POSITIVE_INP_CHANNEL1, TSCADC_NEGATIVE_INP_ADCREFM,
                         TSCADC_POSITIVE_REF_VDDA);

    /* Configure the Analog Supply to Touch screen */
    TSCADCIdleStepAnalogSupplyConfig(SOC_ADC_TSC_0_REGS, TSCADC_XPPSW_PIN_OFF,
                                     TSCADC_XNPSW_PIN_OFF, TSCADC_YPPSW_PIN_OFF);

    /*
    **Configure the Analong Ground of Touch screen.
    */
    TSCADCIdleStepAnalogGroundConfig(SOC_ADC_TSC_0_REGS, TSCADC_XNNSW_PIN_OFF,
                                     TSCADC_YPNSW_PIN_ON, TSCADC_YNNSW_PIN_ON,
                                     TSCADC_WPNSW_PIN_OFF);


    /* Configure ADC to Single ended operation mode */
    TSCADCChargeStepOperationModeControl(SOC_ADC_TSC_0_REGS,
                                         TSCADC_SINGLE_ENDED_OPER_MODE);

    /* Configure reference volatage and input to charge step*/
    TSCADCChargeStepConfig(SOC_ADC_TSC_0_REGS, TSCADC_NEGATIVE_REF_XNUR,
                           TSCADC_POSITIVE_INP_CHANNEL2, TSCADC_NEGATIVE_INP_CHANNEL2,
                           TSCADC_POSITIVE_REF_XPUL);

    /* Configure the Analog Supply to Touch screen */
    TSCADCChargeStepAnalogSupplyConfig(SOC_ADC_TSC_0_REGS, TSCADC_XPPSW_PIN_ON,
                                       TSCADC_XNPSW_PIN_OFF, TSCADC_XPPSW_PIN_OFF);

    /* Configure the Analong Ground to Touch screen */
    TSCADCChargeStepAnalogGroundConfig(SOC_ADC_TSC_0_REGS, TSCADC_XNNSW_PIN_OFF,
                                       TSCADC_YPNSW_PIN_OFF, TSCADC_YNNSW_PIN_ON,
                                       TSCADC_WPNSW_PIN_OFF);

    TSCADCTSChargeStepOpenDelayConfig(SOC_ADC_TSC_0_REGS, 0x200);

    for(i = 0; i < SAMPLES; i++)
    {
         StepConfigX(i);

         TSCADCTSStepOpenDelayConfig(SOC_ADC_TSC_0_REGS, i, 0x98);
    }

    for(i = SAMPLES; i < (2 * SAMPLES); i++)
    {
         StepConfigY(i);

         TSCADCTSStepOpenDelayConfig(SOC_ADC_TSC_0_REGS, i, 0x98);
    }

    /* Configure FIFO1 threshold value */
    TSCADCFIFOIRQThresholdLevelConfig(SOC_ADC_TSC_0_REGS, TSCADC_FIFO_1, 5);

    IsTSPress = 0;
    touchRelease = 0;

	/* timer setup for touch screen */
	//IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ);
    //IntSystemEnable(SYS_INT_TINT3);
    //IntRegister(SYS_INT_TINT3, Timer3Isr);

//    DMTimerModeConfigure(SOC_DMTIMER_3_REGS, DMTIMER_ONESHOT_CMP_ENABLE);
//    DMTimerReloadSet(SOC_DMTIMER_3_REGS, 0xffffffff);
//    DMTimerCompareSet(SOC_DMTIMER_3_REGS, 0xfffff);

//    DMTimerIntStatusClear(SOC_DMTIMER_3_REGS, DMTIMER_INT_MAT_EN_FLAG);

    /* Enable the DMTimer interrupts */
//    DMTimerIntEnable(SOC_DMTIMER_3_REGS, DMTIMER_INT_MAT_EN_FLAG);

	/*	Interrupt register	*/
	TouchIntEnable();
	/*	enable touch	*/
	TouchEnable();
}
Esempio n. 3
0
/*****************************************************************************
* 
*  This is the main loop that runs the application.
* 
*****************************************************************************/
int
main(void)
{
    tRectangle sRect;
	
    MMUConfigAndEnable();
    
	/* Enable USB module clock */
	
	USB0ModuleClkConfig();
	
	/* Enable DM timer 3 module clock */
	
	DMTimer3ModuleClkConfig();
	
	/* Enbale touch screen module colock */
	
	TSCADCModuleClkConfig();
	
	/* Enable touch screen ADC pinmux */
	
	TSCADCPinMuxSetUp();    

	/* configures arm interrupt controller to generate raster interrupt  */
	
	USBInterruptEnable();        
	
	/* LCD Back light setup  */
	
	LCDBackLightEnable();	
	
	/* UPD Pin setup */
	
	UPDNPinControl();

	/* Delay timer setup */
	
	DelayTimerSetup();

	/* Configures raster to display image  */
	
	SetUpLCD();		

	/* Register touch scren interrupt */
	
	TouchIntRegister();

	IntSystemEnable(SYS_INT_TINT3);
    IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ);
	IntSystemEnable(SYS_INT_ADC_TSC_GENINT);
	IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
		
    
	/* Configures raster to display image  and Copy palette info into buffer */	
	LCDInit();
	
	GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT);
	
	/* Initialize a drawing context. */
	GrContextInit(&g_sContext, &g_s35_480x272x24Display);

	/* enable End of frame interrupt */
	RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

	/* enable raster */
	RasterEnable(SOC_LCDC_0_REGS);

	
	/* Fill the top 24 rows of the screen with blue to create the banner. */
	
	sRect.sXMin = 0;
	sRect.sYMin = 0;
	sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
	sRect.sYMax = (MAX_ROW_NUM - 1);
	GrContextForegroundSet(&g_sContext, ClrDarkBlue);
	GrRectFill(&g_sContext, &sRect);

	/* Put a white box around the banner. */
	
	GrContextForegroundSet(&g_sContext, ClrWhite);
	GrRectDraw(&g_sContext, &sRect);

	
	/* Put the application name in the middle of the banner. */
	
	GrContextFontSet(&g_sContext, &g_sFontCm20);
	GrStringDrawCentered(&g_sContext, "usb-dev-composite", -1,
						 GrContextDpyWidthGet(&g_sContext) / 2, 10, 0);
    
    sRect.sXMin = 0;
    sRect.sYMin = (MAX_ROW_NUM + 1);
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2;
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrRectFill(&g_sContext, &sRect);


    
    /* Put a white box around the banner. */
    
    GrContextForegroundSet(&g_sContext, ClrRed);
    GrRectDraw(&g_sContext, &sRect);
	
    
    /* Draw the buttons in their initial (unpressed)state. */
    
    UpdateDisplay(g_ucButtons, true);	
		
    /*  Show the various static text elements on the color STN display. */
     
    GrContextFontSet(&g_sContext, TEXT_FONT);
    GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC_STR_X_POSITION,
                  CDC_STR_Y_POSITION, false);
    GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC_STR_X_POSITION,
                 (CDC_STR_Y_POSITION + CDC_STR_Y_DIFF), false);
    GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC_STR_X_POSITION,
                  (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 3)), false);
    GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC_STR_X_POSITION,
                  (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false);
    DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, BUFFER_METER_Y_POS);
    DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, 
                    (BUFFER_METER_Y_POS + CDC_BUF_METER_Y_DIFF));

    /* Tell the user what we are up to. */
     
    DisplayStatus(&g_sContext, " Waiting for host... ");

	/* Initialize touch screen */
	 
	TouchInit();

	/* Touch screen Interrupt enbale */
	
	TouchIntEnable();
	
	/* Touch Screen Enable */
	
	TouchEnable();	
	
	  
    /* Pass the USB library our device information, initialize the USB
       controller and connect the device to the bus.
    */
    
    g_psCompDevices[0].pvInstance =
        USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice);
    g_psCompDevices[1].pvInstance =
        USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice);

    
    /* Pass the device information to the USB library and place the device
       on the bus.
    */
    
    USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE,
                      g_pucDescriptorData);

    
    /* Initialize the mouse and serial devices. */
    SerialInit();
    
    /* Drop into the main loop. */
    
    while(1)
    {
        
        /* Allow the main serial routine to run. */
        
        SerialMain();
        
        /* Allow the main mouse routine to run. */
        
        MouseMain();
    }
}