Skip to content

Commit

Permalink
feat: AdcDmaMultiChannelStm implements new AdcMultiChannel interface (#…
Browse files Browse the repository at this point in the history
…462)

* Implement new AdcMultiChannel interface

* Update hal_st/stm32fxxx/AdcDmaMultiChannelStm.hpp

---------

Co-authored-by: Richard Peters <[email protected]>
  • Loading branch information
fabiangottstein and richardapeters authored Dec 6, 2024
1 parent a967560 commit bdd2507
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions hal_st/stm32fxxx/AdcDmaMultiChannelStm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ namespace hal
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle(), ADC_SINGLE_ENDED);
assert(result == HAL_OK);
#elif defined(IS_ADC_CALFACT)
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle());
auto result = HAL_ADCEx_Calibration_Start(&adc.Handle());
assert(result == HAL_OK);
#endif

LL_ADC_REG_SetDMATransfer(adc.Handle().Instance, LL_ADC_REG_DMA_TRANSFER_LIMITED);
}

void AdcDmaMultiChannelStmBase::Measure(const infra::Function<void(infra::MemoryRange<uint16_t>)>& onDone)
void AdcDmaMultiChannelStmBase::Measure(const infra::Function<void(Samples)>& onDone)
{
this->onDone = onDone;

Expand Down
8 changes: 6 additions & 2 deletions hal_st/stm32fxxx/AdcDmaMultiChannelStm.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#ifndef HAL_ST_ADC_DMA_MULTI_CHANNEL_HPP
#define HAL_ST_ADC_DMA_MULTI_CHANNEL_HPP

#include "hal/interfaces/AdcMultiChannel.hpp"
#include "hal_st/stm32fxxx/AnalogToDigitalPinStm.hpp"
#include "hal_st/stm32fxxx/DmaStm.hpp"
#include "hal_st/stm32fxxx/GpioStm.hpp"
#include "infra/util/AutoResetFunction.hpp"
#include <array>
#include <cstddef>

/// @brief This ADC implementation supports multiple channels with DMA transfer and software trigger.
/// DMA transfer is one shot mode.
namespace hal
{
class AdcDmaMultiChannelStmBase
: public AdcMultiChannel
{
public:
AdcDmaMultiChannelStmBase(
infra::MemoryRange<uint16_t> buffer, infra::MemoryRange<AnalogPinStm> analogPins, AdcStm& adc,
DmaStm::ReceiveStream& receiveStream);

void Measure(const infra::Function<void(infra::MemoryRange<uint16_t>)>& onDone);
void Measure(const infra::Function<void(Samples)>& onDone) override;

constexpr static std::size_t MaxChannels{ 16 };

Expand All @@ -29,7 +33,7 @@ namespace hal
infra::MemoryRange<AnalogPinStm> analogPins;
AdcStm& adc;
ReceiveDmaChannel dmaStream;
infra::AutoResetFunction<void(infra::MemoryRange<uint16_t>)> onDone;
infra::AutoResetFunction<void(Samples)> onDone;

void TransferDone();
};
Expand Down

0 comments on commit bdd2507

Please sign in to comment.