到https://gitee.com/rtthread/rt-thread/tree/gitee_master/bsp/stm32/stm32l475-atk-pandora/board/ports/lcd
中拷贝drv_lcd.c , drv_lcd.h, lcd_font.h文件到工程中,
根据个人的硬件电路修改引脚,分辨率
#define LCD_DC_PIN GET_PIN(A, 2)
#define LCD_RES_PIN GET_PIN(A, 1)
#define LCD_BL_PIN GET_PIN(A, 0)
#ifndef BSP_USING_LVGL
#define LCD_CLEAR_SEND_NUMBER 76800 /* 320*240 */
static int rt_hw_lcd_config(void)
{
spi_dev_lcd = (struct rt_spi_device *)rt_device_find("spi10");
__HAL_RCC_GPIOA_CLK_ENABLE();
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_3);
lcd_gpio_init();
/* config spi */
{
struct rt_spi_configuration cfg = {0};
cfg.data_width = 8;
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB;
cfg.max_hz = 42 * 1000 * 1000; /* 42M,SPI max 42MHz,lcd 4-wire spi */
rt_spi_configure(spi_dev_lcd, &cfg);
}
return RT_EOK;
}
static void lcd_gpio_init(void)
{
rt_hw_lcd_config();
rt_pin_mode(LCD_DC_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(LCD_RES_PIN, PIN_MODE_OUTPUT);
rt_pin_mode(LCD_BL_PIN, PIN_MODE_OUTPUT);
rt_pin_write(LCD_RES_PIN, PIN_LOW);
//wait at least 100ms for reset
rt_thread_delay(RT_TICK_PER_SECOND / 10);
rt_pin_write(LCD_RES_PIN, PIN_HIGH);
rt_thread_delay(RT_TICK_PER_SECOND / 10);
}
void lcd_display_on(void)
{
rt_pin_write(LCD_BL_PIN, PIN_HIGH);
}
void lcd_display_off(void)
{
rt_pin_write(LCD_BL_PIN, PIN_LOW);
}
以上是我给人根据自己的硬件所做的修改
按照rt-thread 的提示完成以上四小步,然后编译,理论上可以编译通过了,可以lcd_clear(BLACK);清个屏试试看
可以读取sd卡中.bmp文件,用lcd_fill_array接口显示图片。
可以参考
rt_uint8_t play_bin(const char *path)
{
struct stat file_stat;
rt_uint16_t fd;
rt_uint32_t res, i;
fd = open(path, O_RDONLY);
if (fd != -1)
{
rt_kprintf("fd is = %d...\n", fd);
stat(path, &file_stat);
rt_kprintf("%ld\n", file_stat.st_size);
Psize = (rt_uint8_t *) malloc(file_stat.st_size);
Psize = (rt_uint8_t *) malloc(38410);
for (uint16_t i = 0; i < 161; i++)
{
rt_kprintf("i = %d.\n", i);
read(fd, Psize, 38410);
rt_sem_release(dynamic_sem); //释放信号
// rt_thread_mdelay(1);
// lcd_send(Psize, 0, 0, 160, 120);
}
// read(fd, Psize, file_stat.st_size/2);
// lcd_send(Psize, 0, 90, 240, 180);
// lcd_clear(RED);
// while (!flag)
// ;
// flag = 0;
}
return 1;
}