Template for working forward

Dependencies:   mbed PinDetect

Committer:
reedas
Date:
Tue Nov 19 10:04:48 2019 +0000
Revision:
1:402b32a1025f
Basic Hello World tft display library program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
reedas 1:402b32a1025f 1 /*********************************************************************
reedas 1:402b32a1025f 2 * SEGGER Microcontroller GmbH & Co. KG *
reedas 1:402b32a1025f 3 * Solutions for real time microcontroller applications *
reedas 1:402b32a1025f 4 **********************************************************************
reedas 1:402b32a1025f 5 * *
reedas 1:402b32a1025f 6 * (c) 1996 - 2017 SEGGER Microcontroller GmbH & Co. KG *
reedas 1:402b32a1025f 7 * *
reedas 1:402b32a1025f 8 * Internet: www.segger.com Support: support@segger.com *
reedas 1:402b32a1025f 9 * *
reedas 1:402b32a1025f 10 **********************************************************************
reedas 1:402b32a1025f 11
reedas 1:402b32a1025f 12 ** emWin V5.46 - Graphical user interface for embedded applications **
reedas 1:402b32a1025f 13 All Intellectual Property rights in the Software belongs to SEGGER.
reedas 1:402b32a1025f 14 emWin is protected by international copyright laws. Knowledge of the
reedas 1:402b32a1025f 15 source code may not be used to write a similar product. This file may
reedas 1:402b32a1025f 16 only be used in accordance with the following terms:
reedas 1:402b32a1025f 17
reedas 1:402b32a1025f 18 The software has been licensed to Cypress Semiconductor Corporation,
reedas 1:402b32a1025f 19 whose registered office is situated at 198 Champion Ct. San Jose, CA
reedas 1:402b32a1025f 20 95134 USA solely for the purposes of creating libraries for Cypress
reedas 1:402b32a1025f 21 PSoC3 and PSoC5 processor-based devices, sublicensed and distributed
reedas 1:402b32a1025f 22 under the terms and conditions of the Cypress End User License
reedas 1:402b32a1025f 23 Agreement.
reedas 1:402b32a1025f 24 Full source code is available at: www.segger.com
reedas 1:402b32a1025f 25
reedas 1:402b32a1025f 26 We appreciate your understanding and fairness.
reedas 1:402b32a1025f 27 ----------------------------------------------------------------------
reedas 1:402b32a1025f 28 Licensing information
reedas 1:402b32a1025f 29 Licensor: SEGGER Microcontroller Systems LLC
reedas 1:402b32a1025f 30 Licensed to: Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
reedas 1:402b32a1025f 31 Licensed SEGGER software: emWin
reedas 1:402b32a1025f 32 License number: GUI-00319
reedas 1:402b32a1025f 33 License model: Services and License Agreement, signed June 10th, 2009
reedas 1:402b32a1025f 34 Licensed platform: Any Cypress platform (Initial targets are: PSoC3, PSoC5)
reedas 1:402b32a1025f 35 ----------------------------------------------------------------------
reedas 1:402b32a1025f 36 Support and Update Agreement (SUA)
reedas 1:402b32a1025f 37 SUA period: 2009-06-12 - 2022-07-27
reedas 1:402b32a1025f 38 Contact to extend SUA: sales@segger.com
reedas 1:402b32a1025f 39 ----------------------------------------------------------------------
reedas 1:402b32a1025f 40 File : LCDConf.c
reedas 1:402b32a1025f 41 Purpose : Display controller configuration (single layer)
reedas 1:402b32a1025f 42 ---------------------------END-OF-HEADER------------------------------
reedas 1:402b32a1025f 43 */
reedas 1:402b32a1025f 44
reedas 1:402b32a1025f 45 #include "GUI.h"
reedas 1:402b32a1025f 46 #include "GUIDRV_FlexColor.h"
reedas 1:402b32a1025f 47
reedas 1:402b32a1025f 48 #include "cy8ckit_028_tft.h"
reedas 1:402b32a1025f 49
reedas 1:402b32a1025f 50
reedas 1:402b32a1025f 51 /*********************************************************************
reedas 1:402b32a1025f 52 *
reedas 1:402b32a1025f 53 * Layer configuration (to be modified)
reedas 1:402b32a1025f 54 *
reedas 1:402b32a1025f 55 **********************************************************************
reedas 1:402b32a1025f 56 */
reedas 1:402b32a1025f 57 //
reedas 1:402b32a1025f 58 // Physical display size
reedas 1:402b32a1025f 59 // The display size should be adapted in order to match the size of
reedas 1:402b32a1025f 60 // the target display.
reedas 1:402b32a1025f 61 //
reedas 1:402b32a1025f 62 #define XSIZE_PHYS 240
reedas 1:402b32a1025f 63 #define YSIZE_PHYS 320
reedas 1:402b32a1025f 64
reedas 1:402b32a1025f 65 //
reedas 1:402b32a1025f 66 // Color conversion
reedas 1:402b32a1025f 67 // The color conversion functions should be selected according to
reedas 1:402b32a1025f 68 // the color mode of the target display. Details can be found in
reedas 1:402b32a1025f 69 // the chapter "Colors" in the emWin user manual.
reedas 1:402b32a1025f 70 //
reedas 1:402b32a1025f 71 #define COLOR_CONVERSION GUICC_M565
reedas 1:402b32a1025f 72
reedas 1:402b32a1025f 73 //
reedas 1:402b32a1025f 74 // Display driver
reedas 1:402b32a1025f 75 //
reedas 1:402b32a1025f 76 #define DISPLAY_DRIVER GUIDRV_FLEXCOLOR
reedas 1:402b32a1025f 77
reedas 1:402b32a1025f 78 /*********************************************************************
reedas 1:402b32a1025f 79 *
reedas 1:402b32a1025f 80 * Configuration checking
reedas 1:402b32a1025f 81 *
reedas 1:402b32a1025f 82 **********************************************************************
reedas 1:402b32a1025f 83 */
reedas 1:402b32a1025f 84 #ifndef VXSIZE_PHYS
reedas 1:402b32a1025f 85 #define VXSIZE_PHYS XSIZE_PHYS
reedas 1:402b32a1025f 86 #endif
reedas 1:402b32a1025f 87 #ifndef VYSIZE_PHYS
reedas 1:402b32a1025f 88 #define VYSIZE_PHYS YSIZE_PHYS
reedas 1:402b32a1025f 89 #endif
reedas 1:402b32a1025f 90 #ifndef XSIZE_PHYS
reedas 1:402b32a1025f 91 #error Physical X size of display is not defined!
reedas 1:402b32a1025f 92 #endif
reedas 1:402b32a1025f 93 #ifndef YSIZE_PHYS
reedas 1:402b32a1025f 94 #error Physical Y size of display is not defined!
reedas 1:402b32a1025f 95 #endif
reedas 1:402b32a1025f 96 #ifndef COLOR_CONVERSION
reedas 1:402b32a1025f 97 #error Color conversion not defined!
reedas 1:402b32a1025f 98 #endif
reedas 1:402b32a1025f 99 #ifndef DISPLAY_DRIVER
reedas 1:402b32a1025f 100 #error No display driver defined!
reedas 1:402b32a1025f 101 #endif
reedas 1:402b32a1025f 102
reedas 1:402b32a1025f 103 /********************************************************************
reedas 1:402b32a1025f 104 *
reedas 1:402b32a1025f 105 * CY8CKIT_028_TFT_InitController
reedas 1:402b32a1025f 106 *
reedas 1:402b32a1025f 107 * Purpose:
reedas 1:402b32a1025f 108 * Initializes the LCD controller
reedas 1:402b32a1025f 109 *
reedas 1:402b32a1025f 110 */
reedas 1:402b32a1025f 111 static void CY8CKIT_028_TFT_InitController(void) {
reedas 1:402b32a1025f 112 /* Set up the display controller and put it into operation. If the
reedas 1:402b32a1025f 113 * display controller is not initialized by any external routine
reedas 1:402b32a1025f 114 * this needs to be adapted by the customer.
reedas 1:402b32a1025f 115 */
reedas 1:402b32a1025f 116 DisplayIntf_Init();
reedas 1:402b32a1025f 117
reedas 1:402b32a1025f 118 /*
reedas 1:402b32a1025f 119 Cy_GPIO_Set(LCD_RESET_PORT, LCD_RESET_NUM);
reedas 1:402b32a1025f 120 GUI_Delay(20);
reedas 1:402b32a1025f 121 Cy_GPIO_Clr(LCD_RESET_PORT, LCD_RESET_NUM);
reedas 1:402b32a1025f 122 GUI_Delay(100);
reedas 1:402b32a1025f 123 Cy_GPIO_Set(LCD_RESET_PORT, LCD_RESET_NUM);
reedas 1:402b32a1025f 124 GUI_Delay(100);
reedas 1:402b32a1025f 125 */
reedas 1:402b32a1025f 126 LCD_RESET = 1u;
reedas 1:402b32a1025f 127 GUI_Delay(20);
reedas 1:402b32a1025f 128 LCD_RESET = 0u;
reedas 1:402b32a1025f 129 GUI_Delay(100);
reedas 1:402b32a1025f 130
reedas 1:402b32a1025f 131 LCD_RESET = 1u;
reedas 1:402b32a1025f 132 GUI_Delay(100);
reedas 1:402b32a1025f 133
reedas 1:402b32a1025f 134 DisplayIntf_Write8_A0(0x28);
reedas 1:402b32a1025f 135 DisplayIntf_Write8_A0(0x11); /* Exit Sleep mode */
reedas 1:402b32a1025f 136 GUI_Delay(100);
reedas 1:402b32a1025f 137 DisplayIntf_Write8_A0(0x36);
reedas 1:402b32a1025f 138 DisplayIntf_Write8_A1(0xA0); /* MADCTL: memory data access control */
reedas 1:402b32a1025f 139 DisplayIntf_Write8_A0(0x3A);
reedas 1:402b32a1025f 140 DisplayIntf_Write8_A1(0x65); /* COLMOD: Interface Pixel format */
reedas 1:402b32a1025f 141 DisplayIntf_Write8_A0(0xB2);
reedas 1:402b32a1025f 142 DisplayIntf_Write8_A1(0x0C);
reedas 1:402b32a1025f 143 DisplayIntf_Write8_A1(0x0C);
reedas 1:402b32a1025f 144 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 145 DisplayIntf_Write8_A1(0x33);
reedas 1:402b32a1025f 146 DisplayIntf_Write8_A1(0x33); /* PORCTRK: Porch setting */
reedas 1:402b32a1025f 147 DisplayIntf_Write8_A0(0xB7);
reedas 1:402b32a1025f 148 DisplayIntf_Write8_A1(0x35); /* GCTRL: Gate Control */
reedas 1:402b32a1025f 149 DisplayIntf_Write8_A0(0xBB);
reedas 1:402b32a1025f 150 DisplayIntf_Write8_A1(0x2B); /* VCOMS: VCOM setting */
reedas 1:402b32a1025f 151 DisplayIntf_Write8_A0(0xC0);
reedas 1:402b32a1025f 152 DisplayIntf_Write8_A1(0x2C); /* LCMCTRL: LCM Control */
reedas 1:402b32a1025f 153 DisplayIntf_Write8_A0(0xC2);
reedas 1:402b32a1025f 154 DisplayIntf_Write8_A1(0x01);
reedas 1:402b32a1025f 155 DisplayIntf_Write8_A1(0xFF); /* VDVVRHEN: VDV and VRH Command Enable */
reedas 1:402b32a1025f 156 DisplayIntf_Write8_A0(0xC3);
reedas 1:402b32a1025f 157 DisplayIntf_Write8_A1(0x11); /* VRHS: VRH Set */
reedas 1:402b32a1025f 158 DisplayIntf_Write8_A0(0xC4);
reedas 1:402b32a1025f 159 DisplayIntf_Write8_A1(0x20); /* VDVS: VDV Set */
reedas 1:402b32a1025f 160 DisplayIntf_Write8_A0(0xC6);
reedas 1:402b32a1025f 161 DisplayIntf_Write8_A1(0x0F); /* FRCTRL2: Frame Rate control in normal mode */
reedas 1:402b32a1025f 162 DisplayIntf_Write8_A0(0xD0);
reedas 1:402b32a1025f 163 DisplayIntf_Write8_A1(0xA4);
reedas 1:402b32a1025f 164 DisplayIntf_Write8_A1(0xA1); /* PWCTRL1: Power Control 1 */
reedas 1:402b32a1025f 165 DisplayIntf_Write8_A0(0xE0);
reedas 1:402b32a1025f 166 DisplayIntf_Write8_A1(0xD0);
reedas 1:402b32a1025f 167 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 168 DisplayIntf_Write8_A1(0x05);
reedas 1:402b32a1025f 169 DisplayIntf_Write8_A1(0x0E);
reedas 1:402b32a1025f 170 DisplayIntf_Write8_A1(0x15);
reedas 1:402b32a1025f 171 DisplayIntf_Write8_A1(0x0D);
reedas 1:402b32a1025f 172 DisplayIntf_Write8_A1(0x37);
reedas 1:402b32a1025f 173 DisplayIntf_Write8_A1(0x43);
reedas 1:402b32a1025f 174 DisplayIntf_Write8_A1(0x47);
reedas 1:402b32a1025f 175 DisplayIntf_Write8_A1(0x09);
reedas 1:402b32a1025f 176 DisplayIntf_Write8_A1(0x15);
reedas 1:402b32a1025f 177 DisplayIntf_Write8_A1(0x12);
reedas 1:402b32a1025f 178 DisplayIntf_Write8_A1(0x16);
reedas 1:402b32a1025f 179 DisplayIntf_Write8_A1(0x19); /* PVGAMCTRL: Positive Voltage Gamma control */
reedas 1:402b32a1025f 180 DisplayIntf_Write8_A0(0xE1);
reedas 1:402b32a1025f 181 DisplayIntf_Write8_A1(0xD0);
reedas 1:402b32a1025f 182 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 183 DisplayIntf_Write8_A1(0x05);
reedas 1:402b32a1025f 184 DisplayIntf_Write8_A1(0x0D);
reedas 1:402b32a1025f 185 DisplayIntf_Write8_A1(0x0C);
reedas 1:402b32a1025f 186 DisplayIntf_Write8_A1(0x06);
reedas 1:402b32a1025f 187 DisplayIntf_Write8_A1(0x2D);
reedas 1:402b32a1025f 188 DisplayIntf_Write8_A1(0x44);
reedas 1:402b32a1025f 189 DisplayIntf_Write8_A1(0x40);
reedas 1:402b32a1025f 190 DisplayIntf_Write8_A1(0x0E);
reedas 1:402b32a1025f 191 DisplayIntf_Write8_A1(0x1C);
reedas 1:402b32a1025f 192 DisplayIntf_Write8_A1(0x18);
reedas 1:402b32a1025f 193 DisplayIntf_Write8_A1(0x16);
reedas 1:402b32a1025f 194 DisplayIntf_Write8_A1(0x19); /* NVGAMCTRL: Negative Voltage Gamma control */
reedas 1:402b32a1025f 195 DisplayIntf_Write8_A0(0x2B);
reedas 1:402b32a1025f 196 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 197 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 198 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 199 DisplayIntf_Write8_A1(0xEF); /* Y address set */
reedas 1:402b32a1025f 200 DisplayIntf_Write8_A0(0x2A);
reedas 1:402b32a1025f 201 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 202 DisplayIntf_Write8_A1(0x00);
reedas 1:402b32a1025f 203 DisplayIntf_Write8_A1(0x01);
reedas 1:402b32a1025f 204 DisplayIntf_Write8_A1(0x3F); /* X address set */
reedas 1:402b32a1025f 205 GUI_Delay(10);
reedas 1:402b32a1025f 206 DisplayIntf_Write8_A0(0x29);
reedas 1:402b32a1025f 207 }
reedas 1:402b32a1025f 208
reedas 1:402b32a1025f 209 /*********************************************************************
reedas 1:402b32a1025f 210 *
reedas 1:402b32a1025f 211 * Public code
reedas 1:402b32a1025f 212 *
reedas 1:402b32a1025f 213 **********************************************************************
reedas 1:402b32a1025f 214 */
reedas 1:402b32a1025f 215 /*********************************************************************
reedas 1:402b32a1025f 216 *
reedas 1:402b32a1025f 217 * LCD_X_Config
reedas 1:402b32a1025f 218 *
reedas 1:402b32a1025f 219 * Function description
reedas 1:402b32a1025f 220 * Called during the initialization process in order to set up the
reedas 1:402b32a1025f 221 * display driver configuration.
reedas 1:402b32a1025f 222 */
reedas 1:402b32a1025f 223 void LCD_X_Config(void) {
reedas 1:402b32a1025f 224 GUI_DEVICE * pDevice;
reedas 1:402b32a1025f 225 CONFIG_FLEXCOLOR Config = {0};
reedas 1:402b32a1025f 226 GUI_PORT_API PortAPI = {0};
reedas 1:402b32a1025f 227 //
reedas 1:402b32a1025f 228 // Set the display driver and color conversion
reedas 1:402b32a1025f 229 //
reedas 1:402b32a1025f 230 pDevice = GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
reedas 1:402b32a1025f 231 //
reedas 1:402b32a1025f 232 // Display driver configuration
reedas 1:402b32a1025f 233 //
reedas 1:402b32a1025f 234 LCD_SetSizeEx (0, XSIZE_PHYS, YSIZE_PHYS);
reedas 1:402b32a1025f 235 LCD_SetVSizeEx (0, VXSIZE_PHYS, VYSIZE_PHYS);
reedas 1:402b32a1025f 236 //
reedas 1:402b32a1025f 237 // Orientation
reedas 1:402b32a1025f 238 //
reedas 1:402b32a1025f 239 Config.Orientation = GUI_MIRROR_Y | GUI_SWAP_XY;
reedas 1:402b32a1025f 240 GUIDRV_FlexColor_Config(pDevice, &Config);
reedas 1:402b32a1025f 241 //
reedas 1:402b32a1025f 242 // Set controller and operation mode
reedas 1:402b32a1025f 243 //
reedas 1:402b32a1025f 244 PortAPI.pfWrite8_A0 = DisplayIntf_Write8_A0;
reedas 1:402b32a1025f 245 PortAPI.pfWrite8_A1 = DisplayIntf_Write8_A1;
reedas 1:402b32a1025f 246 PortAPI.pfWriteM8_A1 = DisplayIntf_WriteM8_A1;
reedas 1:402b32a1025f 247 PortAPI.pfRead8_A1 = DisplayIntf_Read8_A1;
reedas 1:402b32a1025f 248 PortAPI.pfReadM8_A1 = DisplayIntf_ReadM8_A1;
reedas 1:402b32a1025f 249
reedas 1:402b32a1025f 250 GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B8);
reedas 1:402b32a1025f 251 }
reedas 1:402b32a1025f 252
reedas 1:402b32a1025f 253 /*********************************************************************
reedas 1:402b32a1025f 254 *
reedas 1:402b32a1025f 255 * LCD_X_DisplayDriver
reedas 1:402b32a1025f 256 *
reedas 1:402b32a1025f 257 * Purpose:
reedas 1:402b32a1025f 258 * This function is called by the display driver for several purposes.
reedas 1:402b32a1025f 259 * To support the according task, the routine needs to be adapted to
reedas 1:402b32a1025f 260 * the display controller. Note that the commands marked
reedas 1:402b32a1025f 261 * "optional" are not cogently required and should only be adapted if
reedas 1:402b32a1025f 262 * the display controller supports these features.
reedas 1:402b32a1025f 263 *
reedas 1:402b32a1025f 264 * Parameter:
reedas 1:402b32a1025f 265 * LayerIndex - Zero based layer index
reedas 1:402b32a1025f 266 * Cmd - Command to be executed
reedas 1:402b32a1025f 267 * pData - Pointer to a data structure.
reedas 1:402b32a1025f 268 *
reedas 1:402b32a1025f 269 * Return Value:
reedas 1:402b32a1025f 270 * < -1 - Error
reedas 1:402b32a1025f 271 * -1 - The command is not handled.
reedas 1:402b32a1025f 272 * 0 - OK.
reedas 1:402b32a1025f 273 */
reedas 1:402b32a1025f 274 int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
reedas 1:402b32a1025f 275 int r;
reedas 1:402b32a1025f 276
reedas 1:402b32a1025f 277 GUI_USE_PARA(LayerIndex);
reedas 1:402b32a1025f 278 GUI_USE_PARA(pData);
reedas 1:402b32a1025f 279
reedas 1:402b32a1025f 280 switch (Cmd) {
reedas 1:402b32a1025f 281 case LCD_X_INITCONTROLLER: {
reedas 1:402b32a1025f 282 //
reedas 1:402b32a1025f 283 // Called during the initialization process in order to set up the
reedas 1:402b32a1025f 284 // display controller and put it into operation. If the display
reedas 1:402b32a1025f 285 // controller is not initialized by any external routine, this needs
reedas 1:402b32a1025f 286 // to be adapted by the customer...
reedas 1:402b32a1025f 287 //
reedas 1:402b32a1025f 288 // ...
reedas 1:402b32a1025f 289 CY8CKIT_028_TFT_InitController();
reedas 1:402b32a1025f 290 return 0;
reedas 1:402b32a1025f 291 }
reedas 1:402b32a1025f 292 default:
reedas 1:402b32a1025f 293 r = -1;
reedas 1:402b32a1025f 294 }
reedas 1:402b32a1025f 295 return r;
reedas 1:402b32a1025f 296 }
reedas 1:402b32a1025f 297
reedas 1:402b32a1025f 298 /*************************** End of file ****************************/
reedas 1:402b32a1025f 299