Exemplo n.º 1
0
void SPI1TouchInit(void)
{

    extern NVM_READ_FUNC           pCalDataRead;                  // function pointer to data read
    extern NVM_WRITE_FUNC          pCalDataWrite;                 // function pointer to data write
    extern NVM_SECTORERASE_FUNC    pCalDataSectorErase;           // function pointer to data sector erase

    TouchHardwareInit(NULL);

	// assign the addresses of the callback functions
	// if these are NULL, the TouchLoadCalibration()
	// and TouchStoreCalibration() will skip the actual
	// read and/or writes.
	pCalDataWrite = NVMWrite;
	pCalDataSectorErase = NVMSectorErase;
	pCalDataRead = NVMRead;
    
		// check if version of library is correct
		// MCHP_TOUCHSCREEN_RESISTIVE_VERSION should be defined in the hardware profile.
		if (pCalDataRead(ADDRESS_RESISTIVE_TOUCH_VERSION) !=  0xF100)
		{
            SPI1CONbits.ON=0;
			// not calibrated yet, perform the calibration 
			TouchCalibration();
            SPI1CONbits.ON=1;
			// store the calibration data
			TouchStoreCalibration();
		}
		else
		{
            SPI1CONbits.ON=0;
			// check if user wants to run calibration 
			TouchCheckForCalibration();
		}

		// load the calibration values, to check if the store worked
		TouchLoadCalibration();
        SPI1CONbits.ON=0;
}
Exemplo n.º 2
0
int main(void)
{
    GOL_MSG msg;                    // GOL message structure to interact with GOL
    
    Nop();
    
    #if defined(PIC24FJ256DA210_DEV_BOARD)
    
    _ANSG8 = 0; /* S1 */
    _ANSE9 = 0; /* S2 */
    _ANSB5 = 0; /* S3 */
        
    #else
    /////////////////////////////////////////////////////////////////////////////
    // ADC Explorer 16 Development Board Errata (work around 2)
    // RB15 should be output
    /////////////////////////////////////////////////////////////////////////////
	#ifndef MULTI_MEDIA_BOARD_DM00123
    LATBbits.LATB15 = 0;
    TRISBbits.TRISB15 = 0;
    #endif
	#endif
    /////////////////////////////////////////////////////////////////////////////
    #if defined(__dsPIC33F__) || defined(__PIC24H__)

    // Configure Oscillator to operate the device at 40Mhz
    // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2
    // Fosc= 8M*40(2*2)=80Mhz for 8M input clock
    PLLFBD = 38;                    // M=40
    CLKDIVbits.PLLPOST = 0;         // N1=2
    CLKDIVbits.PLLPRE = 0;          // N2=2
    OSCTUN = 0;                     // Tune FRC oscillator, if FRC is used

    // Disable Watch Dog Timer
    RCONbits.SWDTEN = 0;

    // Clock switching to incorporate PLL
    __builtin_write_OSCCONH(0x03);  // Initiate Clock Switch to Primary

    // Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONL(0x01);  // Start clock switching
    while(OSCCONbits.COSC != 0b011);

    // Wait for Clock switch to occur	
    // Wait for PLL to lock
    while(OSCCONbits.LOCK != 1)
    { };
    
    // Set PMD0 pin functionality to digital
    AD1PCFGL = AD1PCFGL | 0x1000;
    
    #elif defined(__PIC32MX__)
    INTEnableSystemMultiVectoredInt();
    SYSTEMConfigPerformance(GetSystemClock());
    #ifdef MULTI_MEDIA_BOARD_DM00123
    CPLDInitialize();
    CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG);
    CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL);
    #endif // #ifdef MULTI_MEDIA_BOARD_DM00123
    #endif // #if defined(__dsPIC33F__) || defined(__PIC24H__)

    GOLInit();                      // initialize graphics library &
                                    // create default style scheme for GOL

    #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2)
    EEPROMInit();                   // initialize Exp.16 EEPROM SPI
    BeepInit();
    #else
	    #if defined (USE_SST25VF016)
            SST25Init();            // initialize GFX3 SST25 flash SPI
        #endif
    #endif
    
    TouchInit();                    // initialize touch screen
    HardwareButtonInit();           // Initialize the hardware buttons

    // create default style scheme for GOL
    TickInit();                     // initialize tick counter (for random number generation)

    // create default style scheme for GOL
    #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__)

    // If S3 button on Explorer 16 board is pressed calibrate touch screen
    TRISAbits.TRISA9 = 1;
    if(PORTAbits.RA9 == 0)
    {
        TRISAbits.TRISA9 = 0;
        TouchCalibration();
        TouchStoreCalibration();
    }

    TRISAbits.TRISA9 = 0;
	#else

	    /**
	     * Force a touchscreen calibration by pressing the switch
	     * Explorer 16 + GFX PICTail    - S3 (8 bit PMP)
	     * Explorer 16 + GFX PICTail    - S5 (16 bit PMP)
	     * Starter Kit + GFX PICTail    - S0 (8 bit PMP)
	     * Multimedia Expansion Board   - Fire Button
	     * DA210 Developement Board     - S1
	     * NOTE:    Starter Kit + GFX PICTail will switches are shared
	     *          with the 16 bit PMP data bus.
	     **/
	    if(GetHWButtonTouchCal() == HW_BUTTON_PRESS)
	    {
	        TouchCalibration();
	        TouchStoreCalibration();
	    }
    #endif

    // If it's a new board (EEPROM_VERSION byte is not programed) calibrate touch screen
    #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2)
    if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(ADDRESS_VERSION))
    {
        TouchCalibration();
        TouchStoreCalibration();
    }

    #else
        #if defined (USE_SST25VF016)
        if(GRAPHICS_LIBRARY_VERSION != SST25ReadWord(ADDRESS_VERSION))
        {
            TouchCalibration();
            TouchStoreCalibration();
        }
        #elif defined (USE_SST39LF400)
        WORD tempArray[12], tempWord = 0x1234;

        SST39LF400Init(tempArray);
        tempWord = SST39LF400ReadWord(ADDRESS_VERSION);
        SST39LF400DeInit(tempArray);

        if(GRAPHICS_LIBRARY_VERSION != tempWord)
        {
            TouchCalibration();
            TouchStoreCalibration();
        }
        #endif
    #endif

    // Load touch screen calibration parameters from memory
    TouchLoadCalibration();

    GDDDemoCreateFirstScreen();

    while(1)
    {
        if(GOLDraw())               // Draw GOL object
        {
            TouchGetMsg(&msg);      // Get message from touch screen
			
            #if (NUM_GDD_SCREENS > 1)
			// GDD Readme:
			// The following line of code allows a GDD user to touch the touchscreen
			// to cycle through different static screens for viewing. This is useful as a
			// quick way to view how each screen looks on the physical target hardware.
			// This line of code should eventually be commented out for actual development.
			// Also note that widget/object names can be found in GDD_Screens.h
			if(msg.uiEvent == EVENT_RELEASE) GDDDemoNextScreen();
			#endif
			
            GOLMsg(&msg);           // Process message
        }
    }//end while
}