1 /** 2 * @file lv_port_indev_templ.c 3 * 4 */ 5 6 /* Copy this file as "lv_port_indev.c" and set this value to "1" to enable conten */ 7 8 #include <stdlib.h> 9 #include "lvgl.h" 10 #include "lv_port_indev.h" 11 12 #include "evdev.h" 13 #include "key.h" 14 15 typedef struct _GROUP_NODE { 16 struct _GROUP_NODE *next; 17 lv_group_t *group; 18 } GROUP_NODE; 19 20 static int rot_indev; 21 lv_indev_t * indev_touchpad; 22 lv_indev_t * indev_key; 23 24 GROUP_NODE *group_list = NULL; 25 lv_port_indev_group_create(void)26lv_group_t *lv_port_indev_group_create(void) 27 { 28 struct _GROUP_NODE *group_node = NULL; 29 lv_group_t *group = lv_group_create(); 30 31 lv_indev_set_group(indev_key, group); 32 lv_group_set_default(group); 33 34 group_node = (struct _GROUP_NODE *)malloc(sizeof(struct _GROUP_NODE)); 35 group_node->group = group; 36 group_node->next = NULL; 37 if (group_list) { 38 group_node->next = group_list; 39 group_list = group_node; 40 } else { 41 group_list = group_node; 42 } 43 44 return group; 45 } 46 lv_port_indev_group_destroy(lv_group_t * group)47void lv_port_indev_group_destroy(lv_group_t *group) 48 { 49 if (group_list) { 50 struct _GROUP_NODE *group_node = NULL; 51 group_node = group_list; 52 if (group_list->group == group) { 53 group_list = group_list->next; 54 if (group_list) { 55 lv_indev_set_group(indev_key, group_list->group); 56 lv_group_set_default(group_list->group); 57 } else { 58 lv_indev_set_group(indev_key, NULL); 59 lv_group_set_default(NULL); 60 } 61 free(group_node); 62 } else { 63 while (group_node->next) { 64 struct _GROUP_NODE *group_node_next = group_node->next; 65 if (group_node_next->group == group) { 66 group_node->next = group_node_next->next; 67 free(group_node_next); 68 break; 69 } 70 group_node = group_node->next; 71 } 72 } 73 lv_group_del(group); 74 } 75 } 76 lv_port_indev_init(int rot)77void lv_port_indev_init(int rot) 78 { 79 /** 80 * Here you will find example implementation of input devices supported by LittelvGL: 81 * - Touchpad 82 * - Mouse (with cursor support) 83 * - Keypad (supports GUI usage only with key) 84 * - Encoder (supports GUI usage only with: left, right, push) 85 * - Button (external buttons to press points on the screen) 86 * 87 * The `..._read()` function are only examples. 88 * You should shape them according to your hardware 89 */ 90 91 static lv_indev_drv_t indev_drv; 92 static lv_indev_drv_t key_drv; 93 94 rot_indev = rot; 95 96 /*------------------ 97 * Touchpad 98 * -----------------*/ 99 100 /*Initialize your touchpad if you have*/ 101 evdev_init(rot); 102 103 /*Register a touchpad input device*/ 104 lv_indev_drv_init(&indev_drv); 105 indev_drv.type = LV_INDEV_TYPE_POINTER; 106 indev_drv.read_cb = evdev_read; 107 indev_touchpad = lv_indev_drv_register(&indev_drv); 108 109 #if USE_KEY 110 key_init(); 111 lv_indev_drv_init(&key_drv); 112 key_drv.type = LV_INDEV_TYPE_KEYPAD; 113 key_drv.read_cb = key_read; 114 indev_key = lv_indev_drv_register(&key_drv); 115 lv_port_indev_group_create(); 116 #endif 117 } 118