Description
What MCU/Processor/Board and compiler are you using?
STM32F103RCT6, CubeIDE
display: 128*160, RGB565(16 bit), ST7735/ST7789 lcd driver.
What do you want to achieve?
I want to make any object on display.
When I run the only initialization & configuration code (written on lvgl documentation), there is no error.
Actually I’m not sure initialization&configuration is properly done because I can only see the white screen after running the code.
After that, I added the example code on lvgl lib(-lvgl/examples/get_started/lv_example_get_started_1.c/lv_example_get_started_1()), and hard fault occurred.
I guess it is because of memory or lcd driver-lvgl connection.
Is there any other possibility on code? Please help
When I defined lv_disp_buf_t valuable and lv_disp_buf_init func, it was impossible because they aren’t contained in lv_hal_disp.h. Instead of it, lv_disp_draw_buf_t and lv_disp_draw_buf_init are in it. I’ve used them.
What have you tried so far?
initialization and import lv_example_get_started_1() func.
Code to reproduce
Add the relevant code snippets here.
// lv_conf.h file
// attached that I added or revised
/* Maximal horizontal and vertical resolution to support by the library.*/
#define LV_HOR_RES_MAX 128
#define LV_VER_RES_MAX 160
/*Color depth: 1 (1 byte per pixel), 8 (RGB332), 16 (RGB565), 32 (ARGB8888)*/
#define LV_COLOR_DEPTH 16
/*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
# define LV_MEM_SIZE (10U * 1024U) /*[bytes]*/
int main(void)
{
// there are initialization functions above (deleted for posting)
App_Start();
while(1)
{
lv_tick_inc(10);
lv_task_handler();
HAL_Delay(10);
}
}
/*initialization and configuration*/
int lv_config_main(void)
{
lv_init();
static lv_disp_draw_buf_t disp_buf;
static lv_color_t buf_1[LV_HOR_RES_MAX * 10];
lv_disp_draw_buf_init(&disp_buf, buf_1, NULL, LV_HOR_RES_MAX * 10);
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.draw_buf = &disp_buf;
disp_drv.flush_cb = LCD_flush;
lv_disp_t * disp_ex;
disp_ex = lv_disp_drv_register(&disp_drv);
}
void LCD_flush(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_map)
{
uint16_t x, y;
uint32_t size = (area->x2 - area->x1 + 1) * (area->y2 - area->y1 + 1);
for(y = area->y1; y <= area->y2; y++) {
for(x = area->x1; x <= area->x2; x++) {
LCD_DrawPaint((uint16_t ) area->x1, (uint16_t ) area->y1, (uint16_t *)color_map);
color_map++;
}
}
lv_disp_flush_ready(drv);
DEV_Digital_Write(DEV_CS_PIN, 1);
}
void LCD_DrawPaint(uint16_t x, uint16_t y, uint16_t Color)
{
LCD_SetCursor(x, y);
LCD_WriteData_Word(Color);
}
#define DEV_Digital_Write(_pin, _value) HAL_GPIO_WritePin(_pin, _value == 0? GPIO_PIN_RESET:GPIO_PIN_SET)
void DEV_SPI_WRite(uint8_t _dat)
{
HAL_SPI_Transmit(&hspi1, (uint8_t *)&_dat, 1, 500);
}
void LCD_SetCursor(uint16_t X, uint16_t Y)
{
LCD_Write_Command(0x2a);
LCD_WriteData_Byte(X >> 8);
LCD_WriteData_Byte(X);
LCD_WriteData_Byte(X >> 8);
LCD_WriteData_Byte(X);
LCD_Write_Command(0x2b);
LCD_WriteData_Byte(Y >> 8);
LCD_WriteData_Byte(Y);
LCD_WriteData_Byte(Y >> 8);
LCD_WriteData_Byte(Y);
LCD_Write_Command(0x2C);
}
void LCD_WriteData_Word(uint16_t data)
{
DEV_Digital_Write(DEV_CS_PIN, 0);
DEV_Digital_Write(DEV_DC_PIN, 1);
DEV_SPI_WRITE((data>>8) & 0xff);
DEV_SPI_WRITE(data);
DEV_Digital_Write(DEV_CS_PIN, 1);
}
static void LCD_Write_Command(uint16_t data)
{
DEV_Digital_Write(DEV_CS_PIN, 0);
DEV_Digital_Write(DEV_DC_PIN, 0);
DEV_SPI_WRITE(data);
}
void LCD_WriteData_Word(uint16_t data)
{
DEV_Digital_Write(DEV_CS_PIN, 0);
DEV_Digital_Write(DEV_DC_PIN, 1);
DEV_SPI_WRITE((data>>8) & 0xff);
DEV_SPI_WRITE(data);
DEV_Digital_Write(DEV_CS_PIN, 1);
}