Skip to content

Commit 67986c7

Browse files
committed
Fixup
1 parent 06e7907 commit 67986c7

File tree

3 files changed

+23
-46
lines changed

3 files changed

+23
-46
lines changed

examples/nucleo_g070rb/adc_dma/adc_dma.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,13 @@ class AdcDma
5555
setCompletedConversionCallback(completedCallback);
5656

5757
Dma::AdcChannel::template setPeripheralRequest<Dma::AdcRequest>();
58-
Adc::disableDmaMode();
58+
Adc::setDmaMode(Adc::DmaMode::Disabled);
5959
}
6060

6161
static void
6262
startDma()
6363
{
64-
Adc::enableDmaRequests();
65-
Adc::enableDmaMode();
64+
Adc::setDmaMode(Adc::DmaMode::Circular);
6665
DmaChannel::start();
6766
}
6867

src/modm/platform/adc/stm32f0/adc.hpp.in

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ public:
153153
};
154154
MODM_FLAGS32(InterruptFlag);
155155

156+
enum class DmaMode : uint32_t
157+
{
158+
Disabled = 0,
159+
OneShot = ADC_CFGR1_DMAEN,
160+
Circular = ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN,
161+
Mask = Circular
162+
};
163+
156164
enum class ExternalTriggerPolarity
157165
{
158166
NoTriggerDetection = 0x0u,
@@ -402,33 +410,20 @@ public:
402410
ExternalTriggerPolarity externalTriggerPolarity,
403411
RegularConversionExternalTrigger regularConversionExternalTrigger);
404412

405-
/// Enable DMA mode
406-
/// @warning May only be called while no conversion is ongoing
407-
static inline void
408-
enableDmaMode();
409-
410-
/// Disable DMA mode
411-
/// @warning May only be called while no conversion is ongoing
412-
static inline void
413-
disableDmaMode();
414-
415-
static inline bool
416-
getAdcEnabled();
417-
418413
/**
419-
* enable DMA selection for the ADC. If this is enabled DMA
420-
* requests are issued as long as data are converted and
421-
* the adc has dma enabled
414+
* Configure DMA mode (disabled, one-shot or circular)
415+
*
416+
* In one-shot mode DMA requests are disabled at the end of the DMA transfer.
417+
* If circular mode is selected request are being generated as long as
418+
* conversions are performed.
419+
*
420+
* @warning May only be called while no conversion is ongoing
422421
*/
423422
static inline void
424-
enableDmaRequests();
423+
setDmaMode(DmaMode mode);
425424

426-
/**
427-
* disable dma selection for the ADC. If this is disabled
428-
* no new DMA requests are issued after last transfer
429-
*/
430-
static inline void
431-
disableDmaRequests();
425+
static inline bool
426+
getAdcEnabled();
432427

433428
static inline void
434429
enableInternalChannel(Channel channel);

src/modm/platform/adc/stm32f0/adc_impl.hpp.in

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,10 @@ modm::platform::Adc{{ id }}::enableRegularConversionExternalTrigger(
471471
}
472472

473473
void
474-
modm::platform::Adc{{ id }}::enableDmaMode()
474+
modm::platform::Adc{{ id }}::setDmaMode(DmaMode mode)
475475
{
476-
ADC1->CFGR1 |= ADC_CFGR1_DMAEN;
477-
}
478-
479-
void
480-
modm::platform::Adc{{ id }}::disableDmaMode()
481-
{
482-
ADC1->CFGR1 &= ~ADC_CFGR1_DMAEN;
476+
ADC1->CFGR1 = (ADC1->CFGR1 & ~static_cast<uint32_t>(DmaMode::Mask))
477+
| static_cast<uint32_t>(mode);
483478
}
484479

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

491-
void
492-
modm::platform::Adc{{ id }}::enableDmaRequests()
493-
{
494-
ADC1->CFGR1 |= ADC_CFGR1_DMACFG;
495-
}
496-
497-
void
498-
modm::platform::Adc{{ id }}::disableDmaRequests()
499-
{
500-
ADC1->CFGR1 &= ~ADC_CFGR1_DMACFG;
501-
}
502-
503486
%% if target.family in ["g0"]
504487
void
505488
modm::platform::Adc{{ id }}::waitChannelConfigReady()

0 commit comments

Comments
 (0)