13#if defined(STM32) && defined(HAL_TIM_MODULE_ENABLED)
20LinkedQueue<Stm32InputCapture> Stm32InputCapture::m_queue;
22: m_hwHandle(&hwHandle),
24 m_ticksPerSecond{ticksPerSecond}
32 auto state = HAL_TIM_IC_Start_IT(m_hwHandle, m_channel);
35 if (state == HAL_ERROR)
40 else if (state == HAL_BUSY)
45 else if (state == HAL_TIMEOUT)
57 auto state = HAL_TIM_IC_Stop_IT(m_hwHandle, m_channel);
60 if (state == HAL_ERROR)
65 else if (state == HAL_BUSY)
70 else if (state == HAL_TIMEOUT)
81 uint32_t val = HAL_TIM_ReadCapturedValue(m_hwHandle, m_channel);
82 SEMF_INFO(
"value %u on channel %u", val, m_channel);
88 if (m_hwHandle->Lock == HAL_LOCKED)
94 m_hwHandle->Lock = HAL_LOCKED;
97 uint32_t ccer = m_hwHandle->Instance->CCER;
100 m_hwHandle->Instance->CCER &= ~(1 << (m_channel / 2));
104 case Trigger::RisingEdge:
105 ccer &= ~(1 << (m_channel + 1));
106 ccer &= ~(1 << (m_channel + 3));
108 case Trigger::FallingEdge:
109 ccer |= 1 << (m_channel + 1);
110 ccer &= ~(1 << (m_channel + 3));
112 case Trigger::RisingAndFallingEdge:
113 ccer |= 1 << (m_channel + 1);
114 ccer |= 1 << (m_channel + 3);
117 SEMF_ERROR(
"invalid value for trigger: %u",
static_cast<uint32_t
>(trigger));
122 m_hwHandle->Instance->CCER = ccer;
123 __HAL_UNLOCK(m_hwHandle);
128 for (
auto& i : m_queue)
134 if (m_hwHandle == &hwHandle && hwHandle.Channel == m_channel)
143 return m_ticksPerSecond;
149 m_hwHandle->Instance->ARR =
maxTicks;
154 return m_hwHandle->Instance->ARR;
Class for representing errors. Every error should have a unique source code. As a user feel encourage...