lvgl: use LV_INDEV_TYPE_BUTTON cause crash

I’m using a PC simulator. I want to use some hardware button. This is my configuration cause crash. (I use LV_INDEV_TYPE_POINT is normal.)

    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);          /*Basic initialization*/
    indev_drv.type = LV_INDEV_TYPE_BUTTON
    indev_drv.read = button_read;         /*This function will be called periodically (by the library) to get the mouse position and state*/
    lv_indev_drv_register(&indev_drv);

bool button_read(lv_indev_data_t*data)
{
    static uint32_t last_btn = 0;   /*Store the last pressed button*/ 
    int btn_pr = my_btn_read();     /*Get the ID (0,1,2...) of the pressed button*/
    if(btn_pr >= 0) {               /*Is there a button press?*/  
       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*/
    }
  
    data->btn = last_btn;            /*Set the last button*/         
   
    return false;                    /*No buffering so no more data read*/
}

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 25 (19 by maintainers)

Most upvoted comments

Keywords: stm32f429i-disco, hardware button, led toggle, LV_INDEV_TYPE_BUTTON

First step, we record a video for this purpose: https://www.youtube.com/watch?v=dk772McmJs4

Thanks to @ogunduz

https://blog.littlevgl.com/2019-01-08/hardware-button

🔑 Keywords: stm32f429i-disco, hardware button, led toggle, LV_INDEV_TYPE_BUTTON

First step, we record a video for this purpose: https://www.youtube.com/watch?v=dk772McmJs4

Thanks to @ogunduz

@kisvegabor we’ll write a blog entry for the hardware button.

lv_indev_set_button_points(&indev_drv, points_array); [1]

@WangYifa there is error in this line,

# correct
lv_indev_t *indev;
lv_indev_driver_t indev_drv;
[...]
indev = lv_indev_drv_register(&indev_drv.driver);
[...]
lv_indev_set_button_points(indev, points_array);

# wrong
lv_indev_set_button_points(&indev_drv, points_array);

📋 Reference

  1. https://github.com/littlevgl/lvgl/issues/567#issuecomment-440179496