From 2c854e25359e2473665e8fb511471c766028cba4 Mon Sep 17 00:00:00 2001 From: Anatole SCHRAMM Date: Thu, 5 Jan 2023 13:47:39 +0100 Subject: [PATCH] Cleaned the lv_port_indev c file to now use the CST816D chip driver --- .../lvgl/lvgl_port/lv_port_indev.c | 123 ++++++++++++++++++ .../lvgl_port/lv_port_indev.c.bck} | 0 .../gfx => lvgl/lvgl_port}/lv_port_indev.h | 0 .../lvgl_port/touchpad.c.bck} | 0 .../lvgl_port/touchpad.h.bck} | 0 5 files changed, 123 insertions(+) create mode 100644 src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c rename src/W800 SDK v1.00.08/{app/gfx/lv_port_indev.c => lvgl/lvgl_port/lv_port_indev.c.bck} (100%) rename src/W800 SDK v1.00.08/{app/gfx => lvgl/lvgl_port}/lv_port_indev.h (100%) rename src/W800 SDK v1.00.08/{app/gfx/touchpad.c => lvgl/lvgl_port/touchpad.c.bck} (100%) rename src/W800 SDK v1.00.08/{app/gfx/touchpad.h => lvgl/lvgl_port/touchpad.h.bck} (100%) diff --git a/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c new file mode 100644 index 0000000..0365cba --- /dev/null +++ b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c @@ -0,0 +1,123 @@ +/** + * @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 "wm_gpio.h" +#include "app_config.h" +#include "CST816D.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ +static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data); + +/********************** + * STATIC VARIABLES + **********************/ +static lv_indev_t * indev_touchpad; + +/********************** + * MACROS + **********************/ + +/********************** + * LOCAL FUNCTIONS + **********************/ +static void touch_panel_isr(void *arg) +{ + CST816D_Touch_Data_t *p = arg; + tls_clr_gpio_irq_status(LCD_TOUCH_PANEL_IRQ); + CST816D_read_touch_event(p); +} +/********************** + * GLOBAL FUNCTIONS + **********************/ + +void lv_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 + */ + + static lv_indev_drv_t indev_drv; + static CST816D_Touch_Data_t CST816D_Touch_Data; + + /*------------------ + * Touchpad + * -----------------*/ + + /*Initialize your touchpad if you have*/ + // Let's configure the needed interrupt pin to detect and read touch screen events + tls_gpio_cfg(LCD_TOUCH_PANEL_IRQ, WM_GPIO_DIR_INPUT, WM_GPIO_ATTR_PULLHIGH); + tls_gpio_isr_register(LCD_TOUCH_PANEL_IRQ, &(touch_panel_isr), &CST816D_Touch_Data); + tls_gpio_irq_enable(LCD_TOUCH_PANEL_IRQ, WM_GPIO_IRQ_TRIG_FALLING_EDGE); + + memset(&CST816D_Touch_Data, 0, sizeof CST816D_Touch_Data); + + /*Register a touchpad input device*/ + lv_indev_drv_init(&indev_drv); + indev_drv.type = LV_INDEV_TYPE_POINTER; + indev_drv.read_cb = touchpad_read; + indev_drv.user_data = &CST816D_Touch_Data; + indev_touchpad = lv_indev_drv_register(&indev_drv); +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +/*------------------ + * Touchpad + * -----------------*/ + +static void touchpad_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) +{ + static lv_coord_t last_x = 0; + static lv_coord_t last_y = 0; + + CST816D_Touch_Data_t *p = indev_drv->user_data; + + // Save the pressed coordinates and the state + if(p->isValid && p->event == CST816D_Event_Pressed) { + last_x = p->touch_x; + last_y = p->touch_y; + data->state = LV_INDEV_STATE_PR; + } + else { + data->state = LV_INDEV_STATE_REL; + } + + // Set the last pressed coordinates + data->point.x = 239-last_x; + data->point.y = 239-last_y; +} + +#else /*Enable this file at the top*/ + +/*This dummy typedef exists purely to silence -Wpedantic.*/ +typedef int keep_pedantic_happy; +#endif diff --git a/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c.bck similarity index 100% rename from src/W800 SDK v1.00.08/app/gfx/lv_port_indev.c rename to src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.c.bck diff --git a/src/W800 SDK v1.00.08/app/gfx/lv_port_indev.h b/src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.h similarity index 100% rename from src/W800 SDK v1.00.08/app/gfx/lv_port_indev.h rename to src/W800 SDK v1.00.08/lvgl/lvgl_port/lv_port_indev.h diff --git a/src/W800 SDK v1.00.08/app/gfx/touchpad.c b/src/W800 SDK v1.00.08/lvgl/lvgl_port/touchpad.c.bck similarity index 100% rename from src/W800 SDK v1.00.08/app/gfx/touchpad.c rename to src/W800 SDK v1.00.08/lvgl/lvgl_port/touchpad.c.bck diff --git a/src/W800 SDK v1.00.08/app/gfx/touchpad.h b/src/W800 SDK v1.00.08/lvgl/lvgl_port/touchpad.h.bck similarity index 100% rename from src/W800 SDK v1.00.08/app/gfx/touchpad.h rename to src/W800 SDK v1.00.08/lvgl/lvgl_port/touchpad.h.bck