| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /***************************************************************************** |
| 2 | * Microchip Graphics Library |
||
| 3 | * Graphics Display Designer (GDD) Template |
||
| 4 | ***************************************************************************** |
||
| 5 | * FileName: Main.c |
||
| 6 | * Dependencies: Main.h |
||
| 7 | * Processor: PIC24F, PIC24H, dsPIC, PIC32 |
||
| 8 | * Compiler: MPLAB C30/C32 |
||
| 9 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
| 10 | * Company: Microchip Technology Incorporated |
||
| 11 | * |
||
| 12 | * Software License Agreement |
||
| 13 | * |
||
| 14 | * Copyright © 2010 Microchip Technology Inc. All rights reserved. |
||
| 15 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
| 16 | * Software only when embedded on a Microchip microcontroller or digital |
||
| 17 | * signal controller, which is integrated into your product or third party |
||
| 18 | * product (pursuant to the sublicense terms in the accompanying license |
||
| 19 | * agreement). |
||
| 20 | * |
||
| 21 | * You should refer to the license agreement accompanying this Software |
||
| 22 | * for additional information regarding your rights and obligations. |
||
| 23 | * |
||
| 24 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
| 25 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
| 26 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
| 27 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
| 28 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
| 29 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
| 30 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
| 31 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
| 32 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
| 33 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
| 34 | * OR OTHER SIMILAR COSTS. |
||
| 35 | * |
||
| 36 | * Author Date Comment |
||
| 37 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 38 | * |
||
| 39 | *****************************************************************************/ |
||
| 40 | #include "Main.h" |
||
| 41 | #include "GDD_Screens.h" |
||
| 42 | |||
| 43 | // Configuration bits |
||
| 44 | #if defined(__dsPIC33F__) || defined(__PIC24H__) |
||
| 45 | _FOSCSEL(FNOSC_PRI); |
||
| 46 | _FOSC(FCKSM_CSECMD &OSCIOFNC_OFF &POSCMD_XT); |
||
| 47 | _FWDT(FWDTEN_OFF); |
||
| 48 | #elif defined(__PIC32MX__) |
||
| 49 | #pragma config FPLLODIV = DIV_1, FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FWDTEN = OFF, FCKSM = CSECME, FPBDIV = DIV_1 |
||
| 50 | #pragma config OSCIOFNC = ON, POSCMOD = XT, FSOSCEN = ON, FNOSC = PRIPLL |
||
| 51 | #pragma config CP = OFF, BWP = OFF, PWP = OFF |
||
| 52 | #else |
||
| 53 | #if defined(__PIC24FJ256GB110__) |
||
| 54 | _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) |
||
| 55 | _CONFIG2(0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_OFF) |
||
| 56 | #endif |
||
| 57 | #if defined(__PIC24FJ256GA110__) |
||
| 58 | _CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2) |
||
| 59 | _CONFIG2(IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & IOL1WAY_OFF) |
||
| 60 | #endif |
||
| 61 | #if defined(__PIC24FJ128GA010__) |
||
| 62 | _CONFIG2(FNOSC_PRIPLL & POSCMOD_XT) // Primary XT OSC with PLL |
||
| 63 | _CONFIG1(JTAGEN_OFF & FWDTEN_OFF) // JTAG off, watchdog timer off |
||
| 64 | #endif |
||
| 65 | #if defined (__PIC24FJ256GB210__) |
||
| 66 | _CONFIG1( WDTPS_PS32768 & FWPSA_PR128 & ALTVREF_ALTVREDIS & WINDIS_OFF & FWDTEN_OFF & ICS_PGx2 & GWRP_OFF & GCP_OFF & JTAGEN_OFF) |
||
| 67 | _CONFIG2( POSCMOD_HS & IOL1WAY_OFF & OSCIOFNC_OFF & OSCIOFNC_OFF & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF) |
||
| 68 | _CONFIG3( WPFP_WPFP255 & SOSCSEL_SOSC & WUTSEL_LEG & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM) |
||
| 69 | #endif |
||
| 70 | #if defined (__PIC24FJ256DA210__) |
||
| 71 | _CONFIG1( WDTPS_PS32768 & FWPSA_PR128 & ALTVREF_ALTVREDIS & WINDIS_OFF & FWDTEN_OFF & ICS_PGx2 & GWRP_OFF & GCP_OFF & JTAGEN_OFF) |
||
| 72 | _CONFIG2( POSCMOD_HS & IOL1WAY_OFF & OSCIOFNC_OFF & OSCIOFNC_OFF & FCKSM_CSDCMD & FNOSC_PRIPLL & PLL96MHZ_ON & PLLDIV_DIV2 & IESO_OFF) |
||
| 73 | _CONFIG3( WPFP_WPFP255 & SOSCSEL_SOSC & WUTSEL_LEG & ALTPMP_ALTPMPEN & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM) |
||
| 74 | #endif |
||
| 75 | #endif |
||
| 76 | |||
| 77 | ///////////////////////////////////////////////////////////////////////////// |
||
| 78 | // LOCAL PROTOTYPES |
||
| 79 | ///////////////////////////////////////////////////////////////////////////// |
||
| 80 | void TickInit(void); // starts tick counter |
||
| 81 | |||
| 82 | /* */ |
||
| 83 | int main(void) |
||
| 84 | { |
||
| 85 | GOL_MSG msg; // GOL message structure to interact with GOL |
||
| 86 | |||
| 87 | Nop(); |
||
| 88 | |||
| 89 | #if defined(PIC24FJ256DA210_DEV_BOARD) |
||
| 90 | |||
| 91 | _ANSG8 = 0; /* S1 */ |
||
| 92 | _ANSE9 = 0; /* S2 */ |
||
| 93 | _ANSB5 = 0; /* S3 */ |
||
| 94 | |||
| 95 | #else |
||
| 96 | ///////////////////////////////////////////////////////////////////////////// |
||
| 97 | // ADC Explorer 16 Development Board Errata (work around 2) |
||
| 98 | // RB15 should be output |
||
| 99 | ///////////////////////////////////////////////////////////////////////////// |
||
| 100 | LATBbits.LATB15 = 0; |
||
| 101 | TRISBbits.TRISB15 = 0; |
||
| 102 | #endif |
||
| 103 | ///////////////////////////////////////////////////////////////////////////// |
||
| 104 | #if defined(__dsPIC33F__) || defined(__PIC24H__) |
||
| 105 | |||
| 106 | // Configure Oscillator to operate the device at 40Mhz |
||
| 107 | // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 |
||
| 108 | // Fosc= 8M*40(2*2)=80Mhz for 8M input clock |
||
| 109 | PLLFBD = 38; // M=40 |
||
| 110 | CLKDIVbits.PLLPOST = 0; // N1=2 |
||
| 111 | CLKDIVbits.PLLPRE = 0; // N2=2 |
||
| 112 | OSCTUN = 0; // Tune FRC oscillator, if FRC is used |
||
| 113 | |||
| 114 | // Disable Watch Dog Timer |
||
| 115 | RCONbits.SWDTEN = 0; |
||
| 116 | |||
| 117 | // Clock switching to incorporate PLL |
||
| 118 | __builtin_write_OSCCONH(0x03); // Initiate Clock Switch to Primary |
||
| 119 | |||
| 120 | // Oscillator with PLL (NOSC=0b011) |
||
| 121 | __builtin_write_OSCCONL(0x01); // Start clock switching |
||
| 122 | while(OSCCONbits.COSC != 0b011); |
||
| 123 | |||
| 124 | // Wait for Clock switch to occur |
||
| 125 | // Wait for PLL to lock |
||
| 126 | while(OSCCONbits.LOCK != 1) |
||
| 127 | { }; |
||
| 128 | |||
| 129 | // Set PMD0 pin functionality to digital |
||
| 130 | AD1PCFGL = AD1PCFGL | 0x1000; |
||
| 131 | |||
| 132 | #elif defined(__PIC32MX__) |
||
| 133 | INTEnableSystemMultiVectoredInt(); |
||
| 134 | SYSTEMConfigPerformance(GetSystemClock()); |
||
| 135 | #ifdef MULTI_MEDIA_BOARD_DM00123 |
||
| 136 | CPLDInitialize(); |
||
| 137 | CPLDSetGraphicsConfiguration(GRAPHICS_HW_CONFIG); |
||
| 138 | CPLDSetSPIFlashConfiguration(SPI_FLASH_CHANNEL); |
||
| 139 | #endif |
||
| 140 | #endif |
||
| 141 | |||
| 142 | GOLInit(); // initialize graphics library & |
||
| 143 | |||
| 144 | #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2) |
||
| 145 | EEPROMInit(); // initialize Exp.16 EEPROM SPI |
||
| 146 | BeepInit(); |
||
| 147 | #else |
||
| 148 | SST25Init(); // initialize GFX3 SST25 flash SPI |
||
| 149 | #endif |
||
| 150 | |||
| 151 | TouchInit(); // initialize touch screen |
||
| 152 | |||
| 153 | // create default style scheme for GOL |
||
| 154 | TickInit(); // initialize tick counter (for random number generation) |
||
| 155 | |||
| 156 | // create default style scheme for GOL |
||
| 157 | #if defined(__dsPIC33FJ128GP804__) || defined(__PIC24HJ128GP504__) |
||
| 158 | |||
| 159 | // If S3 button on Explorer 16 board is pressed calibrate touch screen |
||
| 160 | TRISAbits.TRISA9 = 1; |
||
| 161 | if(PORTAbits.RA9 == 0) |
||
| 162 | { |
||
| 163 | TRISAbits.TRISA9 = 0; |
||
| 164 | TouchCalibration(); |
||
| 165 | TouchStoreCalibration(); |
||
| 166 | } |
||
| 167 | |||
| 168 | TRISAbits.TRISA9 = 0; |
||
| 169 | #elif defined(__PIC24FJ256DA210__) |
||
| 170 | |||
| 171 | // If S1 button on the PIC24FJ256DA210 Development board is pressed calibrate touch screen |
||
| 172 | if(BTN_S1 == 0) |
||
| 173 | { |
||
| 174 | TouchCalibration(); |
||
| 175 | TouchStoreCalibration(); |
||
| 176 | } |
||
| 177 | |||
| 178 | #else |
||
| 179 | |||
| 180 | // If S3 button on Explorer 16 board is pressed calibrate touch screen |
||
| 181 | if(BTN_S3 == 0) |
||
| 182 | { |
||
| 183 | TouchCalibration(); |
||
| 184 | TouchStoreCalibration(); |
||
| 185 | } |
||
| 186 | |||
| 187 | #endif |
||
| 188 | |||
| 189 | // If it's a new board (EEPROM_VERSION byte is not programed) calibrate touch screen |
||
| 190 | #if defined (GFX_PICTAIL_V1) || defined (GFX_PICTAIL_V2) |
||
| 191 | if(GRAPHICS_LIBRARY_VERSION != EEPROMReadWord(ADDRESS_VERSION)) |
||
| 192 | { |
||
| 193 | TouchCalibration(); |
||
| 194 | TouchStoreCalibration(); |
||
| 195 | } |
||
| 196 | |||
| 197 | #else |
||
| 198 | if(GRAPHICS_LIBRARY_VERSION != SST25ReadWord(ADDRESS_VERSION)) |
||
| 199 | { |
||
| 200 | TouchCalibration(); |
||
| 201 | TouchStoreCalibration(); |
||
| 202 | } |
||
| 203 | |||
| 204 | #endif |
||
| 205 | |||
| 206 | // Load touch screen calibration parameters from memory |
||
| 207 | TouchLoadCalibration(); |
||
| 208 | |||
| 209 | GDDDemoCreateFirstScreen(); |
||
| 210 | |||
| 211 | while(1) |
||
| 212 | { |
||
| 213 | if(GOLDraw()) // Draw GOL object |
||
| 214 | { |
||
| 215 | TouchGetMsg(&msg); // Get message from touch screen |
||
| 216 | |||
| 217 | #if (NUM_GDD_SCREENS > 1) |
||
| 218 | // GDD Readme: |
||
| 219 | // The following line of code allows a GDD user to touch the touchscreen |
||
| 220 | // to cycle through different static screens for viewing. This is useful as a |
||
| 221 | // quick way to view how each screen looks on the physical target hardware. |
||
| 222 | // This line of code should eventually be commented out for actual development. |
||
| 223 | // Also note that widget/object names can be found in GDD_Screens.h |
||
| 224 | if(msg.uiEvent == EVENT_RELEASE) GDDDemoNextScreen(); |
||
| 225 | #endif |
||
| 226 | |||
| 227 | GOLMsg(&msg); // Process message |
||
| 228 | } |
||
| 229 | }//end while |
||
| 230 | } |
||
| 231 | |||
| 232 | ///////////////////////////////////////////////////////////////////////////// |
||
| 233 | // Function: WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) |
||
| 234 | // Input: objMsg - translated message for the object, |
||
| 235 | // pObj - pointer to the object, |
||
| 236 | // pMsg - pointer to the non-translated, raw GOL message |
||
| 237 | // Output: if the function returns non-zero the message will be processed by default |
||
| 238 | // Overview: it's a user defined function. GOLMsg() function calls it each |
||
| 239 | |||
| 240 | // time the valid message for the object received |
||
| 241 | ///////////////////////////////////////////////////////////////////////////// |
||
| 242 | WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER *pObj, GOL_MSG *pMsg) |
||
| 243 | { |
||
| 244 | WORD objectID; |
||
| 245 | |||
| 246 | objectID = GetObjID(pObj); |
||
| 247 | |||
| 248 | GDDDemoGOLMsgCallback(objMsg, pObj, pMsg); |
||
| 249 | |||
| 250 | // Add additional code here... |
||
| 251 | |||
| 252 | return (1); |
||
| 253 | } |
||
| 254 | |||
| 255 | ///////////////////////////////////////////////////////////////////////////// |
||
| 256 | // Function: WORD GOLDrawCallback() |
||
| 257 | // Output: if the function returns non-zero the draw control will be passed to GOL |
||
| 258 | // Overview: it's a user defined function. GOLDraw() function calls it each |
||
| 259 | // time when GOL objects drawing is completed. User drawing should be done here. |
||
| 260 | // GOL will not change color, line type and clipping region settings while |
||
| 261 | |||
| 262 | // this function returns zero. |
||
| 263 | ///////////////////////////////////////////////////////////////////////////// |
||
| 264 | WORD GOLDrawCallback(void) |
||
| 265 | { |
||
| 266 | GDDDemoGOLDrawCallback(); |
||
| 267 | |||
| 268 | // Add additional code here... |
||
| 269 | |||
| 270 | return (1); |
||
| 271 | } |
||
| 272 | |||
| 273 | |||
| 274 | ///////////////////////////////////////////////////////////////////////////// |
||
| 275 | // Function: Timer3 ISR |
||
| 276 | // Input: none |
||
| 277 | // Output: none |
||
| 278 | // Overview: increments tick counter. Tick is approx. 1 ms. |
||
| 279 | ///////////////////////////////////////////////////////////////////////////// |
||
| 280 | #ifdef __PIC32MX__ |
||
| 281 | #define __T3_ISR __ISR(_TIMER_3_VECTOR, ipl4) |
||
| 282 | #else |
||
| 283 | #define __T3_ISR __attribute__((interrupt, shadow, auto_psv)) |
||
| 284 | #endif |
||
| 285 | |||
| 286 | /* */ |
||
| 287 | void __T3_ISR _T3Interrupt(void) |
||
| 288 | { |
||
| 289 | // Clear flag |
||
| 290 | #ifdef __PIC32MX__ |
||
| 291 | mT3ClearIntFlag(); |
||
| 292 | #else |
||
| 293 | IFS0bits.T3IF = 0; |
||
| 294 | #endif |
||
| 295 | |||
| 296 | TouchProcessTouch(); |
||
| 297 | } |
||
| 298 | |||
| 299 | ///////////////////////////////////////////////////////////////////////////// |
||
| 300 | // Function: void TickInit(void) |
||
| 301 | // Input: none |
||
| 302 | // Output: none |
||
| 303 | // Overview: Initilizes the tick timer. |
||
| 304 | ///////////////////////////////////////////////////////////////////////////// |
||
| 305 | |||
| 306 | /********************************************************************* |
||
| 307 | * Section: Tick Delay |
||
| 308 | *********************************************************************/ |
||
| 309 | #define SAMPLE_PERIOD 500 // us |
||
| 310 | #define TICK_PERIOD (GetPeripheralClock() * SAMPLE_PERIOD) / 4000000 |
||
| 311 | |||
| 312 | /* */ |
||
| 313 | void TickInit(void) |
||
| 314 | { |
||
| 315 | |||
| 316 | // Initialize Timer4 |
||
| 317 | #ifdef __PIC32MX__ |
||
| 318 | OpenTimer3(T3_ON | T3_PS_1_8, TICK_PERIOD); |
||
| 319 | ConfigIntTimer3(T3_INT_ON | T3_INT_PRIOR_4); |
||
| 320 | #else |
||
| 321 | TMR3 = 0; |
||
| 322 | PR3 = TICK_PERIOD; |
||
| 323 | IFS0bits.T3IF = 0; //Clear flag |
||
| 324 | IEC0bits.T3IE = 1; //Enable interrupt |
||
| 325 | T3CONbits.TON = 1; //Run timer |
||
| 326 | #endif |
||
| 327 | |||
| 328 | } |
Powered by WebSVN v2.8.3