Refactored UART frontent retrieval system
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
|
||||
|
||||
|
||||
GPIO::GPIO() : m_GPIO_KEY(GPIO_Key::INVALID){
|
||||
SHAL_GPIO::SHAL_GPIO() : m_GPIO_KEY(GPIO_Key::INVALID){
|
||||
//Do not initialize anything
|
||||
}
|
||||
|
||||
GPIO::GPIO(GPIO_Key key) : m_GPIO_KEY(key) {
|
||||
SHAL_GPIO::SHAL_GPIO(GPIO_Key key) : m_GPIO_KEY(key) {
|
||||
|
||||
volatile unsigned long* gpioEnable = getGPIORCCEnable(key).reg;
|
||||
unsigned long gpioOffset = getGPIORCCEnable(key).offset;
|
||||
@@ -19,41 +19,41 @@ GPIO::GPIO(GPIO_Key key) : m_GPIO_KEY(key) {
|
||||
*gpioEnable |= (1 << gpioOffset); //Set enable flag
|
||||
}
|
||||
|
||||
void GPIO::setLow() {
|
||||
void SHAL_GPIO::setLow() {
|
||||
auto gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->ODR &= ~(1 << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
void GPIO::setHigh() {
|
||||
void SHAL_GPIO::setHigh() {
|
||||
auto gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->ODR |= (1 << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
void GPIO::toggle() volatile {
|
||||
void SHAL_GPIO::toggle() volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->ODR ^= (1 << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void GPIO::setPinType(PinType type) volatile {
|
||||
void SHAL_GPIO::setPinType(PinType type) volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->OTYPER &= ~(1 << gpioPeripheral.global_offset);
|
||||
gpioPeripheral.reg->OTYPER |= (static_cast<uint8_t>(type) << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
void GPIO::setOutputSpeed(OutputSpeed speed) volatile {
|
||||
void SHAL_GPIO::setOutputSpeed(OutputSpeed speed) volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->OSPEEDR |= (static_cast<uint8_t>(speed) << (2 * gpioPeripheral.global_offset));
|
||||
}
|
||||
|
||||
void GPIO::setInternalResistor(InternalResistorType type) volatile {
|
||||
void SHAL_GPIO::setInternalResistor(InternalResistorType type) volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->PUPDR &= ~(0x03 << (2 * gpioPeripheral.global_offset));
|
||||
gpioPeripheral.reg->PUPDR |= (static_cast<uint8_t>(type) << (2 * gpioPeripheral.global_offset));
|
||||
}
|
||||
|
||||
void GPIO::setAlternateFunction(GPIO_Alternate_Function AF) volatile {
|
||||
void SHAL_GPIO::setAlternateFunction(GPIO_Alternate_Function AF) volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
|
||||
int afrIndex = gpioPeripheral.global_offset < 8 ? 0 : 1; //Get index of AFR
|
||||
@@ -62,13 +62,13 @@ void GPIO::setAlternateFunction(GPIO_Alternate_Function AF) volatile {
|
||||
gpioPeripheral.reg->AFR[afrIndex] |= (static_cast<int>(AF) << (gpioPeripheral.global_offset * 4));
|
||||
}
|
||||
|
||||
void GPIO::setPinMode(PinMode mode) volatile {
|
||||
void SHAL_GPIO::setPinMode(PinMode mode) volatile {
|
||||
SHAL_GPIO_Peripheral gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
gpioPeripheral.reg->MODER &= ~(0x03 << (2 * gpioPeripheral.global_offset)); //Clear any previous mode
|
||||
gpioPeripheral.reg->MODER |= (static_cast<uint8_t>(mode) << (2 * gpioPeripheral.global_offset)); //Set mode based on pinmode bit structure
|
||||
}
|
||||
|
||||
void GPIO::useAsExternalInterrupt(TriggerMode mode, EXTICallback callback) {
|
||||
void SHAL_GPIO::useAsExternalInterrupt(TriggerMode mode, EXTICallback callback) {
|
||||
|
||||
uint32_t gpioPin = getGPIORegister(m_GPIO_KEY).global_offset; //Use existing structs to get offset
|
||||
|
||||
@@ -108,13 +108,13 @@ void GPIO::useAsExternalInterrupt(TriggerMode mode, EXTICallback callback) {
|
||||
}
|
||||
|
||||
|
||||
GPIO& GPIOManager::get(GPIO_Key key) {
|
||||
SHAL_GPIO& GPIOManager::get(GPIO_Key key) {
|
||||
|
||||
unsigned int gpioPort = getGPIOPortNumber(key);
|
||||
unsigned long gpioPin = getGPIORegister(key).global_offset; //Use existing structs to get offset
|
||||
|
||||
if (m_gpios[gpioPort][gpioPin].m_GPIO_KEY == GPIO_Key::INVALID){
|
||||
m_gpios[gpioPort][gpioPin] = GPIO(key);
|
||||
m_gpios[gpioPort][gpioPin] = SHAL_GPIO(key);
|
||||
}
|
||||
|
||||
return m_gpios[gpioPort][gpioPin];
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
******************************************************************************
|
||||
* @file SHAL_TIM.h
|
||||
* @author Luca Lizaranzu
|
||||
* @brief Related to USART and UART abstractions
|
||||
* @brief Related to USART and SHAL_UART abstractions
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
@@ -10,10 +10,13 @@
|
||||
#include "SHAL_UART.h"
|
||||
#include "SHAL_GPIO.h"
|
||||
|
||||
UART::UART(const UART_Pair pair) : m_UARTPair(pair){
|
||||
void SHAL_UART::init(const UART_Pair pair){
|
||||
|
||||
m_UARTPair = pair;
|
||||
|
||||
SHAL_UART_Pair uart_pair = getUARTPair(pair); //Get the UART_PAIR information to be initialized
|
||||
|
||||
//Get the GPIO pins for this UART setup
|
||||
//Get the SHAL_GPIO pins for this SHAL_UART setup
|
||||
GPIO_Key Tx_Key = uart_pair.TxKey; //Tx pin
|
||||
GPIO_Key Rx_Key = uart_pair.RxKey; //Rx pin
|
||||
|
||||
@@ -23,12 +26,12 @@ UART::UART(const UART_Pair pair) : m_UARTPair(pair){
|
||||
GET_GPIO(Tx_Key).setAlternateFunction(uart_pair.TxAlternateFunctionMask);
|
||||
GET_GPIO(Rx_Key).setAlternateFunction(uart_pair.RxAlternateFunctionMask);
|
||||
|
||||
SHAL_UART_ENABLE_REG pairUARTEnable = getUARTEnableReg(pair); //Register and mask to enable the UART channel
|
||||
SHAL_UART_ENABLE_REG pairUARTEnable = getUARTEnableReg(pair); //Register and mask to enable the SHAL_UART channel
|
||||
|
||||
*pairUARTEnable.reg |= pairUARTEnable.mask; //Enable UART line
|
||||
*pairUARTEnable.reg |= pairUARTEnable.mask; //Enable SHAL_UART line
|
||||
}
|
||||
|
||||
void UART::begin(uint32_t baudRate) volatile {
|
||||
void SHAL_UART::begin(uint32_t baudRate) volatile {
|
||||
|
||||
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
||||
|
||||
@@ -44,11 +47,11 @@ void UART::begin(uint32_t baudRate) volatile {
|
||||
|
||||
}
|
||||
|
||||
void UART::sendString(const char *s) volatile {
|
||||
void SHAL_UART::sendString(const char *s) volatile {
|
||||
while (*s) sendChar(*s++); //Send chars while we haven't reached end of s
|
||||
}
|
||||
|
||||
void UART::sendChar(char c) volatile {
|
||||
void SHAL_UART::sendChar(char c) volatile {
|
||||
|
||||
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
||||
|
||||
@@ -59,11 +62,6 @@ void UART::sendChar(char c) volatile {
|
||||
|
||||
|
||||
|
||||
UART& UARTManager::get(UART_Pair 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)];
|
||||
SHAL_UART& UARTManager::get(uint8_t uart) {
|
||||
return m_UARTs[uart];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user