Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ft5336 touch panel driver and integrate into lvgl #22055

Merged
merged 6 commits into from
Feb 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions boards/arm/mimxrt1050_evk/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ config GPIO_MCUX_IGPIO_5

endif # GPIO_MCUX_IGPIO

config I2C
default y if LVGL

if I2C_MCUX_LPI2C

config I2C_1
Expand All @@ -66,6 +69,19 @@ config UART_MCUX_LPUART_3

endif # UART_MCUX_LPUART

config KSCAN
default y if LVGL

if KSCAN

config KSCAN_FT5336
default y

config KSCAN_INIT_PRIORITY
default 60

endif # KSCAN

if NETWORKING

config NET_L2_ETHERNET
Expand All @@ -81,6 +97,12 @@ if LVGL
config LVGL_DISPLAY_DEV_NAME
default "ELCDIF_1"

config LVGL_POINTER_KSCAN
default y

config LVGL_POINTER_KSCAN_DEV_NAME
default "FT5336"

config LVGL_HOR_RES
default 480

Expand Down
7 changes: 7 additions & 0 deletions boards/arm/mimxrt1050_evk/mimxrt1050_evk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ arduino_serial: &uart3 {};
int1-gpios = <&gpio1 10 0>;
int2-gpios = <&gpio1 11 0>;
};

ft5336@38 {
compatible = "focaltech,ft5336";
reg = <0x38>;
label = "FT5336";
int-gpios = <&gpio1 11 0>;
};
};

&uart1 {
Expand Down
22 changes: 22 additions & 0 deletions boards/arm/mimxrt1060_evk/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ config GPIO_MCUX_IGPIO_5

endif # GPIO_MCUX_IGPIO

config I2C
default y if LVGL

if I2C_MCUX_LPI2C

config I2C_1
Expand All @@ -44,6 +47,19 @@ config UART_MCUX_LPUART_3

endif # UART_MCUX_LPUART

config KSCAN
default y if LVGL

if KSCAN

config KSCAN_FT5336
default y

config KSCAN_INIT_PRIORITY
default 60

endif # KSCAN

if NETWORKING

config NET_L2_ETHERNET
Expand All @@ -59,6 +75,12 @@ if LVGL
config LVGL_DISPLAY_DEV_NAME
default "ELCDIF_1"

config LVGL_POINTER_KSCAN
default y

config LVGL_POINTER_KSCAN_DEV_NAME
default "FT5336"

config LVGL_HOR_RES
default 480

Expand Down
7 changes: 7 additions & 0 deletions boards/arm/mimxrt1060_evk/mimxrt1060_evk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ arduino_serial: &uart3 {};

&i2c1 {
status = "okay";

ft5336@38 {
compatible = "focaltech,ft5336";
reg = <0x38>;
label = "FT5336";
int-gpios = <&gpio1 11 0>;
};
};

&uart1 {
Expand Down
22 changes: 22 additions & 0 deletions boards/arm/mimxrt1064_evk/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ config GPIO_MCUX_IGPIO_5

endif # GPIO_MCUX_IGPIO

config I2C
default y if LVGL

if I2C_MCUX_LPI2C

config I2C_1
Expand All @@ -40,6 +43,19 @@ config UART_MCUX_LPUART_1

endif # UART_MCUX_LPUART

config KSCAN
default y if LVGL

if KSCAN

config KSCAN_FT5336
default y

config KSCAN_INIT_PRIORITY
default 60

endif # KSCAN

if NETWORKING

config NET_L2_ETHERNET
Expand All @@ -55,6 +71,12 @@ if LVGL
config LVGL_DISPLAY_DEV_NAME
default "ELCDIF_1"

config LVGL_POINTER_KSCAN
default y

config LVGL_POINTER_KSCAN_DEV_NAME
default "FT5336"

config LVGL_HOR_RES
default 480

Expand Down
7 changes: 7 additions & 0 deletions boards/arm/mimxrt1064_evk/mimxrt1064_evk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ arduino_i2c: &i2c1 {};
};
};
};

ft5336@38 {
compatible = "focaltech,ft5336";
reg = <0x38>;
label = "FT5336";
int-gpios = <&gpio1 11 0>;
};
};

