1、查阅ST7789V手册
(1)显示属性
(2)像素格式
LCD 驱动部分:
const unsigned char ord[]={0x36,0x3A,0xB2,0xB7,0xBB,0xC0,0xC2,0xC3,0xC4,0xC6,0xD0,0xE0,0xE1,0x2A,0x2B,0x29,0x2C};
const unsigned char dat[]={0x20,
0x65,
0x0C,0x0C,0x00,0x33,0x33,
0x72,
0x3D,
0x2C,
0x01,
0x12,
0x20,
0x0F,
0xA4,0xA1, 0xD0,0x04,0x0D,0x11,0x13,0x2B,0x3F,0x54,0x4C,0x18,0x0D,0x0B,0x1F,0x23, 0xD0,0x04,0x0C,0x11,0x13,0x2C,0x3F,0x44,0x51,0x2F,0x1F,0x1F,0x20,0x23,
0x00,0x00,0x00,0x86,
0x00,0x00,0x00,0xEF
};//数据
const unsigned char ofs[]={0,1,2,7,8,9,10,11,12,13,14,16,30,44,48,0,0};//数据偏移位置
const unsigned char num[]={1,1,5,1,1,1,1,1,1,1,2,14,14,4,4,0,0};//连续发送个数
inline static void ST7789_Config(unsigned char order,unsigned char* pData,unsigned char Size)
{
unsigned short i=0;
//
SPI4->CR2 =1;
SPI4->CR1 = SPI_CR1_SPE;
SPI4->TXDR=order;
SPI4->CR1|=SPI_CR1_CSTART;
//发送命令
IO_Write(DCX,cmd);
while(!(SPI4->SR & SPI_SR_TXC));
SPI4->IFCR |= SPI_IFCR_EOTC+SPI_IFCR_TXTFC;
SPI4->CR1 &=~ SPI_CR1_SPE;
if(Size>4)
{
xplay->NDTR=Size;
xplay->M0AR=(unsigned int)pData;
SPI4->CR2 = Size;
SPI4->CR1 = SPI_CR1_SPE;
SPI4->CR1|=SPI_CR1_CSTART;
IO_Write(DCX,data);//发送数据
xplay->CR |= EN;
//此处经验证其他非阻塞方案会影响后续初始化,此处使用堵塞等待发送完毕,此处使能了dma的FIFO,不能判断DMA是否完成了发送
while(SPI4->CR1 & SPI_CR1_CSTART);
DMA1->LIFCR|=(DMA1->LISR & 0x3F0000);
}
else if(Size>0)
{
SPI4->CR2 = Size;
SPI4->CR1 = SPI_CR1_SPE;
SPI4->CR1|= SPI_CR1_CSTART;
SPI4->TXDR=*(unsigned int*)pData;
IO_Write(DCX,data);//发送数据
while(!(SPI4->SR & SPI_SR_TXC));
//while(SPI4->CR1 & SPI_CR1_CSTART);
}
SPI4->CR1 &=~ SPI_CR1_SPE;
SPI4->IFCR |= SPI_IFCR_EOTC+SPI_IFCR_TXTFC;
//IO_Write(DCX,cmd);
}
void ST7789_Init(void)
{
unsigned int sCR = 0;//config spi4 dma cr
xplay->FCR = DMA_SxFCR_DMDIS|LL_DMA_FIFOTHRESHOLD_1_4;
xplay->PAR= (unsigned int)&(SPI4->TXDR);
((SxCR*)&sCR)->PL=LoW;
((SxCR*)&sCR)->MINC=EN;
((SxCR*)&sCR)->PINC=DIS;
((SxCR*)&sCR)->CIRC=DIS;
((SxCR*)&sCR)->DIR=M2P;
((SxCR*)&sCR)->MBST=FOUR;
((SxCR*)&sCR)->PBST=SINGLE;
xplay->CR = sCR;
//发送softreset
ST7789_Config(0x01,NULL,0);//软件复位
//需要延时130ms,由系统自动调用后续任务ST7789_SlpOut
}
__USED void ST7789_MoreInit(void)
{
//在主循环中完成后续初始化
unsigned char i=0,*loc=(unsigned char*)dat;
for(i=0;i<sizeof(ord);i++)
{
ST7789_Config(ord[i],loc+ofs[i],num[i]);
}
xplay->NDTR=1000;
xplay->M0AR=(unsigned int)gram;
SPI4->CR2 = 1000;
SPI4->CR1 = SPI_CR1_SPE;
SPI4->CR1|= SPI_CR1_CSTART;
SCB_CleanInvalidateDCache_by_Addr((unsigned int*)gram,sizeof(gram));
IO_Write(DCX,data);//发送数据
xplay->CR |= EN;
}