Skip to content

Commit

Permalink
add uGFX toggle driver for button and touchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteYuan committed Nov 14, 2018
1 parent 1026038 commit b29df85
Show file tree
Hide file tree
Showing 17 changed files with 566 additions and 11 deletions.
92 changes: 92 additions & 0 deletions components/__config/Kconfig.projbuild
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,12 @@ menu "IoT Solution settings"
help
"Select to enable uGFX touch screen"

config UGFX_DRIVER_TOGGLE_ENABLE
bool "uGFX Toggle Input Device Enable"
default n
help
"Select to enable uGFX Toggle input device"

choice UGFX_DRIVER_MODE
prompt "Display Driver Mode"
default UGFX_LCD_DRIVER_FRAMEBUFFER_MODE
Expand Down Expand Up @@ -951,6 +957,46 @@ menu "IoT Solution settings"

menu "Config Driver"
depends on UGFX_USE_CONFIGURED_OPTIONS

choice UGFX_DRIVER_TOGGLE
prompt "Choose Toggle Input Driver"
depends on UGFX_DRIVER_TOGGLE_ENABLE

config UGFX_DRIVER_TOGGLE_BUTTON
bool "BUTTON"

config UGFX_DRIVER_TOGGLE_TOUCHPAD
bool "TOUCHPAD"

endchoice

menu "Button Toggle Input Device Configuration"
depends on UGFX_DRIVER_TOGGLE_BUTTON

config UGFX_TOGGLE_BUTTON_GPIO1
int "uGFX Toggle Button Num 1's GPIO"
range 0 39
default 4
config UGFX_TOGGLE_BUTTON_GPIO2
int "uGFX Toggle Button Num 2's GPIO"
range 0 39
default 15

endmenu

menu "TouchPad Toggle Input Device Configuration"
depends on UGFX_DRIVER_TOGGLE_TOUCHPAD

config UGFX_TOGGLE_TOUCHPAD_NUM1
int "uGFX Toggle TouchPad Num 1"
range 0 10
default 3
config UGFX_TOGGLE_TOUCHPAD_NUM2
int "uGFX Toggle TouchPad Num 2"
range 0 10
default 9

endmenu

choice UGFX_DRIVER_TOUCH_SCREEN
prompt "Choose Touch Screen Driver"
Expand Down Expand Up @@ -1380,6 +1426,12 @@ menu "IoT Solution settings"
help
"Select to enable LittlevGL touch screen"

config LVGL_DRIVER_TOGGLE_ENABLE
bool "LittlevGL Toggle Input Device Enable"
default n
help
"Select to enable LittlevGL Toggle input device"

choice LVGL_DRIVER_MODE
prompt "Display Driver Mode"
default LVGL_LCD_DRIVER_FRAMEBUFFER_MODE
Expand Down Expand Up @@ -1426,6 +1478,46 @@ menu "IoT Solution settings"

menu "Config Driver"
depends on LVGL_USE_CONFIGURED_OPTIONS

choice LVGL_DRIVER_TOGGLE
prompt "Choose Toggle Input Driver"
depends on LVGL_DRIVER_TOGGLE_ENABLE

config LVGL_DRIVER_TOGGLE_BUTTON
bool "BUTTON"

config LVGL_DRIVER_TOGGLE_TOUCHPAD
bool "TOUCHPAD"

endchoice

menu "Button Toggle Input Device Configuration"
depends on LVGL_DRIVER_TOGGLE_BUTTON

config LVGL_TOGGLE_BUTTON_GPIO1
int "LittlevGL Toggle Button Num 1's GPIO"
range 0 39
default 4
config LVGL_TOGGLE_BUTTON_GPIO2
int "LittlevGL Toggle Button Num 2's GPIO"
range 0 39
default 15

endmenu

menu "TouchPad Toggle Input Device Configuration"
depends on LVGL_DRIVER_TOGGLE_TOUCHPAD

config LVGL_TOGGLE_TOUCHPAD_NUM1
int "LittlevGL Toggle TouchPad Num 1"
range 0 10
default 3
config LVGL_TOGGLE_TOUCHPAD_NUM2
int "LittlevGL Toggle TouchPad Num 2"
range 0 10
default 9

endmenu

choice LVGL_DRIVER_TOUCH_SCREEN
prompt "Choose Touch Screen Driver"
Expand Down
52 changes: 42 additions & 10 deletions components/hmi/gdrivers/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,36 @@ ifdef CONFIG_UGFX_GUI_ENABLE
COMPONENT_ADD_INCLUDEDIRS += ./gdisp/NT35510
endif

