1================== 2Linux Evdev Driver 3================== 4 5Overview 6-------- 7 8The Linux event device (evdev) is a hardware-independent API that gives access to input events from, 9for example, a mouse or touchscreen. It is exposed via the Linux device file system interface. 10 11Prerequisites 12------------- 13 14Your system has an input device configured (usually under ``/dev/input/`` such as ``/dev/input/event0``). 15 16Configuring the driver 17---------------------- 18 19Enable the Linux LVGL evdev driver support in ``lv_conf.h``. 20 21.. code-block:: c 22 23 #define LV_USE_EVDEV 1 24 25Usage 26----- 27 28To set up an event input, first create an input device with ``lv_edev_create`` setting it to the correct Linux event device. 29Then link this to the LVGL display with ``lv_indev_set_display``. 30 31.. code-block:: c 32 33 lv_indev_t *touch = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event0"); 34 lv_indev_set_display(touch, disp); 35 36Ensure that an ``lv_display_t`` object is already created for ``disp``. An example for this is shown below, using the Linux framebuffer driver. 37 38.. code-block:: c 39 40 lv_display_t * disp = lv_linux_fbdev 41 lv_linux_fbdev_set_file(disp, "/dev/fb0");_create(); 42 43 44Locating your input device 45-------------------------- 46 47If you can't determine your input device, first run 48 49```$cat /proc/bus/input/devices``` 50 51This should show input devices and there will be entries with the word ``event`` which give a clue as to the device to use eg. ``event1`` would be ``/dev/input/event1``. 52 53You can use ``evtest`` to show data from that event source to see if it is actually the one you want. 54 55Try: 56 57``$evtest /dev/input/event1`` replacing ``eventX`` with your event device from above. 58 59Automatic input device discovery 60-------------------------------- 61 62There is support for automatically finding and adding input devices in ``/dev/input/``. New devices will automatically be added 63when they are connected. To enable this feature, you can simply call :cpp:expr:`lv_evdev_discovery_start(NULL, NULL)`. 64 65You may want to react to a new device being added so that a cursor image can be applied, for example. You can provide a callback 66function which will be called when a new device is added. 67 68.. code-block:: c 69 70 #include "lvgl/src/core/lv_global.h" 71 72 static void indev_deleted_cb(lv_event_t * e) 73 { 74 if(LV_GLOBAL_DEFAULT()->deinit_in_progress) return; 75 lv_obj_t * cursor_obj = lv_event_get_user_data(e) 76 lv_obj_delete(cursor_obj); 77 } 78 79 static void discovery_cb(lv_indev_t * indev, lv_evdev_type_t type, void * user_data) 80 { 81 LV_LOG_USER("new '%s' device discovered", type == LV_EVDEV_TYPE_REL ? "REL" : 82 type == LV_EVDEV_TYPE_ABS ? "ABS" : 83 type == LV_EVDEV_TYPE_KEY ? "KEY" : 84 "unknown"); 85 86 if(type == LV_EVDEV_TYPE_REL) { 87 LV_IMAGE_DECLARE(mouse_cursor_icon); 88 lv_obj_t * cursor_obj = lv_image_create(lv_screen_active()); 89 lv_image_set_src(cursor_obj, &mouse_cursor_icon); 90 lv_indev_set_cursor(indev, cursor_obj); 91 lv_indev_add_event_cb(indev, indev_deleted_cb, LV_EVENT_DELETE, cursor_obj); 92 } 93 } 94 95 int main() 96 { 97 /* ... */ 98 lv_evdev_discovery_start(discovery_cb, NULL); 99 /* ... */ 100 } 101 102At the time of writing, this feature is not supported in BSD. 103