John Mitchell / lpc4088_displaymodule_GC500_2_5inch

Dependencies:   DMBasicGUI DMSupport

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GuiDisplay.c Source File

GuiDisplay.c

00001 /* ************************************************************************ */
00002 /*                                                                          */
00003 /*                     (C)2004-2014 IBIS Solutions ApS                      */
00004 /*                            sales@easyGUI.com                             */
00005 /*                             www.easyGUI.com                              */
00006 /*                                                                          */
00007 /*                       easyGUI display driver unit                        */
00008 /*                               v6.0.23.002                                */
00009 /*                                                                          */
00010 /* ************************************************************************ */
00011 
00012 #include "GuiConst.h"
00013 #include "GuiDisplay.h"
00014 #include "GuiLib.h"
00015 #include <stdlib.h>
00016 
00017 #define WANT_DOUBLE_BUFFERING // Also in GuiGraph16.h, GuiLib.c - *** all three must match ***
00018 
00019 #define USE_WAIT_MS
00020 #ifdef USE_WAIT_MS
00021 extern void EasyGUIWaitMs(GuiConst_INT32U msec); // in main.cpp
00022 #endif
00023 
00024 extern void SetupQSPIBitmapArray(int stageNumber); // In main.cpp
00025 
00026 // Make FRAME_ADDRESS able to be set at runtime, not hardcoded
00027 static unsigned long frameAddress = 0L;
00028 // Global function (actually called from the main function, in main.cpp) 
00029 // to set the frame address at startup
00030 void GuiDisplay_SetFrameAddress(void *newFrameAddress)
00031 {
00032     // C/C++ is not happy copying a pointer value direct to an unsigned long
00033     union {
00034         void *ptrValue;
00035         unsigned long ulValue;
00036     } frameAddressUnion;
00037     
00038     frameAddressUnion.ptrValue = newFrameAddress;
00039     
00040     frameAddress = frameAddressUnion.ulValue;
00041 }
00042 
00043 // Select LCD controller type by removing double slashes
00044 //
00045 // Many of the drivers listed here supports more than one display controller.
00046 // To find your driver simply make a text search in this file. Omit eventual
00047 // letters after the display controller type number. Example: For an NJU6450A
00048 // display controller make a search for "NJU6450" - make sure it is a plain
00049 // text search, not a word search.
00050 //
00051 // If your display controller is not found you can contact support at
00052 // sales@ibissolutions.com. We will then quickly supply a driver for it.
00053 //
00054 // You only need to use the relevant display driver, all others may be deleted.
00055 // Make a copy of this file before modifying it.
00056 //
00057 // -----------------------------------------------------------------------------
00058 // #define LCD_CONTROLLER_TYPE_AT32AP7000
00059 // #define LCD_CONTROLLER_TYPE_AT91RM9200_ST7565
00060 // #define LCD_CONTROLLER_TYPE_AT91SAM9263
00061 // #define LCD_CONTROLLER_TYPE_BVGP
00062 // #define LCD_CONTROLLER_TYPE_D51E5TA7601
00063 // #define LCD_CONTROLLER_TYPE_F5529
00064 // #define LCD_CONTROLLER_TYPE_FLEVIPER
00065 // #define LCD_CONTROLLER_TYPE_FSA506
00066 // #define LCD_CONTROLLER_TYPE_H8S2378
00067 // #define LCD_CONTROLLER_TYPE_HD61202_2H
00068 // #define LCD_CONTROLLER_TYPE_HD61202_4H
00069 // #define LCD_CONTROLLER_TYPE_HD61202_2H2V
00070 // #define LCD_CONTROLLER_TYPE_HX8238_AT32AP7000
00071 // #define LCD_CONTROLLER_TYPE_HX8238_TMP92CH21
00072 // #define LCD_CONTROLLER_TYPE_HX8312
00073 // #define LCD_CONTROLLER_TYPE_HX8345
00074 // #define LCD_CONTROLLER_TYPE_HX8346
00075 // #define LCD_CONTROLLER_TYPE_HX8347
00076 // #define LCD_CONTROLLER_TYPE_HX8347G
00077 // #define LCD_CONTROLLER_TYPE_HX8352A
00078 // #define LCD_CONTROLLER_TYPE_ILI9341
00079 // #define LCD_CONTROLLER_TYPE_K70
00080 // #define LCD_CONTROLLER_TYPE_LC7981
00081 // #define LCD_CONTROLLER_TYPE_LS027
00082 // #define LCD_CONTROLLER_TYPE_LS044
00083 // #define LCD_CONTROLLER_TYPE_LH155BA
00084 // #define LCD_CONTROLLER_TYPE_LH75401
00085 // #define LCD_CONTROLLER_TYPE_LH7A400
00086 // #define LCD_CONTROLLER_TYPE_LPC1788
00087 // #define LCD_CONTROLLER_TYPE_LPC1850
00088 // #define LCD_CONTROLLER_TYPE_LPC2478
00089 // #define LCD_CONTROLLER_TYPE_LPC3230
00090 #define LCD_CONTROLLER_TYPE_LPC408X
00091 // #define LCD_CONTROLLER_TYPE_MPC5606S
00092 // #define LCD_CONTROLLER_TYPE_MX257
00093 // #define LCD_CONTROLLER_TYPE_NJU6450A
00094 // #define LCD_CONTROLLER_TYPE_NT39016D
00095 // #define LCD_CONTROLLER_TYPE_NT75451
00096 // #define LCD_CONTROLLER_TYPE_OTM2201A
00097 // #define LCD_CONTROLLER_TYPE_PCF8548
00098 // #define LCD_CONTROLLER_TYPE_PCF8813
00099 // #define LCD_CONTROLLER_TYPE_PIC24FJ256
00100 // #define LCD_CONTROLLER_TYPE_PXA320
00101 // #define LCD_CONTROLLER_TYPE_R61509
00102 // #define LCD_CONTROLLER_TYPE_R61526
00103 // #define LCD_CONTROLLER_TYPE_R61580
00104 // #define LCD_CONTROLLER_TYPE_RA8822
00105 // #define LCD_CONTROLLER_TYPE_RA8875
00106 // #define LCD_CONTROLLER_TYPE_S1D13505
00107 // #define LCD_CONTROLLER_TYPE_S1D13506
00108 // #define LCD_CONTROLLER_TYPE_S1D13700
00109 // #define LCD_CONTROLLER_TYPE_S1D13705
00110 // #define LCD_CONTROLLER_TYPE_S1D13706
00111 // #define LCD_CONTROLLER_TYPE_S1D13715
00112 // #define LCD_CONTROLLER_TYPE_S1D13743
00113 // #define LCD_CONTROLLER_TYPE_S1D13748
00114 // #define LCD_CONTROLLER_TYPE_S1D13781
00115 // #define LCD_CONTROLLER_TYPE_S1D13781_DIRECT
00116 // #define LCD_CONTROLLER_TYPE_S1D13A04
00117 // #define LCD_CONTROLLER_TYPE_S1D13A05
00118 // #define LCD_CONTROLLER_TYPE_S1D15721
00119 // #define LCD_CONTROLLER_TYPE_S6B0741
00120 // #define LCD_CONTROLLER_TYPE_S6B33BL
00121 // #define LCD_CONTROLLER_TYPE_S6D0139
00122 // #define LCD_CONTROLLER_TYPE_S6E63D6
00123 // #define LCD_CONTROLLER_TYPE_SBN1661_2H_SBN0080
00124 // #define LCD_CONTROLLER_TYPE_SED1335
00125 // #define LCD_CONTROLLER_TYPE_SEPS525
00126 // #define LCD_CONTROLLER_TYPE_SH1101A
00127 // #define LCD_CONTROLLER_TYPE_SH1123
00128 // #define LCD_CONTROLLER_TYPE_SPFD5408
00129 // #define LCD_CONTROLLER_TYPE_SPLC502
00130 // #define LCD_CONTROLLER_TYPE_SSD0323
00131 // #define LCD_CONTROLLER_TYPE_SSD1289
00132 // #define LCD_CONTROLLER_TYPE_SSD1305
00133 // #define LCD_CONTROLLER_TYPE_SSD1322
00134 // #define LCD_CONTROLLER_TYPE_SSD1339
00135 // #define LCD_CONTROLLER_TYPE_SSD1815
00136 // #define LCD_CONTROLLER_TYPE_SSD1815_2H
00137 // #define LCD_CONTROLLER_TYPE_SSD1848
00138 // #define LCD_CONTROLLER_TYPE_SSD1858
00139 // #define LCD_CONTROLLER_TYPE_SSD1926
00140 // #define LCD_CONTROLLER_TYPE_SSD1963
00141 // #define LCD_CONTROLLER_TYPE_SSD2119
00142 // #define LCD_CONTROLLER_TYPE_ST7529
00143 // #define LCD_CONTROLLER_TYPE_ST7541
00144 // #define LCD_CONTROLLER_TYPE_ST7561
00145 // #define LCD_CONTROLLER_TYPE_ST7565
00146 // #define LCD_CONTROLLER_TYPE_ST7586
00147 // #define LCD_CONTROLLER_TYPE_ST7637
00148 // #define LCD_CONTROLLER_TYPE_ST7715
00149 // #define LCD_CONTROLLER_TYPE_ST7920
00150 // #define LCD_CONTROLLER_TYPE_STM32F429
00151 // #define LCD_CONTROLLER_TYPE_T6963
00152 // #define LCD_CONTROLLER_TYPE_TLS8201
00153 // #define LCD_CONTROLLER_TYPE_TMPA900
00154 // #define LCD_CONTROLLER_TYPE_TS7390
00155 // #define LCD_CONTROLLER_TYPE_UC1608
00156 // #define LCD_CONTROLLER_TYPE_UC1610
00157 // #define LCD_CONTROLLER_TYPE_UC1611
00158 // #define LCD_CONTROLLER_TYPE_UC1617
00159 // #define LCD_CONTROLLER_TYPE_UC1698
00160 // #define LCD_CONTROLLER_TYPE_UPD161607
00161 // #define LCD_CONTROLLER_TYPE_UC1701
00162 
00163 // ============================================================================
00164 //
00165 // COMMON PART - NOT DEPENDENT ON DISPLAY CONTROLLER TYPE
00166 //
00167 // Do not delete this part of the GuiDisplay.c file.
00168 //
00169 // If your operating system uses pre-emptive execution, i.e. it interrupts tasks
00170 // at random instances, and transfers control to other tasks, display writing
00171 // must be protected from this, by writing code for the two protection
00172 // functions:
00173 //
00174 //   o  GuiDisplay_Lock     Prevent the OS from switching tasks
00175 //   o  GuiDisplay_Unlock   Open up normal task execution again
00176 //
00177 // If your operating system does not use pre-emptive execution, i.e. if you
00178 // must specifically release control in one tasks in order for other tasks to
00179 // be serviced, or if you don't employ an operating system at all, you can just
00180 // leave the two protection functions empty. Failing to write proper code for
00181 // the protection functions will result in a system with unpredictable
00182 // behavior.
00183 //
00184 // ============================================================================
00185 
00186 void GuiDisplay_Lock (void)
00187 {
00188 }
00189 
00190 void GuiDisplay_Unlock (void)
00191 {
00192 }
00193 
00194 // ============================================================================
00195 //
00196 // DISPLAY DRIVER PART
00197 //
00198 // You only need to use the relevant display driver, all others may be deleted.
00199 // Modify the driver so that it fits your specific hardware.
00200 // Make a copy of this file before modifying it.
00201 //
00202 // ============================================================================
00203 
00204 #ifdef LCD_CONTROLLER_TYPE_LPC408X
00205 
00206 // ============================================================================
00207 //
00208 // LPC408x MICROCONTROLLER WITH BUILT-IN DISPLAY CONTROLLER
00209 //
00210 // This driver uses internal LCD controller of LPC408x microcontroller.
00211 // LCD driver of LPC408x in 24 bit RGB parallel interface for TFT type
00212 // display or 4bit parallel interface for STN type display.
00213 // Graphic modes up to 1024x768 pixels.
00214 //
00215 // Compatible display controllers:
00216 //   None
00217 //
00218 // easyGUI setup should be (Parameters window, Display controller tab page):
00219 //   Horizontal bytes
00220 //   Bit 0 at right
00221 //   Number of color planes: 1
00222 //   Color mode: Grayscale, palette or RGB
00223 //   Color depth: 1 bit (B/W), 8 bits, 16 bits, 24 bits
00224 //   Display orientation: Normal, Upside down, 90 degrees left, 90 degrees right
00225 //   Display words with reversed bytes: Off
00226 //   Number of display controllers, horizontally: 1
00227 //   Number of display controllers, vertically: 1
00228 //
00229 // Port addresses (Px.x) must be altered to correspond to your microcontroller
00230 // hardware and compiler syntax.
00231 //
00232 // ============================================================================
00233 
00234 // Hardware connection for TFT display
00235 // LPC408x                        generic TFT display
00236 // LCD_FP               -         VSYNC
00237 // LCD_LP               -         HSYNC
00238 // LCD_LE               -         Line End
00239 // LCD_DCLK             -         Pixel CLK
00240 // LCD_ENAB_M           -         DATA_ENABLE
00241 // LCD_VD[0-7]          -         R0-R7 (for 16bit RGB mode connect R0,R1,R2 to 0)
00242 // LCD_VD[8-15]         -         G0-G7 (for 16bit RGB mode connect G0,G1 to 0)
00243 // LCD_VD[16-23]        -         B0-B7 (for 16bit RGB mode connect B0,B1,B2 to 0)
00244 
00245 // Hardware connection for STN display
00246 // LCD_PWR              -         DISP
00247 // LCD_DCLK             -         CL2
00248 // LCD_FP               -         Frame Pulse
00249 // LCD_LP               -         Line Sync Pulse
00250 // LCD_LE               -         Line End
00251 // LCD_VD[3:0]          -         UD[3:0]
00252 
00253 // Power Control registers
00254 #define PCONP          (*(volatile unsigned long *)0x400FC0C4)
00255 // LCD controller power control bit
00256 #define PCLCD          0
00257 
00258 // Pin setup registers (IOCON)
00259 #define IOCON_P0_4         (*(volatile unsigned long *)0x4002C010)
00260 #define IOCON_P0_5         (*(volatile unsigned long *)0x4002C014)
00261 #define IOCON_P0_6         (*(volatile unsigned long *)0x4002C018)
00262 #define IOCON_P0_7         (*(volatile unsigned long *)0x4002C01C)
00263 #define IOCON_P0_8         (*(volatile unsigned long *)0x4002C020)
00264 #define IOCON_P0_9         (*(volatile unsigned long *)0x4002C024)
00265 #define IOCON_P1_20        (*(volatile unsigned long *)0x4002C0D0)
00266 #define IOCON_P1_21        (*(volatile unsigned long *)0x4002C0D4)
00267 #define IOCON_P1_22        (*(volatile unsigned long *)0x4002C0D8)
00268 #define IOCON_P1_23        (*(volatile unsigned long *)0x4002C0DC)
00269 #define IOCON_P1_24        (*(volatile unsigned long *)0x4002C0E0)
00270 #define IOCON_P1_25        (*(volatile unsigned long *)0x4002C0E4)
00271 #define IOCON_P1_26        (*(volatile unsigned long *)0x4002C0E8)
00272 #define IOCON_P1_27        (*(volatile unsigned long *)0x4002C0EC)
00273 #define IOCON_P1_28        (*(volatile unsigned long *)0x4002C0F0)
00274 #define IOCON_P1_29        (*(volatile unsigned long *)0x4002C0F4)
00275 #define IOCON_P2_0         (*(volatile unsigned long *)0x4002C100)
00276 #define IOCON_P2_1         (*(volatile unsigned long *)0x4002C104)
00277 #define IOCON_P2_2         (*(volatile unsigned long *)0x4002C108)
00278 #define IOCON_P2_3         (*(volatile unsigned long *)0x4002C10C)
00279 #define IOCON_P2_4         (*(volatile unsigned long *)0x4002C110)
00280 #define IOCON_P2_5         (*(volatile unsigned long *)0x4002C114)
00281 #define IOCON_P2_6         (*(volatile unsigned long *)0x4002C118)
00282 #define IOCON_P2_7         (*(volatile unsigned long *)0x4002C11C)
00283 #define IOCON_P2_8         (*(volatile unsigned long *)0x4002C120)
00284 #define IOCON_P2_9         (*(volatile unsigned long *)0x4002C124)
00285 #define IOCON_P2_11        (*(volatile unsigned long *)0x4002C12C)
00286 #define IOCON_P2_12        (*(volatile unsigned long *)0x4002C130)
00287 #define IOCON_P2_13        (*(volatile unsigned long *)0x4002C134)
00288 #define IOCON_P4_28        (*(volatile unsigned long *)0x4002C270)
00289 #define IOCON_P4_29        (*(volatile unsigned long *)0x4002C274)
00290 
00291 // LCD Port Enable
00292 #define LCDPE           1
00293 
00294 // LCD controller registers
00295 // LCD configuration register
00296 #define LCD_CFG         (*(volatile unsigned long *)0x400FC1B8)
00297 
00298 // LCD Controller Base Address
00299 #define LCD_BASE       0x20088000
00300 
00301 // Horizontal Timing Control
00302 #define LCD_TIMH       (*(volatile unsigned long *)(LCD_BASE+0x000))
00303 // Vertical Timing Control
00304 #define LCD_TIMV       (*(volatile unsigned long *)(LCD_BASE+0x004))
00305 // Clock and Signal Polarity Control register
00306 #define LCD_POL        (*(volatile unsigned long *)(LCD_BASE+0x008))
00307 // Line End Control register
00308 #define LCD_LE         (*(volatile unsigned long *)(LCD_BASE+0x00C))
00309 // Upper Panel Frame Base Address register
00310 #define LCD_UPBASE     (*(volatile unsigned long *)(LCD_BASE+0x010))
00311 // Lower Panel Frame Base Address register
00312 #define LCD_LPBASE     (*(volatile unsigned long *)(LCD_BASE+0x014))
00313 // LCD Control register
00314 #define LCD_CTRL       (*(volatile unsigned long *)(LCD_BASE+0x018))
00315 // Interrupt Mask register
00316 #define LCD_INTMSK     (*(volatile unsigned long *)(LCD_BASE+0x01C))
00317 // Raw Interrupt Status register
00318 #define LCD_INTRAW     (*(volatile unsigned long *)(LCD_BASE+0x020))
00319 // Masked Interrupt Status register
00320 #define LCD_INTSTAT    (*(volatile unsigned long *)(LCD_BASE+0x024))
00321 // Interrupt Clear register
00322 #define LCD_INTCLR     (*(volatile unsigned long *)(LCD_BASE+0x028))
00323 // Upper Panel Current Address Value register
00324 #define LCD_UPCURR     (*(volatile unsigned long *)(LCD_BASE+0x02C))
00325 // Lower Panel Current Address Value register
00326 #define LCD_LPCURR     (*(volatile unsigned long *)(LCD_BASE+0x030))
00327 // 256x16-bit Color Palette registers
00328 #define LCD_PAL        (*(volatile unsigned long *)(LCD_BASE+0x200))
00329 // Cursor Image registers
00330 #define CRSR_IMG       (*(volatile unsigned long *)(LCD_BASE+0x800))
00331 // Cursor Control register
00332 #define CRSR_CTRL      (*(volatile unsigned long *)(LCD_BASE+0xC00))
00333 
00334 // LCD controller enable bit
00335 #define LCDEN          0
00336 // LCD controller power bit
00337 #define LCDPWR         11
00338 // Bypass pixel clock divider - for TFT display must be 1
00339 #ifdef GuiConst_COLOR_DEPTH_1
00340 #define BCD            0
00341 #else
00342 #define BCD            1
00343 #endif
00344 // Adjust these values according your display
00345 // PLL clock prescaler selection - only odd numbers 0,1,3,5,..255
00346 // 0 - PLL/1, 1 - PLL/2, 3 - PLL/4
00347 #define PLLDIV         0
00348 // LCD panel clock prescaler selection,  range 0 - 31
00349 // LCD freq = MCU freq /(CLKDIV+1)
00350 #define CLKDIV         7
00351 // Horizontal back porch in pixels, range 3 - 256
00352 #ifdef GuiConst_COLOR_DEPTH_1
00353 #define HBP            5
00354 #else
00355 #define HBP            40
00356 #endif
00357 // Horizontal front porch in pixels, range 3 - 256
00358 #ifdef GuiConst_COLOR_DEPTH_1
00359 #define HFP            5
00360 #else
00361 #define HFP            79
00362 #endif
00363 // Horizontal synchronization pulse width in pixels, range 3 - 256
00364 #ifdef GuiConst_COLOR_DEPTH_1
00365 #define HSW            3
00366 #else
00367 #define HSW            48
00368 #endif
00369 // Pixels-per-line in pixels, must be multiple of 16
00370 #define PPL            GuiConst_DISPLAY_WIDTH_HW
00371 // Vertical back porch in lines, range 1 - 256
00372 #ifdef GuiConst_COLOR_DEPTH_1
00373 #define VBP            2
00374 #else
00375 #define VBP            29
00376 #endif
00377 // Vertical front porch in lines, range 1 - 256
00378 #ifdef GuiConst_COLOR_DEPTH_1
00379 #define VFP            2
00380 #else
00381 #define VFP            40
00382 #endif
00383 // Vertical synchronization pulse width in lines, range 1 - 31
00384 #ifdef GuiConst_COLOR_DEPTH_1
00385 #define VSW            1
00386 #else
00387 #define VSW            3
00388 #endif
00389 // Lines per panel
00390 #define LPP            GuiConst_BYTE_LINES
00391 // Clocks per line
00392 #ifdef GuiConst_COLOR_DEPTH_1
00393 #define CPL            GuiConst_DISPLAY_WIDTH_HW/4
00394 #else
00395 #define CPL            GuiConst_DISPLAY_WIDTH_HW
00396 #endif
00397 // Invert output enable
00398 // 0 = LCDENAB output pin is active HIGH in TFT mode
00399 // 1 = LCDENAB output pin is active LOW in TFT mode
00400 #define IOE            0
00401 // Invert panel clock
00402 // 0 = Data is driven on the LCD data lines on the rising edge of LCDDCLK
00403 // 1 = Data is driven on the LCD data lines on the falling edge of LCDDCLK
00404 #define IPC            0
00405 // Invert horizontal synchronization
00406 // 0 = LCDLP pin is active HIGH and inactive LOW
00407 // 1 = LCDLP pin is active LOW and inactive HIGH
00408 #ifdef GuiConst_COLOR_DEPTH_1
00409 #define IHS            0
00410 #else
00411 #define IHS            1
00412 #endif
00413 // IVS Invert vertical synchronization
00414 // 0 = LCDFP pin is active HIGH and inactive LOW
00415 // 1 = LCDFP pin is active LOW and inactive HIGH
00416 #ifdef GuiConst_COLOR_DEPTH_1
00417 #define IVS            0
00418 #else
00419 #define IVS            1
00420 #endif
00421 // Lower five bits of panel clock divisor
00422 #define PCD_LO         2
00423 // CLKSEL Clock Select
00424 // 0 = the clock source for the LCD block is CCLK
00425 // 1 = the clock source for the LCD block is LCD_DCLK
00426 #define CLKSEL         0
00427 
00428 /****************************************************************************/
00429 /* IMPORTANT!!!                                                             */
00430 /****************************************************************************/
00431 // Set start address of frame buffer in RAM memory
00432 // 0x4000 0000 - 0x4000 FFFF RAM (64 kB)
00433 // 0x8000 0000 - 0x80FF FFFF Static memory bank 0 (16 MB)
00434 // 0x8100 0000 - 0x81FF FFFF Static memory bank 1 (16 MB)
00435 // 0xA000 0000 - 0xAFFF FFFF Dynamic memory bank 0 (256 MB)
00436 // 0xB000 0000 - 0xBFFF FFFF Dynamic memory bank 1 (256 MB)
00437 //#define FRAME_ADDRESS  0xA0000008
00438 //#define FRAME_ADDRESS  0xA00017D8 // As of 26 Oct 2016
00439 #define FRAME_ADDRESS (frameAddress) // Use the static variable set at the top of this file
00440 /****************************************************************************/
00441 
00442 // Address of pallete registers
00443 #define PALETTE_RAM_ADDR LCD_PAL
00444 
00445 // Delay routine
00446 // This constant must be adjusted according to speed of microcontroller
00447 #define ONE_MS               100
00448 // Param msec is delay in miliseconds
00449 void millisecond_delay(GuiConst_INT32U msec)
00450 {
00451 #ifdef USE_WAIT_MS
00452   EasyGUIWaitMs(msec);
00453 #else
00454   GuiConst_INT32U j;
00455 
00456   for (j = 0; j < (ONE_MS * msec) ; j++);
00457 #endif
00458 }
00459 
00460 // Initialises the module and the display
00461 void GuiDisplay_Init (void)
00462 {
00463 //  return; // Test - do we need any display initialisation here? Let the BIOS do it?
00464           // No flickering - but red and blue reversed (again)
00465 // So - can we reinstate some of the code in this function, and get the red and blue 
00466 // the correct way round without flickering?
00467 //#define ALLOW_LPC4088_INIT
00468 // Now allowing initialisation of the LCD control register even with ALLOW_LPC4088_INIT not #defined.
00469 // This appears to have eliminated the flickering while keeping the red and blue components 
00470 // the correct way round.
00471   
00472   GuiConst_INT32U i;
00473 #ifdef GuiConst_COLOR_DEPTH_24
00474   GuiConst_INT32U *framePtr;
00475 #else
00476 #ifdef GuiConst_COLOR_DEPTH_16
00477   GuiConst_INT16U *framePtr;
00478 #else
00479   GuiConst_INT32U PaletteData;
00480   GuiConst_INT8U *framePtr;
00481   GuiConst_INT32U * pDst;
00482 #endif
00483 #endif
00484 
00485 //  SetupQSPIBitmapArray(1);
00486 
00487 /**************************************************/
00488 /* Carefully adjust the IO pins for your system   */
00489 /* Following settings for TFT panel 16/24 bit     */
00490 /**************************************************/
00491 
00492 /* *** DEBUG *** COMMENT OUT THIS BLOCK OF CODE - WHAT HAPPENS?
00493 // PI         SETTING     RGB888      RGB565
00494   IOCON_P1_29  |= 7;   // BLUE7       BLUE4
00495   IOCON_P1_28  |= 7;   // BLUE6       BLUE3
00496   IOCON_P1_27  |= 7;   // BLUE5       BLUE2
00497   IOCON_P1_26  |= 7;   // BLUE4       BLUE1
00498   IOCON_P2_13  |= 7;   // BLUE3       BLUE0
00499   //IOCON_P2_12  |= 7;   // BLUE2       -       !! Comment out for RGB565
00500   //IOCON_P0_9   |= 7;   // BLUE1       -       !! Comment out for RGB565
00501   //IOCON_P0_8   |= 7;   // BLUE0       -       !! Comment out for RGB565
00502   IOCON_P1_25  |= 7;   // GREEN7      GREEN5
00503   IOCON_P1_24  |= 7;   // GREEN6      GREEN4
00504   IOCON_P1_23  |= 7;   // GREEN5      GREEN3
00505   IOCON_P1_22  |= 7;   // GREEN4      GREEN2
00506   IOCON_P1_21  |= 7;   // GREEN3      GREEN1
00507   IOCON_P1_20  |= 7;   // GREEN2      GREEN0
00508   //IOCON_P0_7   |= 7;   // GREEN1      -       !! Comment out for RGB565
00509   //IOCON_P0_6   |= 7;   // GREEN0      -       !! Comment out for RGB565
00510   IOCON_P2_9   |= 7;   // RED7        RED4
00511   IOCON_P2_8   |= 7;   // RED6        RED3
00512   IOCON_P2_7   |= 7;   // RED5        RED2
00513   IOCON_P2_6   |= 7;   // RED4        RED1
00514   //IOCON_P4_29  |= 7;   // RED3        -       !! Comment out for RGB565
00515   IOCON_P2_12  |= 5;   // -           RED0  !! Comment out for RGB888 !!
00516   //IOCON_P4_28  |= 7;   // RED2        -       !! Comment out for RGB565
00517   //IOCON_P0_5   |= 7;   // RED1        -       !! Comment out for RGB565
00518   //IOCON_P0_4   |= 7;   // RED0        -       !! Comment out for RGB565
00519   IOCON_P2_5   |= 7;   // LCD_LP      LCD_LP
00520   IOCON_P2_4   |= 7;   // LCD_ENAB_M  LCD_ENAB_M
00521   IOCON_P2_3   |= 7;   // LCD_FP      LCD_FP
00522   IOCON_P2_2   |= 7;   // LCD_DCLK    LCD_DCLK
00523   IOCON_P2_1   |= 7;   // LCD_LE      LCD_LE
00524   IOCON_P2_0   |= 7;   // LCD_PWR     LCD_PWR
00525   IOCON_P2_11  |= 7;   // LCD_CLKIN   LCD_CLKIN
00526 */ // DEBUG - ANSWER - *** EVERYTHING STILL APPEARS TO WORK ***
00527 
00528 /**************************************************/
00529 
00530 //  SetupQSPIBitmapArray(2);
00531   
00532 #ifdef ALLOW_LPC4088_INIT
00533   // Disable power
00534   LCD_CTRL &= ~(1 << LCDEN);
00535   millisecond_delay(100);
00536   LCD_CTRL &= ~(1 << LCDPWR);
00537   
00538   // ====================================
00539   // Initialize Clock(PLL),EMC and SDRAM!
00540   // ====================================
00541 
00542   // Enable LCD controller
00543   PCONP |= 1<<PCLCD;
00544 
00545   // LCD Configuration init pixel clock
00546   LCD_CFG |= (CLKDIV);
00547 
00548   // Horizontal Timing register
00549   LCD_TIMH |= ((HBP-1) << 24)|((HFP-1) << 16)|((HSW-1) << 8)|((PPL/16-1) << 2);
00550 
00551   // Vertical Timing register
00552   LCD_TIMV |= (VBP << 24)|(VFP << 16)|((VSW-1) << 10)|(LPP-1);
00553 
00554   // Clock and Signal Polarity register
00555   LCD_POL |= (BCD << 26)|((CPL-1) << 16)|(IOE << 14)|(IPC << 13)|
00556              (IHS << 12)|(IVS << 11)|(CLKSEL << 5)| PCD_LO;
00557 
00558   LCD_LE = 0;
00559   LCD_INTMSK = 0;
00560 
00561 #endif // ALLOW_LPC4088_INIT
00562 // If we include the initialisation of the LCD control register,
00563 // does this get red and blue the correct way round without flickering?
00564 
00565   // LCD Control register
00566 #ifdef GuiConst_COLOR_DEPTH_24
00567   // TFT single panel,24bit, normal output
00568   LCD_CTRL = 0x0000002A;
00569 #else
00570 #ifdef GuiConst_COLOR_DEPTH_16
00571   // TFT single panel,16bit, normal output (BGR)
00572   LCD_CTRL = 0x0000102C;
00573 #else
00574 #ifdef GuiConst_COLOR_DEPTH_8
00575   // TFT single panel,8bit, normal output
00576   LCD_CTRL = 0x00000026;
00577 #else
00578   // STN single panel, monochrome, 4bit bus, normal output
00579   LCD_CTRL = 0x00000010;
00580 #endif
00581 #endif
00582 #endif
00583 
00584 
00585 #ifdef GuiConst_COLOR_DEPTH_24
00586   framePtr = (GuiConst_INT32U *)FRAME_ADDRESS;
00587 #else
00588 #ifdef GuiConst_COLOR_DEPTH_16
00589   framePtr = (GuiConst_INT16U *)FRAME_ADDRESS;
00590 #else
00591   framePtr = (GuiConst_INT8U *)FRAME_ADDRESS;
00592   pDst = (GuiConst_INT32U *)PALETTE_RAM_ADDR;
00593   for (i = 0; i < 128; i++)
00594   {
00595 #ifdef GuiConst_COLOR_DEPTH_1
00596     PaletteData = 0xFFFF0000;
00597 #else
00598     PaletteData = GuiStruct_Palette[2*i][0];
00599     PaletteData |= (GuiConst_INT32U)GuiStruct_Palette[2*i][1]<<8;
00600     PaletteData |= (GuiConst_INT32U)GuiStruct_Palette[2*i+1][0]<<16;
00601     PaletteData |= (GuiConst_INT32U)GuiStruct_Palette[2*i+1][1]<<24;
00602 #endif
00603     *pDst++ = PaletteData;
00604   }
00605 #endif
00606 #endif
00607 
00608   // Clear frame buffer by copying the data into frame buffer
00609 #ifdef GuiConst_COLOR_DEPTH_24
00610   for (i = 0; i < GuiConst_DISPLAY_BYTES/3; i++)
00611     *framePtr++ = 0x00000000; // Color
00612 #else
00613 #ifdef GuiConst_COLOR_DEPTH_16
00614     for (i = 0; i < GuiConst_DISPLAY_BYTES/2; i++)
00615     *framePtr++ = 0x0000; // Color
00616 #else
00617   for (i = 0; i < GuiConst_DISPLAY_BYTES; i++)
00618     *framePtr++ = 0x00;  // Color
00619 #endif
00620 #endif
00621 
00622 //  LCD_CFG = 0;
00623 
00624   millisecond_delay(100);
00625   // Power-up sequence
00626   LCD_CTRL |= 1<<LCDEN;
00627   // Apply contrast voltage to LCD panel
00628   // (not controlled or supplied by the LCD controller)
00629   millisecond_delay(100);
00630   LCD_CTRL |= 1<<LCDPWR;
00631 
00632   // Set start address of frame buffer in RAM memory
00633   LCD_LPBASE = FRAME_ADDRESS;
00634   LCD_UPBASE = FRAME_ADDRESS;
00635 }
00636 
00637 #ifdef WANT_DOUBLE_BUFFERING
00638 // *** Need complete GuiDisplay_Refresh ***
00639 
00640 // Refreshes display buffer to display
00641 void GuiDisplay_Refresh (void)
00642 {
00643   GuiConst_INT32U Pixel, X, Y, LastByte;
00644 #ifdef GuiConst_COLOR_DEPTH_24
00645   GuiConst_INT32U *framePtr;
00646 #else
00647 #ifdef GuiConst_COLOR_DEPTH_16
00648   GuiConst_INT16U *framePtr;
00649 #else
00650   // Valid also for monochrome STN display
00651   GuiConst_INT8U *framePtr;
00652 #endif
00653 #endif
00654 
00655   GuiDisplay_Lock ();
00656 
00657   // Walk through all lines
00658   for (Y = 0; Y < GuiConst_BYTE_LINES; Y++)
00659   {
00660     if (GuiLib_DisplayRepaint[Y].ByteEnd >= 0)
00661     // Something to redraw in this line
00662     {
00663 #ifdef GuiConst_COLOR_DEPTH_24
00664       // Set video ram base address
00665       framePtr = (GuiConst_INT32U *)FRAME_ADDRESS;
00666       // Pointer offset calculation
00667       framePtr += Y * GuiConst_BYTES_PR_LINE/3 +
00668                   GuiLib_DisplayRepaint[Y].ByteBegin;
00669       // Set amount of data to be changed
00670       LastByte = GuiConst_BYTES_PR_LINE/3 - 1;
00671 #else
00672 #ifdef GuiConst_COLOR_DEPTH_16
00673       // Set video ram base address
00674       framePtr = (GuiConst_INT16U *)FRAME_ADDRESS;
00675       // Pointer offset calculation
00676       framePtr += Y * GuiConst_BYTES_PR_LINE/2 +
00677                   GuiLib_DisplayRepaint[Y].ByteBegin;
00678       // Set amount of data to be changed
00679       LastByte = GuiConst_BYTES_PR_LINE/2 - 1;
00680 #else
00681       // Valid also for monochrome STN display
00682       // Set video ram base address
00683       framePtr = (GuiConst_INT8U *)FRAME_ADDRESS;
00684       // Pointer offset calculation
00685       framePtr += Y * GuiConst_BYTES_PR_LINE +
00686                   GuiLib_DisplayRepaint[Y].ByteBegin;
00687       // Set amount of data to be changed
00688       LastByte = GuiConst_BYTES_PR_LINE - 1;
00689 #endif
00690 #endif
00691       if (GuiLib_DisplayRepaint[Y].ByteEnd < LastByte)
00692         LastByte = GuiLib_DisplayRepaint[Y].ByteEnd;
00693 
00694       // Write data for one line to framebuffer from GuiLib_DisplayBuf
00695 #ifdef GuiConst_COLOR_DEPTH_24
00696       for (X = GuiLib_DisplayRepaint[Y].ByteBegin * 3;
00697                X <= (LastByte * 3 + 2);
00698                X = X + 3)
00699       {
00700         Pixel = GuiLib_DisplayBuf[Y][X];
00701         Pixel |= (GuiConst_INT32U)GuiLib_DisplayBuf[Y][X+1]<<8;
00702         Pixel |= (GuiConst_INT32U)GuiLib_DisplayBuf[Y][X+2]<<16;
00703         *framePtr++ = Pixel;
00704       }
00705 #else
00706 #ifdef GuiConst_COLOR_DEPTH_16
00707       for (X = GuiLib_DisplayRepaint[Y].ByteBegin; X <= LastByte; X++)
00708       {
00709         *framePtr++ = GuiLib_DisplayBuf.Words[Y][X];
00710       }
00711 #else
00712       // Valid also for monochrome STN display
00713       for (X = GuiLib_DisplayRepaint[Y].ByteBegin; X <= LastByte; X++)
00714         *framePtr++ = GuiLib_DisplayBuf[Y][X];
00715 #endif
00716 #endif
00717       // Reset repaint parameters
00718       GuiLib_DisplayRepaint[Y].ByteEnd = -1;
00719     }
00720   }
00721   GuiDisplay_Unlock ();
00722 }
00723 
00724 #else // WANT_DOUBLE_BUFFERING
00725 
00726 // We are already writing direct to the display - 
00727 // GuiDisplay_Refresh does not need to do anything
00728 // (but other code still expects it to exist)
00729 void GuiDisplay_Refresh (void)
00730 {
00731 }
00732 
00733 #endif // WANT_DOUBLE_BUFFERING
00734 
00735 #endif // LCD_CONTROLLER_TYPE_LPC408X
00736 
00737 // ============================================================================
00738 //
00739 // DISPLAY DRIVER PART ENDS
00740 //
00741 // ============================================================================
00742