Added ADC implementation for STM32

This commit is contained in:
dvdb97
2023-07-16 21:17:14 +02:00
parent 0d02d57cbb
commit 266cc46a09
2 changed files with 51 additions and 2 deletions

33
src/devices/stm32/adc.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <sta/devices/stm32/adc.hpp>
#ifdef STA_PLATFORM_STM32
#include <sta/debug/assert.hpp>
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