semf
semf::Stm32InputCapture Class Reference

InputCapture implementation for STM32. More...

#include <stm32inputcapture.h>

Inheritance diagram for semf::Stm32InputCapture:
Inheritance graph
Collaboration diagram for semf::Stm32InputCapture:
Collaboration graph

Public Types

enum class  ErrorCode : uint8_t {
  Start_Error = 0 , Start_Busy , Start_Timeout , Stop_Error ,
  Stop_Busy , Stop_Timeout , SetTrigger_Busy , SetTrigger_TriggerInvalid
}
 
- Public Types inherited from semf::InputCapture
enum  Trigger : uint8_t { RisingEdge = 0 , FallingEdge , RisingAndFallingEdge }
 

Public Member Functions

 Stm32InputCapture (TIM_HandleTypeDef &hwHandle, uint32_t channel, unsigned int ticksPerSecond)
 Constructor. More...
 
 Stm32InputCapture (const Stm32InputCapture &other)=delete
 
virtual ~Stm32InputCapture ()=default
 
unsigned int ticksPerSecond () const override
 Returns the the number of ticks per second (Hardware timer frequency). More...
 
void setMaxTicks (unsigned int maxTicks) override
 Set the maximum number of ticks at which the tick counter will overflow. More...
 
unsigned int maxTicks () const override
 Get the maximum number of ticks from the timer. More...
 
void start () override
 
void stop () override
 
unsigned int ticks () override
 Get the latest number of ticks (at the last change of the input). More...
 
void setTrigger (Trigger trigger) override
 
void isr (TIM_HandleTypeDef &hwHandle)
 Interrupt service routine for input capture. More...
 
- Public Member Functions inherited from semf::InputCapture
virtual ~InputCapture ()=default
 
virtual unsigned int ticksPerSecond () const =0
 Returns the the number of ticks per second (Hardware timer frequency). More...
 
virtual void setMaxTicks (unsigned int maxTicks)=0
 Set the maximum number of ticks at which the tick counter will overflow. More...
 
virtual unsigned int maxTicks () const =0
 Get the maximum number of ticks from the timer. More...
 
virtual void start ()=0
 
virtual void stop ()=0
 
virtual unsigned int ticks ()=0
 Get the latest number of ticks (at the last change of the input). More...
 
virtual void setTrigger (Trigger trigger)=0
 Sets the trigger source. More...
 
- Public Member Functions inherited from semf::LinkedQueue< T >::Node
virtual ~Node ()=default
 
T * next () const
 Returns a pointer to the next element in a queue. More...
 
void setNext (T *next)
 Sets a pointer to the next element in a list. More...
 
bool isInQueue (LinkedQueue &queue)
 Returns if a node is part of this LinkedQueue. More...
 

Static Public Member Functions

static void systemIsr (TIM_HandleTypeDef &hwHandle)
 System-wide interrupt service routine for input capture. More...
 

Additional Inherited Members

- Public Attributes inherited from semf::InputCapture
Signal dataAvailable
 
Signal< Errorerror
 

Detailed Description

InputCapture implementation for STM32.

Definition at line 24 of file stm32inputcapture.h.

Member Enumeration Documentation

◆ ErrorCode

enum class semf::Stm32InputCapture::ErrorCode : uint8_t
strong

Error IDs for this class. Error ID identify a unique error() / onError call (excluding transferring).

Enumerator
Start_Error 
Start_Busy 
Start_Timeout 
Stop_Error 
Stop_Busy 
Stop_Timeout 
SetTrigger_Busy 
SetTrigger_TriggerInvalid 

Definition at line 28 of file stm32inputcapture.h.

Constructor & Destructor Documentation

◆ Stm32InputCapture() [1/2]

semf::Stm32InputCapture::Stm32InputCapture ( TIM_HandleTypeDef &  hwHandle,
uint32_t  channel,
unsigned int  ticksPerSecond 
)

Constructor.

