arch/xtensa/esp32: Add initial support for touch pad polling

This commit is contained in:
Lucas Saavedra Vaz
2022-12-13 16:11:34 -03:00
committed by Xiang Xiao
parent b8ef8daef9
commit 773e3fad43
8 changed files with 2681 additions and 240 deletions
+4
View File
@@ -179,6 +179,10 @@ ifeq ($(CONFIG_ESP32_RT_TIMER),y)
CHIP_CSRCS += esp32_rt_timer.c
endif
ifeq ($(CONFIG_ESP32_TOUCH),y)
CHIP_CSRCS += esp32_touch.c
endif
ifeq ($(CONFIG_ESP32_AES_ACCELERATOR),y)
CHIP_CSRCS += esp32_aes.c
endif
+255 -121
View File
@@ -37,6 +37,7 @@
#include "hardware/esp32_iomux.h"
#include "hardware/esp32_gpio.h"
#include "hardware/esp32_soc.h"
#include "esp32_irq.h"
#include "esp32_rtc_gpio.h"
@@ -47,9 +48,11 @@
* Pre-processor Definitions
****************************************************************************/
#define NGPIO_HPINS (ESP32_NIRQ_GPIO - 32)
#define NGPIO_HMASK ((1ul << NGPIO_HPINS) - 1)
#define _NA_ 0xff
#define NGPIO_HPINS (ESP32_NIRQ_GPIO - 32)
#define NGPIO_HMASK ((UINT32_C(1) << NGPIO_HPINS) - 1)
#define _NA_ 0xff
#define setbits(a, bs) modifyreg32(a, 0, bs)
#define resetbits(a, bs) modifyreg32(a, bs, 0)
/****************************************************************************
* Private Data
@@ -68,6 +71,30 @@ static const uint8_t g_pin2func[40] =
0x1c, 0x20, 0x14, 0x18, 0x04, 0x08, 0x0c, 0x10 /* 32-39 */
};
static const uint32_t rtc_gpio_to_addr[] =
{
RTC_GPIO_PIN0_REG,
RTC_GPIO_PIN1_REG,
RTC_GPIO_PIN2_REG,
RTC_GPIO_PIN3_REG,
RTC_GPIO_PIN4_REG,
RTC_GPIO_PIN5_REG,
RTC_GPIO_PIN6_REG,
RTC_GPIO_PIN7_REG,
RTC_GPIO_PIN8_REG,
RTC_GPIO_PIN9_REG,
RTC_GPIO_PIN10_REG,
RTC_GPIO_PIN11_REG,
RTC_GPIO_PIN12_REG,
RTC_GPIO_PIN13_REG,
RTC_GPIO_PIN14_REG,
RTC_GPIO_PIN15_REG,
RTC_GPIO_PIN16_REG,
RTC_GPIO_PIN17_REG
};
static bool g_pin_rtc_controlled[RTC_GPIO_NUMBER];
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -105,7 +132,7 @@ static void gpio_dispatch(int irq, uint32_t status, uint32_t *regs)
{
/* Check if there is an interrupt pending for this pin */
mask = (1ul << i);
mask = (UINT32_C(1) << i);
if ((status & mask) != 0)
{
/* Yes... perform the second level dispatch */
@@ -185,6 +212,8 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
uintptr_t regaddr;
uint32_t func;
uint32_t cntrl;
uint32_t rtc_gpio_idx;
rtc_io_desc_t rtc_reg_desc;
DEBUGASSERT(pin >= 0 && pin <= ESP32_NGPIOS);
@@ -193,148 +222,251 @@ int esp32_configgpio(int pin, gpio_pinattr_t attr)
func = 0;
cntrl = 0;
if ((attr & INPUT) != 0)
if ((attr & FUNCTION_MASK) == FUNCTION_RTC) /* RTCIO */
{
if (pin < 32)
if (rtc_gpio_is_valid_gpio(pin) == 0)
{
putreg32((1ul << pin), GPIO_ENABLE_W1TC_REG);
gpioerr("Pin %d is not a valid RTC pin!\n", pin);
return -1;
}
rtc_gpio_idx = g_rtc_io_num_map[pin];
rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
g_pin_rtc_controlled[rtc_gpio_idx] = true;
setbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
modifyreg32(rtc_reg_desc.reg,
((RTC_IO_TOUCH_PAD1_FUN_SEL_V) << (rtc_reg_desc.func)),
(((RTCIO_PIN_FUNC) & RTC_IO_TOUCH_PAD1_FUN_SEL_V) <<
(rtc_reg_desc.func)));
resetbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
resetbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
if ((attr & PULLUP) != 0)
{
if (rtc_reg_desc.pullup)
{
setbits(rtc_reg_desc.reg, rtc_reg_desc.pullup);
}
}
else if ((attr & PULLDOWN) != 0)
{
if (rtc_reg_desc.pulldown)
{
setbits(rtc_reg_desc.reg, rtc_reg_desc.pulldown);
}
}
if ((attr & INPUT) != 0)
{
/* Enable Input */
setbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
/* Disable Output */
putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
}
else if ((attr & OUTPUT) != 0)
{
/* Disable Input */
resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
/* Enable Output */
putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TS_REG);
}
else
{
putreg32((1ul << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
resetbits(rtc_reg_desc.reg, rtc_reg_desc.ie);
putreg32((UINT32_C(1) << pin), RTC_GPIO_ENABLE_W1TC_REG);
}
/* Input enable */
func |= FUN_IE;
/* Some pins only support Pull-Up and Pull-Down resistor on RTC GPIO */
if (rtc_gpio_is_valid_gpio(pin))
if ((attr & DRIVE_MASK) != 0)
{
uint32_t rtc_gpio_idx = g_rtc_io_num_map[pin];
if (rtc_gpio_idx >= RTCIO_GPIO34_IDX)
if (rtc_reg_desc.drv_v)
{
gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
modifyreg32(rtc_reg_desc.reg,
((rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)),
(((val) & rtc_reg_desc.drv_v) << (rtc_reg_desc.drv_s)));
}
}
if ((attr & OPEN_DRAIN) != 0)
{
/* All RTC GPIOs have the same position for the drive bits.
* We can use any RTC_GPIO_PINn_PAD_DRIVER.
*/
REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
RTC_GPIO_PIN0_PAD_DRIVER,
true);
}
else
{
REG_SET_FIELD(rtc_gpio_to_addr[rtc_gpio_idx],
RTC_GPIO_PIN0_PAD_DRIVER,
false);
}
return OK;
}
else /* GPIO */
{
if ((attr & INPUT) != 0)
{
if (pin < 32)
{
putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TC_REG);
}
else
{
uint32_t regval;
uint32_t rtc_gpio_pin;
bool en_pu = false;
bool en_pd = false;
putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TC_REG);
}
if ((attr & PULLUP) != 0)
/* Input enable */
func |= FUN_IE;
/* Some pins only support Pull-Up/Pull-Down resistor on RTC GPIO */
if (rtc_gpio_is_valid_gpio(pin))
{
rtc_gpio_idx = g_rtc_io_num_map[pin];
rtc_reg_desc = g_rtc_io_desc[rtc_gpio_idx];
g_pin_rtc_controlled[rtc_gpio_idx] = false;
/* Disable RTC control */
resetbits(rtc_reg_desc.reg, rtc_reg_desc.mux);
if (rtc_reg_desc.pullup == 0)
{
en_pu = true;
}
else if ((attr & PULLDOWN) != 0)
{
en_pd = true;
}
/* Get the pin register */
rtc_gpio_pin = g_rtc_io_desc[rtc_gpio_idx];
/* Read the current value from RTC GPIO pin */
regval = getreg32(rtc_gpio_pin);
/* RTC_IO_X32P (GPIO32) uses different PU/PD bits */
if (rtc_gpio_idx == RTCIO_GPIO32_IDX)
{
/* First, disable PU/PD */
regval &= ~SPECIAL_RTC_PU_BIT;
regval &= ~SPECIAL_RTC_PD_BIT;
/* Enable PU/PD, if needed */
regval |= en_pu ? SPECIAL_RTC_PU_BIT : 0;
regval |= en_pd ? SPECIAL_RTC_PD_BIT : 0;
gpioerr("Pins 34-39 don't support PullUp/PullDown\n");
assert(0);
}
else
{
/* First, disable PU/PD */
uint32_t regval;
uint32_t rtc_gpio_reg;
bool en_pu = false;
bool en_pd = false;
regval &= ~DEFAULT_RTC_PU_BIT;
regval &= ~DEFAULT_RTC_PD_BIT;
if ((attr & PULLUP) != 0)
{
en_pu = true;
}
else if ((attr & PULLDOWN) != 0)
{
en_pd = true;
}
/* Enable PU/PD, if needed */
/* Get the pin register */
regval |= en_pu ? DEFAULT_RTC_PU_BIT : 0;
regval |= en_pd ? DEFAULT_RTC_PD_BIT : 0;
rtc_gpio_reg = g_rtc_io_desc[rtc_gpio_idx].reg;
/* Read the current value from RTC GPIO pin */
regval = getreg32(rtc_gpio_reg);
/* RTC_IO_X32P (GPIO32) uses different PU/PD bits */
if (rtc_gpio_idx == RTCIO_GPIO32_CHANNEL)
{
/* First, disable PU/PD */
regval &= ~SPECIAL_RTC_PU_BIT;
regval &= ~SPECIAL_RTC_PD_BIT;
/* Enable PU/PD, if needed */
regval |= en_pu ? SPECIAL_RTC_PU_BIT : 0;
regval |= en_pd ? SPECIAL_RTC_PD_BIT : 0;
}
else
{
/* First, disable PU/PD */
regval &= ~DEFAULT_RTC_PU_BIT;
regval &= ~DEFAULT_RTC_PD_BIT;
/* Enable PU/PD, if needed */
regval |= en_pu ? DEFAULT_RTC_PU_BIT : 0;
regval |= en_pd ? DEFAULT_RTC_PD_BIT : 0;
}
putreg32(regval, rtc_gpio_reg);
}
putreg32(regval, rtc_gpio_pin);
}
else if ((attr & PULLUP) != 0)
{
func |= FUN_PU;
}
else if (attr & PULLDOWN)
{
func |= FUN_PD;
}
}
else if ((attr & PULLUP) != 0)
{
func |= FUN_PU;
}
else if (attr & PULLDOWN)
{
func |= FUN_PD;
}
}
/* Handle output pins */
/* Handle output pins */
if ((attr & OUTPUT) != 0)
{
if (pin < 32)
if ((attr & OUTPUT) != 0)
{
putreg32((1ul << pin), GPIO_ENABLE_W1TS_REG);
if (pin < 32)
{
putreg32((UINT32_C(1) << pin), GPIO_ENABLE_W1TS_REG);
}
else
{
putreg32((UINT32_C(1) << (pin - 32)), GPIO_ENABLE1_W1TS_REG);
}
}
/* Configure the pad's function */
if ((attr & FUNCTION_MASK) != 0)
{
uint32_t val = ((attr & FUNCTION_MASK) >> FUNCTION_SHIFT) - 1;
func |= val << MCU_SEL_S;
}
else
{
putreg32((1ul << (pin - 32)), GPIO_ENABLE1_W1TS_REG);
/* Function not provided, assuming function GPIO by default */
func |= (uint32_t)(PIN_FUNC_GPIO << MCU_SEL_S);
}
/* Configure the pad's drive strength */
if ((attr & DRIVE_MASK) != 0)
{
uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
func |= val << FUN_DRV_S;
}
else
{
/* Drive strength not provided, assuming strength 2 by default */
func |= UINT32_C(2) << FUN_DRV_S;
}
if ((attr & OPEN_DRAIN) != 0)
{
cntrl |= (1 << GPIO_PIN_PAD_DRIVER_S);
}
regaddr = DR_REG_IO_MUX_BASE + g_pin2func[pin];
putreg32(func, regaddr);
regaddr = GPIO_REG(pin);
putreg32(cntrl, regaddr);
return OK;
}
/* Configure the pad's function */
if ((attr & FUNCTION_MASK) != 0)
{
uint32_t val = ((attr & FUNCTION_MASK) >> FUNCTION_SHIFT) - 1;
func |= val << MCU_SEL_S;
}
else
{
/* Function not provided, assuming function GPIO by default */
func |= (uint32_t)(PIN_FUNC_GPIO << MCU_SEL_S);
}
/* Configure the pad's drive strength */
if ((attr & DRIVE_MASK) != 0)
{
uint32_t val = ((attr & DRIVE_MASK) >> DRIVE_SHIFT) - 1;
func |= val << FUN_DRV_S;
}
else
{
/* Drive strength not provided, assuming strength 2 by default */
func |= UINT32_C(2) << FUN_DRV_S;
}
if ((attr & OPEN_DRAIN) != 0)
{
cntrl |= (1 << GPIO_PIN_PAD_DRIVER_S);
}
regaddr = DR_REG_IO_MUX_BASE + g_pin2func[pin];
putreg32(func, regaddr);
regaddr = GPIO_REG(pin);
putreg32(cntrl, regaddr);
return OK;
}
/****************************************************************************
@@ -353,22 +485,24 @@ void esp32_gpiowrite(int pin, bool value)
{
if (pin < 32)
{
putreg32((uint32_t)(1ul << pin), GPIO_OUT_W1TS_REG);
putreg32((uint32_t)(UINT32_C(1) << pin), GPIO_OUT_W1TS_REG);
}
else
{
putreg32((uint32_t)(1ul << (pin - 32)), GPIO_OUT1_W1TS_REG);
putreg32((uint32_t)(UINT32_C(1) << (pin - 32)),
GPIO_OUT1_W1TS_REG);
}
}
else
{
if (pin < 32)
{
putreg32((uint32_t)(1ul << pin), GPIO_OUT_W1TC_REG);
putreg32((uint32_t)(UINT32_C(1) << pin), GPIO_OUT_W1TC_REG);
}
else
{
putreg32((uint32_t)(1ul << (pin - 32)), GPIO_OUT1_W1TC_REG);
putreg32((uint32_t)(UINT32_C(1) << (pin - 32)),
GPIO_OUT1_W1TC_REG);
}
}
}
@@ -579,11 +713,11 @@ void esp32_gpio_matrix_out(uint32_t gpio, uint32_t signal_idx, bool out_inv,
if (gpio < 32)
{
putreg32((1ul << gpio), GPIO_ENABLE_W1TS_REG);
putreg32((UINT32_C(1) << gpio), GPIO_ENABLE_W1TS_REG);
}
else
{
putreg32((1ul << (gpio - 32)), GPIO_ENABLE1_W1TS_REG);
putreg32((UINT32_C(1) << (gpio - 32)), GPIO_ENABLE1_W1TS_REG);
}
if (out_inv)
+42 -39
View File
@@ -47,49 +47,52 @@
* FN FN FN OD PD PU F O I
*/
#define PINMODE_SHIFT 0
#define PINMODE_MASK (7 << PINMODE_SHIFT)
# define INPUT (1 << 0)
# define OUTPUT (1 << 1)
# define FUNCTION (1 << 2)
#define PINMODE_SHIFT 0
#define PINMODE_MASK (7 << PINMODE_SHIFT)
# define INPUT (1 << 0)
# define OUTPUT (1 << 1)
# define FUNCTION (1 << 2)
#define PULLUP (1 << 3)
#define PULLDOWN (1 << 4)
#define OPEN_DRAIN (1 << 5)
#define PULLUP (1 << 3)
#define PULLDOWN (1 << 4)
#define OPEN_DRAIN (1 << 5)
#define FUNCTION_SHIFT 6
#define FUNCTION_MASK (7 << FUNCTION_SHIFT)
# define FUNCTION_1 (1 << FUNCTION_SHIFT)
# define FUNCTION_2 (2 << FUNCTION_SHIFT)
# define FUNCTION_3 (3 << FUNCTION_SHIFT)
# define FUNCTION_4 (4 << FUNCTION_SHIFT)
# define FUNCTION_5 (5 << FUNCTION_SHIFT)
# define FUNCTION_6 (6 << FUNCTION_SHIFT)
#define FUNCTION_SHIFT 6
#define FUNCTION_MASK (7 << FUNCTION_SHIFT)
# define FUNCTION_1 (1 << FUNCTION_SHIFT)
# define FUNCTION_2 (2 << FUNCTION_SHIFT)
# define FUNCTION_3 (3 << FUNCTION_SHIFT)
# define FUNCTION_4 (4 << FUNCTION_SHIFT)
# define FUNCTION_5 (5 << FUNCTION_SHIFT)
# define FUNCTION_6 (6 << FUNCTION_SHIFT)
# define FUNCTION_RTC (7 << FUNCTION_SHIFT)
#define DRIVE_SHIFT 9
#define DRIVE_MASK (7 << DRIVE_SHIFT)
# define DRIVE_0 (1 << DRIVE_SHIFT)
# define DRIVE_1 (2 << DRIVE_SHIFT)
# define DRIVE_2 (3 << DRIVE_SHIFT)
# define DRIVE_3 (4 << DRIVE_SHIFT)
#define DRIVE_SHIFT 9
#define DRIVE_MASK (7 << DRIVE_SHIFT)
# define DRIVE_0 (1 << DRIVE_SHIFT)
# define DRIVE_1 (2 << DRIVE_SHIFT)
# define DRIVE_2 (3 << DRIVE_SHIFT)
# define DRIVE_3 (4 << DRIVE_SHIFT)
#define INPUT_PULLUP (INPUT | PULLUP)
#define INPUT_PULLDOWN (INPUT | PULLDOWN)
#define OUTPUT_OPEN_DRAIN (OUTPUT | OPEN_DRAIN)
#define INPUT_FUNCTION (INPUT | FUNCTION)
# define INPUT_FUNCTION_1 (INPUT_FUNCTION | FUNCTION_1)
# define INPUT_FUNCTION_2 (INPUT_FUNCTION | FUNCTION_2)
# define INPUT_FUNCTION_3 (INPUT_FUNCTION | FUNCTION_3)
# define INPUT_FUNCTION_4 (INPUT_FUNCTION | FUNCTION_4)
# define INPUT_FUNCTION_5 (INPUT_FUNCTION | FUNCTION_5)
# define INPUT_FUNCTION_6 (INPUT_FUNCTION | FUNCTION_6)
#define OUTPUT_FUNCTION (OUTPUT | FUNCTION)
# define OUTPUT_FUNCTION_1 (OUTPUT_FUNCTION | FUNCTION_1)
# define OUTPUT_FUNCTION_2 (OUTPUT_FUNCTION | FUNCTION_2)
# define OUTPUT_FUNCTION_3 (OUTPUT_FUNCTION | FUNCTION_3)
# define OUTPUT_FUNCTION_4 (OUTPUT_FUNCTION | FUNCTION_4)
# define OUTPUT_FUNCTION_5 (OUTPUT_FUNCTION | FUNCTION_5)
# define OUTPUT_FUNCTION_6 (OUTPUT_FUNCTION | FUNCTION_6)
#define INPUT_PULLUP (INPUT | PULLUP)
#define INPUT_PULLDOWN (INPUT | PULLDOWN)
#define OUTPUT_OPEN_DRAIN (OUTPUT | OPEN_DRAIN)
#define INPUT_FUNCTION (INPUT | FUNCTION)
# define INPUT_FUNCTION_1 (INPUT_FUNCTION | FUNCTION_1)
# define INPUT_FUNCTION_2 (INPUT_FUNCTION | FUNCTION_2)
# define INPUT_FUNCTION_3 (INPUT_FUNCTION | FUNCTION_3)
# define INPUT_FUNCTION_4 (INPUT_FUNCTION | FUNCTION_4)
# define INPUT_FUNCTION_5 (INPUT_FUNCTION | FUNCTION_5)
# define INPUT_FUNCTION_6 (INPUT_FUNCTION | FUNCTION_6)
# define INPUT_FUNCTION_RTC (INPUT_FUNCTION | FUNCTION_RTC)
#define OUTPUT_FUNCTION (OUTPUT | FUNCTION)
# define OUTPUT_FUNCTION_1 (OUTPUT_FUNCTION | FUNCTION_1)
# define OUTPUT_FUNCTION_2 (OUTPUT_FUNCTION | FUNCTION_2)
# define OUTPUT_FUNCTION_3 (OUTPUT_FUNCTION | FUNCTION_3)
# define OUTPUT_FUNCTION_4 (OUTPUT_FUNCTION | FUNCTION_4)
# define OUTPUT_FUNCTION_5 (OUTPUT_FUNCTION | FUNCTION_5)
# define OUTPUT_FUNCTION_6 (OUTPUT_FUNCTION | FUNCTION_6)
# define OUTPUT_FUNCTION_RTC (OUTPUT_FUNCTION | FUNCTION_RTC)
/* Interrupt type used with esp32_gpioirqenable() */
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+145
View File
@@ -0,0 +1,145 @@
/****************************************************************************
* arch/xtensa/src/esp32/esp32_touch.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_TOUCH_H
#define __ARCH_XTENSA_SRC_ESP32_ESP32_TOUCH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include "esp32_touch_lowerhalf.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define TOUCH_BIT_MASK_ALL ((1<<TOUCH_SENSOR_PINS)-1)
#define TOUCH_SLOPE_DEFAULT (TOUCH_SLOPE_7)
#define TOUCH_TIE_OPT_DEFAULT (TOUCH_TIE_OPT_LOW)
#define TOUCH_BIT_MASK_MAX (TOUCH_BIT_MASK_ALL)
#define TOUCH_HIGH_VOLTAGE_THRESHOLD (TOUCH_HVOLT_2V7)
#define TOUCH_LOW_VOLTAGE_THRESHOLD (TOUCH_LVOLT_0V5)
#define TOUCH_ATTEN_VOLTAGE_THRESHOLD (TOUCH_HVOLT_ATTEN_0V5)
#define TOUCH_THRESHOLD_MAX (0)
#define TOUCH_SLEEP_CYCLE_DEFAULT (0x1000)
#define TOUCH_MEASURE_CYCLE_DEFAULT (0x7fff)
#define TOUCH_FSM_MODE_DEFAULT (TOUCH_FSM_MODE_SW)
#define TOUCH_TRIGGER_MODE_DEFAULT (TOUCH_TRIGGER_BELOW)
#define TOUCH_TRIGGER_SOURCE_DEFAULT (TOUCH_TRIGGER_SOURCE_SET1)
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
struct touch_config_s
{
enum touch_high_volt_e refh;
enum touch_low_volt_e refl;
enum touch_volt_atten_e atten;
enum touch_cnt_slope_e slope;
enum touch_tie_opt_e tie_opt;
enum touch_fsm_mode_e fsm_mode;
uint16_t interrupt_threshold;
uint16_t logic_threshold;
uint32_t filter_period;
};
/****************************************************************************
* Public Data
****************************************************************************/
static const uint8_t touch_channel_to_gpio[] =
{
TOUCH_PAD_NUM0_GPIO_NUM,
TOUCH_PAD_NUM1_GPIO_NUM,
TOUCH_PAD_NUM2_GPIO_NUM,
TOUCH_PAD_NUM3_GPIO_NUM,
TOUCH_PAD_NUM4_GPIO_NUM,
TOUCH_PAD_NUM5_GPIO_NUM,
TOUCH_PAD_NUM6_GPIO_NUM,
TOUCH_PAD_NUM7_GPIO_NUM,
TOUCH_PAD_NUM8_GPIO_NUM,
TOUCH_PAD_NUM9_GPIO_NUM
};
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Inline Functions
****************************************************************************/
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: esp32_configtouch
*
* Description:
* Configure a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel;
* config - The touch pad configuration structure.
*
* Returned Value:
* OK.
*
****************************************************************************/
int esp32_configtouch(enum touch_pad_e tp, struct touch_config_s config);
/****************************************************************************
* Name: esp32_touchread
*
* Description:
* Read a touch pad channel.
*
* Input Parameters:
* tp - The touch pad channel.
*
* Returned Value:
* 0 if touch pad pressed, 1 if released.
*
****************************************************************************/
bool esp32_touchread(enum touch_pad_e tp);
#ifdef __cplusplus
}
#endif
#undef EXTERN
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_TOUCH_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,144 @@
/****************************************************************************
* arch/xtensa/src/esp32/hardware/esp32_touch.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __ARCH_XTENSA_SRC_ESP32_HARDWARE_ESP32_TOUCH_H
#define __ARCH_XTENSA_SRC_ESP32_HARDWARE_ESP32_TOUCH_H
/****************************************************************************
* Included Files
****************************************************************************/
/****************************************************************************
* Pre-preprocessor Definitions
****************************************************************************/
#define TOUCH_SENSOR_PINS 10
#define TOUCH_MEASURE_WAIT_MAX (0xff)
/* Touch channel to GPIO */
#define TOUCH_PAD_NUM0_GPIO_NUM 4
#define TOUCH_PAD_NUM1_GPIO_NUM 0
#define TOUCH_PAD_NUM2_GPIO_NUM 2
#define TOUCH_PAD_NUM3_GPIO_NUM 15
#define TOUCH_PAD_NUM4_GPIO_NUM 13
#define TOUCH_PAD_NUM5_GPIO_NUM 12
#define TOUCH_PAD_NUM6_GPIO_NUM 14
#define TOUCH_PAD_NUM7_GPIO_NUM 27
#define TOUCH_PAD_NUM8_GPIO_NUM 33
#define TOUCH_PAD_NUM9_GPIO_NUM 32
/****************************************************************************
* Public Types
****************************************************************************/
/* Touch pad channel */
enum touch_pad_e
{
TOUCH_PAD_NUM0, /* Touch pad channel 0 is GPIO4 */
TOUCH_PAD_NUM1, /* Touch pad channel 1 is GPIO0 */
TOUCH_PAD_NUM2, /* Touch pad channel 2 is GPIO2 */
TOUCH_PAD_NUM3, /* Touch pad channel 3 is GPIO15 */
TOUCH_PAD_NUM4, /* Touch pad channel 4 is GPIO13 */
TOUCH_PAD_NUM5, /* Touch pad channel 5 is GPIO12 */
TOUCH_PAD_NUM6, /* Touch pad channel 6 is GPIO14 */
TOUCH_PAD_NUM7, /* Touch pad channel 7 is GPIO27 */
TOUCH_PAD_NUM8, /* Touch pad channel 8 is GPIO33 */
TOUCH_PAD_NUM9 /* Touch pad channel 9 is GPIO32 */
};
/* Touch sensor high reference voltage */
enum touch_high_volt_e
{
TOUCH_HVOLT_2V4, /* Touch sensor high reference voltage, 2.4V */
TOUCH_HVOLT_2V5, /* Touch sensor high reference voltage, 2.5V */
TOUCH_HVOLT_2V6, /* Touch sensor high reference voltage, 2.6V */
TOUCH_HVOLT_2V7 /* Touch sensor high reference voltage, 2.7V */
};
/* Touch sensor low reference voltage */
enum touch_low_volt_e
{
TOUCH_LVOLT_0V5, /* Touch sensor low reference voltage, 0.5V */
TOUCH_LVOLT_0V6, /* Touch sensor low reference voltage, 0.6V */
TOUCH_LVOLT_0V7, /* Touch sensor low reference voltage, 0.7V */
TOUCH_LVOLT_0V8 /* Touch sensor low reference voltage, 0.8V */
};
/* Touch sensor high reference voltage attenuation */
enum touch_volt_atten_e
{
TOUCH_HVOLT_ATTEN_1V5, /* 1.5V attenuation */
TOUCH_HVOLT_ATTEN_1V, /* 1.0V attenuation */
TOUCH_HVOLT_ATTEN_0V5, /* 0.5V attenuation */
TOUCH_HVOLT_ATTEN_0V /* 0V attenuation */
};
/* Touch sensor charge/discharge speed */
enum touch_cnt_slope_e
{
TOUCH_SLOPE_0, /* Touch sensor charge/discharge speed, always zero */
TOUCH_SLOPE_1, /* Touch sensor charge/discharge speed, slowest */
TOUCH_SLOPE_2, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_3, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_4, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_5, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_6, /* Touch sensor charge/discharge speed */
TOUCH_SLOPE_7 /* Touch sensor charge/discharge speed, fast */
};
/* Touch sensor initial charge level */
enum touch_tie_opt_e
{
TOUCH_TIE_OPT_LOW, /* Initial level of charging voltage, low level */
TOUCH_TIE_OPT_HIGH /* Initial level of charging voltage, high level */
};
/* Touch sensor FSM mode */
enum touch_fsm_mode_e
{
TOUCH_FSM_MODE_TIMER, /* To start touch FSM by timer */
TOUCH_FSM_MODE_SW /* To start touch FSM by software trigger */
};
/* Touch sensor touch IRQ trigger */
enum touch_trigger_mode_e
{
TOUCH_TRIGGER_BELOW, /* Interrupt if value is less than threshold. */
TOUCH_TRIGGER_ABOVE /* Interrupt if value is larger than threshold. */
};
/* Touch sensor wakeup IRQ trigger */
enum touch_trigger_src_e
{
TOUCH_TRIGGER_SOURCE_BOTH, /* Interrupt if SET1 and SET2 are "touched" */
TOUCH_TRIGGER_SOURCE_SET1 /* Interrupt if SET1 is "touched" */
};
#endif /* __ARCH_XTENSA_SRC_ESP32_HARDWARE_ESP32_TOUCH_H */