diff --git a/include/sta/devices/stm32/adc.hpp b/include/sta/devices/stm32/adc.hpp index 62b2985..e9b6292 100644 --- a/include/sta/devices/stm32/adc.hpp +++ b/include/sta/devices/stm32/adc.hpp @@ -31,6 +31,14 @@ namespace sta */ void start(); + /** + * @brief Starts conversion of the incoming analog signal in DMA mode. + * + * @param buffer The buffer to write the converted values to. + * @param length The length of the buffer to write the converted values to. + */ + void startDMA(uint32_t * buffer, size_t length); + /** * @brief Polls for the converted analog signal. * diff --git a/src/devices/stm32/adc.cpp b/src/devices/stm32/adc.cpp index 5c5d663..fa57930 100644 --- a/src/devices/stm32/adc.cpp +++ b/src/devices/stm32/adc.cpp @@ -17,6 +17,17 @@ namespace sta HAL_ADC_Start(handle_); } + void STM32ADC::startDMA(uint32_t * buffer, size_t length) + { + STA_ASSERT(buffer != nullptr); + STA_ASSERT(length != 0); + STA_ASSERT(handle_->DMA_Handle != nullptr); + + HAL_StatusTypeDef res = HAL_ADC_Start_DMA(handle_, buffer, length); + + STA_ASSERT(res == HAL_OK); + } + void STM32ADC::poll(uint32_t timeout) { HAL_StatusTypeDef res = HAL_ADC_PollForConversion(handle_, timeout);