Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
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 00032 DigitalInOut LCD_REG0(P9_0); 00033 DigitalInOut LCD_REG1(P9_1); 00034 DigitalInOut LCD_REG2(P9_2); 00035 DigitalInOut LCD_REG3(P9_4); 00036 DigitalInOut LCD_REG4(P9_5); 00037 DigitalInOut LCD_REG5(P0_2); 00038 DigitalInOut LCD_REG6(P13_0); 00039 DigitalInOut LCD_REG7(P13_1); 00040 00041 DigitalOut LCD_NWR(P12_0); 00042 DigitalOut LCD_DC(P12_1); 00043 DigitalOut LCD_RESET(P12_2); 00044 DigitalOut LCD_NRD(P12_3); 00045 00046 /******************************************************************************* 00047 * Function Name: DataWrite 00048 ****************************************************************************//** 00049 * 00050 * \brief 00051 * Writes one byte of data to the software i8080 interface. 00052 * 00053 * \details 00054 * This function: 00055 * - Writes data to the data bus 00056 * - Sends low pulse to the LCD_NWR line to write data 00057 * 00058 * \todo 00059 * All this should be replaced with a udb register to save all the shifting 00060 * and individual bit writing. 00061 * 00062 *******************************************************************************/ 00063 void DataWrite(U8 data) 00064 { 00065 LCD_REG0 = (data & 0x01); 00066 LCD_REG1 = ((data>>1) & 0x01); 00067 LCD_REG2 = ((data>>2) & 0x01); 00068 LCD_REG3 = ((data>>3) & 0x01); 00069 LCD_REG4 = ((data>>4) & 0x01); 00070 LCD_REG5 = ((data>>5) & 0x01); 00071 LCD_REG6 = ((data>>6) & 0x01); 00072 LCD_REG7 = ((data>>7) & 0x01); 00073 00074 LCD_NWR = 0u; 00075 LCD_NWR = 1u; 00076 00077 } 00078 00079 00080 /******************************************************************************* 00081 * Function Name: DataRead 00082 ****************************************************************************//** 00083 * 00084 * \brief 00085 * Reads one byte of data from the software i8080 interface. 00086 * 00087 * \details 00088 * This function: 00089 * - Changes data bus GPIO pins drive mode to digital Hi-Z with enabled input 00090 * buffer 00091 * - Sends low pulse to LCD_NRD line to read data 00092 * - Reads data from the data bus 00093 * - Sends low pulse to the LCD_NWR line to write data 00094 * - Changes data bus GPIO pins drive mode back to to Strong Drive mode 00095 * 00096 * \todo 00097 * All this should be replaced with a udb register to save all the shifting 00098 * and individual bit reading. 00099 * 00100 *******************************************************************************/ 00101 U8 DataRead(void) 00102 { 00103 U8 data = 0u; 00104 00105 /* enable input */ 00106 LCD_REG0.input(); 00107 LCD_REG1.input(); 00108 LCD_REG2.input(); 00109 LCD_REG3.input(); 00110 LCD_REG4.input(); 00111 LCD_REG5.input(); 00112 LCD_REG6.input(); 00113 LCD_REG7.input(); 00114 00115 LCD_NRD = 0u; // Pulse read line low then read the data port 00116 00117 data = (U8)LCD_REG0.read(); 00118 data |= (U8)LCD_REG1.read()<<1; 00119 data |= (U8)LCD_REG2.read()<<2; 00120 data |= (U8)LCD_REG3.read()<<3; 00121 data |= (U8)LCD_REG4.read()<<4; 00122 data |= (U8)LCD_REG5.read()<<5; 00123 data |= (U8)LCD_REG6.read()<<6; 00124 data |= (U8)LCD_REG7.read()<<7; 00125 00126 LCD_NRD = 1u; // Raise the read line and then go back to output port 00127 00128 LCD_REG0.output(); 00129 LCD_REG1.output(); 00130 LCD_REG2.output(); 00131 LCD_REG3.output(); 00132 LCD_REG4.output(); 00133 LCD_REG5.output(); 00134 LCD_REG6.output(); 00135 LCD_REG7.output(); 00136 00137 return data; 00138 } 00139 00140 00141 /******************************************************************************* 00142 * Function Name: DisplayIntf_Init 00143 ****************************************************************************//** 00144 * 00145 * \brief 00146 * Initializes software i8080 interface. 00147 * 00148 * \details 00149 * This function: 00150 * - Initializes interface GPIO pins 00151 * 00152 *******************************************************************************/ 00153 void DisplayIntf_Init(void) 00154 { 00155 /* All pins are initialized by the Device Configurator. */ 00156 LCD_RESET = 1u; 00157 LCD_NRD = 1u; 00158 LCD_NWR = 1u; 00159 LCD_DC = 0u; 00160 LCD_REG0.output(); 00161 LCD_REG1.output(); 00162 LCD_REG2.output(); 00163 LCD_REG3.output(); 00164 LCD_REG4.output(); 00165 LCD_REG5.output(); 00166 LCD_REG6.output(); 00167 LCD_REG7.output(); 00168 wait_ms(20); 00169 LCD_RESET = 0u; 00170 wait_ms(100); 00171 00172 LCD_RESET = 1u; 00173 wait_ms(100); 00174 00175 DisplayIntf_Write8_A0(0x28); 00176 DisplayIntf_Write8_A0(0x11); /* Exit Sleep mode */ 00177 wait_ms(100); 00178 DisplayIntf_Write8_A0(0x36); 00179 DisplayIntf_Write8_A1(0xA0); /* MADCTL: memory data access control */ 00180 DisplayIntf_Write8_A0(0x3A); 00181 DisplayIntf_Write8_A1(0x65); /* COLMOD: Interface Pixel format */ 00182 DisplayIntf_Write8_A0(0xB2); 00183 DisplayIntf_Write8_A1(0x0C); 00184 DisplayIntf_Write8_A1(0x0C); 00185 DisplayIntf_Write8_A1(0x00); 00186 DisplayIntf_Write8_A1(0x33); 00187 DisplayIntf_Write8_A1(0x33); /* PORCTRK: Porch setting */ 00188 DisplayIntf_Write8_A0(0xB7); 00189 DisplayIntf_Write8_A1(0x35); /* GCTRL: Gate Control */ 00190 DisplayIntf_Write8_A0(0xBB); 00191 DisplayIntf_Write8_A1(0x2B); /* VCOMS: VCOM setting */ 00192 DisplayIntf_Write8_A0(0xC0); 00193 DisplayIntf_Write8_A1(0x2C); /* LCMCTRL: LCM Control */ 00194 DisplayIntf_Write8_A0(0xC2); 00195 DisplayIntf_Write8_A1(0x01); 00196 DisplayIntf_Write8_A1(0xFF); /* VDVVRHEN: VDV and VRH Command Enable */ 00197 DisplayIntf_Write8_A0(0xC3); 00198 DisplayIntf_Write8_A1(0x11); /* VRHS: VRH Set */ 00199 DisplayIntf_Write8_A0(0xC4); 00200 DisplayIntf_Write8_A1(0x20); /* VDVS: VDV Set */ 00201 DisplayIntf_Write8_A0(0xC6); 00202 DisplayIntf_Write8_A1(0x0F); /* FRCTRL2: Frame Rate control in normal mode */ 00203 DisplayIntf_Write8_A0(0xD0); 00204 DisplayIntf_Write8_A1(0xA4); 00205 DisplayIntf_Write8_A1(0xA1); /* PWCTRL1: Power Control 1 */ 00206 DisplayIntf_Write8_A0(0xE0); 00207 DisplayIntf_Write8_A1(0xD0); 00208 DisplayIntf_Write8_A1(0x00); 00209 DisplayIntf_Write8_A1(0x05); 00210 DisplayIntf_Write8_A1(0x0E); 00211 DisplayIntf_Write8_A1(0x15); 00212 DisplayIntf_Write8_A1(0x0D); 00213 DisplayIntf_Write8_A1(0x37); 00214 DisplayIntf_Write8_A1(0x43); 00215 DisplayIntf_Write8_A1(0x47); 00216 DisplayIntf_Write8_A1(0x09); 00217 DisplayIntf_Write8_A1(0x15); 00218 DisplayIntf_Write8_A1(0x12); 00219 DisplayIntf_Write8_A1(0x16); 00220 DisplayIntf_Write8_A1(0x19); /* PVGAMCTRL: Positive Voltage Gamma control */ 00221 DisplayIntf_Write8_A0(0xE1); 00222 DisplayIntf_Write8_A1(0xD0); 00223 DisplayIntf_Write8_A1(0x00); 00224 DisplayIntf_Write8_A1(0x05); 00225 DisplayIntf_Write8_A1(0x0D); 00226 DisplayIntf_Write8_A1(0x0C); 00227 DisplayIntf_Write8_A1(0x06); 00228 DisplayIntf_Write8_A1(0x2D); 00229 DisplayIntf_Write8_A1(0x44); 00230 DisplayIntf_Write8_A1(0x40); 00231 DisplayIntf_Write8_A1(0x0E); 00232 DisplayIntf_Write8_A1(0x1C); 00233 DisplayIntf_Write8_A1(0x18); 00234 DisplayIntf_Write8_A1(0x16); 00235 DisplayIntf_Write8_A1(0x19); /* NVGAMCTRL: Negative Voltage Gamma control */ 00236 DisplayIntf_Write8_A0(0x2B); 00237 DisplayIntf_Write8_A1(0x00); 00238 DisplayIntf_Write8_A1(0x00); 00239 DisplayIntf_Write8_A1(0x00); 00240 DisplayIntf_Write8_A1(0xEF); /* Y address set */ 00241 DisplayIntf_Write8_A0(0x2A); 00242 DisplayIntf_Write8_A1(0x00); 00243 DisplayIntf_Write8_A1(0x00); 00244 DisplayIntf_Write8_A1(0x01); 00245 DisplayIntf_Write8_A1(0x3F); /* X address set */ 00246 wait_ms(10); 00247 DisplayIntf_Write8_A0(0x29); 00248 00249 00250 } 00251 00252 00253 /******************************************************************************* 00254 * Function Name: DisplayIntf_Write8_A0 00255 ****************************************************************************//** 00256 * 00257 * \brief 00258 * Writes one byte of data to the software i8080 interface with the LCD_DC pin 00259 * set to 0 00260 * 00261 * \details 00262 * This function: 00263 * - Sets LCD_DC pin to 0 00264 * - Writes one data byte 00265 * 00266 *******************************************************************************/ 00267 void DisplayIntf_Write8_A0(U8 data) 00268 { 00269 LCD_DC = 0u; 00270 DataWrite(data); 00271 } 00272 00273 00274 /******************************************************************************* 00275 * Function Name: DisplayIntf_Write8_A1 00276 ****************************************************************************//** 00277 * 00278 * \brief 00279 * Writes one byte of data to the software i8080 interface with the LCD_DC pin 00280 * set to 1 00281 * 00282 * \details 00283 * This function: 00284 * - Sets LCD_DC pin to 1 00285 * - Writes one data byte 00286 * 00287 *******************************************************************************/ 00288 void DisplayIntf_Write8_A1(U8 data) 00289 { 00290 LCD_DC = 1u; 00291 DataWrite(data); 00292 } 00293 00294 00295 /******************************************************************************* 00296 * Function Name: DisplayIntf_WriteM8_A1 00297 ****************************************************************************//** 00298 * 00299 * \brief 00300 * Writes multiple bytes of data to the software i8080 interface with the LCD_DC 00301 * pin set to 1 00302 * 00303 * \details 00304 * This function: 00305 * - Sets LCD_DC pin to 1 00306 * - Writes data bytes 00307 * 00308 *******************************************************************************/ 00309 void DisplayIntf_WriteM8_A1(U8 data[], int num) 00310 { 00311 int i = 0; 00312 00313 LCD_DC = 1u; 00314 00315 for(i = 0; i < num; i++) 00316 { 00317 DataWrite(data[i]); 00318 } 00319 } 00320 00321 00322 /******************************************************************************* 00323 * Function Name: DisplayIntf_Read8_A1 00324 ****************************************************************************//** 00325 * 00326 * \brief 00327 * Reads one byte of data from the software i8080 interface with the LCD_DC pin 00328 * set to 1 00329 * 00330 * \details 00331 * This function: 00332 * - Sets LCD_DC pin to 1 00333 * - Reads one data byte 00334 * 00335 *******************************************************************************/ 00336 U8 DisplayIntf_Read8_A1(void) 00337 { 00338 LCD_DC = 1u; 00339 return DataRead(); 00340 } 00341 00342 00343 /******************************************************************************* 00344 * Function Name: DisplayIntf_ReadM8_A1 00345 ****************************************************************************//** 00346 * 00347 * \brief 00348 * Reads multiple bytes of data from the software i8080 interface with the LCD_DC 00349 * pin set to 1 00350 * 00351 * \details 00352 * This function: 00353 * - Sets LCD_DC pin to 1 00354 * - Reads data bytes 00355 * 00356 *******************************************************************************/ 00357 void DisplayIntf_ReadM8_A1(U8 data[], int num) 00358 { 00359 int i = 0; 00360 00361 LCD_DC = 1u; 00362 00363 for(i = 0; i < num; i++) 00364 { 00365 data[i] = DataRead(); 00366 } 00367 } 00368 00369 00370 /* [] END OF FILE */ 00371 00372
Generated on Tue Jul 19 2022 08:23:47 by
