summaryrefslogtreecommitdiffstatshomepage
path: root/ports/esp32/machine_hw_spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/esp32/machine_hw_spi.c')
-rw-r--r--ports/esp32/machine_hw_spi.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/ports/esp32/machine_hw_spi.c b/ports/esp32/machine_hw_spi.c
index 36f8d3f069..662d0e5994 100644
--- a/ports/esp32/machine_hw_spi.c
+++ b/ports/esp32/machine_hw_spi.c
@@ -35,6 +35,8 @@
#include "modmachine.h"
#include "driver/spi_master.h"
+#include "soc/gpio_sig_map.h"
+#include "soc/spi_pins.h"
// SPI mappings by device, naming used by IDF old/new
// upython | ESP32 | ESP32S2 | ESP32S3 | ESP32C3
@@ -57,9 +59,9 @@
#define MICROPY_HW_SPI1_MOSI FSPI_IOMUX_PIN_NUM_MOSI
#define MICROPY_HW_SPI1_MISO FSPI_IOMUX_PIN_NUM_MISO
#else
-#define MICROPY_HW_SPI1_SCK HSPI_IOMUX_PIN_NUM_CLK
-#define MICROPY_HW_SPI1_MOSI HSPI_IOMUX_PIN_NUM_MOSI
-#define MICROPY_HW_SPI1_MISO HSPI_IOMUX_PIN_NUM_MISO
+#define MICROPY_HW_SPI1_SCK SPI2_IOMUX_PIN_NUM_CLK
+#define MICROPY_HW_SPI1_MOSI SPI2_IOMUX_PIN_NUM_MOSI
+#define MICROPY_HW_SPI1_MISO SPI2_IOMUX_PIN_NUM_MISO
#endif
#endif
@@ -67,9 +69,9 @@
#ifndef MICROPY_HW_SPI2_SCK
#if CONFIG_IDF_TARGET_ESP32
// ESP32 has IO_MUX pins for VSPI/SPI3 lines, use them as defaults
-#define MICROPY_HW_SPI2_SCK VSPI_IOMUX_PIN_NUM_CLK // pin 18
-#define MICROPY_HW_SPI2_MOSI VSPI_IOMUX_PIN_NUM_MOSI // pin 23
-#define MICROPY_HW_SPI2_MISO VSPI_IOMUX_PIN_NUM_MISO // pin 19
+#define MICROPY_HW_SPI2_SCK SPI3_IOMUX_PIN_NUM_CLK // pin 18
+#define MICROPY_HW_SPI2_MOSI SPI3_IOMUX_PIN_NUM_MOSI // pin 23
+#define MICROPY_HW_SPI2_MISO SPI3_IOMUX_PIN_NUM_MISO // pin 19
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
// ESP32S2 and S3 uses GPIO matrix for SPI3 pins, no IO_MUX possible
// Set defaults to the pins used by SPI2 in Octal mode
@@ -83,9 +85,9 @@
#define MP_HW_SPI_MAX_XFER_BITS (MP_HW_SPI_MAX_XFER_BYTES * 8) // Has to be an even multiple of 8
#if CONFIG_IDF_TARGET_ESP32C3
-#define HSPI_HOST SPI2_HOST
+#define SPI2_HOST SPI2_HOST
#elif CONFIG_IDF_TARGET_ESP32S3
-#define HSPI_HOST SPI3_HOST
+#define SPI2_HOST SPI3_HOST
#define FSPI_HOST SPI2_HOST
#endif
@@ -122,7 +124,7 @@ STATIC const machine_hw_spi_default_pins_t machine_hw_spi_default_pins[2] = {
#endif
};
-// Static objects mapping to HSPI and VSPI hardware peripherals
+// Static objects mapping to SPI2 and SPI3 hardware peripherals
STATIC machine_hw_spi_obj_t machine_hw_spi_obj[2];
STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) {
@@ -150,8 +152,8 @@ STATIC void machine_hw_spi_deinit_internal(machine_hw_spi_obj_t *self) {
for (int i = 0; i < 3; i++) {
if (pins[i] != -1) {
- gpio_pad_select_gpio(pins[i]);
- gpio_matrix_out(pins[i], SIG_GPIO_OUT_IDX, false, false);
+ esp_rom_gpio_pad_select_gpio(pins[i]);
+ esp_rom_gpio_connect_out_signal(pins[i], SIG_GPIO_OUT_IDX, false, false);
gpio_set_direction(pins[i], GPIO_MODE_INPUT);
}
}
@@ -226,12 +228,12 @@ STATIC void machine_hw_spi_init_internal(
changed = true;
}
- if (self->host != HSPI_HOST
+ if (self->host != SPI2_HOST
#ifdef FSPI_HOST
&& self->host != FSPI_HOST
#endif
- #ifdef VSPI_HOST
- && self->host != VSPI_HOST
+ #ifdef SPI3_HOST
+ && self->host != SPI3_HOST
#endif
) {
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("SPI(%d) doesn't exist"), self->host);
@@ -270,7 +272,7 @@ STATIC void machine_hw_spi_init_internal(
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
dma_chan = SPI_DMA_CH_AUTO;
#else
- if (self->host == HSPI_HOST) {
+ if (self->host == SPI2_HOST) {
dma_chan = 1;
} else {
dma_chan = 2;
@@ -483,7 +485,7 @@ mp_obj_t machine_hw_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_
machine_hw_spi_obj_t *self;
const machine_hw_spi_default_pins_t *default_pins;
- if (args[ARG_id].u_int == 1) { // SPI2_HOST which is FSPI_HOST on ESP32Sx, HSPI_HOST on others
+ if (args[ARG_id].u_int == 1) { // SPI2_HOST which is FSPI_HOST on ESP32Sx, SPI2_HOST on others
self = &machine_hw_spi_obj[0];
default_pins = &machine_hw_spi_default_pins[0];
} else {