What MCU/Processor/Board and compiler are you using?
STM32F407VET6
What do you want to achieve?
add a button as in device
What have you tried so far?
I consult materials at https://docs.littlevgl.com/zh-CN/html/porting/indev.html to give you, but it won’t work, I can assure you my key program is right.
I can detect that the data-> BTN is changing, but it is not a trigger event source for BTN
Code to reproduce
bool button_read(lv_indev_data_t*data){
static uint32_t last_btn = 0; /*Store the last pressed button*/
int btn_pr=0;
btn_pr = KEY_Scan(); /*Get the ID (0,1,2...) of the pressed button*/
if(btn_pr >= 1) { /*Is there a button press? (E.g. -1 indicated no button was pressed)*/
last_btn = btn_pr; /*Save the ID of the pressed button*/
data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/
} else {
data->state = LV_INDEV_STATE_REL; /*Set the released state*/
}
if(btn_pr)
{
rt_kprintf("%d\r\n",btn_pr);
}
data->btn = last_btn; /*Save the last button*/
return false; /*No buffering now so no more data read*/
}
void lv_key_init(void)
{
static lv_indev_t *indev;
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.read = button_read;
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev = lv_indev_drv_register(&indev_drv);
/*points_array: these points will be assigned to the buttons to press a specific point on the screen.*/
static lv_point_t points_array[] = {{40, 40}};
lv_indev_set_button_points(indev, points_array);
}
static lv_res_t key_event_cb(lv_obj_t * btn)
{
Bsp_LCD_ColorBox(100,50,50,50,RED);
rt_kprintf("123");
}
void key_ui()
{
static lv_obj_t *btn1;
btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_obj_set_size(btn1, 100, 100);
lv_obj_set_pos(btn1, 20, 20);
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK,key_event_cb);
}
void rt_key_thread_entry(void * parameter)
{
(void)parameter;
lv_key_init();
key_ui();
while(1)
{
lv_tick_inc(1);
lv_task_handler();
delay_ms(1);
}
}
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.