From 48d7cf4af9f26fc9dcc09283831efa5dbbea269c Mon Sep 17 00:00:00 2001 From: tyustli <1225613647@qq.com> Date: Fri, 25 Dec 2020 17:31:16 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91=E8=A7=A3?= =?UTF-8?q?=E8=80=A6=20touch=20=E5=92=8C=20pin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/Kconfig | 5 +++++ components/drivers/touch/touch.c | 26 ++++++++++++++++++-------- components/drivers/touch/touch.h | 5 +++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 198f1bbbf8..006497519f 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -291,6 +291,11 @@ endif config RT_USING_TOUCH bool "Using Touch device drivers" default n + if RT_USING_TOUCH + config RT_TOUCH_PIN_IRQ + bool "touch irq use pin irq" + default n + endif menuconfig RT_USING_HWCRYPTO bool "Using Hardware Crypto drivers" diff --git a/components/drivers/touch/touch.c b/components/drivers/touch/touch.c index 80ba6378bb..e9595e9f8f 100644 --- a/components/drivers/touch/touch.c +++ b/components/drivers/touch/touch.c @@ -16,12 +16,9 @@ #include /* ISR for touch interrupt */ -static void irq_callback(void *args) +void rt_hw_touch_isr(rt_touch_t touch) { - rt_touch_t touch; - - touch = (rt_touch_t)args; - + RT_ASSERT(touch); if (touch->parent.rx_indicate == RT_NULL) { return; @@ -35,9 +32,17 @@ static void irq_callback(void *args) touch->parent.rx_indicate(&touch->parent, 1); } +#ifdef RT_TOUCH_PIN_IRQ +static void touch_irq_callback(void *param) +{ + rt_hw_touch_isr((rt_touch_t)param); +} +#endif + /* touch interrupt initialization function */ static rt_err_t rt_touch_irq_init(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin == RT_PIN_NONE) { return -RT_EINVAL; @@ -47,18 +52,19 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch) if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLDOWN) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING, touch_irq_callback, (void *)touch); } else if (touch->config.irq_pin.mode == PIN_MODE_INPUT_PULLUP) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_FALLING, touch_irq_callback, (void *)touch); } else if (touch->config.irq_pin.mode == PIN_MODE_INPUT) { - rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, irq_callback, (void *)touch); + rt_pin_attach_irq(touch->config.irq_pin.pin, PIN_IRQ_MODE_RISING_FALLING, touch_irq_callback, (void *)touch); } rt_pin_irq_enable(touch->config.irq_pin.pin, PIN_IRQ_ENABLE); +#endif return RT_EOK; } @@ -66,19 +72,23 @@ static rt_err_t rt_touch_irq_init(rt_touch_t touch) /* touch interrupt enable */ static void rt_touch_irq_enable(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin != RT_PIN_NONE) { rt_pin_irq_enable(touch->config.irq_pin.pin, RT_TRUE); } +#endif } /* touch interrupt disable */ static void rt_touch_irq_disable(rt_touch_t touch) { +#ifdef RT_TOUCH_PIN_IRQ if (touch->config.irq_pin.pin != RT_PIN_NONE) { rt_pin_irq_enable(touch->config.irq_pin.pin, RT_FALSE); } +#endif } static rt_err_t rt_touch_open(rt_device_t dev, rt_uint16_t oflag) diff --git a/components/drivers/touch/touch.h b/components/drivers/touch/touch.h index c33fe17520..be12c24206 100644 --- a/components/drivers/touch/touch.h +++ b/components/drivers/touch/touch.h @@ -66,7 +66,9 @@ struct rt_touch_info struct rt_touch_config { +#ifdef RT_TOUCH_PIN_IRQ struct rt_device_pin_mode irq_pin; /* Interrupt pin, The purpose of this pin is to notification read data */ +#endif char *dev_name; /* The name of the communication device */ void *user_data; }; @@ -103,6 +105,9 @@ int rt_hw_touch_register(rt_touch_t touch, rt_uint32_t flag, void *data); +/* if you doesn't use pin device. you must call this function in your touch irq callback */ +void rt_hw_touch_isr(rt_touch_t touch); + #ifdef __cplusplus } #endif