EXTI interrupt abstraction feature complete
This commit is contained in:
@@ -22,11 +22,11 @@ extern "C" void EXTI##EXTI_Channel##_IRQHandler(void) { \
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DEFINE_MULTI_EXTI_IRQ(EXTI_Channel_Min, EXTI_Channel_Max) \
|
#define DEFINE_MULTI_EXTI_IRQ(EXTI_Channel_Min, EXTI_Channel_Max) \
|
||||||
extern "C" void EXTI##EXTI_Channel_Max##_##EXTI_Channel_Min##_IRQHandler(void) { \
|
extern "C" void EXTI##EXTI_Channel_Min##_##EXTI_Channel_Max##_IRQHandler(void) { \
|
||||||
for(uint8_t line = EXTI_Channel_Min; line <= EXTI_Channel_Max; line++){ \
|
for(uint8_t line = EXTI_Channel_Min; line <= EXTI_Channel_Max; line++){ \
|
||||||
if (EXTI->PR & (1 << line)) { \
|
if (EXTI->PR & (1 << line)) { \
|
||||||
EXTI->PR |= (1 << line); /*clear flag */ \
|
EXTI->PR |= (1 << line); /*clear flag */ \
|
||||||
auto cb = EXTI_callbacks[line]; \
|
auto cb = EXTI_callbacks[line]; \
|
||||||
if (cb) cb(); \
|
if (cb) cb(); \
|
||||||
}; \
|
}; \
|
||||||
} \
|
} \
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ constexpr SHAL_Peripheral_Register getGPIORCCEnable(const GPIO_Key g){
|
|||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr unsigned int getGPIOPortNumber(const GPIO_Key g){
|
constexpr uint32_t getGPIOPortNumber(const GPIO_Key g){
|
||||||
switch(g) {
|
switch(g) {
|
||||||
case GPIO_Key::A0:
|
case GPIO_Key::A0:
|
||||||
case GPIO_Key::A1:
|
case GPIO_Key::A1:
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ class UART{
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
//begins Tx and Usart TODO either modify this function or add a new one that supports Rx
|
//begins Tx and Usart TODO either modify this function or add a new one that supports Rx
|
||||||
void begin(uint32_t baudRate);
|
void begin(uint32_t baudRate) volatile;
|
||||||
|
|
||||||
//Sends a string
|
//Sends a string
|
||||||
void sendString(const char* s);
|
void sendString(const char* s) volatile;
|
||||||
|
|
||||||
//Sends a char
|
//Sends a char
|
||||||
void sendChar(char c);
|
void sendChar(char c) volatile;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,9 @@ GPIO& GPIOManager::get(GPIO_Key key, PinMode pinMode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GPIOManager::getInterruptGPIO(GPIO_Key key, TriggerMode triggerMode, EXTICallback callback) {
|
void GPIOManager::getInterruptGPIO(GPIO_Key key, TriggerMode triggerMode, EXTICallback callback) {
|
||||||
unsigned int gpioPort = getGPIOPortNumber(key);
|
|
||||||
unsigned long gpioPin = getGPIORegister(key).global_offset; //Use existing structs to get offset
|
uint32_t gpioPort = getGPIOPortNumber(key);
|
||||||
|
uint32_t gpioPin = getGPIORegister(key).global_offset; //Use existing structs to get offset
|
||||||
|
|
||||||
if (m_gpios[gpioPort][gpioPin].m_GPIO_KEY == GPIO_Key::INVALID){
|
if (m_gpios[gpioPort][gpioPin].m_GPIO_KEY == GPIO_Key::INVALID){
|
||||||
m_gpios[gpioPort][gpioPin] = GPIO(key,PinMode::INPUT_MODE); //Hardcode input mode for interrupt
|
m_gpios[gpioPort][gpioPin] = GPIO(key,PinMode::INPUT_MODE); //Hardcode input mode for interrupt
|
||||||
@@ -112,4 +113,6 @@ void GPIOManager::getInterruptGPIO(GPIO_Key key, TriggerMode triggerMode, EXTICa
|
|||||||
|
|
||||||
//Set callback
|
//Set callback
|
||||||
registerEXTICallback(key,callback);
|
registerEXTICallback(key,callback);
|
||||||
|
|
||||||
|
__enable_irq(); //Enable IRQ just in case
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ UART::UART(const UART_Pair pair) : m_UARTPair(pair){
|
|||||||
*pairUARTEnable.reg |= pairUARTEnable.mask; //Enable UART line
|
*pairUARTEnable.reg |= pairUARTEnable.mask; //Enable UART line
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART::begin(uint32_t baudRate) {
|
void UART::begin(uint32_t baudRate) volatile {
|
||||||
|
|
||||||
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
||||||
|
|
||||||
@@ -57,11 +57,11 @@ void UART::begin(uint32_t baudRate) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART::sendString(const char *s) {
|
void UART::sendString(const char *s) volatile {
|
||||||
while (*s) sendChar(*s++); //Send chars while we haven't reached end of s
|
while (*s) sendChar(*s++); //Send chars while we haven't reached end of s
|
||||||
}
|
}
|
||||||
|
|
||||||
void UART::sendChar(char c) {
|
void UART::sendChar(char c) volatile {
|
||||||
|
|
||||||
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
USART_TypeDef* usart = getUARTPair(m_UARTPair).USARTReg;
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,10 @@
|
|||||||
|
|
||||||
volatile GPIO* blueLED = nullptr;
|
volatile GPIO* blueLED = nullptr;
|
||||||
volatile GPIO* greenLED = nullptr;
|
volatile GPIO* greenLED = nullptr;
|
||||||
|
volatile UART* uart2;
|
||||||
|
|
||||||
extern "C" void EXTI0_1_IRQHandler(void) {
|
void c3Interrupt(){
|
||||||
if (EXTI->PR & (1 << 0)) { //Check pending flag
|
greenLED->toggle();
|
||||||
EXTI->PR |= (1 << 0); //Clear it by writing 1
|
|
||||||
greenLED->toggle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tim2Handler(){
|
void tim2Handler(){
|
||||||
@@ -18,11 +16,11 @@ void tim2Handler(){
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
UART uart2 = getUART(UART_Pair::Tx2A2_Rx2A3);
|
uart2 = &getUART(UART_Pair::Tx2A2_Rx2A3);
|
||||||
|
|
||||||
uart2.begin(115200);
|
uart2->begin(115200);
|
||||||
|
|
||||||
RCC->AHBENR |= RCC_AHBENR_GPIOBEN;
|
useGPIOAsInterrupt(GPIO_Key::C3,TriggerMode::RISING_EDGE,c3Interrupt);
|
||||||
|
|
||||||
Timer timer2 = getTimer(Timer_Key::S_TIM2);
|
Timer timer2 = getTimer(Timer_Key::S_TIM2);
|
||||||
|
|
||||||
@@ -34,20 +32,7 @@ int main() {
|
|||||||
timer2.setCallbackFunc(tim2Handler);
|
timer2.setCallbackFunc(tim2Handler);
|
||||||
timer2.start();
|
timer2.start();
|
||||||
|
|
||||||
RCC->APB2ENR |= RCC_APB2ENR_SYSCFGCOMPEN; //Enable SYSCFG clock (needed for EXTI)
|
|
||||||
|
|
||||||
SYSCFG->EXTICR[0] &= ~SYSCFG_EXTICR1_EXTI0; //Clear EXTI0 mapping
|
|
||||||
SYSCFG->EXTICR[0] |= SYSCFG_EXTICR1_EXTI0_PB; //Map PA0 -> EXTI0
|
|
||||||
|
|
||||||
EXTI->IMR |= (1 << 0); //Unmask EXTI0
|
|
||||||
EXTI->RTSR |= (1 << 0); //Trigger on rising edge
|
|
||||||
|
|
||||||
NVIC_EnableIRQ(EXTI0_1_IRQn); //EXTI lines 0 and 1 share an IRQ vector
|
|
||||||
|
|
||||||
__enable_irq();
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
__WFI();
|
__WFI();
|
||||||
uart2.sendString("Hello\r\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user