13#if defined(STM32) && defined(HAL_ADC_MODULE_ENABLED)
14#if defined(STM32F1) || defined(STM32F3) || defined(STM32F4) || defined(STM32F7)
18Stm32AnalogInInjected::Stm32AnalogInInjected(ADC_HandleTypeDef& hwHandle, uint32_t injectedRank)
19: m_hwHandle(&hwHandle),
20 m_injectedRank(injectedRank)
25void Stm32AnalogInInjected::start()
29 HAL_StatusTypeDef state = HAL_ADCEx_InjectedStart_IT(m_hwHandle);
32 if (state == HAL_ERROR)
35 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Start_HalError)));
37 else if (state == HAL_BUSY)
40 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Start_HalBusy)));
42 else if (state == HAL_TIMEOUT)
45 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Start_HalTimeout)));
51uint32_t Stm32AnalogInInjected::value()
53 uint32_t val = HAL_ADCEx_InjectedGetValue(m_hwHandle, m_injectedRank);
58void Stm32AnalogInInjected::stop()
61 HAL_StatusTypeDef state = HAL_ADC_Stop_IT(m_hwHandle);
64 if (state == HAL_ERROR)
67 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Stop_HalError)));
69 else if (state == HAL_BUSY)
72 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Stop_HalBusy)));
74 else if (state == HAL_TIMEOUT)
77 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::Stop_HalTimeout)));
83LinkedQueue<Stm32AnalogInInjected>* Stm32AnalogInInjected::queue()
85 static LinkedQueue<Stm32AnalogInInjected> queue;
89void Stm32AnalogInInjected::systemIsr(ADC_HandleTypeDef& adc)
91 for (Stm32AnalogInInjected& i : *(queue()))
95void Stm32AnalogInInjected::systemIsrError(ADC_HandleTypeDef& adc)
97 for (Stm32AnalogInInjected& i : *(queue()))
101void Stm32AnalogInInjected::isr(ADC_HandleTypeDef& adc)
103 if (&adc == m_hwHandle)
110void Stm32AnalogInInjected::isrError(ADC_HandleTypeDef& adc)
112 if (&adc == m_hwHandle)
115 error(Error(kSemfClassId,
static_cast<uint8_t
>(ErrorCode::IsrError_Isr)));