mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	Always use IDF SPI on ESP32
This commit is contained in:
		| @@ -268,10 +268,10 @@ def validate_spi_config(config): | |||||||
|  |  | ||||||
| # Given an SPI index, convert to a string that represents the C++ object for it. | # Given an SPI index, convert to a string that represents the C++ object for it. | ||||||
| def get_spi_interface(index): | def get_spi_interface(index): | ||||||
|     if CORE.using_esp_idf: |     platform = get_target_platform() | ||||||
|  |     if platform == PLATFORM_ESP32: | ||||||
|         return ["SPI2_HOST", "SPI3_HOST"][index] |         return ["SPI2_HOST", "SPI3_HOST"][index] | ||||||
|     # Arduino code follows |     # Arduino code follows | ||||||
|     platform = get_target_platform() |  | ||||||
|     if platform == PLATFORM_RP2040: |     if platform == PLATFORM_RP2040: | ||||||
|         return ["&SPI", "&SPI1"][index] |         return ["&SPI", "&SPI1"][index] | ||||||
|     if index == 0: |     if index == 0: | ||||||
| @@ -306,7 +306,7 @@ def spi_mode_schema(mode): | |||||||
|     if mode == TYPE_SINGLE: |     if mode == TYPE_SINGLE: | ||||||
|         return SPI_SINGLE_SCHEMA |         return SPI_SINGLE_SCHEMA | ||||||
|     pin_count = 4 if mode == TYPE_QUAD else 8 |     pin_count = 4 if mode == TYPE_QUAD else 8 | ||||||
|     onlys = [cv.only_on([PLATFORM_ESP32]), cv.only_with_esp_idf] |     onlys = [cv.only_on([PLATFORM_ESP32])] | ||||||
|     if pin_count == 8: |     if pin_count == 8: | ||||||
|         onlys.append( |         onlys.append( | ||||||
|             only_on_variant( |             only_on_variant( | ||||||
| @@ -352,7 +352,7 @@ CONFIG_SCHEMA = cv.All( | |||||||
| async def to_code(configs): | async def to_code(configs): | ||||||
|     cg.add_define("USE_SPI") |     cg.add_define("USE_SPI") | ||||||
|     cg.add_global(spi_ns.using) |     cg.add_global(spi_ns.using) | ||||||
|     if CORE.using_arduino: |     if CORE.using_arduino and get_target_platform() != PLATFORM_ESP32: | ||||||
|         cg.add_library("SPI", None) |         cg.add_library("SPI", None) | ||||||
|     for spi in configs: |     for spi in configs: | ||||||
|         var = cg.new_Pvariable(spi[CONF_ID]) |         var = cg.new_Pvariable(spi[CONF_ID]) | ||||||
| @@ -394,7 +394,9 @@ def spi_device_schema( | |||||||
|         cv.Optional(CONF_SPI_MODE, default=default_mode): cv.enum( |         cv.Optional(CONF_SPI_MODE, default=default_mode): cv.enum( | ||||||
|             SPI_MODE_OPTIONS, upper=True |             SPI_MODE_OPTIONS, upper=True | ||||||
|         ), |         ), | ||||||
|         cv.Optional(CONF_RELEASE_DEVICE): cv.All(cv.boolean, cv.only_with_esp_idf), |         cv.Optional(CONF_RELEASE_DEVICE): cv.All( | ||||||
|  |             cv.boolean, cv.only_on([PLATFORM_ESP32]) | ||||||
|  |         ), | ||||||
|     } |     } | ||||||
|     if cs_pin_required: |     if cs_pin_required: | ||||||
|         schema[cv.Required(CONF_CS_PIN)] = pins.gpio_output_pin_schema |         schema[cv.Required(CONF_CS_PIN)] = pins.gpio_output_pin_schema | ||||||
| @@ -443,13 +445,15 @@ def final_validate_device_schema(name: str, *, require_mosi: bool, require_miso: | |||||||
| FILTER_SOURCE_FILES = filter_source_files_from_platform( | FILTER_SOURCE_FILES = filter_source_files_from_platform( | ||||||
|     { |     { | ||||||
|         "spi_arduino.cpp": { |         "spi_arduino.cpp": { | ||||||
|             PlatformFramework.ESP32_ARDUINO, |  | ||||||
|             PlatformFramework.ESP8266_ARDUINO, |             PlatformFramework.ESP8266_ARDUINO, | ||||||
|             PlatformFramework.RP2040_ARDUINO, |             PlatformFramework.RP2040_ARDUINO, | ||||||
|             PlatformFramework.BK72XX_ARDUINO, |             PlatformFramework.BK72XX_ARDUINO, | ||||||
|             PlatformFramework.RTL87XX_ARDUINO, |             PlatformFramework.RTL87XX_ARDUINO, | ||||||
|             PlatformFramework.LN882X_ARDUINO, |             PlatformFramework.LN882X_ARDUINO, | ||||||
|         }, |         }, | ||||||
|         "spi_esp_idf.cpp": {PlatformFramework.ESP32_IDF}, |         "spi_esp_idf.cpp": { | ||||||
|  |             PlatformFramework.ESP32_IDF, | ||||||
|  |             PlatformFramework.ESP32_ARDUINO, | ||||||
|  |         }, | ||||||
|     } |     } | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -7,7 +7,7 @@ | |||||||
| #include <utility> | #include <utility> | ||||||
| #include <vector> | #include <vector> | ||||||
|  |  | ||||||
| #ifdef USE_ARDUINO | #if defined(USE_ARDUINO) && !defined(USE_ESP32) | ||||||
|  |  | ||||||
| #include <SPI.h> | #include <SPI.h> | ||||||
|  |  | ||||||
| @@ -19,13 +19,13 @@ using SPIInterface = SPIClass *; | |||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #ifdef USE_ESP_IDF | #ifdef USE_ESP32 | ||||||
|  |  | ||||||
| #include "driver/spi_master.h" | #include "driver/spi_master.h" | ||||||
|  |  | ||||||
| using SPIInterface = spi_host_device_t; | using SPIInterface = spi_host_device_t; | ||||||
|  |  | ||||||
| #endif  // USE_ESP_IDF | #endif  // USE_ESP32 | ||||||
|  |  | ||||||
| #ifdef USE_ZEPHYR | #ifdef USE_ZEPHYR | ||||||
| // TODO supprse clang-tidy. Remove after SPI driver for nrf52 is added. | // TODO supprse clang-tidy. Remove after SPI driver for nrf52 is added. | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
|  |  | ||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace spi { | namespace spi { | ||||||
| #ifdef USE_ARDUINO | #if defined(USE_ARDUINO) && !defined(USE_ESP32) | ||||||
|  |  | ||||||
| static const char *const TAG = "spi-esp-arduino"; | static const char *const TAG = "spi-esp-arduino"; | ||||||
| class SPIDelegateHw : public SPIDelegate { | class SPIDelegateHw : public SPIDelegate { | ||||||
| @@ -73,9 +73,6 @@ class SPIBusHw : public SPIBus { | |||||||
|     channel->pins(Utility::get_pin_no(clk), Utility::get_pin_no(sdi), Utility::get_pin_no(sdo), -1); |     channel->pins(Utility::get_pin_no(clk), Utility::get_pin_no(sdi), Utility::get_pin_no(sdo), -1); | ||||||
|     channel->begin(); |     channel->begin(); | ||||||
| #endif  // USE_ESP8266 | #endif  // USE_ESP8266 | ||||||
| #ifdef USE_ESP32 |  | ||||||
|     channel->begin(Utility::get_pin_no(clk), Utility::get_pin_no(sdi), Utility::get_pin_no(sdo), -1); |  | ||||||
| #endif |  | ||||||
| #ifdef USE_RP2040 | #ifdef USE_RP2040 | ||||||
|     if (Utility::get_pin_no(sdi) != -1) |     if (Utility::get_pin_no(sdi) != -1) | ||||||
|       channel->setRX(Utility::get_pin_no(sdi)); |       channel->setRX(Utility::get_pin_no(sdi)); | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ | |||||||
| namespace esphome { | namespace esphome { | ||||||
| namespace spi { | namespace spi { | ||||||
|  |  | ||||||
| #ifdef USE_ESP_IDF | #ifdef USE_ESP32 | ||||||
| static const char *const TAG = "spi-esp-idf"; | static const char *const TAG = "spi-esp-idf"; | ||||||
| static const size_t MAX_TRANSFER_SIZE = 4092;  // dictated by ESP-IDF API. | static const size_t MAX_TRANSFER_SIZE = 4092;  // dictated by ESP-IDF API. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,6 +1,16 @@ | |||||||
| substitutions: | spi: | ||||||
|   clk_pin: GPIO6 |   - id: quad_spi | ||||||
|   mosi_pin: GPIO7 |     type: quad | ||||||
|   miso_pin: GPIO5 |     interface: hardware | ||||||
|  |     clk_pin: | ||||||
| <<: !include common.yaml |       number: 6 | ||||||
|  |     data_pins: | ||||||
|  |       - 7 | ||||||
|  |       - 2 | ||||||
|  |       - 10 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 3 | ||||||
|  |   - id: spi_id_2 | ||||||
|  |     interface: any | ||||||
|  |     clk_pin: 4 | ||||||
|  |     mosi_pin: 5 | ||||||
|   | |||||||
| @@ -1,13 +1,37 @@ | |||||||
| spi: | spi: | ||||||
|   - id: three_spi |   - id: quad_spi | ||||||
|  |     type: quad | ||||||
|     interface: spi3 |     interface: spi3 | ||||||
|     clk_pin: |     clk_pin: | ||||||
|       number: 47 |       number: 47 | ||||||
|     mosi_pin: |     data_pins: | ||||||
|       number: 40 |       - allow_other_uses: true | ||||||
|   - id: hw_spi |         number: 40 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 41 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 42 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 43 | ||||||
|  |   - id: octal_spi | ||||||
|  |     type: octal | ||||||
|     interface: hardware |     interface: hardware | ||||||
|     clk_pin: |     clk_pin: | ||||||
|       number: 0 |       number: 0 | ||||||
|     miso_pin: |     data_pins: | ||||||
|       number: 41 |       - 36 | ||||||
|  |       - 37 | ||||||
|  |       - 38 | ||||||
|  |       - 39 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 40 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 41 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 42 | ||||||
|  |       - allow_other_uses: true | ||||||
|  |         number: 43 | ||||||
|  |   - id: spi_id_3 | ||||||
|  |     interface: any | ||||||
|  |     clk_pin: 8 | ||||||
|  |     mosi_pin: 9 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user