Parameters
hwHandleHardware handler.
channelChannel selection define from STM timer HAL description. Use TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3 or TIM_CHANNEL_4.
ticksPerSecondThe number of ticks per second (hardware timer frequency).

Definition at line 21 of file stm32inputcapture.cpp.

◆ Stm32InputCapture() [2/2]

semf::Stm32InputCapture::Stm32InputCapture ( const Stm32InputCapture other)
explicitdelete

◆ ~Stm32InputCapture()

virtual semf::Stm32InputCapture::~Stm32InputCapture ( )
virtualdefault

Member Function Documentation

◆ isr()

void semf::Stm32InputCapture::isr ( TIM_HandleTypeDef &  hwHandle)

Interrupt service routine for input capture.

Parameters
hwHandleHardware handler.

Definition at line 132 of file stm32inputcapture.cpp.

◆ maxTicks()

unsigned int semf::Stm32InputCapture::maxTicks ( ) const
overridevirtual

Get the maximum number of ticks from the timer.

Returns
The maximum number of ticks from the timer.

Implements semf::InputCapture.

Definition at line 152 of file stm32inputcapture.cpp.

Here is the caller graph for this function:

◆ setMaxTicks()

void semf::Stm32InputCapture::setMaxTicks ( unsigned int  maxTicks)
overridevirtual

Set the maximum number of ticks at which the tick counter will overflow.

Parameters
maxTicksNumber of ticks at which the tick counter will overflow.

Implements semf::InputCapture.

Definition at line 146 of file stm32inputcapture.cpp.

Here is the call graph for this function:

◆ setTrigger()

void semf::Stm32InputCapture::setTrigger ( Trigger  trigger)
overridevirtual

Starts capturing the input signals.

Exceptions
SetTrigger_BusyIf m_hwHandle is locked.
SetTrigger_TriggerInvalidIf trigger contains an invalid value.

Implements semf::InputCapture.

Definition at line 86 of file stm32inputcapture.cpp.

◆ start()

void semf::Stm32InputCapture::start ( )
overridevirtual

Starts capturing the input signals.

Exceptions
Start_ErrorIf HAL_TIM_IC_Start_IT returns HAL_ERROR.
Start_BusyIf HAL_TIM_IC_Start_IT returns HAL_BUSY.
Start_TimeoutIf HAL_TIM_IC_Start_IT returns HAL_TIMEOUT.

Implements semf::InputCapture.

Definition at line 29 of file stm32inputcapture.cpp.

◆ stop()

void semf::Stm32InputCapture::stop ( )
overridevirtual

Stops capturing the input signals.

Exceptions
Stop_ErrorIf HAL_TIM_IC_Stop_IT returns HAL_ERROR.
Stop_BusyIf HAL_TIM_IC_Stop_IT returns HAL_BUSY.
Stop_TimeoutIf HAL_TIM_IC_Stop_IT returns HAL_TIMEOUT.

Implements semf::InputCapture.

Definition at line 54 of file stm32inputcapture.cpp.

◆ systemIsr()

void semf::Stm32InputCapture::systemIsr ( TIM_HandleTypeDef &  hwHandle)
static

System-wide interrupt service routine for input capture.

Parameters
hwHandleHardware handler.

Definition at line 126 of file stm32inputcapture.cpp.

Here is the caller graph for this function:

◆ ticks()

unsigned int semf::Stm32InputCapture::ticks ( )
overridevirtual

Get the latest number of ticks (at the last change of the input).

Returns
The timer ticks at the last change of the input.

Implements semf::InputCapture.

Definition at line 79 of file stm32inputcapture.cpp.

◆ ticksPerSecond()

unsigned int semf::Stm32InputCapture::ticksPerSecond ( ) const
overridevirtual

Returns the the number of ticks per second (Hardware timer frequency).

Returns
Ticks per second.

Implements semf::InputCapture.

Definition at line 141 of file stm32inputcapture.cpp.