/** * @file lv_port_indev_templ.c * */ /*Copy this file as "lv_port_indev.c" and set this value to "1" to enable content*/ #if 1 /********************* * INCLUDES *********************/ #include"lv_port_indev.h" #include"lvgl.h" #include"hal_btn.h" /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ /********************** * STATIC PROTOTYPES **********************/ staticvoidkeypad_init(void); staticvoidkeypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); staticuint32_tkeypad_get_key(void); /********************** * STATIC VARIABLES **********************/ lv_indev_t * indev_keypad; // lv_group_t *key_group; /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ voidlv_port_indev_init(void) { /** * Here you will find example implementation of input devices supported by LittelvGL: * - Touchpad * - Mouse (with cursor support) * - Keypad (supports GUI usage only with key) * - Encoder (supports GUI usage only with: left, right, push) * - Button (external buttons to press points on the screen) * * The `..._read()` function are only examples. * You should shape them according to your hardware */ staticlv_indev_drv_t indev_drv; /*------------------ * Keypad * -----------------*/ /*Initialize your keypad or keyboard if you have*/ keypad_init(); /*Register a keypad input device*/ lv_indev_drv_init(&indev_drv); indev_drv.type = LV_INDEV_TYPE_KEYPAD; indev_drv.read_cb = keypad_read; indev_keypad = lv_indev_drv_register(&indev_drv); /*Later you should create group(s) with `lv_group_t * group = lv_group_create()`, *add objects to the group with `lv_group_add_obj(group, obj)` *and assign this input device to group to navigate in it: *`lv_indev_set_group(indev_keypad, group);`*/ } /********************** * STATIC FUNCTIONS **********************/ /*------------------ * Keypad * -----------------*/ /*Initialize your keypad*/ staticvoidkeypad_init(void) { btn_init(0,UP); btn_init(20,UP); btn_init(19,UP); } /*Will be called by the library to read the mouse*/ staticvoidkeypad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) { staticuint32_t last_key = 0; /*Get the current x and y coordinates*/ // mouse_get_xy(&data->point.x, &data->point.y); /*Get whether the a key is pressed and save the pressed key*/ uint32_t act_key = keypad_get_key(); // printf("key:%d\n",act_key); if(act_key != 0) { data->state = LV_INDEV_STATE_PR; /*Translate the keys to LVGL control characters according to your key definitions*/ switch(act_key) { case1: act_key = LV_KEY_NEXT; break; case2: act_key = LV_KEY_PREV; break; case3: act_key = LV_KEY_LEFT; break; case4: act_key = LV_KEY_RIGHT; break; case5: act_key = LV_KEY_ENTER; break; } last_key = act_key; } else { data->state = LV_INDEV_STATE_REL; } data->key = last_key; } /*Get the currently being pressed key. 0 if no key is pressed*/ staticuint32_tkeypad_get_key(void) { if(btn_get_level(0)==0) return1; elseif(btn_get_level(20)==0) return4; elseif(btn_get_level(19)==0) return5; return0; } #endif
/*Later you should create group(s) with `lv_group_t * group = lv_group_create()`, *add objects to the group with `lv_group_add_obj(group, obj)` *and assign this input device to group to navigate in it: *`lv_indev_set_group(indev_keypad, group);`*/