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

« Back to documentation index

Show/hide line numbers cy8ckit_028_tft.cpp Source File

cy8ckit_028_tft.cpp

00001 /***************************************************************************//**
00002 * \file DisplayInterface.h
00003 * \version 1.0
00004 *
00005 * \brief
00006 * Objective:
00007 *    This is display software i8080 interface source file
00008 *
00009 ********************************************************************************
00010 * \copyright
00011 * Copyright 2018-2019 Cypress Semiconductor Corporation
00012 * SPDX-License-Identifier: Apache-2.0
00013 *
00014 * Licensed under the Apache License, Version 2.0 (the "License");
00015 * you may not use this file except in compliance with the License.
00016 * You may obtain a copy of the License at
00017 *
00018 *     http://www.apache.org/licenses/LICENSE-2.0
00019 *
00020 * Unless required by applicable law or agreed to in writing, software
00021 * distributed under the License is distributed on an "AS IS" BASIS,
00022 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00023 * See the License for the specific language governing permissions and
00024 * limitations under the License.
00025 *******************************************************************************/
00026 
00027 
00028 #include "cy8ckit_028_tft.h"
00029 #include <mbed_wait_api.h>
00030 #include "mbed.h"
00031 #include "PortInOut.h"
00032 
00033 /*
00034 DigitalInOut LCD_REG0(P9_0);
00035 DigitalInOut LCD_REG1(P9_1);
00036 DigitalInOut LCD_REG2(P9_2);
00037 DigitalInOut LCD_REG3(P9_4);
00038 DigitalInOut LCD_REG4(P9_5);
00039 DigitalInOut LCD_REG5(P0_2);
00040 DigitalInOut LCD_REG6(P13_0);
00041 DigitalInOut LCD_REG7(P13_1);
00042 PortInOut P0(Port0, 0x04);
00043 PortInOut P9(Port9, 0x37);
00044 PortInOut P13(Port13, 0x03);
00045 */
00046 BusInOut    tftport(P9_0, P9_1, P9_2, P9_4, P9_5, P0_2, P13_0, P13_1);
00047 
00048 DigitalOut LCD_NWR(P12_0);
00049 DigitalOut LCD_DC(P12_1);
00050 DigitalOut LCD_RESET(P12_2);
00051 DigitalOut LCD_NRD(P12_3);
00052 
00053 /*******************************************************************************
00054 * Function Name: DataWrite
00055 ****************************************************************************/
00056 /**
00057 *
00058 * \brief
00059 *   Writes one byte of data to the software i8080 interface.
00060 *
00061 * \details
00062 *   This function:
00063 *       - Writes data to the data bus
00064 *       - Sends low pulse to the LCD_NWR line to write data
00065 *
00066 *   Changed from individual bit banging to port masked writes to 
00067 *   P9[5,4,2,1,0], P13[1,0], P0[2] to optimise slightly 
00068 * 
00069 * \todo
00070 *   All this should be replaced with a udb register to save all the shifting
00071 *   and individual bit writing.
00072 *
00073 *******************************************************************************/
00074 void DataWrite(U8 data)
00075 {
00076 //    LCD_REG0 = (data & 0x01);
00077 //    LCD_REG1 = ((data>>1) & 0x01);
00078 //    LCD_REG2 = ((data>>2) & 0x01);
00079 //    LCD_REG3 = ((data>>3) & 0x01);
00080 //    LCD_REG4 = ((data>>4) & 0x01);
00081 
00082 /* read the appropriate port and only change the bits we need to then write the
00083  * affected bits back to the port retaining any unaffected bit values
00084  */
00085  //   int pbyte = P9.read();
00086  //   int bit012 = (data & 0x07);
00087  //   int bit34 = (data & 0x18) << 1;
00088  //   pbyte = (pbyte & 0xc8) | bit34 | bit012;
00089  //   P9.write(pbyte);
00090 ////    LCD_REG5 = ((data>>5) & 0x01);
00091 //    pbyte = P0.read();
00092 //    int bit5 = (data & 0x20) >> 3 ;
00093 //    pbyte = (pbyte & 0xfb) | bit5 ;
00094 //    P0.write(pbyte);
00095 //
00096 // //    LCD_REG6 = ((data>>6) & 0x01);
00097 // //    LCD_REG7 = ((data>>7) & 0x01);
00098 //    pbyte = P13.read();
00099 //    int bit67 = (data & 0xc0) >> 6 ;
00100 //    pbyte = (pbyte & 0xfc) | bit67 ;
00101 //    P13.write(pbyte);
00102     tftport.output();
00103     tftport = data;
00104     LCD_NWR = 0u;
00105     LCD_NWR = 1u;
00106 
00107 }
00108 
00109 
00110 /*******************************************************************************
00111 * Function Name: DataRead
00112 ****************************************************************************//**
00113 *
00114 * \brief
00115 *   Reads one byte of data from the software i8080 interface.
00116 *
00117 * \details
00118 *   This function:
00119 *       - Changes data bus GPIO pins drive mode to digital Hi-Z with enabled input 
00120 *         buffer
00121 *       - Sends low pulse to LCD_NRD line to read data
00122 *       - Reads data from the data bus
00123 *       - Sends low pulse to the LCD_NWR line to write data
00124 *       - Changes data bus GPIO pins drive mode back to to Strong Drive mode
00125 * 
00126 * \todo
00127 *   All this should be replaced with a udb register to save all the shifting
00128 *   and individual bit reading.
00129 *
00130 *******************************************************************************/
00131 U8 DataRead(void)
00132 {
00133     U8 data = 0u;
00134 
00135     /* enable input */
00136 //    LCD_REG0.input();
00137 //    LCD_REG1.input();
00138 //    LCD_REG2.input();
00139 //    LCD_REG3.input();
00140 //    LCD_REG4.input();
00141 //    LCD_REG5.input();
00142 //    LCD_REG6.input();
00143 //    LCD_REG7.input();
00144     tftport.input();
00145     LCD_NRD = 0u;  //  Pulse read line low then read the data port
00146     
00147 //    data = (U8)LCD_REG0.read();
00148 //    data |= (U8)LCD_REG1.read()<<1;
00149 //    data |= (U8)LCD_REG2.read()<<2;
00150 //    data |= (U8)LCD_REG3.read()<<3;
00151 //    data |= (U8)LCD_REG4.read()<<4;
00152 //    data |= (U8)LCD_REG5.read()<<5;
00153 //    data |= (U8)LCD_REG6.read()<<6;
00154 //    data |= (U8)LCD_REG7.read()<<7;
00155     data = tftport;   
00156     LCD_NRD = 1u;  // Raise the read line and then go back to output port
00157        
00158 //    LCD_REG0.output();
00159 //    LCD_REG1.output();
00160 //    LCD_REG2.output();
00161 //    LCD_REG3.output();
00162 //    LCD_REG4.output();
00163 //    LCD_REG5.output();
00164 //    LCD_REG6.output();
00165 //    LCD_REG7.output();
00166 
00167     return data;
00168 }
00169 
00170 
00171 /*******************************************************************************
00172 * Function Name: DisplayIntf_Init
00173 ****************************************************************************//**
00174 *
00175 * \brief
00176 *   Initializes software i8080 interface.
00177 *
00178 * \details
00179 *   This function:
00180 *       - Initializes interface GPIO pins
00181 *
00182 *******************************************************************************/
00183 void DisplayIntf_Init(void)
00184 {
00185     /* All pins are initialized by the Device Configurator. */
00186     LCD_RESET = 1u;
00187     LCD_NRD = 1u;
00188     LCD_NWR = 1u;
00189     LCD_DC = 0u;
00190 
00191 //    LCD_REG0.output();
00192 //    LCD_REG1.output();
00193 //    LCD_REG2.output();
00194 //    LCD_REG3.output();
00195 //    LCD_REG4.output();
00196 //    LCD_REG5.output();
00197 //    LCD_REG6.output();
00198 //    LCD_REG7.output();
00199     tftport.output();
00200     wait_ms(20);
00201     LCD_RESET = 0u;
00202     wait_ms(100);
00203     
00204     LCD_RESET = 1u;
00205     wait_ms(100);
00206 
00207     DisplayIntf_Write8_A0(0x28);
00208     DisplayIntf_Write8_A0(0x11);    /* Exit Sleep mode */
00209     wait_ms(100);
00210     DisplayIntf_Write8_A0(0x36);
00211     DisplayIntf_Write8_A1(0xA0);    /* MADCTL: memory data access control */
00212     DisplayIntf_Write8_A0(0x3A);
00213     DisplayIntf_Write8_A1(0x65);    /* COLMOD: Interface Pixel format */
00214     DisplayIntf_Write8_A0(0xB2);
00215     DisplayIntf_Write8_A1(0x0C);
00216     DisplayIntf_Write8_A1(0x0C);
00217     DisplayIntf_Write8_A1(0x00);
00218     DisplayIntf_Write8_A1(0x33);
00219     DisplayIntf_Write8_A1(0x33);    /* PORCTRK: Porch setting */
00220     DisplayIntf_Write8_A0(0xB7);
00221     DisplayIntf_Write8_A1(0x35);    /* GCTRL: Gate Control */
00222     DisplayIntf_Write8_A0(0xBB);
00223     DisplayIntf_Write8_A1(0x2B);    /* VCOMS: VCOM setting */
00224     DisplayIntf_Write8_A0(0xC0);
00225     DisplayIntf_Write8_A1(0x2C);    /* LCMCTRL: LCM Control */
00226     DisplayIntf_Write8_A0(0xC2);
00227     DisplayIntf_Write8_A1(0x01);
00228     DisplayIntf_Write8_A1(0xFF);    /* VDVVRHEN: VDV and VRH Command Enable */
00229     DisplayIntf_Write8_A0(0xC3);
00230     DisplayIntf_Write8_A1(0x11);    /* VRHS: VRH Set */
00231     DisplayIntf_Write8_A0(0xC4);
00232     DisplayIntf_Write8_A1(0x20);    /* VDVS: VDV Set */
00233     DisplayIntf_Write8_A0(0xC6);
00234     DisplayIntf_Write8_A1(0x0F);    /* FRCTRL2: Frame Rate control in normal mode */
00235     DisplayIntf_Write8_A0(0xD0);
00236     DisplayIntf_Write8_A1(0xA4);
00237     DisplayIntf_Write8_A1(0xA1);    /* PWCTRL1: Power Control 1 */
00238     DisplayIntf_Write8_A0(0xE0);
00239     DisplayIntf_Write8_A1(0xD0);
00240     DisplayIntf_Write8_A1(0x00);
00241     DisplayIntf_Write8_A1(0x05);
00242     DisplayIntf_Write8_A1(0x0E);
00243     DisplayIntf_Write8_A1(0x15);
00244     DisplayIntf_Write8_A1(0x0D);
00245     DisplayIntf_Write8_A1(0x37);
00246     DisplayIntf_Write8_A1(0x43);
00247     DisplayIntf_Write8_A1(0x47);
00248     DisplayIntf_Write8_A1(0x09);
00249     DisplayIntf_Write8_A1(0x15);
00250     DisplayIntf_Write8_A1(0x12);
00251     DisplayIntf_Write8_A1(0x16);
00252     DisplayIntf_Write8_A1(0x19);    /* PVGAMCTRL: Positive Voltage Gamma control */
00253     DisplayIntf_Write8_A0(0xE1);
00254     DisplayIntf_Write8_A1(0xD0);
00255     DisplayIntf_Write8_A1(0x00);
00256     DisplayIntf_Write8_A1(0x05);
00257     DisplayIntf_Write8_A1(0x0D);
00258     DisplayIntf_Write8_A1(0x0C);
00259     DisplayIntf_Write8_A1(0x06);
00260     DisplayIntf_Write8_A1(0x2D);
00261     DisplayIntf_Write8_A1(0x44);
00262     DisplayIntf_Write8_A1(0x40);
00263     DisplayIntf_Write8_A1(0x0E);
00264     DisplayIntf_Write8_A1(0x1C);
00265     DisplayIntf_Write8_A1(0x18);
00266     DisplayIntf_Write8_A1(0x16);
00267     DisplayIntf_Write8_A1(0x19);    /* NVGAMCTRL: Negative Voltage Gamma control */
00268     DisplayIntf_Write8_A0(0x2B);
00269     DisplayIntf_Write8_A1(0x00);
00270     DisplayIntf_Write8_A1(0x00);
00271     DisplayIntf_Write8_A1(0x00);
00272     DisplayIntf_Write8_A1(0xEF);    /* Y address set */
00273     DisplayIntf_Write8_A0(0x2A);
00274     DisplayIntf_Write8_A1(0x00);
00275     DisplayIntf_Write8_A1(0x00);
00276     DisplayIntf_Write8_A1(0x01);
00277     DisplayIntf_Write8_A1(0x3F);    /* X address set */
00278     wait_ms(10);
00279     DisplayIntf_Write8_A0(0x29);
00280 
00281 
00282 }
00283 
00284 
00285 /*******************************************************************************
00286 * Function Name: DisplayIntf_Write8_A0
00287 ****************************************************************************//**
00288 *
00289 * \brief
00290 *   Writes one byte of data to the software i8080 interface with the LCD_DC pin 
00291 *   set to 0
00292 *
00293 * \details
00294 *   This function:
00295 *       - Sets LCD_DC pin to 0
00296 *       - Writes one data byte
00297 *
00298 *******************************************************************************/
00299 void DisplayIntf_Write8_A0(U8 data)
00300 {
00301     LCD_DC = 0u;
00302     DataWrite(data);
00303 }
00304 
00305 
00306 /*******************************************************************************
00307 * Function Name: DisplayIntf_Write8_A1
00308 ****************************************************************************//**
00309 *
00310 * \brief
00311 *   Writes one byte of data to the software i8080 interface with the LCD_DC pin 
00312 *   set to 1
00313 *
00314 * \details
00315 *   This function:
00316 *       - Sets LCD_DC pin to 1
00317 *       - Writes one data byte
00318 *
00319 *******************************************************************************/
00320 void DisplayIntf_Write8_A1(U8 data)
00321 {
00322     LCD_DC = 1u;
00323     DataWrite(data);
00324 }
00325 
00326 
00327 /*******************************************************************************
00328 * Function Name: DisplayIntf_WriteM8_A1
00329 ****************************************************************************//**
00330 *
00331 * \brief
00332 *   Writes multiple bytes of data to the software i8080 interface with the LCD_DC 
00333 *   pin set to 1
00334 *
00335 * \details
00336 *   This function:
00337 *       - Sets LCD_DC pin to 1
00338 *       - Writes data bytes
00339 *
00340 *******************************************************************************/
00341 void DisplayIntf_WriteM8_A1(U8 data[], int num)
00342 {
00343     int i = 0;
00344 
00345     LCD_DC = 1u;
00346 
00347     for(i = 0; i < num; i++)
00348     {
00349         DataWrite(data[i]);
00350     }
00351 }
00352 
00353 
00354 /*******************************************************************************
00355 * Function Name: DisplayIntf_Read8_A1
00356 ****************************************************************************//**
00357 *
00358 * \brief
00359 *   Reads one byte of data from the software i8080 interface with the LCD_DC pin 
00360 *   set to 1
00361 *
00362 * \details
00363 *   This function:
00364 *       - Sets LCD_DC pin to 1
00365 *       - Reads one data byte
00366 *
00367 *******************************************************************************/
00368 U8 DisplayIntf_Read8_A1(void)
00369 {
00370     LCD_DC = 1u;
00371     return DataRead();
00372 }
00373 
00374 
00375 /*******************************************************************************
00376 * Function Name: DisplayIntf_ReadM8_A1
00377 ****************************************************************************//**
00378 *
00379 * \brief
00380 *   Reads multiple bytes of data from the software i8080 interface with the LCD_DC 
00381 *   pin set to 1
00382 *
00383 * \details
00384 *   This function:
00385 *       - Sets LCD_DC pin to 1
00386 *       - Reads data bytes
00387 *
00388 *******************************************************************************/
00389 void DisplayIntf_ReadM8_A1(U8 data[], int num)
00390 {
00391     int i = 0;
00392 
00393     LCD_DC = 1u;
00394 
00395     for(i = 0; i < num; i++)
00396     {
00397         data[i] = DataRead();
00398     }
00399 }
00400 
00401 
00402 /* [] END OF FILE */
00403 
00404