目前I2C触摸部分还未开发,显示已经正常。程序的显示画面见封面。
尽管使用TC275控制7寸RS8755有点浪费,主要抱着学习原则写了这些代码。
如有兴趣可以给我留言,源码发给你
以下是SPI的初始化部分
/**********************************************************************************************************************
* \file SPI_CPU.c
* \copyright Copyright (C) Infineon Technologies AG 2019
*
* Use of this file is subject to the terms of use agreed between (i) you or the company in which ordinary course of
* business you are acting and (ii) Infineon Technologies AG or its licensees. If and as long as no such terms of use
* are agreed, use of this file is subject to following:
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and
* accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute,
* and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the
* Software is furnished to do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including the above license grant, this restriction
* and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all
* derivative works of the Software, unless such copies or derivative works are solely in the form of
* machine-executable object code generated by a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*********************************************************************************************************************/
/*********************************************************************************************************************/
/*-----------------------------------------------------Includes------------------------------------------------------*/
/*********************************************************************************************************************/
#include "SPI_CPU.h"
#include "IfxPort.h"
#include "Bsp.h"
#include "LCD_Init.h"
/*********************************************************************************************************************/
/*------------------------------------------------------Macros-------------------------------------------------------*/
/*********************************************************************************************************************/
/* Interrupt Service Routine priorities for Master and Slave SPI communication */
#define ISR_PRIORITY_MASTER_TX 50
#define ISR_PRIORITY_MASTER_RX 51
#define ISR_PRIORITY_MASTER_ER 52
/*********************************************************************************************************************/
/*-------------------------------------------------Global variables--------------------------------------------------*/
/*********************************************************************************************************************/
qspiComm g_qspi;
/*********************************************************************************************************************/
/*------------------------------------------------Function Prototypes------------------------------------------------*/
/*********************************************************************************************************************/
void initQSPI1Master(void);
void initQSPI1MasterChannel(void);
void initQSPI1MasterBuffers(void);
void initQSPI(void);
void initLED(void);
/*********************************************************************************************************************/
/*----------------------------------------------Function Implementations---------------------------------------------*/
/*********************************************************************************************************************/
IFX_INTERRUPT(masterTxISR, 0, ISR_PRIORITY_MASTER_TX); /* SPI Master ISR for transmit data */
IFX_INTERRUPT(masterRxISR, 0, ISR_PRIORITY_MASTER_RX); /* SPI Master ISR for receive data */
IFX_INTERRUPT(masterErISR, 0, ISR_PRIORITY_MASTER_ER); /* SPI Master ISR for error */
void masterTxISR()
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrTransmit(&g_qspi.spiMaster);
}
void masterRxISR()
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrReceive(&g_qspi.spiMaster);
}
void masterErISR()
{
IfxCpu_enableInterrupts();
IfxQspi_SpiMaster_isrError(&g_qspi.spiMaster);
}
/* QSPI Master initialization
* This function initializes the QSPI1 module in Master mode.
*/
void initQSPI1Master(void)
{
IfxQspi_SpiMaster_Config spiMasterConfig; /* Define a Master configuration */
IfxQspi_SpiMaster_initModuleConfig(&spiMasterConfig,&MODULE_QSPI1); /* Initialize it with default values */
spiMasterConfig.base.mode = SpiIf_Mode_master; /* Configure the mode */
/* Set the ISR priorities and the service provider */
spiMasterConfig.base.txPriority = ISR_PRIORITY_MASTER_TX;
spiMasterConfig.base.rxPriority = ISR_PRIORITY_MASTER_RX;
spiMasterConfig.base.erPriority = ISR_PRIORITY_MASTER_ER;
spiMasterConfig.base.isrProvider = IfxSrc_Tos_cpu0;
/* Set the Maximum Baudrate */
spiMasterConfig.base.maximumBaudrate = 50000000;
/* Select the port pins for communication */
const IfxQspi_SpiMaster_Pins qspi1MasterPins = {
&IfxQspi1_SCLK_P10_2_OUT, IfxPort_OutputMode_pushPull, /* SCLK Pin (CLK) */
&IfxQspi1_MTSR_P10_3_OUT, IfxPort_OutputMode_pushPull, /* MasterTransmitSlaveReceive pin (MOSI) */
&IfxQspi1_MRSTA_P10_1_IN, IfxPort_InputMode_pullDown, /* MasterReceiveSlaveTransmit pin (MISO) */
IfxPort_PadDriver_cmosAutomotiveSpeed3 /* Pad driver mode */
};
spiMasterConfig.pins = &qspi1MasterPins; /* Assign the Master's port pins */
/*DMA is not used */
spiMasterConfig.dma.useDma=FALSE;
spiMasterConfig.dma.rxDmaChannelId=IfxDma_ChannelId_none;
spiMasterConfig.dma.txDmaChannelId=IfxDma_ChannelId_none;
/*Set others */
spiMasterConfig.pauseOnBaudrateSpikeErrors=TRUE;
spiMasterConfig.allowSleepMode=FALSE;
spiMasterConfig.pauseRunTransition=IfxQspi_PauseRunTransition_run;
spiMasterConfig.txFifoThreshold=IfxQspi_TxFifoInt_1;
spiMasterConfig.rxFifoThreshold=IfxQspi_RxFifoInt_0;
spiMasterConfig.rxFifoMode=IfxQspi_FifoMode_singleMove;
spiMasterConfig.txFifoMode=IfxQspi_FifoMode_singleMove;
/* Initialize the QSPI Master module */
IfxQspi_SpiMaster_initModule(&g_qspi.spiMaster, &spiMasterConfig);
}
/* QSPI Master channel initialization
* This function initializes the QSPI1 Master channel.
*/
void initQSPI1MasterChannel(void)
{
IfxQspi_SpiMaster_ChannelConfig spiMasterChannelConfig; /* Define a Master Channel configuration */
/* Initialize the configuration with default values */
IfxQspi_SpiMaster_initChannelConfig(&spiMasterChannelConfig, &g_qspi.spiMaster);
spiMasterChannelConfig.base.baudrate = 4000000; /* Set SCLK frequency to 1 MHz */
spiMasterChannelConfig.base.mode.autoCS=1;
spiMasterChannelConfig.base.mode.clockPolarity=SpiIf_ClockPolarity_idleHigh;
spiMasterChannelConfig.base.mode.csActiveLevel=Ifx_ActiveState_low;
spiMasterChannelConfig.base.mode.csInactiveDelay=SpiIf_SlsoTiming_3;
spiMasterChannelConfig.base.mode.csLeadDelay=SpiIf_SlsoTiming_2;
spiMasterChannelConfig.base.mode.csTrailDelay=SpiIf_SlsoTiming_3;
spiMasterChannelConfig.base.mode.dataHeading=SpiIf_DataHeading_msbFirst;
spiMasterChannelConfig.base.mode.dataWidth=8;
spiMasterChannelConfig.base.mode.enabled=1;
spiMasterChannelConfig.base.mode.loopback=0;
spiMasterChannelConfig.base.mode.parityCheck=0;
spiMasterChannelConfig.base.mode.parityMode=Ifx_ParityMode_even;
spiMasterChannelConfig.base.mode.shiftClock=SpiIf_ShiftClock_shiftTransmitDataOnLeadingEdge;
spiMasterChannelConfig.base.errorChecks.baudrate=FALSE;
spiMasterChannelConfig.base.errorChecks.phase=FALSE;
spiMasterChannelConfig.base.errorChecks.receive=FALSE;
spiMasterChannelConfig.base.errorChecks.transmit=FALSE;
spiMasterChannelConfig.base.errorChecks.reserved=28;
spiMasterChannelConfig.channelBasedCs=IfxQspi_SpiMaster_ChannelBasedCs_disabled;
spiMasterChannelConfig.dummyRxValue=0;
spiMasterChannelConfig.dummyTxValue=0;
spiMasterChannelConfig.mode=IfxQspi_SpiMaster_Mode_short;
/* Select the port pin for the Chip Select signal */
const IfxQspi_SpiMaster_Output qspi1SlaveSelect = { /* QSPI1 Master selects the QSPI3 Slave */
&IfxQspi1_SLSO10_P10_0_OUT, IfxPort_OutputMode_pushPull, /* Slave Select port pin (CS) */
IfxPort_PadDriver_cmosAutomotiveSpeed1 /* Pad driver mode */
};
spiMasterChannelConfig.sls.output = qspi1SlaveSelect;
/* Initialize the QSPI Master channel */
IfxQspi_SpiMaster_initChannel(&g_qspi.spiMasterChannel, &spiMasterChannelConfig);
}
/* QSPI Master SW buffer initialization
* This function initializes SW buffers the Master uses.
*/
void initQSPI1MasterBuffers(void)
{
g_qspi.spiBuffers.spiMasterTxBuffer[0] = 0x00; /* Fill TX Master Buffer with pattern */
g_qspi.spiBuffers.spiMasterTxBuffer[1] = 0x00; /* Fill TX Master Buffer with pattern */
g_qspi.spiBuffers.spiMasterRxBuffer = 0x00; /* Clear RX Buffer */
}
/* This function to initialize the LED */
void initLED(void)
{
/* Set the port pin 00.5 (to which the LED1 is connected) to output push-pull mode */
IfxPort_setPinModeOutput(LED1, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
/* Turn off LED (LED is low-level active) */
IfxPort_setPinHigh(LED1);
}
/* This function initialize the QSPI modules */
void initQSPI(void)
{
/* initialize the Master */
initQSPI1Master();
initQSPI1MasterChannel();
initQSPI1MasterBuffers();
}
/* This function to initialize the QSPI modules and the LED */
void initPeripherals(void)
{
initLED();
initQSPI();
LCD_Init();
}
/* This function starts the data transfer */
void transferData(uint16 data)
{
g_qspi.spiBuffers.spiMasterTxBuffer[0]=data&0xFF;
g_qspi.spiBuffers.spiMasterTxBuffer[1]=(data>>8)&0xFF;
while(IfxQspi_SpiMaster_getStatus(&g_qspi.spiMasterChannel) == SpiIf_Status_busy)
{ /* Wait until the previous communication has finished, if any */
}
/* Send a data stream through the SPI Master */
IfxQspi_SpiMaster_exchange(&g_qspi.spiMasterChannel, &g_qspi.spiBuffers.spiMasterTxBuffer[0], NULL_PTR, 2);
}
/* This function starts the data receive */
uint8 receiveData(uint16 senddata)
{
uint8 receivedata;
g_qspi.spiBuffers.spiMasterTxBuffer[0]=senddata&0xFF;
g_qspi.spiBuffers.spiMasterTxBuffer[1]=(senddata>>8)&0xFF;
while(IfxQspi_SpiMaster_getStatus(&g_qspi.spiMasterChannel) == SpiIf_Status_busy)
{ /* Wait until the previous communication has finished, if any */
}
/* receive a data stream through the SPI Master */
IfxQspi_SpiMaster_exchange(&g_qspi.spiMasterChannel, &g_qspi.spiBuffers.spiMasterTxBuffer, &g_qspi.spiBuffers.spiMasterRxBuffer, 1);
receivedata=g_qspi.spiBuffers.spiMasterRxBuffer;
return receivedata;
}
/* This function toggles the port pin and wait 500 milliseconds */
void blinkLED(void)
{
IfxPort_togglePin(LED1); /* Toggle the state of the LED */
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 500)); /* Wait 500 milliseconds */
}
以下是RA8875驱动部分
#ifndef LCD_Init_H_
#define LCD_Init_H_
#include "Platform_Types.h"
/* LCD RST port pin */
#define LCD_RST &MODULE_P10,6 /* LCD RST Port, Pin definition */
/* define color value */
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40
#define BRRED 0XFC07
#define GRAY 0X8430
#define DARKBLUE 0x01CF
#define LIGHTBLUE 0x7D7C
#define GRAYBLUE 0x5458
#define LIGHTGREEN 0x841F
#define LIGHTGRAY 0xEF5B
#define LGRAY 0xC618
#define LGRAYBLUE 0xA651
#define LBBLUE 0x2B12
void LCD_Init(void);
void LCD_GPIO_Init(void);
void LCD_RA8875_RESET(void);
void LCD_CmdWrite(uint8 cmd);
void LCD_DataWrite(uint8 Data);
void LCD_CmdDataWrite(uint8 Cmd, uint8 data);
void LCD_Active_Window(uint16 xStart,uint16 xEnd ,uint16 yStart ,uint16 yEnd);
void LCD_Clear_Color(uint16 b_color);
void LCD_Clear_Window_Color(uint16 b_color,uint16 x,uint16 y,uint16 width,uint16 hight);
#endif
#include "LCD_Init.h"
#include "stdlib.h"
#include "SPI_CPU.h"
#include "IfxPort.h"
#include "Bsp.h"
/* This function initializes the LCD driver */
void LCD_Init(void)
{
LCD_GPIO_Init();
LCD_RA8875_RESET();
LCD_CmdDataWrite(0x20,0x00);
LCD_CmdDataWrite(0x10,0x08);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 100)); /* Wait 100 milliseconds */;
LCD_CmdWrite(0x04);
LCD_DataWrite(0x81);
//Horizontal set
LCD_CmdWrite(0x14);
LCD_DataWrite(0x63); //Horizontal display width(pixels) = (HDWR + 1)*8 =(99+1)*8=800
LCD_CmdWrite(0x15); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0]
LCD_DataWrite(0x04); //(HNDR + 1)*8 +HNDFCR=(4+1)*8=40
LCD_CmdWrite(0x16); //HNDR//Horizontal Non-Display Period Bit[4:0]
LCD_DataWrite(0x0B); //Horizontal Non-Display Period (pixels) = (HNDR + 1)*8=(11+1)*8=96
LCD_CmdWrite(0x17); //HSTR//HSYNC Start Position[4:0]
LCD_DataWrite(0x00); //HSYNC Start Position(PCLK) = (HSTR + 1)*8=(0+1)*8=8
LCD_CmdWrite(0x18); //HPWR//HSYNC Polarity ,The period width of HSYNC.
LCD_DataWrite(0x02); //HSYNC Width [4:0] HSYNC Pulse width(PCLK) = (HPWR + 1)*8=(2+1)*8=24
//Vertical set
LCD_CmdWrite(0x19); //VDHR0 //Vertical Display Height Bit [7:0]
LCD_DataWrite(0xDF); //Vertical pixels = VDHR + 1
LCD_CmdWrite(0x1A); //VDHR1 //Vertical Display Height Bit [8]
LCD_DataWrite(0x01); //Vertical pixels = VDHR + 1=479+1
LCD_CmdWrite(0x1B); //VNDR0 //Vertical Non-Display Period Bit [7:0]
LCD_DataWrite(0x13); //Vertical Non-Display area = (VNDR + 1)
LCD_CmdWrite(0x1C); //VNDR1 //Vertical Non-Display Period Bit [8]
LCD_DataWrite(0x00); //Vertical Non-Display area = (VNDR + 1)=19+1=20
LCD_CmdWrite(0x1D); //VSTR0 //VSYNC Start Position[7:0]
LCD_DataWrite(0x06); //VSYNC Start Position(PCLK) = (VSTR + 1)
LCD_CmdWrite(0x1E); //VSTR1 //VSYNC Start Position[8]
LCD_DataWrite(0x00); //VSYNC Start Position(PCLK) = (VSTR + 1) =6+1=7
LCD_CmdWrite(0x1F); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0]
LCD_DataWrite(0x02); //VSYNC Pulse Width(PCLK) = (VPWR + 1)=2+1=3
//setting pll
LCD_CmdWrite(0x88);
LCD_DataWrite(0x0C);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 100)); /* Wait 100 milliseconds */
LCD_CmdWrite(0x89);
LCD_DataWrite(0x02);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 100)); /* Wait 100 milliseconds */
LCD_Active_Window(0,799,0,479);
LCD_CmdWrite(0x01);//display on
LCD_DataWrite(0x80);
LCD_CmdWrite(0x8A); //PWM
LCD_DataWrite(0x87);
LCD_CmdWrite(0x8B);
LCD_DataWrite(0xF0);
LCD_Clear_Color(DARKBLUE);
}
/* This function initializes the LCD RST Pin */
void LCD_GPIO_Init(void)
{
/* Set the port pin 10.6 (to which the LCD RST is connected) to output push-pull mode */
IfxPort_setPinModeOutput(LCD_RST, IfxPort_OutputMode_pushPull, IfxPort_OutputIdx_general);
/* set the LCD RST to high (LCD RST is low-level active) */
IfxPort_setPinHigh(LCD_RST);
}
/* This function reset the LCD RST Pin */
void LCD_RA8875_RESET(void)
{
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 2)); /* Wait 2 milliseconds */;
IfxPort_setPinLow(LCD_RST);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 100)); /* Wait 10 milliseconds */;
IfxPort_setPinHigh(LCD_RST);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 100)); /* Wait 10 milliseconds */;
}
/* This function write command to the LCD screen */
void LCD_CmdWrite(uint8 cmd)
{
transferData(0x80|(cmd<<8));
}
/* This function write data to the LCD screen */
void LCD_DataWrite(uint8 Data)
{
transferData(0x00|(Data<<8));
}
/* This function write command and data to the LCD screen */
void LCD_CmdDataWrite(uint8 Cmd, uint8 data)
{
LCD_CmdWrite(Cmd);
LCD_DataWrite(data);
}
/* This function active the Window of the LCD screen */
void LCD_Active_Window(uint16 xStart,uint16 xEnd ,uint16 yStart ,uint16 yEnd)
{
uint16 temp;
temp=xStart;
LCD_CmdWrite(0x30);//HSAW0
LCD_DataWrite(temp&0xFF);
temp=xStart>>8;
LCD_CmdWrite(0x31);//HSAW1
LCD_DataWrite(temp&0xFF);
temp=xEnd;
LCD_CmdWrite(0x34);//HEAW0
LCD_DataWrite(temp&0xFF);
temp=xEnd>>8;
LCD_CmdWrite(0x35);//HEAW1
LCD_DataWrite(temp&0xFF);
//setting active window Y
temp=yStart;
LCD_CmdWrite(0x32);//VSAW0
LCD_DataWrite(temp&0xFF);
temp=yStart>>8;
LCD_CmdWrite(0x33);//VSAW1
LCD_DataWrite(temp&0xFF);
temp=yEnd;
LCD_CmdWrite(0x36);//VEAW0
LCD_DataWrite(temp&0xFF);
temp=yEnd>>8;
LCD_CmdWrite(0x37);//VEAW1
LCD_DataWrite(temp&0xFF);
}
/* This function set the color of the LCD screen */
void LCD_Clear_Color(uint16 b_color)
{
LCD_CmdDataWrite(0x58,0x00);
LCD_CmdDataWrite(0x59,0x00);
LCD_CmdDataWrite(0x5A,0x00);
LCD_CmdDataWrite(0x5B,0x00);
LCD_CmdDataWrite(0x5C,0x20);
LCD_CmdDataWrite(0x5D,0x03);
LCD_CmdDataWrite(0x5E,0xE0);
LCD_CmdDataWrite(0x5F,0x01);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x51,0x0C); //solid fill
LCD_CmdDataWrite(0x63,b_color>>11);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x64,(b_color>>5)&0x3F);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x65,b_color&0x1F);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x50,0x80);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
}
/* This function set the window color of the LCD screen */
void LCD_Clear_Window_Color(uint16 b_color,uint16 x,uint16 y,uint16 width,uint16 hight)
{
LCD_CmdDataWrite(0x58,x&0xFF);
LCD_CmdDataWrite(0x59,(x>>8)&0x03);
LCD_CmdDataWrite(0x5A,y&0xFF);
LCD_CmdDataWrite(0x5B,(y>>8)&0x01);
LCD_CmdDataWrite(0x5C,width&0xFF);
LCD_CmdDataWrite(0x5D,(width>>8)&0x03);
LCD_CmdDataWrite(0x5E,hight&0xFF);
LCD_CmdDataWrite(0x5F,(hight>>8)&0x03);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10));
LCD_CmdDataWrite(0x51,0x0C); //solid fill
LCD_CmdDataWrite(0x63,b_color>>11);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x64,(b_color>>5)&0x3F);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x65,b_color&0x1F);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
LCD_CmdDataWrite(0x50,0x80);
waitTime(IfxStm_getTicksFromMilliseconds(BSP_DEFAULT_TIMER, 10)); /* Wait 10 milliseconds */;
}