From a02ec044ce7096cc4b6efeec3f568a6f5d9b8b2d Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 8 Sep 2025 00:42:54 -0700 Subject: [PATCH] Merged branch UART and changed get function --- SHAL/Include/Peripheral/UART/SHAL_UART.h | 2 +- SHAL/Src/Peripheral/UART/SHAL_UART.cpp | 10 +++++----- SHAL/Src/main.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SHAL/Include/Peripheral/UART/SHAL_UART.h b/SHAL/Include/Peripheral/UART/SHAL_UART.h index c8f9f58..ba7ba68 100644 --- a/SHAL/Include/Peripheral/UART/SHAL_UART.h +++ b/SHAL/Include/Peripheral/UART/SHAL_UART.h @@ -37,7 +37,7 @@ private: }; -#define initUART(uart_pair) UARTManager::get(uart_pair) +#define getUART(uart_pair) UARTManager::get(uart_pair) class UARTManager{ diff --git a/SHAL/Src/Peripheral/UART/SHAL_UART.cpp b/SHAL/Src/Peripheral/UART/SHAL_UART.cpp index a866260..ee35724 100644 --- a/SHAL/Src/Peripheral/UART/SHAL_UART.cpp +++ b/SHAL/Src/Peripheral/UART/SHAL_UART.cpp @@ -31,7 +31,7 @@ UART::UART(const UART_Pair pair) : m_UARTPair(pair){ * The AFR register for GPIO_Typedef* is actually two registers - a low reg and high reg. * The low reg handles pins 0-7, and the high reg handles 8-15. * Each pin gets 4 bits in the register for AFR0 - AFR7. Hence 8 * 4 = 32 bits. - * Each AFR is a different function, look at the DATASHEET (not reference manual) to find these alternate functions + * Each AFR is a different function, look at the DATASHEET (not reference manual) to find these alternate function mappings */ getGPIORegister(Tx_Key).reg->AFR[TxAFR] |= getAFMask(uart_pair.TxMask) << (4 * (Tx_Pin % 8)); getGPIORegister(Rx_Key).reg->AFR[RxAFR] |= getAFMask(uart_pair.RxMask) << (4 * (Rx_Pin % 8)); @@ -72,11 +72,11 @@ void UART::sendChar(char c) { - UART& UARTManager::get(UART_Pair pair) { - //Always reassign since we could be changing to different pins for some reason - m_UARTs[getUARTChannel(pair)] = UART(pair); - + //Reassign if pair doesn't match + if(m_UARTs[getUARTChannel(pair)].m_UARTPair != pair) { + m_UARTs[getUARTChannel(pair)] = UART(pair); + } return m_UARTs[getUARTChannel(pair)]; } diff --git a/SHAL/Src/main.cpp b/SHAL/Src/main.cpp index ce78af1..1b880a1 100644 --- a/SHAL/Src/main.cpp +++ b/SHAL/Src/main.cpp @@ -18,7 +18,7 @@ void tim2Handler(){ int main() { - UART uart2 = initUART(UART_Pair::Tx2A2_Rx2A3); + UART uart2 = getUART(UART_Pair::Tx2A2_Rx2A3); uart2.begin(115200);