Implement UART HAL (#212)
- Implement UART HAL - Improved I2C and SPI HAL mocking mechanism (removed mock files)
This commit is contained in:
committed by
GitHub
parent
e1bfdd7c91
commit
c5fc8790bb
@@ -3,6 +3,7 @@
|
||||
#include "./SdCard.h"
|
||||
#include "./i2c/I2c.h"
|
||||
#include "Tactility/hal/spi/Spi.h"
|
||||
#include "Tactility/hal/uart/Uart.h"
|
||||
|
||||
namespace tt::hal {
|
||||
|
||||
@@ -47,6 +48,9 @@ struct Configuration {
|
||||
|
||||
/** A list of SPI interfaces */
|
||||
const std::vector<spi::Configuration> spi = {};
|
||||
|
||||
/** A list of UART interfaces */
|
||||
const std::vector<uart::Configuration> uart = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <driver/gpio.h>
|
||||
#else
|
||||
typedef unsigned int gpio_num_t;
|
||||
#endif
|
||||
@@ -1,39 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <hal/i2c_types.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef int esp_err_t;
|
||||
|
||||
typedef enum {
|
||||
enum i2c_port_t {
|
||||
I2C_NUM_0 = 0,
|
||||
I2C_NUM_1,
|
||||
LP_I2C_NUM_0,
|
||||
I2C_NUM_MAX,
|
||||
} i2c_port_t;
|
||||
};
|
||||
|
||||
typedef enum{
|
||||
enum i2c_mode_t {
|
||||
I2C_MODE_MASTER,
|
||||
I2C_MODE_MAX,
|
||||
} i2c_mode_t;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
struct i2c_config_t {
|
||||
i2c_mode_t mode;
|
||||
int sda_io_num;
|
||||
int scl_io_num;
|
||||
bool sda_pullup_en;
|
||||
bool scl_pullup_en;
|
||||
|
||||
union {
|
||||
struct {
|
||||
uint32_t clk_speed;
|
||||
} master;
|
||||
};
|
||||
uint32_t clk_flags;
|
||||
} i2c_config_t;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,58 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Gpio.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include <driver/spi_common.h>
|
||||
#else
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
enum spi_host_device_t {
|
||||
SPI1_HOST = 0,
|
||||
SPI2_HOST = 1,
|
||||
SPI3_HOST = 2,
|
||||
SPI_HOST_MAX,
|
||||
};
|
||||
|
||||
enum spi_common_dma_t {
|
||||
SPI_DMA_DISABLED = 0, ///< No DMA
|
||||
SPI_DMA_CH1 = 1, ///< DMA, select DMA Channel 1
|
||||
SPI_DMA_CH2 = 2, ///< DMA, select DMA Channel 2
|
||||
SPI_DMA_CH_AUTO = 3, ///< DMA, channel selected by driver
|
||||
};
|
||||
|
||||
enum esp_intr_cpu_affinity_t {
|
||||
ESP_INTR_CPU_AFFINITY_AUTO,
|
||||
ESP_INTR_CPU_AFFINITY_0,
|
||||
ESP_INTR_CPU_AFFINITY_1,
|
||||
};
|
||||
#define SPI_HOST_MAX 3
|
||||
|
||||
typedef int spi_host_device_t;
|
||||
struct spi_bus_config_t {
|
||||
union {
|
||||
int mosi_io_num;
|
||||
int data0_io_num;
|
||||
};
|
||||
union {
|
||||
int miso_io_num;
|
||||
int data1_io_num;
|
||||
};
|
||||
int sclk_io_num;
|
||||
union {
|
||||
int quadwp_io_num;
|
||||
int data2_io_num;
|
||||
};
|
||||
union {
|
||||
int quadhd_io_num;
|
||||
int data3_io_num;
|
||||
};
|
||||
int data4_io_num;
|
||||
int data5_io_num;
|
||||
int data6_io_num;
|
||||
int data7_io_num;
|
||||
bool data_io_default_level;
|
||||
int max_transfer_sz;
|
||||
uint32_t flags;
|
||||
esp_intr_cpu_affinity_t isr_cpu_id;
|
||||
int intr_flags;
|
||||
gpio_num_t miso_io_num;
|
||||
gpio_num_t mosi_io_num;
|
||||
gpio_num_t sclk_io_num;
|
||||
};
|
||||
struct spi_common_dma_t {};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/RtosCompat.h>
|
||||
|
||||
#include "UartCompat.h"
|
||||
#include "../Gpio.h"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace tt::hal::uart {
|
||||
|
||||
enum class InitMode {
|
||||
ByTactility, // Tactility will initialize it in the correct bootup phase
|
||||
ByExternal, // The device is already initialized and Tactility should assume it works
|
||||
Disabled // Not initialized by default
|
||||
};
|
||||
|
||||
struct Configuration {
|
||||
uart_port_t port;
|
||||
/** Whether this bus should be initialized when device starts up */
|
||||
InitMode initMode;
|
||||
/** Whether this bus can stopped and re-started. */
|
||||
bool canReinit;
|
||||
/** Whether .config can be changed. */
|
||||
bool hasMutableConfiguration;
|
||||
/** Receive GPIO pin */
|
||||
gpio_num_t rxPin;
|
||||
/** Transmit GPIO pin */
|
||||
gpio_num_t txPin;
|
||||
/** Read-To-Send GPIO pin */
|
||||
gpio_num_t rtsPin;
|
||||
/** Clear-To-Send Send GPIO pin */
|
||||
gpio_num_t ctsPin;
|
||||
/** Receive buffer size in bytes */
|
||||
unsigned int rxBufferSize;
|
||||
/** Transmit buffer size in bytes */
|
||||
unsigned int txBufferSize;
|
||||
/** Native configuration */
|
||||
uart_config_t config;
|
||||
};
|
||||
|
||||
enum class Status {
|
||||
Started,
|
||||
Stopped,
|
||||
Unknown
|
||||
};
|
||||
|
||||
bool init(const std::vector<uart::Configuration>& configurations);
|
||||
|
||||
bool start(uart_port_t port);
|
||||
bool stop(uart_port_t port);
|
||||
bool isStarted(uart_port_t port);
|
||||
|
||||
bool lock(uart_port_t port, TickType_t timeout = 10 / portTICK_PERIOD_MS);
|
||||
bool unlock(uart_port_t port);
|
||||
|
||||
size_t read(uart_port_t port, uint8_t* buffer, size_t bufferSize, TickType_t timeout = 10 / portTICK_PERIOD_MS);
|
||||
size_t write(uart_port_t port, const uint8_t* buffer, size_t bufferSize, TickType_t timeout = 10 / portTICK_PERIOD_MS);
|
||||
|
||||
} // namespace tt::hal::uart
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
|
||||
#include <driver/uart.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <hal/uart_types.h>
|
||||
|
||||
#else
|
||||
|
||||
#define UART_NUM_MAX 3
|
||||
typedef int uart_port_t;
|
||||
|
||||
typedef struct {
|
||||
} uart_config_t;
|
||||
|
||||
#endif
|
||||
@@ -11,6 +11,8 @@ enum class SystemEvent {
|
||||
BootInitI2cEnd,
|
||||
BootInitSpiBegin,
|
||||
BootInitSpiEnd,
|
||||
BootInitUartBegin,
|
||||
BootInitUartEnd,
|
||||
BootInitLvglBegin,
|
||||
BootInitLvglEnd,
|
||||
BootSplash,
|
||||
|
||||
Reference in New Issue
Block a user