diff --git a/include/sta/devices/stm32/adc.hpp b/include/sta/devices/stm32/adc.hpp index b77555f..b1411be 100644 --- a/include/sta/devices/stm32/adc.hpp +++ b/include/sta/devices/stm32/adc.hpp @@ -11,10 +11,26 @@ namespace sta class STM32ADC { public: - STM32ADC(); + /** + * @param handle A handle to a STM32 ADC. + */ + STM32ADC(ADC_HandleTypeDef * handle); + /** + * @brief Starts conversion of the incoming analog signal. + */ + void start(); + + /** + * @brief + * + * @param timeout + */ + void poll(uint32_t timeout); + + uint32_t getValue(); private: - + ADC_HandleTypeDef * handle_; }; } // namespace sta diff --git a/src/devices/stm32/adc.cpp b/src/devices/stm32/adc.cpp new file mode 100644 index 0000000..01c9eb7 --- /dev/null +++ b/src/devices/stm32/adc.cpp @@ -0,0 +1,33 @@ +#include + +#ifdef STA_PLATFORM_STM32 + +#include + +namespace sta +{ + STM32ADC::STM32ADC(ADC_HandleTypeDef * handle) + : handle_{handle} + { + STA_ASSERT(handle != nullptr); + } + + void STM32ADC::start() + { + HAL_ADC_Start(handle_); + } + + void STM32ADC::poll(uint32_t timeout) + { + HAL_StatusTypeDef res = HAL_ADC_PollForConversion(handle_, timeout); + + STA_ASSERT(res == HAL_OK); + } + + uint32_t STM32ADC::getValue() + { + return HAL_ADC_GetValue(handle_); + } +} // namespace sta + +#endif // STA_PLATFORM_STM32 \ No newline at end of file