Solaris Software
Loading...
Searching...
No Matches
halEsp32.c File Reference

ESP32 HAL port for SPP — polling SPI, no FreeRTOS dependency. More...

#include "spp/hal/hal.h"
#include "spp/hal/gpio/gpio.h"
#include "spp/hal/uart/uart.h"
#include "spp/core/returnTypes.h"
#include "spp/core/types.h"
#include "macrosEsp32.h"
#include "halEsp32.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "driver/gpio.h"
#include "driver/sdspi_host.h"
#include "sdmmc_cmd.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "driver/uart.h"
#include <string.h>
Include dependency graph for halEsp32.c:

Go to the source code of this file.

Functions

static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiBusInit (void)
static void * SPP_PORTS_HAL_ESP32_spiGetHandle (spp_uint8_t deviceIdx)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceInit (void *p_handle)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiTransmit (void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed (void *p_handle, spp_uint32_t speedHz)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioConfigInterrupt (spp_uint32_t pin, spp_uint32_t intrType, spp_uint32_t pull)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioRegisterIsr (spp_uint32_t pin, void *p_isrCtx)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageInit (void)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageWrite (const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
static spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeMs (void)
static spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeUs (void)
static void SPP_PORTS_HAL_ESP32_delayMs (spp_uint32_t ms)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartPortInit (void)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartTransmit (const void *p_data, spp_uint32_t len)
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartRead (void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
 Reads data from the ESP32 UART.
const SPP_HalPort_t * SPP_PORTS_ESP32S3_getHalPorts (void)
 Returns a pointer to the ESP32-S3 HAL port descriptor.
static void IRAM_ATTR SPP_PORTS_HAL_ESP32_gpioIsr (void *p_arg)

Variables

static const SPP_HALSpi_t s_esp32HalSpi
static const SPP_HALGpio_t s_esp32HalGpio
static const SPP_HALStorage_t s_esp32HalStorage
static const SPP_HALTime_t s_esp32HalTime
static const SPP_HALUart_t s_esp32HalUart
static const SPP_HalPort_t s_esp32HalPorts
static const char *const k_tag = "SPP_HAL"
static spi_device_handle_t s_spiHandles [K_ESP32_MAX_SPI_DEVICES]
static spp_uint8_t s_spiDevCount = 0U
static spp_bool_t s_busInitialized = false
static sdspi_dev_handle_t sdHandle
static sdmmc_card_t sdCard
static spp_bool_t s_storageInitialized = false

Detailed Description

ESP32 HAL port for SPP — polling SPI, no FreeRTOS dependency.

Register g_esp32HalPort before calling SPP_CORE_init().

Definition in file halEsp32.c.

Function Documentation

◆ SPP_PORTS_HAL_ESP32_spiBusInit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiBusInit ( void )
static

Definition at line 128 of file halEsp32.c.

References K_ESP32_PIN_CLK, K_ESP32_PIN_MISO, K_ESP32_PIN_MOSI, K_ESP32_SPI_HOST, K_SPP_ERROR, K_SPP_OK, k_tag, s_busInitialized, and SPP_PORTS_HAL_ESP32_spiBusInit().

Referenced by SPP_PORTS_HAL_ESP32_spiBusInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_spiGetHandle()

void * SPP_PORTS_HAL_ESP32_spiGetHandle ( spp_uint8_t deviceIdx)
static

Definition at line 166 of file halEsp32.c.

References K_ESP32_MAX_SPI_DEVICES, s_spiHandles, and SPP_PORTS_HAL_ESP32_spiGetHandle().

Referenced by SPP_PORTS_HAL_ESP32_spiGetHandle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_spiDeviceInit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceInit ( void * p_handle)
static

Definition at line 175 of file halEsp32.c.

References K_ESP32_MAX_SPI_DEVICES, K_ESP32_PIN_CS_BMP, K_ESP32_PIN_CS_ICM, K_ESP32_SPI_HOST, K_ESP32_SPI_IDX_BMP, K_ESP32_SPI_IDX_ICM, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, k_tag, s_spiDevCount, and SPP_PORTS_HAL_ESP32_spiDeviceInit().

Referenced by SPP_PORTS_HAL_ESP32_spiDeviceInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_spiTransmit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiTransmit ( void * p_handle,
spp_uint8_t * p_data,
spp_uint8_t length )
static

Definition at line 220 of file halEsp32.c.

References K_SPP_ERROR_NULL_POINTER, K_SPP_ERROR_ON_SPI_TRANSACTION, K_SPP_OK, and SPP_PORTS_HAL_ESP32_spiTransmit().

Referenced by SPP_PORTS_HAL_ESP32_spiTransmit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed ( void * p_handle,
spp_uint32_t speedHz )
static

Definition at line 267 of file halEsp32.c.

References K_ESP32_PIN_CS_SDC, K_ESP32_SPI_HOST, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, k_tag, and SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed().

Referenced by SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_gpioConfigInterrupt()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioConfigInterrupt ( spp_uint32_t pin,
spp_uint32_t intrType,
spp_uint32_t pull )
static

Definition at line 304 of file halEsp32.c.

References K_SPP_OK, and SPP_PORTS_HAL_ESP32_gpioConfigInterrupt().

Referenced by SPP_PORTS_HAL_ESP32_gpioConfigInterrupt().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_gpioRegisterIsr()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioRegisterIsr ( spp_uint32_t pin,
void * p_isrCtx )
static

Definition at line 327 of file halEsp32.c.

References K_SPP_OK, SPP_PORTS_HAL_ESP32_gpioIsr(), and SPP_PORTS_HAL_ESP32_gpioRegisterIsr().

Referenced by SPP_PORTS_HAL_ESP32_gpioRegisterIsr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_storageInit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageInit ( void )
static

Definition at line 343 of file halEsp32.c.

References K_ESP32_PIN_CS_BMP, K_ESP32_PIN_CS_ICM, K_ESP32_PIN_CS_SDC, K_ESP32_SPI_HOST, K_SPP_ERROR, K_SPP_OK, s_busInitialized, s_storageInitialized, sdCard, sdHandle, and SPP_PORTS_HAL_ESP32_storageInit().

Referenced by SPP_PORTS_HAL_ESP32_storageInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_storageWrite()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageWrite ( const void * p_buffer,
spp_uint32_t first_block,
spp_uint16_t count )
static

Definition at line 398 of file halEsp32.c.

References K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, s_storageInitialized, sdCard, and SPP_PORTS_HAL_ESP32_storageWrite().

Referenced by SPP_PORTS_HAL_ESP32_storageWrite().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_getTimeMs()

spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeMs ( void )
static

Definition at line 430 of file halEsp32.c.

References SPP_PORTS_HAL_ESP32_getTimeMs().

Referenced by SPP_PORTS_HAL_ESP32_delayMs(), and SPP_PORTS_HAL_ESP32_getTimeMs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_getTimeUs()

spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeUs ( void )
static

Definition at line 435 of file halEsp32.c.

References SPP_PORTS_HAL_ESP32_getTimeUs().

Referenced by SPP_PORTS_HAL_ESP32_getTimeUs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_delayMs()

void SPP_PORTS_HAL_ESP32_delayMs ( spp_uint32_t ms)
static

Definition at line 440 of file halEsp32.c.

References SPP_PORTS_HAL_ESP32_delayMs(), and SPP_PORTS_HAL_ESP32_getTimeMs().

Referenced by SPP_PORTS_HAL_ESP32_delayMs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_uartPortInit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartPortInit ( void )
static

Definition at line 451 of file halEsp32.c.

References K_ESP32_UART_BAUD_RATE, K_ESP32_UART_CTS_PIN, K_ESP32_UART_PORT_ID, K_ESP32_UART_RTS_PIN, K_ESP32_UART_RX_BUFFER_SIZE, K_ESP32_UART_RX_PIN, K_ESP32_UART_TX_BUFFER_SIZE, K_ESP32_UART_TX_PIN, K_SPP_ERROR, K_SPP_OK, and SPP_PORTS_HAL_ESP32_uartPortInit().

Referenced by SPP_PORTS_HAL_ESP32_uartPortInit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_uartTransmit()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartTransmit ( const void * p_data,
spp_uint32_t len )
static

Definition at line 497 of file halEsp32.c.

References K_ESP32_UART_PORT_ID, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, and SPP_PORTS_HAL_ESP32_uartTransmit().

Referenced by SPP_PORTS_HAL_ESP32_uartTransmit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_uartRead()

SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartRead ( void * p_data,
spp_uint32_t len,
spp_uint32_t * p_readBytes )
static

Reads data from the ESP32 UART.

Parameters
[out]p_dataPointer to the buffer where received data will be stored.
[in]lenNumber of bytes to read.
[out]p_readBytesPointer to the variable where the number of bytes read will be stored.

Definition at line 523 of file halEsp32.c.

References K_ESP32_UART_MAX_DELAY, K_ESP32_UART_PORT_ID, K_SPP_ERROR, K_SPP_ERROR_NULL_POINTER, K_SPP_OK, and SPP_PORTS_HAL_ESP32_uartRead().

Referenced by SPP_PORTS_HAL_ESP32_uartRead().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_ESP32S3_getHalPorts()

const SPP_HalPort_t * SPP_PORTS_ESP32S3_getHalPorts ( void )

Returns a pointer to the ESP32-S3 HAL port descriptor.

Returns
Pointer to the static SPP_HalPort_t.

Definition at line 105 of file halEsp32.c.

References s_esp32HalPorts, and SPP_PORTS_ESP32S3_getHalPorts().

Referenced by app_main(), and SPP_PORTS_ESP32S3_getHalPorts().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SPP_PORTS_HAL_ESP32_gpioIsr()

void IRAM_ATTR SPP_PORTS_HAL_ESP32_gpioIsr ( void * p_arg)
static

Definition at line 298 of file halEsp32.c.

References SPP_GpioIsrCtx_t::p_flag, and SPP_PORTS_HAL_ESP32_gpioIsr().

Referenced by SPP_PORTS_HAL_ESP32_gpioIsr(), and SPP_PORTS_HAL_ESP32_gpioRegisterIsr().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ s_esp32HalSpi

const SPP_HALSpi_t s_esp32HalSpi
static
Initial value:
= {
}
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceSetSpeed(void *p_handle, spp_uint32_t speedHz)
Definition halEsp32.c:267
static void * SPP_PORTS_HAL_ESP32_spiGetHandle(spp_uint8_t deviceIdx)
Definition halEsp32.c:166
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiBusInit(void)
Definition halEsp32.c:128
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiTransmit(void *p_handle, spp_uint8_t *p_data, spp_uint8_t length)
Definition halEsp32.c:220
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_spiDeviceInit(void *p_handle)
Definition halEsp32.c:175

Definition at line 58 of file halEsp32.c.

◆ s_esp32HalGpio

const SPP_HALGpio_t s_esp32HalGpio
static
Initial value:
= {
}
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioRegisterIsr(spp_uint32_t pin, void *p_isrCtx)
Definition halEsp32.c:327
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_gpioConfigInterrupt(spp_uint32_t pin, spp_uint32_t intrType, spp_uint32_t pull)
Definition halEsp32.c:304

Definition at line 66 of file halEsp32.c.

◆ s_esp32HalStorage

const SPP_HALStorage_t s_esp32HalStorage
static
Initial value:
= {
}
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageInit(void)
Definition halEsp32.c:343
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_storageWrite(const void *p_buffer, spp_uint32_t first_block, spp_uint16_t count)
Definition halEsp32.c:398

Definition at line 71 of file halEsp32.c.

◆ s_esp32HalTime

const SPP_HALTime_t s_esp32HalTime
static
Initial value:
= {
}
static spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeUs(void)
Definition halEsp32.c:435
static spp_uint32_t SPP_PORTS_HAL_ESP32_getTimeMs(void)
Definition halEsp32.c:430
static void SPP_PORTS_HAL_ESP32_delayMs(spp_uint32_t ms)
Definition halEsp32.c:440

Definition at line 76 of file halEsp32.c.

◆ s_esp32HalUart

const SPP_HALUart_t s_esp32HalUart
static
Initial value:
= {
}
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartRead(void *p_data, spp_uint32_t len, spp_uint32_t *p_readBytes)
Reads data from the ESP32 UART.
Definition halEsp32.c:523
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartPortInit(void)
Definition halEsp32.c:451
static SPP_RetVal_t SPP_PORTS_HAL_ESP32_uartTransmit(const void *p_data, spp_uint32_t len)
Definition halEsp32.c:497

Definition at line 82 of file halEsp32.c.

◆ s_esp32HalPorts

const SPP_HalPort_t s_esp32HalPorts
static
Initial value:
= {
.spi = s_esp32HalSpi,
.gpio = s_esp32HalGpio,
.storage = s_esp32HalStorage,
.time = s_esp32HalTime,
.uart = s_esp32HalUart,
}
static const SPP_HALTime_t s_esp32HalTime
Definition halEsp32.c:76
static const SPP_HALStorage_t s_esp32HalStorage
Definition halEsp32.c:71
static const SPP_HALGpio_t s_esp32HalGpio
Definition halEsp32.c:66
static const SPP_HALSpi_t s_esp32HalSpi
Definition halEsp32.c:58
static const SPP_HALUart_t s_esp32HalUart
Definition halEsp32.c:82

Definition at line 89 of file halEsp32.c.

Referenced by SPP_PORTS_ESP32S3_getHalPorts().

◆ k_tag

const char* const k_tag = "SPP_HAL"
static

◆ s_spiHandles

spi_device_handle_t s_spiHandles[K_ESP32_MAX_SPI_DEVICES]
static

Definition at line 116 of file halEsp32.c.

Referenced by SPP_PORTS_HAL_ESP32_spiGetHandle().

◆ s_spiDevCount

spp_uint8_t s_spiDevCount = 0U
static

Definition at line 117 of file halEsp32.c.

Referenced by SPP_PORTS_HAL_ESP32_spiDeviceInit().

◆ s_busInitialized

spp_bool_t s_busInitialized = false
static

Definition at line 118 of file halEsp32.c.

Referenced by SPP_PORTS_HAL_ESP32_spiBusInit(), and SPP_PORTS_HAL_ESP32_storageInit().

◆ sdHandle

sdspi_dev_handle_t sdHandle
static

Definition at line 120 of file halEsp32.c.

Referenced by SPP_PORTS_HAL_ESP32_storageInit().

◆ sdCard

sdmmc_card_t sdCard
static

◆ s_storageInitialized

spp_bool_t s_storageInitialized = false
static