Created structs and enums for alternate function UART pins
This commit is contained in:
@@ -23,11 +23,7 @@ struct SHAL_Peripheral_Register {
|
||||
unsigned long offset;
|
||||
};
|
||||
|
||||
struct SHAL_EXTIO_Register{
|
||||
volatile uint32_t* EXT_ICR;
|
||||
unsigned long mask;
|
||||
IRQn_Type IRQN;
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
|
||||
39
SHAL/Include/Peripheral/GPIO/Reg/SHAL_GPIO_REG.h
Normal file
39
SHAL/Include/Peripheral/GPIO/Reg/SHAL_GPIO_REG.h
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by Luca on 9/6/2025.
|
||||
//
|
||||
|
||||
#ifndef SHMINGO_HAL_SHAL_GPIO_REG_H
|
||||
#define SHMINGO_HAL_SHAL_GPIO_REG_H
|
||||
|
||||
#include "SHAL_CORE.h"
|
||||
|
||||
struct SHAL_EXTIO_Register{
|
||||
volatile uint32_t* EXT_ICR;
|
||||
uint32_t mask;
|
||||
IRQn_Type IRQN;
|
||||
};
|
||||
|
||||
enum class AF_Mask : uint8_t{
|
||||
AF0 = 0x00,
|
||||
AF1 = 0x01,
|
||||
AF2 = 0x02,
|
||||
AF3 = 0x03,
|
||||
AF4 = 0x04,
|
||||
AF5 = 0x05,
|
||||
AF6 = 0x06,
|
||||
AF7 = 0x07
|
||||
};
|
||||
|
||||
//Represents a pair of pins usable for USART Tx + Rx in combination, and their alternate function mapping
|
||||
struct SHAL_UART_Pair{
|
||||
uint8_t TxPinNumber;
|
||||
uint8_t RxPinNumber;
|
||||
volatile uint32_t* TxReg;
|
||||
volatile uint32_t* RxReg;
|
||||
AF_Mask TxMask;
|
||||
AF_Mask RxMask;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif //SHMINGO_HAL_SHAL_GPIO_REG_H
|
||||
@@ -8,7 +8,7 @@
|
||||
#include <stm32f072xb.h>
|
||||
#include <cassert>
|
||||
|
||||
#include "SHAL_CORE.h"
|
||||
#include "SHAL_GPIO_REG.h"
|
||||
|
||||
#define AVAILABLE_PORTS 3
|
||||
#define PINS_PER_PORT 16
|
||||
@@ -29,6 +29,40 @@ enum class GPIO_Key : uint8_t {
|
||||
INVALID
|
||||
};
|
||||
|
||||
//Valid usart Tx and Rx pairings for STM32F072
|
||||
enum class UART_Pair : uint8_t{
|
||||
//UART1
|
||||
Tx1A9_Rx1A10,
|
||||
Tx1B6_Rx1B7,
|
||||
|
||||
//UART2
|
||||
Tx2A2_Rx2A3,
|
||||
Tx2A14_Rx2A15,
|
||||
|
||||
//UART3
|
||||
Tx3B10_Rx3B11,
|
||||
Tx3C4_Rx3C5,
|
||||
Tx3C10_Rx3C11,
|
||||
|
||||
//UART4
|
||||
Tx4A0_Rx4A1,
|
||||
Tx4C10_Rx4C11
|
||||
};
|
||||
|
||||
constexpr SHAL_UART_Pair getUARTPair(const UART_Pair pair){
|
||||
switch(pair){
|
||||
case UART_Pair::Tx1A9_Rx1A10: return {9,10,&GPIOA->AFR[1],&GPIOA->AFR[1],AF_Mask::AF1,AF_Mask::AF1};
|
||||
case UART_Pair::Tx1B6_Rx1B7: return {6,7,&GPIOB->AFR[0],&GPIOB->AFR[0],AF_Mask::AF0,AF_Mask::AF0};
|
||||
case UART_Pair::Tx2A2_Rx2A3: return {2,3,&GPIOA->AFR[0],&GPIOA->AFR[0],AF_Mask::AF1,AF_Mask::AF1};
|
||||
case UART_Pair::Tx2A14_Rx2A15: return {14,15,&GPIOA->AFR[1],&GPIOA->AFR[1],AF_Mask::AF1,AF_Mask::AF1};
|
||||
case UART_Pair::Tx3B10_Rx3B11: return {10,11,&GPIOB->AFR[1],&GPIOB->AFR[1],AF_Mask::AF4,AF_Mask::AF4};
|
||||
case UART_Pair::Tx3C4_Rx3C5: return {4,5,&GPIOC->AFR[0],&GPIOC->AFR[0],AF_Mask::AF1,AF_Mask::AF1};
|
||||
case UART_Pair::Tx3C10_Rx3C11: return {10,11,&GPIOC->AFR[1],&GPIOC->AFR[1],AF_Mask::AF1,AF_Mask::AF1};
|
||||
case UART_Pair::Tx4A0_Rx4A1: return {0,1,&GPIOA->AFR[0],&GPIOA->AFR[0],AF_Mask::AF4,AF_Mask::AF4};
|
||||
case UART_Pair::Tx4C10_Rx4C11: return {10,11,&GPIOC->AFR[1],&GPIOC->AFR[1],AF_Mask::AF0,AF_Mask::AF0};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
constexpr SHAL_Peripheral getGPIORegister(const GPIO_Key g){
|
||||
switch(g) {
|
||||
@@ -269,4 +303,6 @@ constexpr unsigned int getGPIOPortNumber(const GPIO_Key g){
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif //SHMINGO_HAL_SHAL_GPIO_REG_F072XB_H
|
||||
|
||||
@@ -40,7 +40,7 @@ class GPIO{
|
||||
|
||||
public:
|
||||
|
||||
void toggle();
|
||||
void toggle() volatile;
|
||||
|
||||
//TODO replace stupid offset hack from APB
|
||||
void setHigh();
|
||||
|
||||
@@ -55,7 +55,7 @@ void GPIO::setHigh() {
|
||||
static_cast<GPIO_TypeDef*>(gpioPeripheral.registers)->ODR |= (1 << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
void GPIO::toggle() {
|
||||
void GPIO::toggle() volatile {
|
||||
auto gpioPeripheral = getGPIORegister(m_GPIO_KEY);
|
||||
static_cast<GPIO_TypeDef*>(gpioPeripheral.registers)->ODR ^= (1 << gpioPeripheral.global_offset);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "stm32f0xx.h"
|
||||
|
||||
|
||||
GPIO* blueLED = nullptr;
|
||||
GPIO* greenLED = nullptr;
|
||||
volatile GPIO* blueLED = nullptr;
|
||||
volatile GPIO* greenLED = nullptr;
|
||||
|
||||
extern "C" void EXTI0_1_IRQHandler(void) {
|
||||
if (EXTI->PR & (1 << 0)) { //Check pending flag
|
||||
|
||||
Reference in New Issue
Block a user