&uart1 {
Expand Down
1 change: 1 addition & 0 deletions drivers/kscan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

zephyr_library()

zephyr_library_sources_ifdef(CONFIG_KSCAN_FT5336 kscan_ft5336.c)
zephyr_library_sources_ifdef(CONFIG_KSCAN_XEC kscan_mchp_xec.c)

zephyr_library_sources_ifdef(CONFIG_USERSPACE kscan_handlers.c)
1 change: 1 addition & 0 deletions drivers/kscan/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ menuconfig KSCAN

if KSCAN

source "drivers/kscan/Kconfig.ft5336"
source "drivers/kscan/Kconfig.xec"

module = KSCAN
Expand Down
16 changes: 16 additions & 0 deletions drivers/kscan/Kconfig.ft5336
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2020 NXP
# SPDX-License-Identifier: Apache-2.0

menuconfig KSCAN_FT5336
bool "FT5336 capacitive touch panel driver"
depends on I2C && HAS_DTS_I2C
help
Enable driver for the FT5336 capacitive touch panel controller.

if KSCAN_FT5336

config KSCAN_FT5336_PERIOD
int "Sample period (ms)"
default 10

endif # KSCAN_FT5336
151 changes: 151 additions & 0 deletions drivers/kscan/kscan_ft5336.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* Copyright (c) 2020 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <drivers/kscan.h>
#include <drivers/i2c.h>
#include <logging/log.h>

LOG_MODULE_REGISTER(ft5336, CONFIG_KSCAN_LOG_LEVEL);

#define FT5406_DATA_SIZE 0x20

enum ft5336_event {
FT5336_EVENT_DOWN = 0,
FT5336_EVENT_UP = 1,
FT5336_EVENT_CONTACT = 2,
FT5336_EVENT_RESERVED = 3,
};

struct ft5336_config {
char *i2c_name;
u8_t i2c_address;
};

struct ft5336_data {
struct device *i2c;
kscan_callback_t callback;
struct k_work work;
struct k_timer timer;
struct device *dev;
};

static int ft5336_read(struct device *dev)
{
const struct ft5336_config *config = dev->config->config_info;
struct ft5336_data *data = dev->driver_data;
u8_t buffer[FT5406_DATA_SIZE];
u8_t event;
u16_t row, column;
bool pressed;

if (i2c_burst_read(data->i2c, config->i2c_address, 1, buffer,
sizeof(buffer))) {
LOG_ERR("Could not read point");
return -EIO;
}

event = buffer[2] >> 6;
pressed = (event == FT5336_EVENT_DOWN) ||
(event == FT5336_EVENT_CONTACT);

row = ((buffer[2] & 0x0f) << 8) | buffer[3];
column = ((buffer[4] & 0x0f) << 8) | buffer[5];

data->callback(dev, row, column, pressed);

return 0;
}

static void ft5336_timer_handler(struct k_timer *timer)
{
struct ft5336_data *data =
CONTAINER_OF(timer, struct ft5336_data, timer);

k_work_submit(&data->work);
}

static void ft5336_work_handler(struct k_work *work)
{
struct ft5336_data *data =
CONTAINER_OF(work, struct ft5336_data, work);

ft5336_read(data->dev);
}

static int ft5336_configure(struct device *dev, kscan_callback_t callback)
{
struct ft5336_data *data = dev->driver_data;

if (!callback) {
return -EINVAL;
}

data->callback = callback;

return 0;
}

static int ft5336_enable_callback(struct device *dev)
{
struct ft5336_data *data = dev->driver_data;

k_timer_start(&data->timer, K_MSEC(CONFIG_KSCAN_FT5336_PERIOD),
K_MSEC(CONFIG_KSCAN_FT5336_PERIOD));

return 0;
}

static int ft5336_disable_callback(struct device *dev)
{
struct ft5336_data *data = dev->driver_data;

k_timer_stop(&data->timer);

return 0;
}

static int ft5336_init(struct device *dev)
{
const struct ft5336_config *config = dev->config->config_info;
struct ft5336_data *data = dev->driver_data;

data->i2c = device_get_binding(config->i2c_name);
if (data->i2c == NULL) {
LOG_ERR("Could not find I2C device");
return -EINVAL;
}

if (i2c_reg_write_byte(data->i2c, config->i2c_address, 0, 0)) {
LOG_ERR("Could not enable");
return -EINVAL;
}

data->dev = dev;

k_work_init(&data->work, ft5336_work_handler);
k_timer_init(&data->timer, ft5336_timer_handler, NULL);

return 0;
}


static const struct kscan_driver_api ft5336_driver_api = {
.config = ft5336_configure,
.enable_callback = ft5336_enable_callback,
.disable_callback = ft5336_disable_callback,
};

static const struct ft5336_config ft5336_config = {
.i2c_name = DT_INST_0_FOCALTECH_FT5336_BUS_NAME,
.i2c_address = DT_INST_0_FOCALTECH_FT5336_BASE_ADDRESS,
};

static struct ft5336_data ft5336_data;

DEVICE_AND_API_INIT(ft5336, DT_INST_0_FOCALTECH_FT5336_LABEL, ft5336_init,
&ft5336_data, &ft5336_config,
POST_KERNEL, CONFIG_KSCAN_INIT_PRIORITY,
&ft5336_driver_api);
13 changes: 13 additions & 0 deletions dts/bindings/kscan/focaltech,ft5336.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2020 NXP
# SPDX-License-Identifier: Apache-2.0

description: FT5336 capacitive touch panel

compatible: "focaltech,ft5336"

include: [kscan.yaml, i2c-device.yaml]

properties:
int-gpios:
type: phandle-array
required: false
6 changes: 0 additions & 6 deletions dts/bindings/kscan/kscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,5 @@ include: base.yaml
bus: kscan

properties:
"#address-cells":
required: true
const: 1
"#size-cells":
type: int
const: 0
label:
required: true
6 changes: 6 additions & 0 deletions dts/bindings/kscan/microchip,xec-kscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ compatible: "microchip,xec-kscan"
include: kscan.yaml

properties:
"#address-cells":
required: true
const: 1
"#size-cells":
type: int
const: 0
reg:
required: true

Expand Down
Loading