Andrew Reed / Mbed OS CITY1082-capsense-tft
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LCDConf.cpp Source File

LCDConf.cpp

00001 /*********************************************************************
00002 *                SEGGER Microcontroller GmbH & Co. KG                *
00003 *        Solutions for real time microcontroller applications        *
00004 **********************************************************************
00005 *                                                                    *
00006 *        (c) 1996 - 2017  SEGGER Microcontroller GmbH & Co. KG       *
00007 *                                                                    *
00008 *        Internet: www.segger.com    Support:  support@segger.com    *
00009 *                                                                    *
00010 **********************************************************************
00011 
00012 ** emWin V5.46 - Graphical user interface for embedded applications **
00013 All  Intellectual Property rights  in the Software belongs to  SEGGER.
00014 emWin is protected by  international copyright laws.  Knowledge of the
00015 source code may not be used to write a similar product.  This file may
00016 only be used in accordance with the following terms:
00017 
00018 The software  has been licensed to  Cypress Semiconductor Corporation,
00019 whose registered  office is situated  at 198 Champion Ct. San Jose, CA 
00020 95134 USA  solely for the  purposes of creating  libraries for Cypress
00021 PSoC3 and  PSoC5 processor-based devices,  sublicensed and distributed
00022 under  the  terms  and  conditions  of  the  Cypress  End User License
00023 Agreement.
00024 Full source code is available at: www.segger.com
00025 
00026 We appreciate your understanding and fairness.
00027 ----------------------------------------------------------------------
00028 Licensing information
00029 Licensor:                 SEGGER Microcontroller Systems LLC
00030 Licensed to:              Cypress Semiconductor Corp, 198 Champion Ct., San Jose, CA 95134, USA
00031 Licensed SEGGER software: emWin
00032 License number:           GUI-00319
00033 License model:            Services and License Agreement, signed June 10th, 2009
00034 Licensed platform:        Any Cypress platform (Initial targets are: PSoC3, PSoC5)
00035 ----------------------------------------------------------------------
00036 Support and Update Agreement (SUA)
00037 SUA period:               2009-06-12 - 2022-07-27
00038 Contact to extend SUA:    sales@segger.com
00039 ----------------------------------------------------------------------
00040 File        : LCDConf.c
00041 Purpose     : Display controller configuration (single layer)
00042 ---------------------------END-OF-HEADER------------------------------
00043 */
00044 
00045 #include "GUI.h"
00046 #include "GUIDRV_FlexColor.h"
00047 
00048 #include "cy8ckit_028_tft.h"
00049 
00050 
00051 /*********************************************************************
00052 *
00053 *       Layer configuration (to be modified)
00054 *
00055 **********************************************************************
00056 */
00057 //
00058 // Physical display size
00059 //   The display size should be adapted in order to match the size of
00060 //   the target display.
00061 //
00062 #define XSIZE_PHYS 240
00063 #define YSIZE_PHYS 320
00064 
00065 //
00066 // Color conversion
00067 //   The color conversion functions should be selected according to
00068 //   the color mode of the target display. Details can be found in
00069 //   the chapter "Colors" in the emWin user manual.
00070 //
00071 #define COLOR_CONVERSION GUICC_M565
00072 
00073 //
00074 // Display driver
00075 //
00076 #define DISPLAY_DRIVER GUIDRV_FLEXCOLOR
00077 
00078 /*********************************************************************
00079 *
00080 *       Configuration checking
00081 *
00082 **********************************************************************
00083 */
00084 #ifndef   VXSIZE_PHYS
00085   #define VXSIZE_PHYS XSIZE_PHYS
00086 #endif
00087 #ifndef   VYSIZE_PHYS
00088   #define VYSIZE_PHYS YSIZE_PHYS
00089 #endif
00090 #ifndef   XSIZE_PHYS
00091   #error Physical X size of display is not defined!
00092 #endif
00093 #ifndef   YSIZE_PHYS
00094   #error Physical Y size of display is not defined!
00095 #endif
00096 #ifndef   COLOR_CONVERSION
00097   #error Color conversion not defined!
00098 #endif
00099 #ifndef   DISPLAY_DRIVER
00100   #error No display driver defined!
00101 #endif
00102 
00103 /********************************************************************
00104 *
00105 *       CY8CKIT_028_TFT_InitController
00106 *
00107 * Purpose:
00108 *   Initializes the LCD controller
00109 *
00110 */
00111 static void CY8CKIT_028_TFT_InitController(void) {
00112   /* Set up the display controller and put it into operation. If the 
00113   *  display controller is not initialized by any external routine 
00114   *  this needs to be adapted by the customer.
00115   */
00116     DisplayIntf_Init();
00117 
00118 /*
00119     Cy_GPIO_Set(LCD_RESET_PORT, LCD_RESET_NUM);
00120     GUI_Delay(20);
00121     Cy_GPIO_Clr(LCD_RESET_PORT, LCD_RESET_NUM);
00122     GUI_Delay(100);
00123     Cy_GPIO_Set(LCD_RESET_PORT, LCD_RESET_NUM);
00124     GUI_Delay(100);
00125  */
00126     LCD_RESET = 1u;
00127     GUI_Delay(20);
00128     LCD_RESET = 0u;
00129     GUI_Delay(100);
00130     
00131     LCD_RESET = 1u;
00132     GUI_Delay(100);
00133 
00134     DisplayIntf_Write8_A0(0x28);
00135     DisplayIntf_Write8_A0(0x11);    /* Exit Sleep mode */
00136     GUI_Delay(100);
00137     DisplayIntf_Write8_A0(0x36);
00138     DisplayIntf_Write8_A1(0xA0);    /* MADCTL: memory data access control */
00139     DisplayIntf_Write8_A0(0x3A);
00140     DisplayIntf_Write8_A1(0x65);    /* COLMOD: Interface Pixel format */
00141     DisplayIntf_Write8_A0(0xB2);
00142     DisplayIntf_Write8_A1(0x0C);
00143     DisplayIntf_Write8_A1(0x0C);
00144     DisplayIntf_Write8_A1(0x00);
00145     DisplayIntf_Write8_A1(0x33);
00146     DisplayIntf_Write8_A1(0x33);    /* PORCTRK: Porch setting */
00147     DisplayIntf_Write8_A0(0xB7);
00148     DisplayIntf_Write8_A1(0x35);    /* GCTRL: Gate Control */
00149     DisplayIntf_Write8_A0(0xBB);
00150     DisplayIntf_Write8_A1(0x2B);    /* VCOMS: VCOM setting */
00151     DisplayIntf_Write8_A0(0xC0);
00152     DisplayIntf_Write8_A1(0x2C);    /* LCMCTRL: LCM Control */
00153     DisplayIntf_Write8_A0(0xC2);
00154     DisplayIntf_Write8_A1(0x01);
00155     DisplayIntf_Write8_A1(0xFF);    /* VDVVRHEN: VDV and VRH Command Enable */
00156     DisplayIntf_Write8_A0(0xC3);
00157     DisplayIntf_Write8_A1(0x11);    /* VRHS: VRH Set */
00158     DisplayIntf_Write8_A0(0xC4);
00159     DisplayIntf_Write8_A1(0x20);    /* VDVS: VDV Set */
00160     DisplayIntf_Write8_A0(0xC6);
00161     DisplayIntf_Write8_A1(0x0F);    /* FRCTRL2: Frame Rate control in normal mode */
00162     DisplayIntf_Write8_A0(0xD0);
00163     DisplayIntf_Write8_A1(0xA4);
00164     DisplayIntf_Write8_A1(0xA1);    /* PWCTRL1: Power Control 1 */
00165     DisplayIntf_Write8_A0(0xE0);
00166     DisplayIntf_Write8_A1(0xD0);
00167     DisplayIntf_Write8_A1(0x00);
00168     DisplayIntf_Write8_A1(0x05);
00169     DisplayIntf_Write8_A1(0x0E);
00170     DisplayIntf_Write8_A1(0x15);
00171     DisplayIntf_Write8_A1(0x0D);
00172     DisplayIntf_Write8_A1(0x37);
00173     DisplayIntf_Write8_A1(0x43);
00174     DisplayIntf_Write8_A1(0x47);
00175     DisplayIntf_Write8_A1(0x09);
00176     DisplayIntf_Write8_A1(0x15);
00177     DisplayIntf_Write8_A1(0x12);
00178     DisplayIntf_Write8_A1(0x16);
00179     DisplayIntf_Write8_A1(0x19);    /* PVGAMCTRL: Positive Voltage Gamma control */
00180     DisplayIntf_Write8_A0(0xE1);
00181     DisplayIntf_Write8_A1(0xD0);
00182     DisplayIntf_Write8_A1(0x00);
00183     DisplayIntf_Write8_A1(0x05);
00184     DisplayIntf_Write8_A1(0x0D);
00185     DisplayIntf_Write8_A1(0x0C);
00186     DisplayIntf_Write8_A1(0x06);
00187     DisplayIntf_Write8_A1(0x2D);
00188     DisplayIntf_Write8_A1(0x44);
00189     DisplayIntf_Write8_A1(0x40);
00190     DisplayIntf_Write8_A1(0x0E);
00191     DisplayIntf_Write8_A1(0x1C);
00192     DisplayIntf_Write8_A1(0x18);
00193     DisplayIntf_Write8_A1(0x16);
00194     DisplayIntf_Write8_A1(0x19);    /* NVGAMCTRL: Negative Voltage Gamma control */
00195     DisplayIntf_Write8_A0(0x2B);
00196     DisplayIntf_Write8_A1(0x00);
00197     DisplayIntf_Write8_A1(0x00);
00198     DisplayIntf_Write8_A1(0x00);
00199     DisplayIntf_Write8_A1(0xEF);    /* Y address set */
00200     DisplayIntf_Write8_A0(0x2A);
00201     DisplayIntf_Write8_A1(0x00);
00202     DisplayIntf_Write8_A1(0x00);
00203     DisplayIntf_Write8_A1(0x01);
00204     DisplayIntf_Write8_A1(0x3F);    /* X address set */
00205     GUI_Delay(10);
00206     DisplayIntf_Write8_A0(0x29);
00207 }
00208 
00209 /*********************************************************************
00210 *
00211 *       Public code
00212 *
00213 **********************************************************************
00214 */
00215 /*********************************************************************
00216 *
00217 *       LCD_X_Config
00218 *
00219 * Function description
00220 *   Called during the initialization process in order to set up the
00221 *   display driver configuration.
00222 */
00223 void LCD_X_Config(void) {
00224   GUI_DEVICE * pDevice;
00225   CONFIG_FLEXCOLOR Config = {0};
00226   GUI_PORT_API PortAPI = {0};
00227   //
00228   // Set the display driver and color conversion
00229   //
00230   pDevice = GUI_DEVICE_CreateAndLink(DISPLAY_DRIVER, COLOR_CONVERSION, 0, 0);
00231   //
00232   // Display driver configuration
00233   //
00234   LCD_SetSizeEx    (0, XSIZE_PHYS,   YSIZE_PHYS);
00235   LCD_SetVSizeEx   (0, VXSIZE_PHYS,  VYSIZE_PHYS);
00236   //
00237   // Orientation
00238   //
00239   Config.Orientation   = GUI_MIRROR_Y | GUI_SWAP_XY;
00240   GUIDRV_FlexColor_Config(pDevice, &Config);
00241   //
00242   // Set controller and operation mode
00243   //
00244   PortAPI.pfWrite8_A0  = DisplayIntf_Write8_A0;
00245   PortAPI.pfWrite8_A1  = DisplayIntf_Write8_A1;
00246   PortAPI.pfWriteM8_A1 = DisplayIntf_WriteM8_A1;
00247   PortAPI.pfRead8_A1   = DisplayIntf_Read8_A1;
00248   PortAPI.pfReadM8_A1  = DisplayIntf_ReadM8_A1;
00249   
00250   GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66709, GUIDRV_FLEXCOLOR_M16C0B8);
00251 }
00252 
00253 /*********************************************************************
00254 *
00255 *       LCD_X_DisplayDriver
00256 *
00257 * Purpose:
00258 *   This function is called by the display driver for several purposes.
00259 *   To support the according task, the routine needs to be adapted to
00260 *   the display controller. Note that the commands marked
00261 *   "optional" are not cogently required and should only be adapted if 
00262 *   the display controller supports these features.
00263 *
00264 * Parameter:
00265 *   LayerIndex - Zero based layer index
00266 *   Cmd        - Command to be executed
00267 *   pData      - Pointer to a data structure.
00268 * 
00269 * Return Value:
00270 *   < -1 - Error
00271 *     -1 - The command is not handled.
00272 *      0 - OK.
00273 */
00274 int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
00275   int r;
00276   
00277   GUI_USE_PARA(LayerIndex);
00278   GUI_USE_PARA(pData);
00279   
00280   switch (Cmd) {
00281   case LCD_X_INITCONTROLLER: {
00282     //
00283     // Called during the initialization process in order to set up the
00284     // display controller and put it into operation. If the display
00285     // controller is not initialized by any external routine, this needs
00286     // to be adapted by the customer...
00287     //
00288     // ...
00289     CY8CKIT_028_TFT_InitController();
00290     return 0;
00291   }
00292   default:
00293     r = -1;
00294   }
00295   return r;
00296 }
00297 
00298 /*************************** End of file ****************************/
00299