gpiofd_write(resetIO, 1);
usleep(50000);
gpiofd_write(resetIO, 0);
usleep(100000);
gpiofd_write(resetIO, 1);
usleep(100000);
st7789s芯片是分大小端的,当使用RGB16位方式发送数据时要注意发送数据的大小端问题
send_ctrl_cmd(0x11);
usleep(120000);
send_ctrl_cmd(0x36);
send_data_cmd(0x00);//更改显示方式
send_ctrl_cmd(0x3a);
send_data_cmd(0x06);//更改rgb颜色为多少位
send_ctrl_cmd(0xb0);
send_data_cmd(0xa0);//06
send_ctrl_cmd(0xb2);
send_data_cmd(0x28);
send_data_cmd(0x28);
send_data_cmd(0x05);
send_data_cmd(0x33);
send_data_cmd(0x33);
send_ctrl_cmd(0xb7);
send_data_cmd(0x35);
send_ctrl_cmd(0xbb);
send_data_cmd(0x3c);//23
send_ctrl_cmd(0xb1);
send_data_cmd(0x80);
send_data_cmd(0x10);
send_ctrl_cmd(0xc0);
send_data_cmd(0x2c);
send_ctrl_cmd(0xc2);
send_data_cmd(0x01);
send_ctrl_cmd(0xc3);
send_data_cmd(0x05);//14
send_ctrl_cmd(0xc4);
send_data_cmd(0x20);
send_ctrl_cmd(0xc6);
send_data_cmd(0x14); // 14
send_ctrl_cmd(0xd0);
send_data_cmd(0xa4);
send_data_cmd(0xa1);
send_ctrl_cmd(0xe0);
send_data_cmd(0xd0);
send_data_cmd(0x00);
send_data_cmd(0x02);
send_data_cmd(0x07);
send_data_cmd(0x07);
send_data_cmd(0x19);
send_data_cmd(0x2e);
send_data_cmd(0x54);
send_data_cmd(0x41);
send_data_cmd(0x2d);
send_data_cmd(0x17);
send_data_cmd(0x18);
send_data_cmd(0x14);
send_data_cmd(0x18);
send_ctrl_cmd(0xe1);
send_data_cmd(0xd0);
send_data_cmd(0x00);
send_data_cmd(0x02);
send_data_cmd(0x07);
send_data_cmd(0x04);
send_data_cmd(0x24);
send_data_cmd(0x2c);
send_data_cmd(0x44);
send_data_cmd(0x42);
send_data_cmd(0x1c);
send_data_cmd(0x1a);
send_data_cmd(0x17);
send_data_cmd(0x15);
send_data_cmd(0x18);
send_ctrl_cmd(0x35);
send_data_cmd(0x00);//40
send_ctrl_cmd(0x44);
send_data_cmd(0x19);
send_ctrl_cmd(0x29);
********************************清屏代码,把屏幕全部刷成一个色判断驱动是否有问题**********************
static void sw_clear_panel(unsigned int color)
{
unsigned short x0, y0, x1, y1, x, y;
unsigned short h_X_start,l_X_start,h_X_end,l_X_end,h_Y_start,l_Y_start,h_Y_end,l_Y_end;
x0 = (unsigned short)0;
y0 = (unsigned short)0;
x1 = (unsigned short)FRAME_WIDTH-1;
y1 = (unsigned short)FRAME_HEIGHT-1;
h_X_start=((x0&0xFF00)>>8);
l_X_start=(x0&0x00FF);
h_X_end=((x1&0xFF00)>>8);
l_X_end=(x1&0x00FF);
h_Y_start=((y0&0xFF00)>>8);
l_Y_start=(y0&0x00FF);
h_Y_end=((y1&0xFF00)>>8);
l_Y_end=(y1&0x00FF);
send_ctrl_cmd(0x2A);
send_data_cmd(h_X_start);
send_data_cmd(l_X_start);
send_data_cmd(h_X_end);
send_data_cmd(l_X_end);
send_ctrl_cmd(0x2B);
send_data_cmd(h_Y_start);
send_data_cmd(l_Y_start);
send_data_cmd(h_Y_end);
send_data_cmd(l_Y_end);
send_ctrl_cmd(0x29);
send_ctrl_cmd(0x2C);
for (y = y0; y <= y1; ++ y) {
for (x = x0; x <= x1; ++ x) { //采用了RGB24位的数据,所以发送三次
send_data_cmd(0xff);
send_data_cmd(0);
send_data_cmd(0);
}
}
}
我使用这个2.8寸的屏幕有IO引脚控制发送的是数据还是命令给主控芯片,所以在发送时候要注意在主控芯片控制命令和数据引脚的高低电平
VOID send_ctrl_cmd (UCHAR cmd) {
gpiofd_write(cmdDataIO, 0);
lib_bzero(&spiMsg, sizeof(spiMsg));
spiMsg.SPIMSG_pucRdBuffer =pucDestBuffer;
spiMsg.SPIMSG_pucWrBuffer = &cmd;
spiMsg.SPIMSG_uiLen = 1;
if (API_SpiDeviceTransfer(pSpiDevice, &spiMsg, 1) != 1) {
printf("failed to spi transfer!\n");
API_SpiDeviceDelete(pSpiDevice);
API_VmmDmaFree(pucSrcBuffer);
return;
}
gpiofd_write(cmdDataIO, 1);
}
VOID send_data_cmd (UCHAR data) {
gpiofd_write(cmdDataIO, 1);
lib_bzero(&spiMsg, sizeof(spiMsg));
spiMsg.SPIMSG_pucRdBuffer = pucDestBuffer;
spiMsg.SPIMSG_pucWrBuffer = &data;
spiMsg.SPIMSG_uiLen = 1;
if (API_SpiDeviceTransfer(pSpiDevice, &spiMsg, 1) != 1) {
printf("failed to spi transfer!\n");
API_SpiDeviceDelete(pSpiDevice);
API_VmmDmaFree(pucSrcBuffer);
return;
}
gpiofd_write(cmdDataIO, 0);
}