Skip to content

Commit

Permalink
driver: input: esp32 touch_sensor: fixes conflict with COUNTER_RTC_ESP32
Browse files Browse the repository at this point in the history
Fixes conflict with COUNTER_RTC_ESP32 by changing isr registration strategy

Signed-off-by: Marcio Ribeiro <[email protected]>
  • Loading branch information
wmrsouza committed Oct 15, 2024
1 parent 6e9c604 commit 762910a
Showing 1 changed file with 39 additions and 83 deletions.
122 changes: 39 additions & 83 deletions drivers/input/input_esp32_touch_sensor.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -16,14 +16,13 @@
#include <soc/periph_defs.h>
#include <hal/touch_sensor_types.h>
#include <hal/touch_sensor_hal.h>
#include <driver/touch_sensor_common.h>
#include <driver/rtc_io.h>
#include <esp_private/rtc_ctrl.h>
#include <esp_intr_alloc.h>

LOG_MODULE_REGISTER(espressif_esp32_touch, CONFIG_INPUT_LOG_LEVEL);

BUILD_ASSERT(!IS_ENABLED(CONFIG_COUNTER_RTC_ESP32),
"Conflict detected: COUNTER_RTC_ESP32 enabled");

#define ESP32_SCAN_DONE_MAX_COUNT 5

#if defined(CONFIG_SOC_SERIES_ESP32)
Expand Down Expand Up @@ -73,14 +72,9 @@ struct esp32_touch_sensor_channel_data {
#endif /* defined(CONFIG_SOC_SERIES_ESP32S2) || defined(CONFIG_SOC_SERIES_ESP32S3) */
};

struct esp32_touch_sensor_data {
uint32_t rtc_intr_msk;
};

static void esp32_touch_sensor_interrupt_cb(void *arg)
static void esp32_touch_sensor_isr_handler(void *arg)
{
const struct device *dev = arg;
struct esp32_touch_sensor_data *dev_data = dev->data;
const struct esp32_touch_sensor_config *dev_cfg = dev->config;
const struct esp32_touch_sensor_channel_config *channel_cfg;
const int num_channels = dev_cfg->num_channels;
Expand Down Expand Up @@ -140,37 +134,6 @@ static void esp32_touch_sensor_interrupt_cb(void *arg)
}
}

static void esp32_rtc_isr(void *arg)
{
uint32_t status = REG_READ(RTC_CNTL_INT_ST_REG);

if (arg != NULL) {
const struct device *dev = arg;
struct esp32_touch_sensor_data *dev_data = dev->data;

if (dev_data->rtc_intr_msk & status) {
esp32_touch_sensor_interrupt_cb(arg);
}
}

REG_WRITE(RTC_CNTL_INT_CLR_REG, status);
}

static esp_err_t esp32_rtc_isr_install(intr_handler_t intr_handler, const void *handler_arg)
{
esp_err_t err;

REG_WRITE(RTC_CNTL_INT_ENA_REG, 0);
REG_WRITE(RTC_CNTL_INT_CLR_REG, UINT32_MAX);

err = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, irq),
ESP_PRIO_TO_FLAGS(DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, priority)) |
ESP_INT_FLAGS_CHECK(DT_IRQ_BY_IDX(DT_NODELABEL(touch), 0, flags)),
intr_handler, (void *)handler_arg, NULL);

return err;
}

/**
* Handle debounced touch sensor touch state.
*/
Expand Down Expand Up @@ -198,7 +161,6 @@ static void esp32_touch_sensor_change_deferred(struct k_work *work)

static int esp32_touch_sensor_init(const struct device *dev)
{
struct esp32_touch_sensor_data *dev_data = dev->data;
const struct esp32_touch_sensor_config *dev_cfg = dev->config;
const int num_channels = dev_cfg->num_channels;

Expand Down Expand Up @@ -293,8 +255,8 @@ static int esp32_touch_sensor_init(const struct device *dev)
touch_hal_timeout_set_threshold(SOC_TOUCH_PAD_THRESHOLD_MAX);
#endif /* defined(CONFIG_SOC_SERIES_ESP32) */

dev_data->rtc_intr_msk = ESP32_RTC_INTR_MSK;
esp32_rtc_isr_install(&esp32_rtc_isr, dev);
rtc_isr_register(esp32_touch_sensor_isr_handler, (void *)dev, ESP32_RTC_INTR_MSK, 0);

#if defined(CONFIG_SOC_SERIES_ESP32)
touch_hal_intr_enable();
#elif defined(CONFIG_SOC_SERIES_ESP32S2) || defined(CONFIG_SOC_SERIES_ESP32S3)
Expand All @@ -307,46 +269,40 @@ static int esp32_touch_sensor_init(const struct device *dev)
return 0;
}