#Input driver
#Input driver
#Touch driver
ifdef CONFIG_UGFX_DRIVER_TOUCH_SCREEN_ENABLE

ifdef CONFIG_UGFX_DRIVER_TOUCH_XPT2046
COMPONENT_SRCDIRS += ./ginput/XPT2046
COMPONENT_ADD_INCLUDEDIRS += ./ginput/XPT2046
COMPONENT_SRCDIRS += ./ginput/touch/XPT2046
COMPONENT_ADD_INCLUDEDIRS += ./ginput/touch/XPT2046
endif

ifdef CONFIG_UGFX_DRIVER_TOUCH_FT5X06
COMPONENT_SRCDIRS += ./ginput/FT5X06
COMPONENT_ADD_INCLUDEDIRS += ./ginput/FT5X06
COMPONENT_SRCDIRS += ./ginput/touch/FT5X06
COMPONENT_ADD_INCLUDEDIRS += ./ginput/touch/FT5X06
endif

endif

#Toggle driver
ifdef CONFIG_UGFX_DRIVER_TOGGLE_ENABLE

ifdef CONFIG_UGFX_DRIVER_TOGGLE_BUTTON
COMPONENT_SRCDIRS += ./ginput/toggle/button
COMPONENT_ADD_INCLUDEDIRS += ./ginput/toggle/button
endif

ifdef CONFIG_UGFX_DRIVER_TOGGLE_TOUCHPAD
COMPONENT_SRCDIRS += ./ginput/toggle/touchpad
COMPONENT_ADD_INCLUDEDIRS += ./ginput/toggle/touchpad
endif

endif

endif

Expand Down Expand Up @@ -84,20 +100,36 @@ else
COMPONENT_ADD_INCLUDEDIRS += ./gdisp/NT35510
endif

#Input driver
#Input driver
#Touch driver
ifdef CONFIG_LVGL_DRIVER_TOUCH_SCREEN_ENABLE

ifdef CONFIG_LVGL_DRIVER_TOUCH_XPT2046
COMPONENT_SRCDIRS += ./ginput/XPT2046
COMPONENT_ADD_INCLUDEDIRS += ./ginput/XPT2046
COMPONENT_SRCDIRS += ./ginput/touch/XPT2046
COMPONENT_ADD_INCLUDEDIRS += ./ginput/touch/XPT2046
endif

ifdef CONFIG_LVGL_DRIVER_TOUCH_FT5X06
COMPONENT_SRCDIRS += ./ginput/FT5X06
COMPONENT_ADD_INCLUDEDIRS += ./ginput/FT5X06
COMPONENT_SRCDIRS += ./ginput/touch/FT5X06
COMPONENT_ADD_INCLUDEDIRS += ./ginput/touch/FT5X06
endif

endif

#Toggle driver
ifdef CONFIG_LVGL_DRIVER_TOGGLE_ENABLE

ifdef CONFIG_LVGL_DRIVER_TOGGLE_BUTTON
COMPONENT_SRCDIRS += ./ginput/toggle/button
COMPONENT_ADD_INCLUDEDIRS += ./ginput/toggle/button
endif

ifdef CONFIG_LVGL_DRIVER_TOGGLE_TOUCHPAD
COMPONENT_SRCDIRS += ./ginput/toggle/touchpad
COMPONENT_ADD_INCLUDEDIRS += ./ginput/toggle/touchpad
endif

endif

endif

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/

/* uGFX Config Include */
#include "sdkconfig.h"
#include "esp_log.h"

/* RTOS Includes */
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
#include "freertos/semphr.h"

/* GPIO Include */
#include "driver/gpio.h"

#define BUTTON_QUEUE_LENGTH 10
#define BUTTON_WAITQUEUE_TIME 20 // millisecond

#define GPIO_BUTTON_1 CONFIG_UGFX_TOGGLE_BUTTON_GPIO1
#define GPIO_BUTTON_2 CONFIG_UGFX_TOGGLE_BUTTON_GPIO2
#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_BUTTON_1) | (1ULL<<GPIO_BUTTON_2))

#define ESP_INTR_FLAG_DEFAULT 0

static QueueHandle_t gpio_evt_queue = NULL;

static void IRAM_ATTR gpio_isr_handler(void *arg)
{
gpio_num_t gpio_num = (uint32_t)arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}

