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