Skip to content

Commit 704fe54

Browse files
committed
peripherals/touch.c: update for ESP32-P4
1 parent b9602c7 commit 704fe54

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

ports/espressif/peripherals/touch.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,29 @@ uint16_t peripherals_touch_read(int channel_id) {
119119
}
120120

121121
uint32_t touch_value = 0;
122-
touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value);
123122

124123
#if SOC_TOUCH_SENSOR_VERSION == 1
125124
// ESP32 touch reads a lower value when touched.
126125
// Flip the values to be consistent with TouchIn assumptions.
126+
touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value);
127127
if (touch_value > UINT16_MAX) {
128128
return 0;
129129
}
130130
return UINT16_MAX - (uint16_t)touch_value;
131-
#else
131+
touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_RAW, &touch_value);
132+
return UINT16_MAX - (uint16_t)touch_value;
133+
#elif SOC_TOUCH_SENSOR_VERSION == 2
132134
if (touch_value > UINT16_MAX) {
133135
return UINT16_MAX;
134136
}
135137
return (uint16_t)touch_value;
138+
#elif SOC_TOUCH_SENSOR_VERSION == 3
139+
touch_channel_read_data(touch_channels[idx], TOUCH_CHAN_DATA_TYPE_SMOOTH, &touch_value);
140+
if (touch_value > UINT16_MAX) {
141+
return UINT16_MAX;
142+
}
143+
return (uint16_t)touch_value;
144+
#else
145+
#error bad SOC_TOUCH_SENSOR_VERSION
136146
#endif
137147
}

0 commit comments

Comments
 (0)