Can i use my custom indev driver like keypad not using lvgl driver?

Hi <3

I have some button to control things such as roller, btn matrix,… I found that lvgl driver use an timer to read input device like keypad and send event to navigation. I don’t want to read keypad callback .I don’t want to read button press continuously but i want to use interrupt or other return events to send event to the screen that controls the rollers or btn matrix. Is that possible? (Although I received the return event and called the callback functions to change the screen, it only got 1 time)

Code snippet:

if(driver->disp == NULL) driver->disp = lv_disp_get_default();

if(driver->disp == NULL) {
    LV_LOG_WARN("lv_indev_drv_register: no display registered hence can't attach the indev to "
                "a display");
    return NULL;
}

lv_indev_t * indev = _lv_ll_ins_head(&LV_GC_ROOT(_lv_indev_ll));
LV_ASSERT_MALLOC(indev);
if(!indev) {
    return NULL;
}

lv_memset_00(indev, sizeof(lv_indev_t));
indev->driver = driver;

indev->proc.reset_query  = 1;
//indev->driver->read_timer = lv_timer_create(lv_indev_read_timer_cb, LV_INDEV_DEF_READ_PERIOD, indev);
lv_indev_read_btn_cb(indev);
return indev;

Code snippet:

void lv_indev_read_btn_cb(lv_indev_t* indev)
{
INDEV_TRACE(“begin”);

lv_indev_data_t data;

/*Read and process all indevs*/
if(indev_act->driver->disp == NULL) return; /*Not assigned to any displays*/

/*Handle reset query before processing the point*/
indev_proc_reset_query_handler(indev_act);

if(indev_act->proc.disabled ||
   indev_act->driver->disp->prev_scr != NULL) return; /*Input disabled or screen animation active*/
bool continue_reading;
do {
     /*Read the data*/
     _lv_indev_read(indev_act, &data);


    continue_reading = data.continue_reading;

    /*The active object might be deleted even in the read function*/
    indev_proc_reset_query_handler(indev_act);
    indev_obj_act = NULL;

    indev_act->proc.state = data.state;

    /*Save the last activity time*/
    if(indev_act->proc.state == LV_INDEV_STATE_PRESSED) {
        indev_act->driver->disp->last_activity_time = lv_tick_get();
    }
    else if(indev_act->driver->type == LV_INDEV_TYPE_ENCODER && data.enc_diff) {
        indev_act->driver->disp->last_activity_time = lv_tick_get();
    }

    if(indev_act->driver->type == LV_INDEV_TYPE_POINTER) {
        indev_pointer_proc(indev_act, &data);
    }
    else if(indev_act->driver->type == LV_INDEV_TYPE_KEYPAD) {

        indev_keypad_proc(indev_act, &data);
   

    }
    else if(indev_act->driver->type == LV_INDEV_TYPE_ENCODER) {
        indev_encoder_proc(indev_act, &data);
    }
    else if(indev_act->driver->type == LV_INDEV_TYPE_BUTTON) {
        indev_button_proc(indev_act, &data);
    }
    /*Handle reset query if it happened in during processing*/
    indev_proc_reset_query_handler(indev_act);

} while(continue_reading);

/*End of indev processing, so no act indev*/
indev_act     = NULL;
indev_obj_act = NULL;

INDEV_TRACE("finished");

}

So that in event callback of my button, i can call lv_indev_read_btn_cb(lv_indev_t* indev) to read data of indev keypad

I suggest using the interrupt to save the pressed button (or other required states) in global variables and just read these global variables in your read_cb.

There are other options too but it’s the simplest.

1 Like

Thanks you very much !!!

I have added a group keypad indev with my button. I have already read events like LV_KEY_ENTER, LV_KEY_LEFT, LV_KEY_RIGHT in my event handler for object such as roller. But it has changed only one time on my LCD screen. I just remove this line of code in file lv_hal_indev.c:
indev->driver->read_timer = lv_timer_create(lv_indev_read_timer_cb, LV_INDEV_DEF_READ_PERIOD, indev);
and call lv_indev_read_timer_cb any time a button is pressed and send the event such as data->key = ;
LV_EVENT_ENTER but it only works one time.
Thanks you very much.

Hii,

if i turn off these lvgl driver and use interrupt, i can’t use some objec can scroll t as scrollbar, roller, … How can i use interrupt button with these scroll feature or i have to customize it. Thanks you anh wish you have a nice day!

If there is no timer the scrolling is not working as the timer handles the scrolling too.

So it’d be great to figure out why you need to disable the timer. Can you debug your project to see what’s going on?