Skip to content

Commit

Permalink
esp32: Fix machine_touchpad compiling on IDFv5.3.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
DvdGiessen authored and dpgeorge committed Dec 10, 2024
1 parent 5564f30 commit 5fb846d
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions ports/esp32/machine_touchpad.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@

#if SOC_TOUCH_SENSOR_SUPPORTED

#if SOC_TOUCH_VERSION_1 // ESP32 only
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 3, 0)
#if SOC_TOUCH_VERSION_1
#define SOC_TOUCH_SENSOR_VERSION (1)
#elif SOC_TOUCH_VERSION_2
#define SOC_TOUCH_SENSOR_VERSION (2)
#endif
#endif

#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 only
#include "driver/touch_pad.h"
#elif SOC_TOUCH_VERSION_2 // All other SoCs with touch, to date
#elif SOC_TOUCH_SENSOR_VERSION == 2 // All other SoCs with touch, to date
#include "driver/touch_sensor.h"
#else
#error "Unknown touch hardware version"
Expand Down Expand Up @@ -98,13 +106,13 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
initialized = 1;
}
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
esp_err_t err = touch_pad_config(self->touchpad_id, 0);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
esp_err_t err = touch_pad_config(self->touchpad_id);
#endif
if (err == ESP_OK) {
#if SOC_TOUCH_VERSION_2
#if SOC_TOUCH_SENSOR_VERSION == 2
touch_pad_fsm_start();
#endif

Expand All @@ -115,10 +123,10 @@ static mp_obj_t mtp_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_

static mp_obj_t mtp_config(mp_obj_t self_in, mp_obj_t value_in) {
mtp_obj_t *self = self_in;
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
uint16_t value = mp_obj_get_int(value_in);
esp_err_t err = touch_pad_config(self->touchpad_id, value);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
esp_err_t err = touch_pad_config(self->touchpad_id);
#endif
if (err == ESP_OK) {
Expand All @@ -130,10 +138,10 @@ MP_DEFINE_CONST_FUN_OBJ_2(mtp_config_obj, mtp_config);

static mp_obj_t mtp_read(mp_obj_t self_in) {
mtp_obj_t *self = self_in;
#if SOC_TOUCH_VERSION_1
#if SOC_TOUCH_SENSOR_VERSION == 1
uint16_t value;
esp_err_t err = touch_pad_read(self->touchpad_id, &value);
#elif SOC_TOUCH_VERSION_2
#elif SOC_TOUCH_SENSOR_VERSION == 2
uint32_t value;
esp_err_t err = touch_pad_read_raw_data(self->touchpad_id, &value);
#endif
Expand Down

0 comments on commit 5fb846d

Please sign in to comment.