NuMaker emWin HMI

Committer:
csyang2
Date:
Mon Mar 04 15:47:41 2024 +0800
Revision:
10:c8165817d92a
Parent:
6:d15151941247
Support NuMaker-IoT-M467

Who changed what in which revision?

UserRevisionLine numberNew contents of line
csyang2 1:c0f972361605 1 /*********************************************************************
csyang2 1:c0f972361605 2 * SEGGER Software GmbH *
csyang2 1:c0f972361605 3 * Solutions for real time microcontroller applications *
csyang2 1:c0f972361605 4 **********************************************************************
csyang2 1:c0f972361605 5 * *
csyang2 1:c0f972361605 6 * (c) 1996 - 2018 SEGGER Microcontroller GmbH *
csyang2 1:c0f972361605 7 * *
csyang2 1:c0f972361605 8 * Internet: www.segger.com Support: support@segger.com *
csyang2 1:c0f972361605 9 * *
csyang2 1:c0f972361605 10 **********************************************************************
csyang2 1:c0f972361605 11
csyang2 1:c0f972361605 12 ** emWin V5.48 - Graphical user interface for embedded applications **
csyang2 1:c0f972361605 13 All Intellectual Property rights in the Software belongs to SEGGER.
csyang2 1:c0f972361605 14 emWin is protected by international copyright laws. Knowledge of the
csyang2 1:c0f972361605 15 source code may not be used to write a similar product. This file may
csyang2 1:c0f972361605 16 only be used in accordance with the following terms:
csyang2 1:c0f972361605 17
csyang2 1:c0f972361605 18 The software has been licensed by SEGGER Software GmbH to Nuvoton Technology Corporationat the address: No. 4, Creation Rd. III, Hsinchu Science Park, Taiwan
csyang2 1:c0f972361605 19 for the purposes of creating libraries for its
csyang2 1:c0f972361605 20 Arm Cortex-M and Arm9 32-bit microcontrollers, commercialized and distributed by Nuvoton Technology Corporation
csyang2 1:c0f972361605 21 under the terms and conditions of an End User
csyang2 1:c0f972361605 22 License Agreement supplied with the libraries.
csyang2 1:c0f972361605 23 Full source code is available at: www.segger.com
csyang2 1:c0f972361605 24
csyang2 1:c0f972361605 25 We appreciate your understanding and fairness.
csyang2 1:c0f972361605 26 ----------------------------------------------------------------------
csyang2 1:c0f972361605 27 Licensing information
csyang2 1:c0f972361605 28 Licensor: SEGGER Software GmbH
csyang2 1:c0f972361605 29 Licensed to: Nuvoton Technology Corporation, No. 4, Creation Rd. III, Hsinchu Science Park, 30077 Hsinchu City, Taiwan
csyang2 1:c0f972361605 30 Licensed SEGGER software: emWin
csyang2 1:c0f972361605 31 License number: GUI-00735
csyang2 1:c0f972361605 32 License model: emWin License Agreement, signed February 27, 2018
csyang2 1:c0f972361605 33 Licensed platform: Cortex-M and ARM9 32-bit series microcontroller designed and manufactured by or for Nuvoton Technology Corporation
csyang2 1:c0f972361605 34 ----------------------------------------------------------------------
csyang2 1:c0f972361605 35 Support and Update Agreement (SUA)
csyang2 1:c0f972361605 36 SUA period: 2018-03-26 - 2019-03-27
csyang2 1:c0f972361605 37 Contact to extend SUA: sales@segger.com
csyang2 1:c0f972361605 38 ----------------------------------------------------------------------
csyang2 1:c0f972361605 39 File : LCDConf.c
csyang2 1:c0f972361605 40 Purpose : Display controller configuration (single layer)
csyang2 1:c0f972361605 41 ---------------------------END-OF-HEADER------------------------------
csyang2 1:c0f972361605 42 */
csyang2 6:d15151941247 43 #if 0 // moved to the related target folders
csyang2 1:c0f972361605 44 #include <stddef.h>
csyang2 1:c0f972361605 45 #include <stdio.h>
csyang2 1:c0f972361605 46
csyang2 1:c0f972361605 47 #include "GUI.h"
csyang2 1:c0f972361605 48 #include "GUIDRV_FlexColor.h"
csyang2 1:c0f972361605 49
csyang2 1:c0f972361605 50 #include "M480.h"
csyang2 1:c0f972361605 51
csyang2 1:c0f972361605 52 #include "M48XTouchPanel.h"
csyang2 1:c0f972361605 53
csyang2 1:c0f972361605 54 /*********************************************************************
csyang2 1:c0f972361605 55 *
csyang2 1:c0f972361605 56 * Layer configuration
csyang2 1:c0f972361605 57 *
csyang2 1:c0f972361605 58 **********************************************************************
csyang2 1:c0f972361605 59 */
csyang2 1:c0f972361605 60 //
csyang2 1:c0f972361605 61 // Physical display size
csyang2 1:c0f972361605 62 //
csyang2 1:c0f972361605 63 #define XSIZE_PHYS 240
csyang2 1:c0f972361605 64 #define YSIZE_PHYS 320
csyang2 1:c0f972361605 65
csyang2 1:c0f972361605 66 //
csyang2 1:c0f972361605 67 // Color conversion
csyang2 1:c0f972361605 68 //
csyang2 1:c0f972361605 69 #define COLOR_CONVERSION GUICC_565
csyang2 1:c0f972361605 70
csyang2 1:c0f972361605 71 //
csyang2 1:c0f972361605 72 // Display driver
csyang2 1:c0f972361605 73 //
csyang2 1:c0f972361605 74 #define DISPLAY_DRIVER GUIDRV_FLEXCOLOR
csyang2 1:c0f972361605 75
csyang2 1:c0f972361605 76 //
csyang2 1:c0f972361605 77 // Orientation
csyang2 1:c0f972361605 78 //
csyang2 1:c0f972361605 79 #define DISPLAY_ORIENTATION (0)
csyang2 1:c0f972361605 80
csyang2 1:c0f972361605 81 //
csyang2 1:c0f972361605 82 // Hardware related
csyang2 1:c0f972361605 83 //
csyang2 1:c0f972361605 84 /* LCD Module "RS" */
csyang2 1:c0f972361605 85 #define PH_CTRL_RS 1
csyang2 1:c0f972361605 86 #if PH_CTRL_RS
csyang2 1:c0f972361605 87 #define SET_RS PH3 = 1;
csyang2 1:c0f972361605 88 #define CLR_RS PH3 = 0;
csyang2 1:c0f972361605 89 #endif
csyang2 1:c0f972361605 90
csyang2 1:c0f972361605 91 /* LCD Module "RESET" */
csyang2 1:c0f972361605 92 #define SET_RST PB6 = 1;
csyang2 1:c0f972361605 93 #define CLR_RST PB6 = 0;
csyang2 1:c0f972361605 94
csyang2 1:c0f972361605 95 /*********************************************************************
csyang2 1:c0f972361605 96 *
csyang2 1:c0f972361605 97 * Configuration checking
csyang2 1:c0f972361605 98 *
csyang2 1:c0f972361605 99 **********************************************************************
csyang2 1:c0f972361605 100 */
csyang2 1:c0f972361605 101 #ifndef VXSIZE_PHYS
csyang2 1:c0f972361605 102 #define VXSIZE_PHYS XSIZE_PHYS
csyang2 1:c0f972361605 103 #endif
csyang2 1:c0f972361605 104 #ifndef VYSIZE_PHYS
csyang2 1:c0f972361605 105 #define VYSIZE_PHYS YSIZE_PHYS
csyang2 1:c0f972361605 106 #endif
csyang2 1:c0f972361605 107 #ifndef XSIZE_PHYS
csyang2 1:c0f972361605 108 #error Physical X size of display is not defined!
csyang2 1:c0f972361605 109 #endif
csyang2 1:c0f972361605 110 #ifndef YSIZE_PHYS
csyang2 1:c0f972361605 111 #error Physical Y size of display is not defined!
csyang2 1:c0f972361605 112 #endif
csyang2 1:c0f972361605 113 #ifndef COLOR_CONVERSION
csyang2 1:c0f972361605 114 #error Color conversion not defined!
csyang2 1:c0f972361605 115 #endif
csyang2 1:c0f972361605 116 #ifndef DISPLAY_DRIVER
csyang2 1:c0f972361605 117 #error No display driver defined!
csyang2 1:c0f972361605 118 #endif
csyang2 1:c0f972361605 119 #ifndef DISPLAY_ORIENTATION
csyang2 1:c0f972361605 120 #define DISPLAY_ORIENTATION 0
csyang2 1:c0f972361605 121 #endif
csyang2 1:c0f972361605 122
csyang2 1:c0f972361605 123 /*********************************************************************
csyang2 1:c0f972361605 124 *
csyang2 1:c0f972361605 125 * Static code
csyang2 1:c0f972361605 126 *
csyang2 1:c0f972361605 127 **********************************************************************/
csyang2 1:c0f972361605 128 /*-----------------------------------------------*/
csyang2 1:c0f972361605 129 // Write control registers of LCD module
csyang2 1:c0f972361605 130 //
csyang2 1:c0f972361605 131 /*-----------------------------------------------*/
csyang2 1:c0f972361605 132 #if PH_CTRL_RS
csyang2 1:c0f972361605 133 void LCD_WR_REG(uint16_t cmd)
csyang2 1:c0f972361605 134 {
csyang2 1:c0f972361605 135 CLR_RS
csyang2 1:c0f972361605 136 EBI0_WRITE_DATA16(0x00000000, cmd);
csyang2 1:c0f972361605 137 SET_RS
csyang2 1:c0f972361605 138
csyang2 1:c0f972361605 139 }
csyang2 1:c0f972361605 140
csyang2 1:c0f972361605 141 #else
csyang2 1:c0f972361605 142 void LCD_WR_REG(uint16_t cmd)
csyang2 1:c0f972361605 143 {
csyang2 1:c0f972361605 144 EBI0_WRITE_DATA16(0x00000000, cmd);
csyang2 1:c0f972361605 145 }
csyang2 1:c0f972361605 146
csyang2 1:c0f972361605 147 #endif
csyang2 1:c0f972361605 148
csyang2 1:c0f972361605 149
csyang2 1:c0f972361605 150 /*-----------------------------------------------*/
csyang2 1:c0f972361605 151 // Write data to SRAM of LCD module
csyang2 1:c0f972361605 152 //
csyang2 1:c0f972361605 153 /*-----------------------------------------------*/
csyang2 1:c0f972361605 154 void LCD_WR_DATA(uint16_t dat)
csyang2 1:c0f972361605 155 {
csyang2 1:c0f972361605 156 EBI0_WRITE_DATA16(0x00030000, dat);
csyang2 1:c0f972361605 157
csyang2 1:c0f972361605 158 }
csyang2 1:c0f972361605 159
csyang2 1:c0f972361605 160
csyang2 1:c0f972361605 161 /*-----------------------------------------------*/
csyang2 1:c0f972361605 162 // Read data from SRAM of LCD module
csyang2 1:c0f972361605 163 //
csyang2 1:c0f972361605 164 /*-----------------------------------------------*/
csyang2 1:c0f972361605 165 uint16_t LCD_RD_DATA(void)
csyang2 1:c0f972361605 166 {
csyang2 1:c0f972361605 167 return EBI0_READ_DATA16(0x00030000);
csyang2 1:c0f972361605 168
csyang2 1:c0f972361605 169 }
csyang2 1:c0f972361605 170
csyang2 1:c0f972361605 171 /********************************************************************
csyang2 1:c0f972361605 172 *
csyang2 1:c0f972361605 173 * LcdWriteDataMultiple
csyang2 1:c0f972361605 174 *
csyang2 1:c0f972361605 175 * Function description:
csyang2 1:c0f972361605 176 * Writes multiple values to a display register.
csyang2 1:c0f972361605 177 */
csyang2 1:c0f972361605 178 static void LcdWriteDataMultiple(uint16_t * pData, int NumItems)
csyang2 1:c0f972361605 179 {
csyang2 1:c0f972361605 180 while (NumItems--) {
csyang2 1:c0f972361605 181 EBI0_WRITE_DATA16(0x00030000,*pData++);
csyang2 1:c0f972361605 182 }
csyang2 1:c0f972361605 183 }
csyang2 1:c0f972361605 184
csyang2 1:c0f972361605 185 /********************************************************************
csyang2 1:c0f972361605 186 *
csyang2 1:c0f972361605 187 * LcdReadDataMultiple
csyang2 1:c0f972361605 188 *
csyang2 1:c0f972361605 189 * Function description:
csyang2 1:c0f972361605 190 * Reads multiple values from a display register.
csyang2 1:c0f972361605 191 */
csyang2 1:c0f972361605 192 static void LcdReadDataMultiple(uint16_t * pData, int NumItems)
csyang2 1:c0f972361605 193 {
csyang2 1:c0f972361605 194 while (NumItems--) {
csyang2 1:c0f972361605 195 *pData++ = EBI0_READ_DATA16(0x00030000);
csyang2 1:c0f972361605 196 }
csyang2 1:c0f972361605 197 }
csyang2 1:c0f972361605 198
csyang2 1:c0f972361605 199 /*-----------------------------------------------*/
csyang2 1:c0f972361605 200 // Set cursor positon on the LCD screen
csyang2 1:c0f972361605 201 //
csyang2 1:c0f972361605 202 /*-----------------------------------------------*/
csyang2 1:c0f972361605 203 #if 0
csyang2 1:c0f972361605 204 void LCD_SetCursor(uint16_t x_s, uint16_t y_s)
csyang2 1:c0f972361605 205 {
csyang2 1:c0f972361605 206 uint16_t x_e = x_s+1;
csyang2 1:c0f972361605 207 uint16_t y_e = y_s+1;
csyang2 1:c0f972361605 208
csyang2 1:c0f972361605 209 /* X range */
csyang2 1:c0f972361605 210 LCD_WR_REG(0x2A);
csyang2 1:c0f972361605 211 LCD_WR_DATA(x_s>>8);
csyang2 1:c0f972361605 212 LCD_WR_DATA(x_s);
csyang2 1:c0f972361605 213 LCD_WR_DATA(x_e>>8);
csyang2 1:c0f972361605 214 LCD_WR_DATA(x_e);
csyang2 1:c0f972361605 215
csyang2 1:c0f972361605 216 /* Y range */
csyang2 1:c0f972361605 217 LCD_WR_REG(0x2B);
csyang2 1:c0f972361605 218 LCD_WR_DATA(y_s>>8);
csyang2 1:c0f972361605 219 LCD_WR_DATA(y_s);
csyang2 1:c0f972361605 220 LCD_WR_DATA(y_e>>8);
csyang2 1:c0f972361605 221 LCD_WR_DATA(y_e);
csyang2 1:c0f972361605 222
csyang2 1:c0f972361605 223 /* Memory write */
csyang2 1:c0f972361605 224 LCD_WR_REG(0x2C);
csyang2 1:c0f972361605 225
csyang2 1:c0f972361605 226 }
csyang2 1:c0f972361605 227 #endif
csyang2 1:c0f972361605 228
csyang2 1:c0f972361605 229 /*-----------------------------------------------*/
csyang2 1:c0f972361605 230 // Initial LIL9341 LCD driver chip
csyang2 1:c0f972361605 231 //
csyang2 1:c0f972361605 232 /*-----------------------------------------------*/
csyang2 1:c0f972361605 233 void ILI9341_Initial(void)
csyang2 1:c0f972361605 234 {
csyang2 1:c0f972361605 235 uint16_t Reg = 0;
csyang2 1:c0f972361605 236
csyang2 1:c0f972361605 237 /* Hardware reset */
csyang2 1:c0f972361605 238 SET_RST;
csyang2 1:c0f972361605 239 GUI_X_Delay(5); // Delay 5ms
csyang2 1:c0f972361605 240
csyang2 1:c0f972361605 241 CLR_RST;
csyang2 1:c0f972361605 242 GUI_X_Delay(20); // Delay 20ms
csyang2 1:c0f972361605 243
csyang2 1:c0f972361605 244 SET_RST;
csyang2 1:c0f972361605 245 GUI_X_Delay(40); // Delay 40ms
csyang2 1:c0f972361605 246
csyang2 1:c0f972361605 247 /* Initial control registers */
csyang2 1:c0f972361605 248 LCD_WR_REG(0xCB);
csyang2 1:c0f972361605 249 LCD_WR_DATA(0x39);
csyang2 1:c0f972361605 250 LCD_WR_DATA(0x2C);
csyang2 1:c0f972361605 251 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 252 LCD_WR_DATA(0x34);
csyang2 1:c0f972361605 253 LCD_WR_DATA(0x02);
csyang2 1:c0f972361605 254
csyang2 1:c0f972361605 255 LCD_WR_REG(0xCF);
csyang2 1:c0f972361605 256 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 257 LCD_WR_DATA(0xC1);
csyang2 1:c0f972361605 258 LCD_WR_DATA(0x30);
csyang2 1:c0f972361605 259
csyang2 1:c0f972361605 260 LCD_WR_REG(0xE8);
csyang2 1:c0f972361605 261 LCD_WR_DATA(0x85);
csyang2 1:c0f972361605 262 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 263 LCD_WR_DATA(0x78);
csyang2 1:c0f972361605 264
csyang2 1:c0f972361605 265 LCD_WR_REG(0xEA);
csyang2 1:c0f972361605 266 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 267 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 268
csyang2 1:c0f972361605 269 LCD_WR_REG(0xED);
csyang2 1:c0f972361605 270 LCD_WR_DATA(0x64);
csyang2 1:c0f972361605 271 LCD_WR_DATA(0x03);
csyang2 1:c0f972361605 272 LCD_WR_DATA(0x12);
csyang2 1:c0f972361605 273 LCD_WR_DATA(0x81);
csyang2 1:c0f972361605 274
csyang2 1:c0f972361605 275 LCD_WR_REG(0xF7);
csyang2 1:c0f972361605 276 LCD_WR_DATA(0x20);
csyang2 1:c0f972361605 277
csyang2 1:c0f972361605 278 LCD_WR_REG(0xC0);
csyang2 1:c0f972361605 279 LCD_WR_DATA(0x23);
csyang2 1:c0f972361605 280
csyang2 1:c0f972361605 281 LCD_WR_REG(0xC1);
csyang2 1:c0f972361605 282 LCD_WR_DATA(0x10);
csyang2 1:c0f972361605 283
csyang2 1:c0f972361605 284 LCD_WR_REG(0xC5);
csyang2 1:c0f972361605 285 LCD_WR_DATA(0x3e);
csyang2 1:c0f972361605 286 LCD_WR_DATA(0x28);
csyang2 1:c0f972361605 287
csyang2 1:c0f972361605 288 LCD_WR_REG(0xC7);
csyang2 1:c0f972361605 289 LCD_WR_DATA(0x86);
csyang2 1:c0f972361605 290
csyang2 1:c0f972361605 291 LCD_WR_REG(0x36);
csyang2 1:c0f972361605 292 LCD_WR_DATA(0x48);
csyang2 1:c0f972361605 293
csyang2 1:c0f972361605 294 LCD_WR_REG(0x3A);
csyang2 1:c0f972361605 295 LCD_WR_DATA(0x55);
csyang2 1:c0f972361605 296
csyang2 1:c0f972361605 297 LCD_WR_REG(0xB1);
csyang2 1:c0f972361605 298 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 299 LCD_WR_DATA(0x18);
csyang2 1:c0f972361605 300
csyang2 1:c0f972361605 301 LCD_WR_REG(0xB6);
csyang2 1:c0f972361605 302 LCD_WR_DATA(0x08);
csyang2 1:c0f972361605 303 LCD_WR_DATA(0x82);
csyang2 1:c0f972361605 304 LCD_WR_DATA(0x27);
csyang2 1:c0f972361605 305
csyang2 1:c0f972361605 306 LCD_WR_REG(0xF2);
csyang2 1:c0f972361605 307 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 308
csyang2 1:c0f972361605 309 LCD_WR_REG(0x26);
csyang2 1:c0f972361605 310 LCD_WR_DATA(0x01);
csyang2 1:c0f972361605 311
csyang2 1:c0f972361605 312 LCD_WR_REG(0xE0);
csyang2 1:c0f972361605 313 LCD_WR_DATA(0x0F);
csyang2 1:c0f972361605 314 LCD_WR_DATA(0x31);
csyang2 1:c0f972361605 315 LCD_WR_DATA(0x2B);
csyang2 1:c0f972361605 316 LCD_WR_DATA(0x0C);
csyang2 1:c0f972361605 317 LCD_WR_DATA(0x0E);
csyang2 1:c0f972361605 318 LCD_WR_DATA(0x08);
csyang2 1:c0f972361605 319 LCD_WR_DATA(0x4E);
csyang2 1:c0f972361605 320 LCD_WR_DATA(0xF1);
csyang2 1:c0f972361605 321 LCD_WR_DATA(0x37);
csyang2 1:c0f972361605 322 LCD_WR_DATA(0x07);
csyang2 1:c0f972361605 323 LCD_WR_DATA(0x10);
csyang2 1:c0f972361605 324 LCD_WR_DATA(0x03);
csyang2 1:c0f972361605 325 LCD_WR_DATA(0x0E);
csyang2 1:c0f972361605 326 LCD_WR_DATA(0x09);
csyang2 1:c0f972361605 327 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 328
csyang2 1:c0f972361605 329 LCD_WR_REG(0xE1);
csyang2 1:c0f972361605 330 LCD_WR_DATA(0x00);
csyang2 1:c0f972361605 331 LCD_WR_DATA(0x0E);
csyang2 1:c0f972361605 332 LCD_WR_DATA(0x14);
csyang2 1:c0f972361605 333 LCD_WR_DATA(0x03);
csyang2 1:c0f972361605 334 LCD_WR_DATA(0x11);
csyang2 1:c0f972361605 335 LCD_WR_DATA(0x07);
csyang2 1:c0f972361605 336 LCD_WR_DATA(0x31);
csyang2 1:c0f972361605 337 LCD_WR_DATA(0xC1);
csyang2 1:c0f972361605 338 LCD_WR_DATA(0x48);
csyang2 1:c0f972361605 339 LCD_WR_DATA(0x08);
csyang2 1:c0f972361605 340 LCD_WR_DATA(0x0F);
csyang2 1:c0f972361605 341 LCD_WR_DATA(0x0C);
csyang2 1:c0f972361605 342 LCD_WR_DATA(0x31);
csyang2 1:c0f972361605 343 LCD_WR_DATA(0x36);
csyang2 1:c0f972361605 344 LCD_WR_DATA(0x0F);
csyang2 1:c0f972361605 345
csyang2 1:c0f972361605 346 LCD_WR_REG(0x11);
csyang2 1:c0f972361605 347 GUI_X_Delay(200); // Delay 200ms
csyang2 1:c0f972361605 348
csyang2 1:c0f972361605 349 LCD_WR_REG(0x29); //Display on
csyang2 1:c0f972361605 350
csyang2 1:c0f972361605 351 LCD_WR_REG(0x0A);
csyang2 1:c0f972361605 352 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 353 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 354 printf("0Ah = %02x.\n", Reg);
csyang2 1:c0f972361605 355
csyang2 1:c0f972361605 356 LCD_WR_REG(0x0B);
csyang2 1:c0f972361605 357 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 358 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 359 printf("0Bh = %02x.\n", Reg);
csyang2 1:c0f972361605 360
csyang2 1:c0f972361605 361 LCD_WR_REG(0x0C);
csyang2 1:c0f972361605 362 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 363 Reg = LCD_RD_DATA();
csyang2 1:c0f972361605 364 printf("0Ch = %02x.\n", Reg);
csyang2 1:c0f972361605 365
csyang2 1:c0f972361605 366 printf("Initial ILI9341 LCD Module done.\n\n");
csyang2 1:c0f972361605 367
csyang2 1:c0f972361605 368 }
csyang2 1:c0f972361605 369
csyang2 1:c0f972361605 370 //void I2C2_Init(void)
csyang2 1:c0f972361605 371 //{
csyang2 1:c0f972361605 372 /* Open I2C2 and set clock to 100k */
csyang2 1:c0f972361605 373 //I2C_Open(I2C2, 100000);
csyang2 1:c0f972361605 374 //}
csyang2 1:c0f972361605 375
csyang2 1:c0f972361605 376 //void EINT7_IRQHandler(void)
csyang2 1:c0f972361605 377 //{
csyang2 1:c0f972361605 378 // /* To check if PB.9 external interrupt occurred */
csyang2 1:c0f972361605 379 // if(GPIO_GET_INT_FLAG(PB, BIT9)) {
csyang2 1:c0f972361605 380 // GPIO_CLR_INT_FLAG(PB, BIT9);
csyang2 1:c0f972361605 381 // printf("PB.9 EINT7 occurred.\n");
csyang2 1:c0f972361605 382 // }
csyang2 1:c0f972361605 383
csyang2 1:c0f972361605 384 //}
csyang2 1:c0f972361605 385
csyang2 1:c0f972361605 386
csyang2 1:c0f972361605 387 void EBI_FuncPinInit(void)
csyang2 1:c0f972361605 388 {
csyang2 1:c0f972361605 389 /*=== EBI (LCD module) mult-function pins ===*/
csyang2 1:c0f972361605 390 /* EBI AD0~5 pins on PG.9~14 */
csyang2 1:c0f972361605 391 SYS->GPG_MFPH &= ~(SYS_GPG_MFPH_PG9MFP_Msk | SYS_GPG_MFPH_PG10MFP_Msk |
csyang2 1:c0f972361605 392 SYS_GPG_MFPH_PG11MFP_Msk | SYS_GPG_MFPH_PG12MFP_Msk |
csyang2 1:c0f972361605 393 SYS_GPG_MFPH_PG13MFP_Msk | SYS_GPG_MFPH_PG14MFP_Msk);
csyang2 1:c0f972361605 394 SYS->GPG_MFPH |= (SYS_GPG_MFPH_PG9MFP_EBI_AD0 | SYS_GPG_MFPH_PG10MFP_EBI_AD1 |
csyang2 1:c0f972361605 395 SYS_GPG_MFPH_PG11MFP_EBI_AD2 | SYS_GPG_MFPH_PG12MFP_EBI_AD3 |
csyang2 1:c0f972361605 396 SYS_GPG_MFPH_PG13MFP_EBI_AD4 | SYS_GPG_MFPH_PG14MFP_EBI_AD5);
csyang2 1:c0f972361605 397
csyang2 1:c0f972361605 398 /* EBI AD6, AD7 pins on PD.8, PD.9 */
csyang2 1:c0f972361605 399 SYS->GPD_MFPH &= ~(SYS_GPD_MFPH_PD8MFP_Msk | SYS_GPD_MFPH_PD9MFP_Msk);
csyang2 1:c0f972361605 400 SYS->GPD_MFPH |= (SYS_GPD_MFPH_PD8MFP_EBI_AD6 | SYS_GPD_MFPH_PD9MFP_EBI_AD7);
csyang2 1:c0f972361605 401
csyang2 1:c0f972361605 402 /* EBI AD8, AD9 pins on PE.14, PE.15 */
csyang2 1:c0f972361605 403 SYS->GPE_MFPH &= ~(SYS_GPE_MFPH_PE14MFP_Msk | SYS_GPE_MFPH_PE15MFP_Msk);
csyang2 1:c0f972361605 404 SYS->GPE_MFPH |= (SYS_GPE_MFPH_PE14MFP_EBI_AD8 | SYS_GPE_MFPH_PE15MFP_EBI_AD9);
csyang2 1:c0f972361605 405
csyang2 1:c0f972361605 406 /* EBI AD10, AD11 pins on PE.1, PE.0 */
csyang2 1:c0f972361605 407 SYS->GPE_MFPL &= ~(SYS_GPE_MFPL_PE1MFP_Msk | SYS_GPE_MFPL_PE0MFP_Msk);
csyang2 1:c0f972361605 408 SYS->GPE_MFPL |= (SYS_GPE_MFPL_PE1MFP_EBI_AD10 | SYS_GPE_MFPL_PE0MFP_EBI_AD11);
csyang2 1:c0f972361605 409
csyang2 1:c0f972361605 410 /* EBI AD12~15 pins on PH.8~11 */
csyang2 1:c0f972361605 411 SYS->GPH_MFPH &= ~(SYS_GPH_MFPH_PH8MFP_Msk | SYS_GPH_MFPH_PH9MFP_Msk |
csyang2 1:c0f972361605 412 SYS_GPH_MFPH_PH10MFP_Msk | SYS_GPH_MFPH_PH11MFP_Msk);
csyang2 1:c0f972361605 413 SYS->GPH_MFPH |= (SYS_GPH_MFPH_PH8MFP_EBI_AD12 | SYS_GPH_MFPH_PH9MFP_EBI_AD13 |
csyang2 1:c0f972361605 414 SYS_GPH_MFPH_PH10MFP_EBI_AD14 | SYS_GPH_MFPH_PH11MFP_EBI_AD15);
csyang2 1:c0f972361605 415
csyang2 1:c0f972361605 416 /* Configure PH.3 as Output mode for LCD_RS (use GPIO PH.3 to control LCD_RS) */
csyang2 1:c0f972361605 417 GPIO_SetMode(PH, BIT3, GPIO_MODE_OUTPUT);
csyang2 1:c0f972361605 418 PH3 = 1;
csyang2 1:c0f972361605 419
csyang2 1:c0f972361605 420 /* EBI RD and WR pins on PE.4 and PE.5 */
csyang2 1:c0f972361605 421 SYS->GPE_MFPL &= ~(SYS_GPE_MFPL_PE4MFP_Msk | SYS_GPE_MFPL_PE5MFP_Msk);
csyang2 1:c0f972361605 422 SYS->GPE_MFPL |= (SYS_GPE_MFPL_PE4MFP_EBI_nWR | SYS_GPE_MFPL_PE5MFP_EBI_nRD);
csyang2 1:c0f972361605 423
csyang2 1:c0f972361605 424 /* EBI CS0 pin on PD.14 */
csyang2 1:c0f972361605 425 SYS->GPD_MFPH &= ~SYS_GPD_MFPH_PD14MFP_Msk;
csyang2 1:c0f972361605 426 SYS->GPD_MFPH |= SYS_GPD_MFPH_PD14MFP_EBI_nCS0;
csyang2 1:c0f972361605 427
csyang2 1:c0f972361605 428 /* Configure PB.6 and PB.7 as Output mode for LCD_RST and LCD_Backlight */
csyang2 1:c0f972361605 429 GPIO_SetMode(PB, BIT6, GPIO_MODE_OUTPUT);
csyang2 1:c0f972361605 430 GPIO_SetMode(PB, BIT7, GPIO_MODE_OUTPUT);
csyang2 1:c0f972361605 431 PB6 = 1;
csyang2 1:c0f972361605 432 PB7 = 0;
csyang2 1:c0f972361605 433
csyang2 1:c0f972361605 434 //GPIO_SetMode(PH, BIT5, GPIO_MODE_INPUT);
csyang2 1:c0f972361605 435 //GPIO_SetMode(PH, BIT6, GPIO_MODE_INPUT);
csyang2 1:c0f972361605 436 //GPIO_SetMode(PH, BIT7, GPIO_MODE_INPUT);
csyang2 1:c0f972361605 437
csyang2 1:c0f972361605 438 }
csyang2 1:c0f972361605 439
csyang2 1:c0f972361605 440 /*********************************************************************
csyang2 1:c0f972361605 441 *
csyang2 1:c0f972361605 442 * _InitController
csyang2 1:c0f972361605 443 *
csyang2 1:c0f972361605 444 * Purpose:
csyang2 1:c0f972361605 445 * Initializes the display controller
csyang2 1:c0f972361605 446 */
csyang2 1:c0f972361605 447 static void _InitController(void)
csyang2 1:c0f972361605 448 {
csyang2 1:c0f972361605 449 static uint8_t s_InitOnce = 0;
csyang2 1:c0f972361605 450
csyang2 1:c0f972361605 451 if (s_InitOnce == 0)
csyang2 1:c0f972361605 452 s_InitOnce = 1;
csyang2 1:c0f972361605 453 else
csyang2 1:c0f972361605 454 return;
csyang2 1:c0f972361605 455
csyang2 1:c0f972361605 456 CLK_EnableModuleClock(EBI_MODULE);
csyang2 1:c0f972361605 457
csyang2 1:c0f972361605 458 /* Configure DC/RESET/LED pins */
csyang2 1:c0f972361605 459 EBI_FuncPinInit();
csyang2 1:c0f972361605 460
csyang2 1:c0f972361605 461 /* Initialize EBI bank0 to access external LCD Module */
csyang2 1:c0f972361605 462 EBI_Open(EBI_BANK0, EBI_BUSWIDTH_16BIT, EBI_TIMING_NORMAL, 0, EBI_CS_ACTIVE_LOW);
csyang2 1:c0f972361605 463 EBI->CTL0 |= EBI_CTL0_CACCESS_Msk;
csyang2 1:c0f972361605 464 EBI->TCTL0 |= (EBI_TCTL0_WAHDOFF_Msk | EBI_TCTL0_RAHDOFF_Msk);
csyang2 1:c0f972361605 465 printf("\n[EBI CTL0:0x%08X, TCLT0:0x%08X]\n\n", EBI->CTL0, EBI->TCTL0);
csyang2 1:c0f972361605 466
csyang2 1:c0f972361605 467 /* Init LCD Module */
csyang2 1:c0f972361605 468 ILI9341_Initial();
csyang2 1:c0f972361605 469
csyang2 1:c0f972361605 470 /* PB.7 BL_CTRL pin */
csyang2 1:c0f972361605 471 PB7 = 1;
csyang2 1:c0f972361605 472
csyang2 1:c0f972361605 473 /* Init I2C2 to TP of LCD module */
csyang2 1:c0f972361605 474 //I2C2_Init();
csyang2 1:c0f972361605 475
csyang2 1:c0f972361605 476 // /* Configure PB.9 as Quasi-bidirection mode and enable interrupt by falling edge trigger */
csyang2 1:c0f972361605 477 // GPIO_SetMode(PB, BIT9, GPIO_MODE_QUASI);
csyang2 1:c0f972361605 478 // GPIO_EnableInt(PB, 9, GPIO_INT_FALLING);
csyang2 1:c0f972361605 479 // NVIC_EnableIRQ(EINT7_IRQn);
csyang2 1:c0f972361605 480 }
csyang2 1:c0f972361605 481
csyang2 1:c0f972361605 482 /*********************************************************************
csyang2 1:c0f972361605 483 *
csyang2 1:c0f972361605 484 * Public code
csyang2 1:c0f972361605 485 *
csyang2 1:c0f972361605 486 **********************************************************************
csyang2 1:c0f972361605 487 */
csyang2 1:c0f972361605 488 #if GUI_SUPPORT_TOUCH
csyang2 1:c0f972361605 489 extern int ts_phy2log(int *sumx, int *sumy);
csyang2 1:c0f972361605 490
csyang2 1:c0f972361605 491 void GUI_TOUCH_X_ActivateX(void) {
csyang2 1:c0f972361605 492 }
csyang2 1:c0f972361605 493
csyang2 1:c0f972361605 494 void GUI_TOUCH_X_ActivateY(void) {
csyang2 1:c0f972361605 495 }
csyang2 1:c0f972361605 496
csyang2 1:c0f972361605 497
csyang2 1:c0f972361605 498
csyang2 1:c0f972361605 499 int GUI_TOUCH_X_MeasureX(void) {
csyang2 1:c0f972361605 500 int sumx;
csyang2 1:c0f972361605 501 int sumy;
csyang2 1:c0f972361605 502 if (Read_TouchPanel(&sumx, &sumy))
csyang2 1:c0f972361605 503 {
csyang2 1:c0f972361605 504 // sysprintf("X = %d\n", sumx);
csyang2 1:c0f972361605 505 ts_phy2log(&sumx, &sumy);
csyang2 1:c0f972361605 506 return sumx;
csyang2 1:c0f972361605 507 }
csyang2 1:c0f972361605 508 return -1;
csyang2 1:c0f972361605 509 }
csyang2 1:c0f972361605 510
csyang2 1:c0f972361605 511 int GUI_TOUCH_X_MeasureY(void) {
csyang2 1:c0f972361605 512 int sumx;
csyang2 1:c0f972361605 513 int sumy;
csyang2 1:c0f972361605 514 if ( Read_TouchPanel(&sumx, &sumy) )
csyang2 1:c0f972361605 515 {
csyang2 1:c0f972361605 516 // sysprintf("Y = %d\n", sumy);
csyang2 1:c0f972361605 517 ts_phy2log(&sumx, &sumy);
csyang2 1:c0f972361605 518 return sumy;
csyang2 1:c0f972361605 519 }
csyang2 1:c0f972361605 520 return -1;
csyang2 1:c0f972361605 521 }
csyang2 1:c0f972361605 522 #endif
csyang2 1:c0f972361605 523 /*********************************************************************
csyang2 1:c0f972361605 524 *
csyang2 1:c0f972361605 525 * LCD_X_Config
csyang2 1:c0f972361605 526 *
csyang2 1:c0f972361605 527 * Purpose:
csyang2 1:c0f972361605 528 * Called during the initialization process in order to set up the
csyang2 1:c0f972361605 529 * display driver configuration.
csyang2 1:c0f972361605 530 *
csyang2 1:c0f972361605 531 */
csyang2 1:c0f972361605 532 void LCD_X_Config(void)
csyang2 1:c0f972361605 533 {
csyang2 1:c0f972361605 534 GUI_DEVICE * pDevice;
csyang2 1:c0f972361605 535 CONFIG_FLEXCOLOR Config = {0};
csyang2 1:c0f972361605 536 GUI_PORT_API PortAPI = {0};
csyang2 1:c0f972361605 537 //
csyang2 1:c0f972361605 538 // Set display driver and color conversion
csyang2 1:c0f972361605 539 //
csyang2 1:c0f972361605 540 pDevice = GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
csyang2 1:c0f972361605 541
csyang2 1:c0f972361605 542 //
csyang2 1:c0f972361605 543 // Display driver configuration
csyang2 1:c0f972361605 544 //
csyang2 1:c0f972361605 545 LCD_SetSizeEx (0, XSIZE_PHYS, YSIZE_PHYS);
csyang2 1:c0f972361605 546 LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
csyang2 1:c0f972361605 547 //
csyang2 1:c0f972361605 548 // Orientation
csyang2 1:c0f972361605 549 //
csyang2 1:c0f972361605 550 Config.Orientation = GUI_MIRROR_X | GUI_MIRROR_Y | GUI_SWAP_XY;
csyang2 1:c0f972361605 551 GUIDRV_FlexColor_Config(pDevice, &Config);
csyang2 1:c0f972361605 552 //
csyang2 1:c0f972361605 553 // Set controller and operation mode
csyang2 1:c0f972361605 554 //
csyang2 1:c0f972361605 555 PortAPI.pfWrite16_A0 = LCD_WR_REG;
csyang2 1:c0f972361605 556 PortAPI.pfWrite16_A1 = LCD_WR_DATA;
csyang2 1:c0f972361605 557 PortAPI.pfWriteM16_A0 = LcdWriteDataMultiple;
csyang2 1:c0f972361605 558 PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
csyang2 1:c0f972361605 559 PortAPI.pfRead16_A0 = LCD_RD_DATA;
csyang2 1:c0f972361605 560 PortAPI.pfRead16_A1 = LCD_RD_DATA;
csyang2 1:c0f972361605 561 PortAPI.pfReadM16_A0 = LcdReadDataMultiple;
csyang2 1:c0f972361605 562 PortAPI.pfReadM16_A1 = LcdReadDataMultiple;
csyang2 1:c0f972361605 563 GUIDRV_FlexColor_SetReadFunc66709_B16(pDevice, GUIDRV_FLEXCOLOR_READ_FUNC_III);
csyang2 1:c0f972361605 564 GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B16);
csyang2 1:c0f972361605 565
csyang2 1:c0f972361605 566 #if GUI_SUPPORT_TOUCH
csyang2 1:c0f972361605 567 // LCD calibration
csyang2 1:c0f972361605 568 //
csyang2 1:c0f972361605 569 // Calibrate touch screen
csyang2 1:c0f972361605 570 //
csyang2 1:c0f972361605 571 GUI_TOUCH_Calibrate(GUI_COORD_X, 0, (__DEMO_TS_WIDTH__ - 1), 0, (__DEMO_TS_WIDTH__ - 1));
csyang2 1:c0f972361605 572 GUI_TOUCH_Calibrate(GUI_COORD_Y, 0, (__DEMO_TS_HEIGHT__- 1), 0, (__DEMO_TS_HEIGHT__- 1));
csyang2 1:c0f972361605 573 #endif
csyang2 1:c0f972361605 574 }
csyang2 1:c0f972361605 575 /*********************************************************************
csyang2 1:c0f972361605 576 *
csyang2 1:c0f972361605 577 * LCD_X_DisplayDriver
csyang2 1:c0f972361605 578 *
csyang2 1:c0f972361605 579 * Purpose:
csyang2 1:c0f972361605 580 * This function is called by the display driver for several purposes.
csyang2 1:c0f972361605 581 * To support the according task the routine needs to be adapted to
csyang2 1:c0f972361605 582 * the display controller. Please note that the commands marked with
csyang2 1:c0f972361605 583 * 'optional' are not cogently required and should only be adapted if
csyang2 1:c0f972361605 584 * the display controller supports these features.
csyang2 1:c0f972361605 585 *
csyang2 1:c0f972361605 586 * Parameter:
csyang2 1:c0f972361605 587 * LayerIndex - Index of layer to be configured
csyang2 1:c0f972361605 588 * Cmd - Please refer to the details in the switch statement below
csyang2 1:c0f972361605 589 * pData - Pointer to a LCD_X_DATA structure
csyang2 1:c0f972361605 590 */
csyang2 1:c0f972361605 591 int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData)
csyang2 1:c0f972361605 592 {
csyang2 1:c0f972361605 593 int r;
csyang2 1:c0f972361605 594
csyang2 1:c0f972361605 595 GUI_USE_PARA(LayerIndex);
csyang2 1:c0f972361605 596 GUI_USE_PARA(pData);
csyang2 1:c0f972361605 597 switch (Cmd) {
csyang2 1:c0f972361605 598 //
csyang2 1:c0f972361605 599 // Required
csyang2 1:c0f972361605 600 //
csyang2 1:c0f972361605 601 case LCD_X_INITCONTROLLER: {
csyang2 1:c0f972361605 602 //
csyang2 1:c0f972361605 603 // Called during the initialization process in order to set up the
csyang2 1:c0f972361605 604 // display controller and put it into operation. If the display
csyang2 1:c0f972361605 605 // controller is not initialized by any external routine this needs
csyang2 1:c0f972361605 606 // to be adapted by the customer...
csyang2 1:c0f972361605 607 //
csyang2 1:c0f972361605 608 _InitController();
csyang2 1:c0f972361605 609 //printf("\n************ _InitController \n\n");
csyang2 1:c0f972361605 610 return 0;
csyang2 1:c0f972361605 611 }
csyang2 1:c0f972361605 612 default:
csyang2 1:c0f972361605 613 r = -1;
csyang2 1:c0f972361605 614 }
csyang2 1:c0f972361605 615 return r;
csyang2 1:c0f972361605 616 }
csyang2 6:d15151941247 617 #endif
csyang2 1:c0f972361605 618 /*************************** End of file ****************************/