Refactored UART frontent retrieval system
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
X(C0) X(C1) X(C2) X(C3) X(C4) X(C5) X(C6) X(C7) X(C8) X(C9) X(C10) X(C11) X(C12) X(C13) X(C14) X(C15)
|
||||
|
||||
|
||||
//Build enum map of available GPIO pins
|
||||
//Build enum map of available SHAL_GPIO pins
|
||||
enum class GPIO_Key : uint8_t {
|
||||
#define X(key) key,
|
||||
AVAILABLE_GPIO
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
|
||||
|
||||
|
||||
//Abstraction of GPIO registers
|
||||
class GPIO{
|
||||
//Abstraction of SHAL_GPIO registers
|
||||
class SHAL_GPIO{
|
||||
|
||||
public:
|
||||
|
||||
@@ -43,8 +43,8 @@ private:
|
||||
|
||||
friend class GPIOManager;
|
||||
|
||||
explicit GPIO(GPIO_Key key);
|
||||
GPIO();
|
||||
explicit SHAL_GPIO(GPIO_Key key);
|
||||
SHAL_GPIO();
|
||||
|
||||
GPIO_Key m_GPIO_KEY = GPIO_Key::INVALID;
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
|
||||
|
||||
|
||||
//Init GPIO for normal use
|
||||
//Init SHAL_GPIO for normal use
|
||||
#define PIN_TO_KEY(name) GPIO_Key::name
|
||||
#define PIN(name) GPIOManager::get(PIN_TO_KEY(name))
|
||||
|
||||
@@ -62,19 +62,19 @@ private:
|
||||
|
||||
#define GPIO_A
|
||||
|
||||
//Manages instances of GPIO objects
|
||||
//Manages instances of SHAL_GPIO objects
|
||||
class GPIOManager{
|
||||
|
||||
public:
|
||||
|
||||
static GPIO& get(GPIO_Key);
|
||||
static SHAL_GPIO& get(GPIO_Key);
|
||||
|
||||
|
||||
GPIOManager() = delete;
|
||||
|
||||
private:
|
||||
|
||||
inline static GPIO m_gpios[AVAILABLE_PORTS][PINS_PER_PORT] = {{}};
|
||||
inline static SHAL_GPIO m_gpios[AVAILABLE_PORTS][PINS_PER_PORT] = {{}};
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
* @file SHAL_TIM.h
|
||||
* @author Luca Lizaranzu
|
||||
* @brief Relating to UART and USART object abstractions
|
||||
* @brief Relating to SHAL_UART and USART object abstractions
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
|
||||
#include "SHAL_UART_REG.h"
|
||||
|
||||
class UART{
|
||||
class SHAL_UART{
|
||||
|
||||
friend class UARTManager;
|
||||
public:
|
||||
|
||||
void init(UART_Pair pair);
|
||||
|
||||
//begins Tx and Usart TODO either modify this function or add a new one that supports Rx
|
||||
void begin(uint32_t baudRate) volatile;
|
||||
|
||||
@@ -27,30 +29,29 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
UART() = default; //Initializer for array
|
||||
SHAL_UART() = default; //Initializer for array
|
||||
|
||||
//Creates a UART based on a pair of two valid U(S)ART pins
|
||||
explicit UART(UART_Pair pair);
|
||||
//Creates a SHAL_UART based on a pair of two valid U(S)ART pins
|
||||
|
||||
UART_Pair m_UARTPair = UART_Pair::INVALID;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define getUART(uart_pair) UARTManager::get(uart_pair)
|
||||
#define UART(num) UARTManager::get(num)
|
||||
|
||||
class UARTManager{
|
||||
|
||||
public:
|
||||
|
||||
static UART& get(UART_Pair pair);
|
||||
static SHAL_UART& get(uint8_t uart);
|
||||
|
||||
|
||||
UARTManager() = delete;
|
||||
|
||||
private:
|
||||
|
||||
inline static UART m_UARTs[NUM_USART_LINES] = {};
|
||||
inline static SHAL_UART m_UARTs[NUM_USART_LINES] = {};
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user