diff --git a/components/esp8266_wrapper/esp8266_wrapper.c b/components/esp8266_wrapper/esp8266_wrapper.c index c4bbb1a..5f00fe7 100644 --- a/components/esp8266_wrapper/esp8266_wrapper.c +++ b/components/esp8266_wrapper/esp8266_wrapper.c @@ -129,9 +129,10 @@ int i2c_slave_read (uint8_t bus, uint8_t addr, const uint8_t *reg, // esp-open-rtos SPI interface wrapper -#define SPI_MAX_BUS 3 // ESP32 features three SPIs (SPI, HSPI and VSPI) +#define SPI_MAX_BUS 3 // ESP32 features three SPIs (SPI_HOST, HSPI_HOST and VSPI_HOST) #define SPI_MAX_CS 34 // GPIO 33 is the last port that can be used as output +SemaphoreHandle_t spi_semaphores[SPI_MAX_BUS] = { 0 }; spi_device_handle_t spi_handles[SPI_MAX_CS] = { 0 }; bool spi_bus_init (spi_host_device_t host, uint8_t sclk , uint8_t miso, uint8_t mosi) diff --git a/components/esp8266_wrapper/esp8266_wrapper.h b/components/esp8266_wrapper/esp8266_wrapper.h index 35ddcde..b76e6af 100644 --- a/components/esp8266_wrapper/esp8266_wrapper.h +++ b/components/esp8266_wrapper/esp8266_wrapper.h @@ -99,6 +99,13 @@ bool spi_device_init (uint8_t bus, uint8_t cs); size_t spi_transfer_pf(uint8_t bus, uint8_t cs, const uint8_t *mosi, uint8_t *miso, uint16_t len); +extern SemaphoreHandle_t spi_semaphores[]; + +// platform specific definitions +#define spi_semaphore_take(d) if (d) xSemaphoreTake(spi_semaphores[d->bus], portMAX_DELAY) +#define spi_semaphore_give(d) if (d) xSemaphoreGive(spi_semaphores[d->bus]) +#define spi_semaphore_init(d) if (d && !spi_semaphores[d->bus]) spi_semaphores[d->bus] = xSemaphoreCreateMutex() + /* * freertos api wrapper */