提交 c14dbe8a 编写于 作者: mysterywolf's avatar mysterywolf 提交者: guo

[lvgl] beautify code

上级 0d2b96d7
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
* 2021-10-18 Meco Man The first version * 2021-10-18 Meco Man The first version
*/ */
#include <lvgl.h> #include <lvgl.h>
#include <stdbool.h>
#include <rtdevice.h> #include <rtdevice.h>
static lv_indev_state_t last_state = LV_INDEV_STATE_REL; static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
static rt_int16_t last_x = 0; static rt_int16_t last_x = 0;
static rt_int16_t last_y = 0; static rt_int16_t last_y = 0;
lv_indev_t * touch_indev;
static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{ {
data->point.x = last_x; data->point.x = last_x;
...@@ -29,16 +30,15 @@ void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state) ...@@ -29,16 +30,15 @@ void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
last_y = LV_HOR_RES_MAX - y; last_y = LV_HOR_RES_MAX - y;
} }
lv_indev_t * button_indev;
void lv_port_indev_init(void) void lv_port_indev_init(void)
{ {
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv); /*Basic initialization*/ /* Has not supported touch sensor! */
indev_drv.type = LV_INDEV_TYPE_POINTER; // lv_indev_drv_init(&indev_drv); /*Basic initialization*/
indev_drv.read_cb = input_read; // indev_drv.type = LV_INDEV_TYPE_POINTER;
// indev_drv.read_cb = input_read;
/*Register the driver in LVGL and save the created input device object*/ // /*Register the driver in LVGL and save the created input device object*/
button_indev = lv_indev_drv_register(&indev_drv); // touch_indev = lv_indev_drv_register(&indev_drv);
} }
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
extern "C" { extern "C" {
#endif #endif
#include <lv_hal_indev.h>
extern lv_indev_t * button_indev;
void lv_port_indev_init(void); void lv_port_indev_init(void);
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state); void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#define BUTTON2_PIN 16 #define BUTTON2_PIN 16
#define BUTTON_WKUP_PIN 20 #define BUTTON_WKUP_PIN 20
lv_indev_t * button_indev;
/*Test if `id` button is pressed or not*/ /*Test if `id` button is pressed or not*/
static bool button_is_pressed(uint8_t id) static bool button_is_pressed(uint8_t id)
{ {
...@@ -83,9 +85,6 @@ void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data) ...@@ -83,9 +85,6 @@ void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
data->btn_id = last_btn; /*Save the last button*/ data->btn_id = last_btn; /*Save the last button*/
} }
lv_indev_t * button_indev;
void lv_port_indev_init(void) void lv_port_indev_init(void)
{ {
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
extern "C" { extern "C" {
#endif #endif
#include <lv_hal_indev.h>
extern lv_indev_t * button_indev;
void lv_port_indev_init(void); void lv_port_indev_init(void);
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state); void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
......
...@@ -17,6 +17,8 @@ static lv_indev_state_t last_state = LV_INDEV_STATE_REL; ...@@ -17,6 +17,8 @@ static lv_indev_state_t last_state = LV_INDEV_STATE_REL;
static rt_int16_t last_x = 0; static rt_int16_t last_x = 0;
static rt_int16_t last_y = 0; static rt_int16_t last_y = 0;
lv_indev_t * touch_indev;
static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) static void input_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data)
{ {
data->point.x = last_x; data->point.x = last_x;
...@@ -31,8 +33,6 @@ void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state) ...@@ -31,8 +33,6 @@ void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state)
last_y = LCD_HEIGHT - y; last_y = LCD_HEIGHT - y;
} }
lv_indev_t * button_indev;
void lv_port_indev_init(void) void lv_port_indev_init(void)
{ {
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
...@@ -42,5 +42,5 @@ void lv_port_indev_init(void) ...@@ -42,5 +42,5 @@ void lv_port_indev_init(void)
indev_drv.read_cb = input_read; indev_drv.read_cb = input_read;
/*Register the driver in LVGL and save the created input device object*/ /*Register the driver in LVGL and save the created input device object*/
button_indev = lv_indev_drv_register(&indev_drv); touch_indev = lv_indev_drv_register(&indev_drv);
} }
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
extern "C" { extern "C" {
#endif #endif
#include <lv_hal_indev.h>
extern lv_indev_t * button_indev;
void lv_port_indev_init(void); void lv_port_indev_init(void);
void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state); void lv_port_indev_input(rt_int16_t x, rt_int16_t y, lv_indev_state_t state);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#define BUTTON2_PIN GET_PIN(D, 8) #define BUTTON2_PIN GET_PIN(D, 8)
#define BUTTON_WKUP_PIN GET_PIN(C, 13) #define BUTTON_WKUP_PIN GET_PIN(C, 13)
lv_indev_t * button_indev;
/*Test if `id` button is pressed or not*/ /*Test if `id` button is pressed or not*/
static bool button_is_pressed(uint8_t id) static bool button_is_pressed(uint8_t id)
{ {
...@@ -78,9 +80,6 @@ void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data) ...@@ -78,9 +80,6 @@ void button_read(lv_indev_drv_t * drv, lv_indev_data_t*data)
data->btn_id = last_btn; /*Save the last button*/ data->btn_id = last_btn; /*Save the last button*/
} }
lv_indev_t * button_indev;
void lv_port_indev_init(void) void lv_port_indev_init(void)
{ {
static lv_indev_drv_t indev_drv; static lv_indev_drv_t indev_drv;
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
extern "C" { extern "C" {
#endif #endif
#include <lv_hal_indev.h>
extern lv_indev_t * button_indev;
void lv_port_indev_init(void); void lv_port_indev_init(void);
#ifdef __cplusplus #ifdef __cplusplus
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册