How to call it correctly when the input device is a button


What MCU/Processor/Board and compiler are you using?


What do you want to achieve?

How to use the button type input device normally in the interface

What have you tried so far?

By referring to the “lv_port_indev_template.c” file, I completed the docking of the button reading between LVGL and MCU, and set the analog point corresponding to the button. However, when I tested pressing these buttons, I found that these simulated points did not show any signs of being pressed. I suspect that because LVGL did not call the button scan without updating, but this is just my guess, I hope to find the answer as soon as possible

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

void lv_port_indev_init(void)
lv_indev_drv_t indev_drv;
* Button
* -----------------

/*Initialize your button if you have*/

/*Register a button input device*/
indev_drv.type = LV_INDEV_TYPE_BUTTON;
indev_drv.read_cb = button_read;
indev_button = lv_indev_drv_register(&indev_drv);

/*Assign buttons to points on the screen*/
static const lv_point_t btn_points[2] = {
        {64, 32},   /*Button 0 -> x:10; y:10*/
        {32, 64},  /*Button 1 -> x:40; y:100*/
lv_indev_set_button_points(indev_button, btn_points);


Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Can you show the code for button_read and the code you’re using on the UI end to find out when a button is pressed?

This blog post can be also useful.