STM32H750VBT6 DMA驱动TFT-LCD(ST7789V)
1、查閱ST7789V手冊(cè)
(1)顯示屬性
(2)像素格式
?
LCD 驅(qū)動(dòng)部分:
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
?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?
};//數(shù)據(jù)
const unsigned char ofs[]={0,1,2,7,8,9,10,11,12,13,14,16,30,44,48,0,0};//數(shù)據(jù)偏移位置
const unsigned char num[]={1,1,5,1,1,1,1,1,1,1,2,14,14,4,4,0,0};//連續(xù)發(fā)送個(gè)數(shù)
?? ?
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;
?? ?
?? ?//發(fā)送命令?
?? ?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);//發(fā)送數(shù)據(jù)
?? ??? ?xplay->CR |= EN;
?? ??? ?
?? ??? ?//此處經(jīng)驗(yàn)證其他非阻塞方案會(huì)影響后續(xù)初始化,此處使用堵塞等待發(fā)送完畢,此處使能了dma的FIFO,不能判斷DMA是否完成了發(fā)送
?? ??? ?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);//發(fā)送數(shù)據(jù)
?? ??? ?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;?? ??
?? ?//發(fā)送softreset
?? ?ST7789_Config(0x01,NULL,0);//軟件復(fù)位
?? ?//需要延時(shí)130ms,由系統(tǒng)自動(dòng)調(diào)用后續(xù)任務(wù)ST7789_SlpOut
}
__USED void ST7789_MoreInit(void)
{
?? ?//在主循環(huán)中完成后續(xù)初始化
?? ?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);//發(fā)送數(shù)據(jù)
?? ?xplay->CR |= EN;
}
?
總結(jié)
以上是生活随笔為你收集整理的STM32H750VBT6 DMA驱动TFT-LCD(ST7789V)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Soloπ 工具使用见解
- 下一篇: postgresql 事务隔离级别 se