semf
stm32externalinterrupt.cpp
Go to the documentation of this file.
1
12
13#if defined(STM32)
14extern "C" void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
15{
17}
18namespace semf
19{
20Stm32ExternalInterrupt::Stm32ExternalInterrupt(uint32_t externalInterruptPort, uint32_t externalInterruptPinLine)
21: m_externalInterruptPort(externalInterruptPort),
22 m_handle{externalInterruptPinLine, nullptr}
23{
24 queue()->push(*this);
25}
26
28{
30 return &queue;
31}
32
34{
35 for (Stm32ExternalInterrupt& i : *(queue()))
36 i.isr(pin);
37}
38
40{
41 if (pin == 0x01 << (m_handle.Line & EXTI_PIN_MASK))
42 {
43 SEMF_INFO("changed on pin %u", pin);
44 changed();
45 }
46}
47
49{
50 EXTI_ConfigTypeDef configTypeDef;
51 configTypeDef.Trigger = trigger;
52 configTypeDef.Line = m_handle.Line;
53 configTypeDef.Mode = EXTI_MODE_INTERRUPT;
54 configTypeDef.GPIOSel = m_externalInterruptPort;
55
56 SEMF_INFO("set trigger %u for pin on line %u", trigger, 0x01 << (m_handle.Line & EXTI_PIN_MASK));
57
58 HAL_StatusTypeDef hal_status = HAL_EXTI_SetConfigLine(&m_handle, &configTypeDef);
59
60 if (hal_status != HAL_OK)
61 {
62 if (hal_status != HAL_OK)
63 {
64 if (hal_status == HAL_ERROR)
65 {
66 SEMF_ERROR("hal error");
67 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::SetConfigLine_HalError)));
68 }
69 else if (hal_status == HAL_BUSY)
70 {
71 SEMF_ERROR("hal busy");
72 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::SetConfigLine_HalBusy)));
73 }
74 else if (hal_status == HAL_TIMEOUT)
75 {
76 SEMF_ERROR("hal timeout");
77 error(Error(kSemfClassId, static_cast<uint8_t>(ErrorCode::SetConfigLine_HalTimeout)));
78 }
79 return;
80 }
81 }
82}
83} /* namespace semf */
84#endif
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
Definition: error.h:22
LinkedQueue is an managed single linked queue implementation.
Definition: linkedqueue.h:38
ExternalInterrupt implementation for STM32.
static LinkedQueue< Stm32ExternalInterrupt > * queue()
Get the list with all external interrupts.
Stm32ExternalInterrupt(uint32_t externalInterruptPort, uint32_t externalInterruptPinLine)
Constructor.
static void systemIsr(uint16_t pin)
void setTrigger(Trigger trigger) override
Sets the trigger condition of an EXTI.
#define SEMF_ERROR(...)
Definition: debug.h:39
#define SEMF_INFO(...)
Definition: debug.h:41
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)