From 84ab921291d8b8d54eb4435820a86f69e76cbcab Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 7 Sep 2025 03:54:03 -0700 Subject: [PATCH] Began UART initializer --- .../UART/Reg/SHAL_UART_REG_F072xB.h | 1 - .../Peripheral/UART/Reg/SHAL_UART_TYPES.h | 6 ++--- SHAL/Include/Peripheral/UART/SHAL_UART.h | 2 +- SHAL/Src/Peripheral/UART/SHAL_UART.cpp | 22 ++++++++++++++++++- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_F072xB.h b/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_F072xB.h index 0224c49..fbf31b4 100644 --- a/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_F072xB.h +++ b/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_REG_F072xB.h @@ -9,7 +9,6 @@ #include #include "SHAL_UART_TYPES.h" -#include "SHAL_GPIO_REG.h" #define NUM_USART_LINES 4 diff --git a/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_TYPES.h b/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_TYPES.h index e86f644..30de033 100644 --- a/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_TYPES.h +++ b/SHAL/Include/Peripheral/UART/Reg/SHAL_UART_TYPES.h @@ -6,7 +6,7 @@ #define SHMINGO_HAL_SHAL_UART_TYPES_H #include "SHAL_CORE.h" -#include "SHAL_GPIO_REG.h" +#include "SHAL_GPIO.h" enum class AF_Mask : uint8_t{ AF0 = 0x00, @@ -30,8 +30,8 @@ struct SHAL_UART_Pair{ }; struct SHAL_UART_ENABLE_REG{ - volatile uint32_t* USART_EN_Reg; - uint32_t USART_EN_Mask; + volatile uint32_t* reg; + uint32_t mask; }; #endif //SHMINGO_HAL_SHAL_UART_TYPES_H diff --git a/SHAL/Include/Peripheral/UART/SHAL_UART.h b/SHAL/Include/Peripheral/UART/SHAL_UART.h index 0959999..1283129 100644 --- a/SHAL/Include/Peripheral/UART/SHAL_UART.h +++ b/SHAL/Include/Peripheral/UART/SHAL_UART.h @@ -27,7 +27,7 @@ private: UART() = default; //Initializer for array //Creates a UART based on a pair of two valid U(S)ART pins - explicit UART(const UART_Pair pair); + explicit UART(UART_Pair pair); UART_Pair m_UARTPair = UART_Pair::INVALID; diff --git a/SHAL/Src/Peripheral/UART/SHAL_UART.cpp b/SHAL/Src/Peripheral/UART/SHAL_UART.cpp index 6e6f65a..881ebf6 100644 --- a/SHAL/Src/Peripheral/UART/SHAL_UART.cpp +++ b/SHAL/Src/Peripheral/UART/SHAL_UART.cpp @@ -8,7 +8,27 @@ #include "SHAL_UART.h" +#include "SHAL_GPIO.h" UART::UART(const UART_Pair pair){ + SHAL_UART_Pair uart_pair = getUARTPair(pair); //Get the UART_PAIR information to be initialized -} \ No newline at end of file + //Get the GPIO pins for this UART setup + GPIO_Key Tx_Key = uart_pair.TxKey; //Tx pin + GPIO_Key Rx_Key = uart_pair.RxKey; //Rx pin + + initGPIO(Tx_Key,PinMode::ALTERNATE_FUNCTION_MODE); //Initialize Tx GPIO with alternate function (initializes GPIO port as well) + initGPIO(Rx_Key,PinMode::ALTERNATE_FUNCTION_MODE); //Initialize Rx GPIO with alternate function + + SHAL_UART_ENABLE_REG pairUARTEnable = getUARTEnableReg(pair); //Register and mask to enable the UART channel + + *pairUARTEnable.reg |= pairUARTEnable.mask; //Enable UART line +} + + +UART& UARTManager::get(UART_Pair pair) { + + //Perform logic for reassigning UART object in array + + return m_UARTs[getUARTChannel(pair)]; +}