我正在使用连接到FTDI FT801 LCD的STM32F446E。我在Micro和LCD控制器之间的SPI上进行命令通信。我必须在液晶显示屏上加载几张图像,但我没有在网上找到合适的指南。有很多关于LCD控制器的指南,我读过的那些没有解释关于在微观上调用的正确指令序列的任何内容。
我编写了新的以下函数,以便将原始字节存储到FTDI协处理器的图形RAM中。我已完成以下步骤:
我希望有人已经遇到同样的问题,因为我真的不知道该怎么做才能解决这个问题。有没有人有一些想法?
谢谢你的时间!
安娜
void Load_Image_From_SD3() {
FATFS SDFatFs;
char SDPath[4];
FIL MyFile_R; /* File object */
uint8_t data[4];
uint32_t data32;
uint32_t bytesread; /* File read counts */
uint32_t filesize;
uint16_t blocklen;
uint32_t image_width = 100;
uint32_t image_height = 102;
int32_t count;
int16_t num_bytes;
uint32_t check=0;
uint32_t n=0;
char buffer1[10];
uint8_t CURRENTDIR1[40];
char buffer[5];
uint8_t CURRENTDIR[40];
uint32_t length = 0, SizeTransfered = 0;
uint16_t availablefreesize;
uint8_t value1c, value2c, value3c, value4c;
uint32_t data_readc;
uint8_t check_wrong = 0;
uint32_t index_ram = 0x000000;
FIL MyFile_R2;
/* Link the SD disk I/O driver */
if (BSP_SD_Init() == 0) {
if (FATFS_LinkDriver(&SD_Driver, SDPath) == 0) {
/*## Register the file system object to the FatFs module ##############*/
if (f_mount(&SDFatFs, (TCHAR const*) SDPath, 0) != FR_OK) {
/* FatFs Initialization Error */
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("Cannot mount the SD", 19, 1, 27,
Color_RGB(0, 0, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
} else {
FRESULT res_jpg = f_open(&MyFile_R, "usbg7.raw", FA_OPEN_EXISTING | FA_READ);
filesize =(uint32_t)(MyFile_R.fsize);
uint32_t address = 0x10000000;
//Writing raw image into RAM_G
while(filesize > 0){
blocklen = filesize > 2000 ? 2000 : filesize;
filesize -= blocklen;
Ft_Gpu_Hal_WaitCmdfifo_empty();
Address_RAM_CMD = 0x908000;
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0xFFFFFF00, 7);// DLSTART
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0x26000007, 7); // CLEAR
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0xffffff1a, 7); // CMD_MEMWRITE
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, address, 7); // Destination starting address in Graphics RAM
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, (uint32_t)blocklen, 7);
count = blocklen;
do{
length = count;
availablefreesize = Ft_Gpu_Cmdfifo_Freespace();
if (length > availablefreesize) {
length = availablefreesize;
}
num_bytes = length;
while (num_bytes > 0) {
f_read(&MyFile_R, data, sizeof(data), (UINT*) &bytesread);
data32 = ((uint32_t) data[3] << 24 + ((uint32_t) data[2] << 16) + ((uint32_t) data[1] << 8) + (uint32_t) data[0];
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, data32, 7);
n += 4;
SizeTransfered += 4;
address += 4;
num_bytes -= 4;
}
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 7);
length = SizeTransfered;
count -= length;
SPI_Send(0x9024E8, (uint16_t) (ft_cmd_fifo_wp), 7);
Ft_Gpu_Hal_WaitCmdfifo_empty();
} while (count > 0);
HAL_Delay(800);
}
// Check if the data written are correct
f_close(&MyFile_R);
f_open(&MyFile_R2, "usbg7.raw", FA_OPEN_EXISTING | FA_READ);
filesize = (uint32_t) (MyFile_R2.fsize);
do {
f_read(&MyFile_R2, data, sizeof(data), (UINT*) &bytesread);
data32 = ((uint32_t) data[3] << 24) + ((uint32_t) data[2] << 16) + ((uint32_t) data[1] << 8) + (uint32_t) data[0];
value1c = SPI_Receive_8(index_ram);
value2c = SPI_Receive_8(index_ram + 1);
value3c = SPI_Receive_8(index_ram + 2);
value4c = SPI_Receive_8(index_ram + 3);
index_ram += 4;
filesize -= 4;
data_readc = ((uint32_t) value4c << 24) + ((uint32_t) value3c << 16) + ((uint32_t) value2c << 8) + (uint32_t) value1c;
if (data32 != data_readc)
check_wrong = 1;
} while (check_wrong == 0 && filesize>0);
f_close(&MyFile_R2);
if (check_wrong) {
char bufferw[10];
uint8_t CURRENTDIRw[40];
itoa(index_ram - 4, bufferw, 16);
for (int k = 0; k < strlen(bufferw); k++) {
CURRENTDIRw[k] = bufferw[k];
}
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("wrong data at index:", 19, 3, 16,
Color_RGB(255, 255, 255));
SPI_Send_String(CURRENTDIRw, strlen(bufferw), 8, 16, Color_RGB(255, 255, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
itoa(data_readc, buffer, 16);
for (int k = 0; k < strlen(buffer); k++){
CURRENTDIR[k] = buffer[k];
}
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("value read:", 11, 3, 16,Color_RGB(255, 255, 255));
SPI_Send_String(CURRENTDIR, strlen(buffer), 8, 16,(255, 255, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
itoa(data32, buffer1, 16);
for (int k = 0; k < strlen(buffer1); k++) {
CURRENTDIR1[k] = buffer1[k];
}
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("value sent:", 11, 3, 16, Color_RGB(255, 255, 255));
SPI_Send_String(CURRENTDIR1, strlen(buffer1), 8, 16, Color_RGB(255, 255, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
}
else if(check_wrong == 0){
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("ALL DATA CORRECT!", 17, 7, 16, Color_RGB(255, 255, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
}
//Show the bitmap
Ft_Gpu_Hal_WaitCmdfifo_empty();
Address_RAM_CMD = 0x908000;
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0xFFFFFF00, 7); // DLSTART
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0x26000007, 7); // CLEAR
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0x1F000001,7); // BEGIN BITMAPS
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, BITMAP_SOURCE(0x00000000), 7);
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, BITMAP_LAYOUT( 0x07, 200, 102), 7);
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, BITMAP_SIZE(0x00, 0x00, 0x00, image_width, image_height),7);
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, VERTEX2II(189, 83, 0, 0), 7);
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0x21000000,7); // END
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0x00000000,7); // DISPLAY
SPI_Send_RAM_CMD2(Address_RAM_CMD + ft_cmd_fifo_wp, 0xFFFFFF01,7); // SWAP
SPI_Send(0x9024E8, (uint16_t) (ft_cmd_fifo_wp), 7); // REG_CMD_WRITE
Ft_Gpu_Hal_WaitCmdfifo_empty();
HAL_Delay(1000);
}
f_mount(0, (TCHAR const*) SDPath, 0);
} else{
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("Cannot Link the SD Key I/O driver", 33, 1, 27, Color_RGB(0, 0, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
}
FATFS_UnLinkDriver(SDPath);
} else {
Address_RAM_DL = 0x900000;
SPI_Send_RAM_DL(Address_RAM_DL, 0x26000007, 7); // CLEAR
SPI_Send_String("Cannot Init SD", 14, 1, 27, Color_RGB(0, 0, 255));
SPI_Send_RAM_DL(Address_RAM_DL, 0x00000000, 7); // DISPLAY
SPI_Send(0x902450, 0x02, 4); // REG_DLSWAP
HAL_Delay(1000);
}
}
其中:
void SPI_Send_RAM_CMD2(uint32_t Address, uint32_t Data, uint16_t Size)
{
uint8_t buffer[7];
buffer[0] = ((Address >> 16) & 0xFF);
buffer[1] = ((Address >> 8) & 0xFF);
buffer[2] = (Address & 0xFF);
buffer[3] = (Data & 0xFF);
buffer[4] = ((Data >> 8) & 0xFF);
buffer[5] = ((Data >> 16) & 0xFF);
buffer[6] = ((Data >> 24) & 0xFF);
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_SPI_Transmit(&spi_handle_structure, buffer, Size, 10000);
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET);
ft_cmd_fifo_wp = ft_Inc_CMD_Offset(ft_cmd_fifo_wp, 4);
}
uint16_t ft_Inc_CMD_Offset(uint16_t currentOffset, uint8_t commandSize)
{
uint16_t newOffset;
newOffset = currentOffset + commandSize;
if (newOffset > 4095) { // If new offset past boundary...
newOffset = (newOffset - 4096); // ... roll over pointer
}
return newOffset;
}
void SPI_Send(uint32_t Address, uint32_t Data, uint16_t Size)
{
uint8_t buffer[7];
buffer[0] = ((Address >> 16) & 0xFF);
buffer[1] = ((Address >> 8) & 0xFF);
buffer[2] = (Address & 0xFF);
buffer[3] = (Data & 0xFF);
buffer[4] = ((Data >> 8) & 0xFF);
buffer[5] = ((Data >> 16) & 0xFF);
buffer[6] = ((Data >> 24) & 0xFF);
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_RESET);
HAL_SPI_Transmit(&spi_handle_structure, buffer, Size, 10000);
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_14, GPIO_PIN_SET);
}