Added DMA support for ADC

This commit is contained in:
dario 2024-03-15 13:00:23 +01:00
parent 8901abdb9c
commit 1fc34fa574
2 changed files with 19 additions and 0 deletions

View File

@ -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.
*

View File

@ -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);