static void gpio_toggle_init()
{
gpio_config_t io_conf;
//disable interrupt
io_conf.intr_type = GPIO_INTR_LOW_LEVEL;
//set as output mode
io_conf.mode = GPIO_MODE_INPUT;
//bit mask of the pins that you want to set,e.g.GPIO4/15
io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
gpio_config(&io_conf);

if (gpio_evt_queue == NULL) {
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(BUTTON_QUEUE_LENGTH, sizeof(gpio_num_t));
}

//install gpio isr service
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);

//hook isr handler for specific gpio pin
gpio_isr_handler_add(GPIO_BUTTON_1, gpio_isr_handler, (void *)GPIO_BUTTON_1);
gpio_isr_handler_add(GPIO_BUTTON_2, gpio_isr_handler, (void *)GPIO_BUTTON_2);
}

static unsigned get_gpio_num()
{
gpio_num_t gpio_num;
if (xQueueReceive(gpio_evt_queue, &gpio_num, BUTTON_WAITQUEUE_TIME / portTICK_PERIOD_MS) == pdTRUE) {
return gpio_num;
} else {
return GPIO_NUM_MAX;
}
}

#ifdef CONFIG_UGFX_GUI_ENABLE

/* uGFX Includes */
#include "gos_freertos_priv.h"
#include "gfx.h"

#if (GFX_USE_GINPUT && GINPUT_NEED_TOGGLE) /*|| defined(__DOXYGEN__)*/

#include "src/ginput/ginput_driver_toggle.h"

GINPUT_TOGGLE_DECLARE_STRUCTURE();

void ginput_lld_toggle_init(const GToggleConfig *ptc)
{
gpio_toggle_init();
}

unsigned ginput_lld_toggle_getbits(const GToggleConfig *ptc)
{
static unsigned btn = 0;
switch (get_gpio_num()) {
case GPIO_BUTTON_1:
btn = 1; // number 1 toggle device touch
break;

case GPIO_BUTTON_2:
btn = 2; // number 2 toggle device touch
break;

case GPIO_NUM_MAX:
btn = 0; // no toggle device touch
break;

default:
btn = 0; // no toggle device touch
break;
}
return btn;
}

#endif /* GFX_USE_GINPUT && GINPUT_NEED_TOGGLE */

#endif /* CONFIG_UGFX_GUI_ENABLE */

#ifdef CONFIG_LVGL_GUI_ENABLE

/* lvgl include */
#include "lvgl_indev_config.h"

/*Function pointer to read data. Return 'true' if there is still data to be read (buffered)*/
static bool ex_tp_read(lv_indev_data_t *data)
{
/*Save the lastly pressed/released button's ID*/
static uint32_t btn = 0;
data->state = LV_INDEV_STATE_REL;

switch (get_gpio_num()) {
case GPIO_BUTTON_1:
data->state = LV_INDEV_STATE_PR;
btn = 0; // 0 means: number 1 toggle device button
break;

case GPIO_BUTTON_2:
data->state = LV_INDEV_STATE_PR;
btn = 1; // 1 means: number 2 toggle device button
break;

case GPIO_NUM_MAX:
data->state = LV_INDEV_STATE_REL;
break; // no toggle device button

default:
data->state = LV_INDEV_STATE_REL;
break; // no toggle device button
}
// please be sure that your button driver every time return old (last clcked) value.
data->btn = btn; /*0 ... number of buttons-1*/

// Return 'true' if there is still data to be read (buffered)*/
return false;
}

/* Input device interface,Initialize your input device */
lv_indev_drv_t lvgl_indev_init()
{
gpio_toggle_init();

lv_indev_drv_t indev_drv; /*Descriptor of an input device driver*/
lv_indev_drv_init(&indev_drv); /*Basic initialization*/

indev_drv.type = LV_INDEV_TYPE_BUTTON; /*The touchpad is button type device*/
indev_drv.read = ex_tp_read; /*Library ready your button via this function*/

lv_indev_drv_register(&indev_drv); /*Finally register the driver*/
return indev_drv;
}

/**
* Example :
* static lv_points_t points[] = {{20, 30},{ 50, 70},{100, 150}}; // Points for 3 buttons
* lv_indev_set_button_points(button_indev, points);
*/
#endif /* CONFIG_LVGL_GUI_ENABLE */
Loading

0 comments on commit b29df85

Please sign in to comment.