From 4de9cbcf0ff6fec37993b7edcc9f1c84d75b4a62 Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Thu, 15 Apr 2021 14:41:01 +0800 Subject: [PATCH] spi: update examples to use the new GDMA driver --- .../spi_master/hd_eeprom/main/spi_eeprom_main.c | 7 ++----- .../spi_master/lcd/main/spi_master_example_main.c | 9 +++------ examples/peripherals/spi_slave/receiver/main/app_main.c | 5 +---- examples/peripherals/spi_slave/sender/main/app_main.c | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c b/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c index 1833c3fc0f..bf16e10404 100644 --- a/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c +++ b/examples/peripherals/spi_master/hd_eeprom/main/spi_eeprom_main.c @@ -26,14 +26,12 @@ #ifdef CONFIG_IDF_TARGET_ESP32 # ifdef CONFIG_EXAMPLE_USE_SPI1_PINS # define EEPROM_HOST SPI1_HOST -# define DMA_CHAN 0 // Use default pins, same as the flash chip. # define PIN_NUM_MISO 7 # define PIN_NUM_MOSI 8 # define PIN_NUM_CLK 6 # else # define EEPROM_HOST HSPI_HOST -# define DMA_CHAN 2 # define PIN_NUM_MISO 18 # define PIN_NUM_MOSI 23 # define PIN_NUM_CLK 19 @@ -42,7 +40,6 @@ # define PIN_NUM_CS 13 #elif defined CONFIG_IDF_TARGET_ESP32S2 # define EEPROM_HOST SPI2_HOST -# define DMA_CHAN EEPROM_HOST # define PIN_NUM_MISO 37 # define PIN_NUM_MOSI 35 @@ -50,7 +47,6 @@ # define PIN_NUM_CS 34 #elif defined CONFIG_IDF_TARGET_ESP32C3 # define EEPROM_HOST SPI2_HOST -# define DMA_CHAN EEPROM_HOST # define PIN_NUM_MISO 2 # define PIN_NUM_MOSI 7 @@ -58,6 +54,7 @@ # define PIN_NUM_CS 10 #endif + static const char TAG[] = "main"; void app_main(void) @@ -74,7 +71,7 @@ void app_main(void) .max_transfer_sz = 32, }; //Initialize the SPI bus - ret = spi_bus_initialize(EEPROM_HOST, &buscfg, DMA_CHAN); + ret = spi_bus_initialize(EEPROM_HOST, &buscfg, SPI_DMA_CH_AUTO); ESP_ERROR_CHECK(ret); #else ESP_LOGI(TAG, "Attach to main flash bus..."); diff --git a/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c b/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c index 71184658ae..f25d0787f8 100644 --- a/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c +++ b/examples/peripherals/spi_master/lcd/main/spi_master_example_main.c @@ -30,7 +30,6 @@ #ifdef CONFIG_IDF_TARGET_ESP32 #define LCD_HOST HSPI_HOST -#define DMA_CHAN 2 #define PIN_NUM_MISO 25 #define PIN_NUM_MOSI 23 @@ -42,7 +41,6 @@ #define PIN_NUM_BCKL 5 #elif defined CONFIG_IDF_TARGET_ESP32S2 #define LCD_HOST SPI2_HOST -#define DMA_CHAN LCD_HOST #define PIN_NUM_MISO 37 #define PIN_NUM_MOSI 35 @@ -54,7 +52,6 @@ #define PIN_NUM_BCKL 6 #elif defined CONFIG_IDF_TARGET_ESP32C3 #define LCD_HOST SPI2_HOST -#define DMA_CHAN LCD_HOST #define PIN_NUM_MISO 2 #define PIN_NUM_MOSI 7 @@ -62,8 +59,8 @@ #define PIN_NUM_CS 10 #define PIN_NUM_DC 9 -#define PIN_NUM_RST 18 -#define PIN_NUM_BCKL 19 +#define PIN_NUM_RST 4 +#define PIN_NUM_BCKL 5 #endif //To speed up transfers, every SPI transfer sends a bunch of lines. This define specifies how many. More means more memory use, @@ -439,7 +436,7 @@ void app_main(void) .pre_cb=lcd_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line }; //Initialize the SPI bus - ret=spi_bus_initialize(LCD_HOST, &buscfg, DMA_CHAN); + ret=spi_bus_initialize(LCD_HOST, &buscfg, SPI_DMA_CH_AUTO); ESP_ERROR_CHECK(ret); //Attach the LCD to the SPI bus ret=spi_bus_add_device(LCD_HOST, &devcfg, &spi); diff --git a/examples/peripherals/spi_slave/receiver/main/app_main.c b/examples/peripherals/spi_slave/receiver/main/app_main.c index 2321db6dbc..874fdbb50a 100644 --- a/examples/peripherals/spi_slave/receiver/main/app_main.c +++ b/examples/peripherals/spi_slave/receiver/main/app_main.c @@ -68,15 +68,12 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i #ifdef CONFIG_IDF_TARGET_ESP32 #define RCV_HOST HSPI_HOST -#define DMA_CHAN 2 #elif defined CONFIG_IDF_TARGET_ESP32S2 #define RCV_HOST SPI2_HOST -#define DMA_CHAN RCV_HOST #elif defined CONFIG_IDF_TARGET_ESP32C3 #define RCV_HOST SPI2_HOST -#define DMA_CHAN RCV_HOST #endif @@ -132,7 +129,7 @@ void app_main(void) gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY); //Initialize SPI slave interface - ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, DMA_CHAN); + ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO); assert(ret==ESP_OK); WORD_ALIGNED_ATTR char sendbuf[129]=""; diff --git a/examples/peripherals/spi_slave/sender/main/app_main.c b/examples/peripherals/spi_slave/sender/main/app_main.c index 34d5e2536f..7c70cf2799 100644 --- a/examples/peripherals/spi_slave/sender/main/app_main.c +++ b/examples/peripherals/spi_slave/sender/main/app_main.c @@ -69,15 +69,12 @@ Pins in use. The SPI Master can use the GPIO mux, so feel free to change these i #ifdef CONFIG_IDF_TARGET_ESP32 #define SENDER_HOST HSPI_HOST -#define DMA_CHAN 2 #elif defined CONFIG_IDF_TARGET_ESP32S2 #define SENDER_HOST SPI2_HOST -#define DMA_CHAN SENDER_HOST #elif defined CONFIG_IDF_TARGET_ESP32C3 -#define SENDER_HOST SPI2_HOST -#define DMA_CHAN SENDER_HOST +#define SENDER_HOST SPI2_HOST #endif @@ -156,7 +153,7 @@ void app_main(void) gpio_isr_handler_add(GPIO_HANDSHAKE, gpio_handshake_isr_handler, NULL); //Initialize the SPI bus and add the device we want to send stuff to. - ret=spi_bus_initialize(SENDER_HOST, &buscfg, DMA_CHAN); + ret=spi_bus_initialize(SENDER_HOST, &buscfg, SPI_DMA_CH_AUTO); assert(ret==ESP_OK); ret=spi_bus_add_device(SENDER_HOST, &devcfg, &handle); assert(ret==ESP_OK);