![](/media/cache/profiles/20200518_163046.jpg.50x50_q85.jpg)
Capsense buttons and Slider, output to Serial over i2c and tft display
Diff: tft_interface/cy8ckit_028_tft.cpp
- Revision:
- 0:4ad2c16b6e43
- Child:
- 1:cf461b359823
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tft_interface/cy8ckit_028_tft.cpp Fri Aug 09 23:18:24 2019 +0000 @@ -0,0 +1,358 @@ +/***************************************************************************//** +* \file DisplayInterface.h +* \version 1.0 +* +* \brief +* Objective: +* This is display software i8080 interface source file +* +******************************************************************************** +* \copyright +* Copyright 2018-2019 Cypress Semiconductor Corporation +* SPDX-License-Identifier: Apache-2.0 +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*******************************************************************************/ + + +#include "cy8ckit_028_tft.h" +#include <mbed_wait_api.h> + + +/******************************************************************************* +* Function Name: DataWrite +****************************************************************************//** +* +* \brief +* Writes one byte of data to the software i8080 interface. +* +* \details +* This function: +* - Writes data to the data bus +* - Sends low pulse to the LCD_NWR line to write data +* +* \todo +* All this should be replaced with a udb register to save all the shifting +* and individual bit writing. +* +*******************************************************************************/ +void DataWrite(U8 data) +{ + LCD_REG0 = (data & 0x01); + LCD_REG1 = ((data>>1) & 0x01); + LCD_REG2 = ((data>>2) & 0x01); + LCD_REG3 = ((data>>3) & 0x01); + LCD_REG4 = ((data>>4) & 0x01); + LCD_REG5 = ((data>>5) & 0x01); + LCD_REG6 = ((data>>6) & 0x01); + LCD_REG7 = ((data>>7) & 0x01); + + LCD_NWR = 0u; + LCD_NWR = 1u; + +} + + +/******************************************************************************* +* Function Name: DataRead +****************************************************************************//** +* +* \brief +* Reads one byte of data from the software i8080 interface. +* +* \details +* This function: +* - Changes data bus GPIO pins drive mode to digital Hi-Z with enabled input +* buffer +* - Sends low pulse to LCD_NRD line to read data +* - Reads data from the data bus +* - Sends low pulse to the LCD_NWR line to write data +* - Changes data bus GPIO pins drive mode back to to Strong Drive mode +* +* \todo +* All this should be replaced with a udb register to save all the shifting +* and individual bit reading. +* +*******************************************************************************/ +U8 DataRead(void) +{ + U8 data = 0u; + + /* enable input */ + LCD_REG0.input(); + LCD_REG1.input(); + LCD_REG2.input(); + LCD_REG3.input(); + LCD_REG4.input(); + LCD_REG5.input(); + LCD_REG6.input(); + LCD_REG7.input(); + + LCD_NRD = 0u; // Pulse read line low then read the data port + + data = (U8)LCD_REG0.read(); + data |= (U8)LCD_REG1.read()<<1; + data |= (U8)LCD_REG2.read()<<2; + data |= (U8)LCD_REG3.read()<<3; + data |= (U8)LCD_REG4.read()<<4; + data |= (U8)LCD_REG5.read()<<5; + data |= (U8)LCD_REG6.read()<<6; + data |= (U8)LCD_REG7.read()<<7; + + LCD_NRD = 1u; // Raise the read line and then go back to output port + + LCD_REG0.output(); + LCD_REG1.output(); + LCD_REG2.output(); + LCD_REG3.output(); + LCD_REG4.output(); + LCD_REG5.output(); + LCD_REG6.output(); + LCD_REG7.output(); + + return data; +} + + +/******************************************************************************* +* Function Name: DisplayIntf_Init +****************************************************************************//** +* +* \brief +* Initializes software i8080 interface. +* +* \details +* This function: +* - Initializes interface GPIO pins +* +*******************************************************************************/ +void DisplayIntf_Init(void) +{ + /* All pins are initialized by the Device Configurator. */ + LCD_RESET = 1u; + LCD_NRD = 1u; + LCD_NWR = 1u; + LCD_DC = 0u; + LCD_REG0.output(); + LCD_REG1.output(); + LCD_REG2.output(); + LCD_REG3.output(); + LCD_REG4.output(); + LCD_REG5.output(); + LCD_REG6.output(); + LCD_REG7.output(); + wait_ms(20); + LCD_RESET = 0u; + wait_ms(100); + + LCD_RESET = 1u; + wait_ms(100); + + DisplayIntf_Write8_A0(0x28); + DisplayIntf_Write8_A0(0x11); /* Exit Sleep mode */ + wait_ms(100); + DisplayIntf_Write8_A0(0x36); + DisplayIntf_Write8_A1(0xA0); /* MADCTL: memory data access control */ + DisplayIntf_Write8_A0(0x3A); + DisplayIntf_Write8_A1(0x65); /* COLMOD: Interface Pixel format */ + DisplayIntf_Write8_A0(0xB2); + DisplayIntf_Write8_A1(0x0C); + DisplayIntf_Write8_A1(0x0C); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x33); + DisplayIntf_Write8_A1(0x33); /* PORCTRK: Porch setting */ + DisplayIntf_Write8_A0(0xB7); + DisplayIntf_Write8_A1(0x35); /* GCTRL: Gate Control */ + DisplayIntf_Write8_A0(0xBB); + DisplayIntf_Write8_A1(0x2B); /* VCOMS: VCOM setting */ + DisplayIntf_Write8_A0(0xC0); + DisplayIntf_Write8_A1(0x2C); /* LCMCTRL: LCM Control */ + DisplayIntf_Write8_A0(0xC2); + DisplayIntf_Write8_A1(0x01); + DisplayIntf_Write8_A1(0xFF); /* VDVVRHEN: VDV and VRH Command Enable */ + DisplayIntf_Write8_A0(0xC3); + DisplayIntf_Write8_A1(0x11); /* VRHS: VRH Set */ + DisplayIntf_Write8_A0(0xC4); + DisplayIntf_Write8_A1(0x20); /* VDVS: VDV Set */ + DisplayIntf_Write8_A0(0xC6); + DisplayIntf_Write8_A1(0x0F); /* FRCTRL2: Frame Rate control in normal mode */ + DisplayIntf_Write8_A0(0xD0); + DisplayIntf_Write8_A1(0xA4); + DisplayIntf_Write8_A1(0xA1); /* PWCTRL1: Power Control 1 */ + DisplayIntf_Write8_A0(0xE0); + DisplayIntf_Write8_A1(0xD0); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x05); + DisplayIntf_Write8_A1(0x0E); + DisplayIntf_Write8_A1(0x15); + DisplayIntf_Write8_A1(0x0D); + DisplayIntf_Write8_A1(0x37); + DisplayIntf_Write8_A1(0x43); + DisplayIntf_Write8_A1(0x47); + DisplayIntf_Write8_A1(0x09); + DisplayIntf_Write8_A1(0x15); + DisplayIntf_Write8_A1(0x12); + DisplayIntf_Write8_A1(0x16); + DisplayIntf_Write8_A1(0x19); /* PVGAMCTRL: Positive Voltage Gamma control */ + DisplayIntf_Write8_A0(0xE1); + DisplayIntf_Write8_A1(0xD0); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x05); + DisplayIntf_Write8_A1(0x0D); + DisplayIntf_Write8_A1(0x0C); + DisplayIntf_Write8_A1(0x06); + DisplayIntf_Write8_A1(0x2D); + DisplayIntf_Write8_A1(0x44); + DisplayIntf_Write8_A1(0x40); + DisplayIntf_Write8_A1(0x0E); + DisplayIntf_Write8_A1(0x1C); + DisplayIntf_Write8_A1(0x18); + DisplayIntf_Write8_A1(0x16); + DisplayIntf_Write8_A1(0x19); /* NVGAMCTRL: Negative Voltage Gamma control */ + DisplayIntf_Write8_A0(0x2B); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0xEF); /* Y address set */ + DisplayIntf_Write8_A0(0x2A); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x00); + DisplayIntf_Write8_A1(0x01); + DisplayIntf_Write8_A1(0x3F); /* X address set */ + wait_ms(10); + DisplayIntf_Write8_A0(0x29); + + +} + + +/******************************************************************************* +* Function Name: DisplayIntf_Write8_A0 +****************************************************************************//** +* +* \brief +* Writes one byte of data to the software i8080 interface with the LCD_DC pin +* set to 0 +* +* \details +* This function: +* - Sets LCD_DC pin to 0 +* - Writes one data byte +* +*******************************************************************************/ +void DisplayIntf_Write8_A0(U8 data) +{ + LCD_DC = 0u; + DataWrite(data); +} + + +/******************************************************************************* +* Function Name: DisplayIntf_Write8_A1 +****************************************************************************//** +* +* \brief +* Writes one byte of data to the software i8080 interface with the LCD_DC pin +* set to 1 +* +* \details +* This function: +* - Sets LCD_DC pin to 1 +* - Writes one data byte +* +*******************************************************************************/ +void DisplayIntf_Write8_A1(U8 data) +{ + LCD_DC = 1u; + DataWrite(data); +} + + +/******************************************************************************* +* Function Name: DisplayIntf_WriteM8_A1 +****************************************************************************//** +* +* \brief +* Writes multiple bytes of data to the software i8080 interface with the LCD_DC +* pin set to 1 +* +* \details +* This function: +* - Sets LCD_DC pin to 1 +* - Writes data bytes +* +*******************************************************************************/ +void DisplayIntf_WriteM8_A1(U8 data[], int num) +{ + int i = 0; + + LCD_DC = 1u; + + for(i = 0; i < num; i++) + { + DataWrite(data[i]); + } +} + + +/******************************************************************************* +* Function Name: DisplayIntf_Read8_A1 +****************************************************************************//** +* +* \brief +* Reads one byte of data from the software i8080 interface with the LCD_DC pin +* set to 1 +* +* \details +* This function: +* - Sets LCD_DC pin to 1 +* - Reads one data byte +* +*******************************************************************************/ +U8 DisplayIntf_Read8_A1(void) +{ + LCD_DC = 1u; + return DataRead(); +} + + +/******************************************************************************* +* Function Name: DisplayIntf_ReadM8_A1 +****************************************************************************//** +* +* \brief +* Reads multiple bytes of data from the software i8080 interface with the LCD_DC +* pin set to 1 +* +* \details +* This function: +* - Sets LCD_DC pin to 1 +* - Reads data bytes +* +*******************************************************************************/ +void DisplayIntf_ReadM8_A1(U8 data[], int num) +{ + int i = 0; + + LCD_DC = 1u; + + for(i = 0; i < num; i++) + { + data[i] = DataRead(); + } +} + + +/* [] END OF FILE */ + +