#define ESP32_TOUCH_SENSOR_CHANNEL_CFG_INIT(node_id) \
{ \
.channel_num = DT_PROP(node_id, channel_num), \
.channel_sens = DT_PROP(node_id, channel_sens), \
.zephyr_code = DT_PROP(node_id, zephyr_code), \
#define ESP32_TOUCH_SENSOR_CHANNEL_CFG_INIT(node_id) \
{ \
.channel_num = DT_PROP(node_id, channel_num), \
.channel_sens = DT_PROP(node_id, channel_sens), \
.zephyr_code = DT_PROP(node_id, zephyr_code), \
}

#define ESP32_TOUCH_SENSOR_INIT(inst) \
static const struct esp32_touch_sensor_channel_config \
esp32_touch_sensor_channel_config_##inst[] = { \
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(inst, \
ESP32_TOUCH_SENSOR_CHANNEL_CFG_INIT, (,)) \
}; \
\
static struct esp32_touch_sensor_channel_data esp32_touch_sensor_channel_data_##inst \
[ARRAY_SIZE(esp32_touch_sensor_channel_config_##inst)]; \
\
static const struct esp32_touch_sensor_config esp32_touch_sensor_config_##inst = { \
.debounce_interval_ms = DT_INST_PROP(inst, debounce_interval_ms), \
.num_channels = ARRAY_SIZE(esp32_touch_sensor_channel_config_##inst), \
.href_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, href_microvolt), \
.lref_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, lref_microvolt), \
.href_atten_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, href_atten_microvolt), \
.filter_mode = DT_INST_PROP(inst, filter_mode), \
.filter_debounce_cnt = DT_INST_PROP(inst, filter_debounce_cnt), \
.filter_noise_thr = DT_INST_PROP(inst, filter_noise_thr), \
.filter_jitter_step = DT_INST_PROP(inst, filter_jitter_step), \
.filter_smooth_level = DT_INST_PROP(inst, filter_smooth_level), \
.channel_cfg = esp32_touch_sensor_channel_config_##inst, \
.channel_data = esp32_touch_sensor_channel_data_##inst, \
}; \
\
static struct esp32_touch_sensor_data esp32_touch_sensor_data_##inst; \
\
DEVICE_DT_INST_DEFINE(inst, \
&esp32_touch_sensor_init, \
NULL, \
&esp32_touch_sensor_data_##inst, \
&esp32_touch_sensor_config_##inst, \
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \
NULL);
#define ESP32_TOUCH_SENSOR_INIT(inst) \
static const struct esp32_touch_sensor_channel_config \
esp32_touch_sensor_channel_config_##inst[] = { \
DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP( \
inst, ESP32_TOUCH_SENSOR_CHANNEL_CFG_INIT, (, ))}; \

Check failure on line 283 in drivers/input/input_esp32_touch_sensor.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

SPACING

drivers/input/input_esp32_touch_sensor.c:283 space prohibited before that close parenthesis ')'
\
static struct esp32_touch_sensor_channel_data \
esp32_touch_sensor_channel_data_##inst[ARRAY_SIZE( \
esp32_touch_sensor_channel_config_##inst)]; \
\
static const struct esp32_touch_sensor_config esp32_touch_sensor_config_##inst = { \
.debounce_interval_ms = DT_INST_PROP(inst, debounce_interval_ms), \
.num_channels = ARRAY_SIZE(esp32_touch_sensor_channel_config_##inst), \
.href_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, href_microvolt), \
.lref_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, lref_microvolt), \
.href_atten_microvolt_enum_idx = DT_INST_ENUM_IDX(inst, href_atten_microvolt), \
.filter_mode = DT_INST_PROP(inst, filter_mode), \
.filter_debounce_cnt = DT_INST_PROP(inst, filter_debounce_cnt), \
.filter_noise_thr = DT_INST_PROP(inst, filter_noise_thr), \
.filter_jitter_step = DT_INST_PROP(inst, filter_jitter_step), \
.filter_smooth_level = DT_INST_PROP(inst, filter_smooth_level), \
.channel_cfg = esp32_touch_sensor_channel_config_##inst, \
.channel_data = esp32_touch_sensor_channel_data_##inst, \
}; \
\
DEVICE_DT_INST_DEFINE(inst, &esp32_touch_sensor_init, NULL, NULL, \
&esp32_touch_sensor_config_##inst, POST_KERNEL, \
CONFIG_INPUT_INIT_PRIORITY, NULL);

DT_INST_FOREACH_STATUS_OKAY(ESP32_TOUCH_SENSOR_INIT)

0 comments on commit 762910a

Please sign in to comment.