semf
stm32inputcapture.h
Go to the documentation of this file.
1
10#ifndef SEMF_HARDWAREABSTRACTION_STM32_STM32INPUTCAPTURE_H_
11#define SEMF_HARDWAREABSTRACTION_STM32_STM32INPUTCAPTURE_H_
12
15
16#if defined(STM32) && defined(HAL_TIM_MODULE_ENABLED)
18#include <cstdint>
19namespace semf
20{
24class Stm32InputCapture : public InputCapture, public LinkedQueue<Stm32InputCapture>::Node
25{
26public:
28 enum class ErrorCode : uint8_t
29 {
30 Start_Error = 0,
31 Start_Busy,
32 Start_Timeout,
33 Stop_Error,
34 Stop_Busy,
35 Stop_Timeout,
36 SetTrigger_Busy,
37 SetTrigger_TriggerInvalid
38 };
39
46 Stm32InputCapture(TIM_HandleTypeDef& hwHandle, uint32_t channel, unsigned int ticksPerSecond);
47 explicit Stm32InputCapture(const Stm32InputCapture& other) = delete;
48 virtual ~Stm32InputCapture() = default;
49
50 unsigned int ticksPerSecond() const override;
51 void setMaxTicks(unsigned int maxTicks) override;
52 unsigned int maxTicks() const override;
59 void start() override;
66 void stop() override;
67 unsigned int ticks() override;
73 void setTrigger(Trigger trigger) override;
78 static void systemIsr(TIM_HandleTypeDef& hwHandle);
83 void isr(TIM_HandleTypeDef& hwHandle);
84
85private:
87 static LinkedQueue<Stm32InputCapture> m_queue;
89 TIM_HandleTypeDef* m_hwHandle;
91 uint32_t m_channel;
93 const unsigned int m_ticksPerSecond;
95 static constexpr Error::ClassID kSemfClassId = Error::ClassID::Stm32InputCapture;
96};
97} /* namespace semf */
98#endif
99#endif /* SEMF_HARDWAREABSTRACTION_STM32_STM32INPUTCAPTURE_H_ */
ClassID
Semf class IDs.
Definition: error.h:28
Class for utilizing the input capture from the uC.
Definition: inputcapture.h:24
LinkedQueue is an managed single linked queue implementation.
Definition: linkedqueue.h:38
InputCapture implementation for STM32.
unsigned int ticks() override
Get the latest number of ticks (at the last change of the input).
void setMaxTicks(unsigned int maxTicks) override
Set the maximum number of ticks at which the tick counter will overflow.
Stm32InputCapture(const Stm32InputCapture &other)=delete
static void systemIsr(TIM_HandleTypeDef &hwHandle)
System-wide interrupt service routine for input capture.
void setTrigger(Trigger trigger) override
unsigned int maxTicks() const override
Get the maximum number of ticks from the timer.
Stm32InputCapture(TIM_HandleTypeDef &hwHandle, uint32_t channel, unsigned int ticksPerSecond)
Constructor.
virtual ~Stm32InputCapture()=default
unsigned int ticksPerSecond() const override
Returns the the number of ticks per second (Hardware timer frequency).
void isr(TIM_HandleTypeDef &hwHandle)
Interrupt service routine for input capture.