summaryrefslogtreecommitdiff
path: root/ports/esp32s2/peripherals
diff options
context:
space:
mode:
Diffstat (limited to 'ports/esp32s2/peripherals')
-rw-r--r--ports/esp32s2/peripherals/pcnt.c66
-rw-r--r--ports/esp32s2/peripherals/pcnt.h35
-rwxr-xr-xports/esp32s2/peripherals/pins.c97
-rw-r--r--ports/esp32s2/peripherals/pins.h8
-rw-r--r--ports/esp32s2/peripherals/rmt.c2
-rw-r--r--ports/esp32s2/peripherals/rmt.h2
6 files changed, 161 insertions, 49 deletions
diff --git a/ports/esp32s2/peripherals/pcnt.c b/ports/esp32s2/peripherals/pcnt.c
new file mode 100644
index 000000000..555a0ec1d
--- /dev/null
+++ b/ports/esp32s2/peripherals/pcnt.c
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "peripherals/pcnt.h"
+
+#define PCNT_UNIT_ACTIVE 1
+#define PCNT_UNIT_INACTIVE 0
+
+static uint8_t pcnt_state[4];
+
+int peripherals_pcnt_init(pcnt_config_t pcnt_config) {
+ // Look for available pcnt unit
+ for (uint8_t i = 0; i<=3; i++) {
+ if (pcnt_state[i] == PCNT_UNIT_INACTIVE) {
+ pcnt_config.unit = (pcnt_unit_t)i;
+ pcnt_state[i] = PCNT_UNIT_ACTIVE;
+ break;
+ } else if (i == 3) {
+ return -1;
+ }
+ }
+
+ // Initialize PCNT unit
+ pcnt_unit_config(&pcnt_config);
+
+ // Configure and enable the input filter
+ pcnt_set_filter_value(pcnt_config.unit, 100);
+ pcnt_filter_enable(pcnt_config.unit);
+
+ // Initialize PCNT's counter
+ pcnt_counter_pause(pcnt_config.unit);
+ pcnt_counter_clear(pcnt_config.unit);
+
+ // Everything is set up, now go to counting
+ pcnt_counter_resume(pcnt_config.unit);
+
+ return pcnt_config.unit;
+}
+
+void peripherals_pcnt_deinit(pcnt_unit_t* unit) {
+ pcnt_state[*unit] = PCNT_UNIT_INACTIVE;
+ *unit = PCNT_UNIT_MAX;
+}
diff --git a/ports/esp32s2/peripherals/pcnt.h b/ports/esp32s2/peripherals/pcnt.h
new file mode 100644
index 000000000..abed80fd0
--- /dev/null
+++ b/ports/esp32s2/peripherals/pcnt.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 microDev
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H
+#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H
+
+#include "driver/pcnt.h"
+
+extern int peripherals_pcnt_init(pcnt_config_t pcnt_config);
+extern void peripherals_pcnt_deinit(pcnt_unit_t* unit);
+
+#endif // MICROPY_INCLUDED_ESP32S2_PERIPHERALS_PCNT_HANDLER_H
diff --git a/ports/esp32s2/peripherals/pins.c b/ports/esp32s2/peripherals/pins.c
index 34fd6483e..0d3d89ad5 100755
--- a/ports/esp32s2/peripherals/pins.c
+++ b/ports/esp32s2/peripherals/pins.c
@@ -26,56 +26,61 @@
#include "peripherals/pins.h"
-#define NO_ADC 0xff
+#define NO_ADC 0
+#define NO_ADC_CHANNEL ADC_CHANNEL_MAX
+
+#define NO_TOUCH_CHANNEL TOUCH_PAD_MAX
// This macro is used to simplify pin definition in boards/<board>/pins.c
-#define PIN(p_name, p_number) \
+#define PIN(p_name, p_number, p_adc_index, p_adc_channel, p_touch_channel) \
const mcu_pin_obj_t pin_## p_name = { \
PIN_PREFIX_VALUES \
.number = p_number, \
+ .adc_index = p_adc_index, \
+ .adc_channel = p_adc_channel, \
+ .touch_channel = p_touch_channel, \
}
-PIN(GPIO0, 0);
-PIN(GPIO1, 1);
-PIN(GPIO2, 2);
-PIN(GPIO3, 3);
-PIN(GPIO4, 4);
-PIN(GPIO5, 5);
-PIN(GPIO6, 6);
-PIN(GPIO7, 7);
-PIN(GPIO8, 8);
-PIN(GPIO9, 9);
-PIN(GPIO10, 10);
-PIN(GPIO11, 11);
-PIN(GPIO12, 12);
-PIN(GPIO13, 13);
-PIN(GPIO14, 14);
-PIN(GPIO15, 15);
-PIN(GPIO16, 16);
-PIN(GPIO17, 17);
-PIN(GPIO18, 18);
-
-PIN(GPIO19, 19);
-PIN(GPIO20, 20);
-PIN(GPIO21, 21);
-PIN(GPIO26, 26);
-PIN(GPIO27, 27);
-PIN(GPIO28, 28);
-PIN(GPIO29, 29);
-PIN(GPIO30, 30);
-PIN(GPIO31, 31);
-PIN(GPIO32, 32);
-PIN(GPIO33, 33);
-PIN(GPIO34, 34);
-PIN(GPIO35, 35);
-PIN(GPIO36, 36);
-PIN(GPIO37, 37);
-PIN(GPIO38, 38);
-PIN(GPIO39, 39);
-PIN(GPIO40, 40);
-PIN(GPIO41, 41);
-PIN(GPIO42, 42);
-PIN(GPIO43, 43);
-PIN(GPIO44, 44);
-PIN(GPIO45, 45);
-PIN(GPIO46, 46);
+PIN(GPIO0, 0, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO1, 1, ADC_UNIT_1, ADC_CHANNEL_0, TOUCH_PAD_NUM1);
+PIN(GPIO2, 2, ADC_UNIT_1, ADC_CHANNEL_1, TOUCH_PAD_NUM2);
+PIN(GPIO3, 3, ADC_UNIT_1, ADC_CHANNEL_2, TOUCH_PAD_NUM3);
+PIN(GPIO4, 4, ADC_UNIT_1, ADC_CHANNEL_3, TOUCH_PAD_NUM4);
+PIN(GPIO5, 5, ADC_UNIT_1, ADC_CHANNEL_4, TOUCH_PAD_NUM5);
+PIN(GPIO6, 6, ADC_UNIT_1, ADC_CHANNEL_5, TOUCH_PAD_NUM6);
+PIN(GPIO7, 7, ADC_UNIT_1, ADC_CHANNEL_6, TOUCH_PAD_NUM7);
+PIN(GPIO8, 8, ADC_UNIT_1, ADC_CHANNEL_7, TOUCH_PAD_NUM8);
+PIN(GPIO9, 9, ADC_UNIT_1, ADC_CHANNEL_8, TOUCH_PAD_NUM9);
+PIN(GPIO10, 10, ADC_UNIT_1, ADC_CHANNEL_9, TOUCH_PAD_NUM10);
+PIN(GPIO11, 11, ADC_UNIT_2, ADC_CHANNEL_0, TOUCH_PAD_NUM11);
+PIN(GPIO12, 12, ADC_UNIT_2, ADC_CHANNEL_1, TOUCH_PAD_NUM12);
+PIN(GPIO13, 13, ADC_UNIT_2, ADC_CHANNEL_2, TOUCH_PAD_NUM13);
+PIN(GPIO14, 14, ADC_UNIT_2, ADC_CHANNEL_3, TOUCH_PAD_NUM14);
+PIN(GPIO15, 15, ADC_UNIT_2, ADC_CHANNEL_4, NO_TOUCH_CHANNEL);
+PIN(GPIO16, 16, ADC_UNIT_2, ADC_CHANNEL_5, NO_TOUCH_CHANNEL);
+PIN(GPIO17, 17, ADC_UNIT_2, ADC_CHANNEL_6, NO_TOUCH_CHANNEL);
+PIN(GPIO18, 18, ADC_UNIT_2, ADC_CHANNEL_7, NO_TOUCH_CHANNEL);
+PIN(GPIO19, 19, ADC_UNIT_2, ADC_CHANNEL_8, NO_TOUCH_CHANNEL);
+PIN(GPIO20, 20, ADC_UNIT_2, ADC_CHANNEL_9, NO_TOUCH_CHANNEL);
+PIN(GPIO21, 21, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO26, 26, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO27, 27, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO28, 28, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO29, 29, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO30, 30, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO31, 31, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO32, 32, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO33, 33, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO34, 34, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO35, 35, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO36, 36, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO37, 37, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO38, 38, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO39, 39, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO40, 40, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO41, 41, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO42, 42, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO43, 43, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO44, 44, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO45, 45, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
+PIN(GPIO46, 46, NO_ADC, NO_ADC_CHANNEL, NO_TOUCH_CHANNEL);
diff --git a/ports/esp32s2/peripherals/pins.h b/ports/esp32s2/peripherals/pins.h
index 07d0b908e..c78eb8385 100644
--- a/ports/esp32s2/peripherals/pins.h
+++ b/ports/esp32s2/peripherals/pins.h
@@ -34,11 +34,17 @@
#include "esp32s2_peripherals_config.h"
#include "esp-idf/config/sdkconfig.h"
-#include "esp-idf/components/soc/include/hal/gpio_types.h"
+
+#include "components/hal/include/hal/gpio_types.h"
+#include "components/hal/include/hal/adc_types.h"
+#include "components/hal/include/hal/touch_sensor_types.h"
typedef struct {
PIN_PREFIX_FIELDS
gpio_num_t number;
+ uint8_t adc_index:2;
+ uint8_t adc_channel:6;
+ uint8_t touch_channel;
} mcu_pin_obj_t;
extern const mcu_pin_obj_t pin_GPIO0;
diff --git a/ports/esp32s2/peripherals/rmt.c b/ports/esp32s2/peripherals/rmt.c
index b7629dbd5..2be5f06d8 100644
--- a/ports/esp32s2/peripherals/rmt.c
+++ b/ports/esp32s2/peripherals/rmt.c
@@ -24,7 +24,7 @@
* THE SOFTWARE.
*/
-#include "rmt.h"
+#include "peripherals/rmt.h"
#include "py/runtime.h"
bool rmt_reserved_channels[RMT_CHANNEL_MAX];
diff --git a/ports/esp32s2/peripherals/rmt.h b/ports/esp32s2/peripherals/rmt.h
index 01ed09907..020f8dc3e 100644
--- a/ports/esp32s2/peripherals/rmt.h
+++ b/ports/esp32s2/peripherals/rmt.h
@@ -28,7 +28,7 @@
#define MICROPY_INCLUDED_ESP32S2_PERIPHERALS_RMT_H
#include "py/mphal.h"
-#include "driver/rmt.h"
+#include "components/driver/include/driver/rmt.h"
#include <stdint.h>
void esp32s2_peripherals_rmt_reset(void);