Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Apr 26, 2024
1 parent 06e7907 commit 67986c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 46 deletions.
5 changes: 2 additions & 3 deletions examples/nucleo_g070rb/adc_dma/adc_dma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ class AdcDma
setCompletedConversionCallback(completedCallback);

Dma::AdcChannel::template setPeripheralRequest<Dma::AdcRequest>();
Adc::disableDmaMode();
Adc::setDmaMode(Adc::DmaMode::Disabled);
}

static void
startDma()
{
Adc::enableDmaRequests();
Adc::enableDmaMode();
Adc::setDmaMode(Adc::DmaMode::Circular);
DmaChannel::start();
}

Expand Down
41 changes: 18 additions & 23 deletions src/modm/platform/adc/stm32f0/adc.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ public:
};
MODM_FLAGS32(InterruptFlag);

enum class DmaMode : uint32_t
{
Disabled = 0,
OneShot = ADC_CFGR1_DMAEN,
Circular = ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN,
Mask = Circular
};

enum class ExternalTriggerPolarity
{
NoTriggerDetection = 0x0u,
Expand Down Expand Up @@ -402,33 +410,20 @@ public:
ExternalTriggerPolarity externalTriggerPolarity,
RegularConversionExternalTrigger regularConversionExternalTrigger);

/// Enable DMA mode
/// @warning May only be called while no conversion is ongoing
static inline void
enableDmaMode();

/// Disable DMA mode
/// @warning May only be called while no conversion is ongoing
static inline void
disableDmaMode();

static inline bool
getAdcEnabled();

/**
* enable DMA selection for the ADC. If this is enabled DMA
* requests are issued as long as data are converted and
* the adc has dma enabled
* Configure DMA mode (disabled, one-shot or circular)
*
* In one-shot mode DMA requests are disabled at the end of the DMA transfer.
* If circular mode is selected request are being generated as long as
* conversions are performed.
*
* @warning May only be called while no conversion is ongoing
*/
static inline void
enableDmaRequests();
setDmaMode(DmaMode mode);

/**
* disable dma selection for the ADC. If this is disabled
* no new DMA requests are issued after last transfer
*/
static inline void
disableDmaRequests();
static inline bool
getAdcEnabled();

static inline void
enableInternalChannel(Channel channel);
Expand Down
23 changes: 3 additions & 20 deletions src/modm/platform/adc/stm32f0/adc_impl.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,10 @@ modm::platform::Adc{{ id }}::enableRegularConversionExternalTrigger(
}

void
modm::platform::Adc{{ id }}::enableDmaMode()
modm::platform::Adc{{ id }}::setDmaMode(DmaMode mode)
{
ADC1->CFGR1 |= ADC_CFGR1_DMAEN;
}

void
modm::platform::Adc{{ id }}::disableDmaMode()
{
ADC1->CFGR1 &= ~ADC_CFGR1_DMAEN;
ADC1->CFGR1 = (ADC1->CFGR1 & ~static_cast<uint32_t>(DmaMode::Mask))
| static_cast<uint32_t>(mode);
}

bool
Expand All @@ -488,18 +483,6 @@ modm::platform::Adc{{ id }}::getAdcEnabled()
return (ADC1->CR & ADC_CR_ADEN);
}

void
modm::platform::Adc{{ id }}::enableDmaRequests()
{
ADC1->CFGR1 |= ADC_CFGR1_DMACFG;
}

void
modm::platform::Adc{{ id }}::disableDmaRequests()
{
ADC1->CFGR1 &= ~ADC_CFGR1_DMACFG;
}

%% if target.family in ["g0"]
void
modm::platform::Adc{{ id }}::waitChannelConfigReady()
Expand Down

0 comments on commit 67986c7

Please sign in to comment.