What MCU/Processor/Board and compiler are you using?
STM32F103RCT6 (RAM 48 KB, custom board)
display: 128*160, RGB565(16 bit), ST7735/ST7789 lcd driver, SPI comm.
IDE: STM32CubeIDE
What LVGL version are you using?
the latest one (v8.0)
What do you want to achieve?
When I add lvgl examples that have event callback function, it makes hard fault error, I don’t know the reason. All of the examples with events make hardfault errors.
Do I need another custom function in main.c?
And I couldn’t find the information of lv_obj_add_event_cb() function.
When I’ve searched it, it was set_event_cb in previous version.
I added log printf result. How can I solve this problem?
What have you tried so far?
Code to reproduce
main function
void App_Start(void)
{
// lcd init
lv_init();
LCD_Init();
HAL_Delay(5);
// function for setting lcd and touch configuration
lv_disp_config();
lv_touch_config();
// put button example function
lv_example_btn_1();
}
indev setting
void lv_touch_config(void)
{
static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); // basic initialization
indev_drv.type = LV_INDEV_TYPE_POINTER;
static lv_indev_data_t data;
my_input_read(&indev_drv, &data);
indev_drv.read_cb = my_input_read;
lv_indev_t * my_indev = lv_indev_drv_register(&indev_drv);
}
my_input_read()
bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
{
static int8_t lastX = 0;
static int8_t lastY = 0;
if(XPT2046_TouchPressed())
{
XPT2046_TouchGetCoordinates(&lastX, &lastY);
data->state = LV_INDEV_STATE_PRESSED;
}
else
{
data->point.x = lastX;
data->point.y = lastY;
data->state = LV_INDEV_STATE_RELEASED;
}
return false;
}
example that I imported
static void event_handler(lv_obj_t * obj, lv_event_t event)
{
LV_UNUSED(obj);
if(event == LV_EVENT_CLICKED) {
LV_LOG_USER("Clicked");
}
else if(event == LV_EVENT_VALUE_CHANGED) {
LV_LOG_USER("Toggled");
}
}
void lv_example_btn_1(void)
{
lv_obj_t * label;
lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_pos(btn1, 10, 10);
lv_obj_set_size(btn1, 80, 50);
lv_obj_add_event_cb(btn1, event_handler, NULL);
lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Button");
lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_add_event_cb(btn2, event_handler, NULL);
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40);
lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_height(btn2, LV_SIZE_CONTENT);
label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Toggle");
}
#endif
Screenshot and/or video
spi setting