modm API documentation
modm::platform::AdcInterrupt1 Class Reference

#include <modm/platform/adc/adc_interrupt.hpp>

Inheritance diagram for modm::platform::AdcInterrupt1:
modm::platform::Adc1 modm::AdcInterrupt modm::Adc modm::Adc modm::PeripheralDriver modm::PeripheralDriver

Public Types

enum  Channel : uint8_t {
  In0 = 0, In1 = 1, In2 = 2, In3 = 3,
  In4 = 4, In5 = 5, In6 = 6, In7 = 7,
  In8 = 8, In9 = 9, In10 = 10, In11 = 11,
  Temperature = 12, InternalReference = 13, Battery = 14, In15 = 15,
  In16 = 16, In17 = 17, In18 = 18
}
 
enum  ChannelMask : uint32_t {
  In0 = (1u << 0), In1 = (1u << 1), In2 = (1u << 2), In3 = (1u << 3),
  In4 = (1u << 4), In5 = (1u << 5), In6 = (1u << 6), In7 = (1u << 7),
  In8 = (1u << 8), In9 = (1u << 9), In10 = (1u << 10), In11 = (1u << 11),
  Temperature = (1u << 12), InternalReference = (1u << 13), Battery = (1u << 14), In15 = (1u << 15),
  In16 = (1u << 16), In17 = (1u << 17), In18 = (1u << 18)
}
 
enum  ClockMode { Synchronous, Asynchronous }
 
enum  DmaMode : uint32_t { Disabled = 0, OneShot = ADC_CFGR1_DMAEN, Circular = ADC_CFGR1_DMACFG | ADC_CFGR1_DMAEN, Mask = Circular }
 
enum  ExternalTriggerPolarity { NoTriggerDetection = 0x0u, RisingEdge = 0x1u, FallingEdge = 0x2u, RisingAndFallingEdge = 0x3u }
 
enum  Interrupt : uint32_t {
  Ready = ADC_IER_ADRDYIE, EndOfSampling = ADC_IER_EOSMPIE, EndOfConversion = ADC_IER_EOCIE, EndOfSequence = ADC_IER_EOSIE,
  Overrun = ADC_IER_OVRIE, AnalogWatchdog = ADC_IER_AWD1IE
}
 
enum  InterruptFlag : uint32_t {
  Ready = ADC_ISR_ADRDY, EndOfSampling = ADC_ISR_EOSMP, EndOfConversion = ADC_ISR_EOC, EndOfSequence = ADC_ISR_EOS,
  Overrun = ADC_ISR_OVR, AnalogWatchdog = ADC_ISR_AWD1, All = ADC_ISR_ADRDY | ADC_ISR_EOSMP | ADC_ISR_EOC | ADC_ISR_EOS | ADC_ISR_OVR | ADC_ISR_AWD1
}
 
enum  OversampleRatio : uint32_t {
  x2 = (0 << ADC_CFGR2_OVSR_Pos), x4 = (1 << ADC_CFGR2_OVSR_Pos), x8 = (2 << ADC_CFGR2_OVSR_Pos), x16 = (3 << ADC_CFGR2_OVSR_Pos),
  x32 = (4 << ADC_CFGR2_OVSR_Pos), x64 = (5 << ADC_CFGR2_OVSR_Pos), x128 = (6 << ADC_CFGR2_OVSR_Pos), x256 = (7 << ADC_CFGR2_OVSR_Pos)
}
 
enum  OversampleShift : uint32_t {
  Div1 = (0 << ADC_CFGR2_OVSS_Pos), Div2 = (1 << ADC_CFGR2_OVSS_Pos), Div4 = (2 << ADC_CFGR2_OVSS_Pos), Div8 = (3 << ADC_CFGR2_OVSS_Pos),
  Div16 = (4 << ADC_CFGR2_OVSS_Pos), Div32 = (5 << ADC_CFGR2_OVSS_Pos), Div64 = (6 << ADC_CFGR2_OVSS_Pos), Div128 = (7 << ADC_CFGR2_OVSS_Pos),
  Div256 = (8 << ADC_CFGR2_OVSS_Pos)
}
 
enum  RegularConversionExternalTrigger {
  Event0 = 0x0u, Event1 = 0x1u, Event2 = 0x2u, Event3 = 0x3u,
  Event4 = 0x4u, Event5 = 0x5u, Event6 = 0x6u, Event7 = 0x7u
}
 
enum  Resolution : uint8_t { Bits12 = 0, Bits10 = ADC_CFGR1_RES_0, Bits8 = ADC_CFGR1_RES_1, Bits6 = ADC_CFGR1_RES_0 | ADC_CFGR1_RES_1 }
 
enum  SampleTime : uint8_t {
  Cycles1_5 = 0b000, SampleTime::Cycles3_5 = 0b001, SampleTime::Cycles7_5 = 0b010, SampleTime::Cycles12_5 = 0b011,
  SampleTime::Cycles19_5 = 0b100, SampleTime::Cycles39_5 = 0b101, SampleTime::Cycles79_5 = 0b110, SampleTime::Cycles160_5 = 0b111
}
 
enum  SampleTimeGroup { Group1, Group2 }
 

Public Member Functions

 MODM_FLAGS32 (ChannelMask)
 
 MODM_FLAGS32 (Interrupt)
 
 MODM_FLAGS32 (InterruptFlag)
 

Static Public Member Functions

static void attachInterruptHandler (Handler handler)
 
static void acknowledgeInterruptFlag ()
 
static void acknowledgeInterruptFlags (InterruptFlag_t flags)
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static uint16_t calibrate ()
 
template<typename... Gpios>
static consteval ChannelMask_t channelMaskFromPins ()
 
template<typename... Gpios>
static consteval std::array< Channel, sizeof...(Gpios)> channelSequenceFromPins ()
 
static void clearChannel (Channel channel)
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
template<class... Signals>
static void connect ()
 
static void disable ()
 
static void disableFreeRunningMode ()
 
static void disableInterrupt (Interrupt_t interrupt)
 
static void disableOversampling ()
 
static void enable ()
 
static void enableFreeRunningMode ()
 
static void enableInternalChannel (Channel channel)
 
static void enableInterrupt (Interrupt_t interrupt)
 
static void enableInterruptVector (uint32_t priority, bool enable=true)
 
static void enableOversampling (OversampleRatio ratio, OversampleShift shift=OversampleShift::Div1)
 
static void enableRegularConversionExternalTrigger (ExternalTriggerPolarity externalTriggerPolarity, RegularConversionExternalTrigger regularConversionExternalTrigger)
 
static bool getAdcEnabled ()
 
static uint8_t getChannel ()
 
static uintptr_t getDataRegisterAddress ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static InterruptFlag_t getInterruptFlags ()
 
static void getParameter ()
 returns a parameter
 
template<class Gpio >
static constexpr Channel getPinChannel ()
 Get the channel for a Pin.
 
static uint16_t getValue ()
 
template<class SystemClock , ClockMode mode, frequency_t frequency = MHz(1), percent_t tolerance = pct(10)>
static void initialize ()
 
static bool isConversionFinished ()
 
static bool isReady ()
 
static uint16_t readChannel (Channel channel)
 
static uint16_t readInternalVoltageReference ()
 Reads the calibrated Internal Reference Voltage in mV.
 
template<class Gpio >
static uint16_t readPinChannel ()
 
static int16_t readTemperature (uint16_t Vref)
 Reads the calibrated temperature in degree Celsius.
 
static void setAutoOffMode (bool enable)
 
static bool setChannel (Channel channel, SampleTimeGroup group=SampleTimeGroup::Group1)
 
static bool setChannel (Channel channel)
 
static void setChannels (ChannelMask_t channels)
 
static bool setChannels (std::span< const Channel > channels)
 
static void setDmaMode (DmaMode mode)
 
static void setLeftAdjustResult ()
 
static void setParameter ()
 sets a parameter
 
template<class Gpio >
static bool setPinChannel (SampleTimeGroup group=SampleTimeGroup::Group1)
 Setting the channel for a Pin.
 
static void setResolution (Resolution resolution)
 
static void setRightAdjustResult ()
 
static void setSampleTime (SampleTime sampleTime, SampleTimeGroup group=SampleTimeGroup::Group1)
 
static void setSampleTimeGroup (Channel channel, SampleTimeGroup group=SampleTimeGroup::Group1)
 
static void setWaitMode (bool enable)
 
static void startConversion ()
 
static void stopConversion ()
 
static void acknowledgeInterruptFlag ()
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
static uint8_t getChannel ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void getParameter ()
 returns a parameter
 
static bool setChannel (Channel channel)
 
static void setParameter ()
 sets a parameter
 

Static Public Attributes

static Handler handler
 
static volatile uint16_t *const TS_CAL1 {(volatile uint16_t *)0x1FFF75A8}
 
static constexpr uint8_t TS_CAL1_TEMP {30}
 
static volatile uint16_t *const TS_CAL2 {(volatile uint16_t *)0x1FFF75CA}
 
static constexpr uint8_t TS_CAL2_TEMP {130}
 
static constexpr uint16_t VDDA_CAL {3000}
 
static volatile uint16_t *const VREFINT_CAL {(volatile uint16_t *)0x1FFF75AA}
 

Protected Typedefs

typedef void (* Handler) ()
 

Detailed Description

ADC Interrupt module

This class allows you to attach functions to the ADC Conversion Complete Interrupt via function pointers. Be aware however, that this implementation is slower and requires more resources than writing the function code directly into the interrupt service routines.

See also
AnalogSensors uses this implemenation.
Author
Niklas Hauser

Member Enumeration Documentation

Regular conversion external trigger sources

The source mapped to each event varies per controller family, refer to the ADC external trigger section in the reference manual of your controller for more information

enum modm::platform::Adc1::SampleTime : uint8_t
inheritedstrong
Enum ValuesDocumentation
Cycles3_5 

000: 1.5 ADC clock cycles

Cycles7_5 

001: 3.5 ADC clock cycles

Cycles12_5 

010: 7.5 ADC clock cycles

Cycles19_5 

011: 12.5 ADC clock cycles

Cycles39_5 

100: 19.5 ADC clock cycles

Cycles79_5 

101: 39.5 ADC clock cycles

Cycles160_5 

110: 79.5 ADC clock cycles

Member Function Documentation

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

static uint8_t modm::Adc::getChannel ( )
inheritedstatic
Returns
the currently selected analog channel
static uint8_t modm::Adc::getChannel ( )
inheritedstatic
Returns
the currently selected analog channel
template<class SystemClock , ClockMode mode, frequency_t frequency = MHz(1), percent_t tolerance = pct(10)>
static void modm::platform::Adc1::initialize ( )
inheritedstatic

Initialize and enable the A/D converter.

Enables the ADC clock and switches on the ADC. The ADC clock prescaler will be set as well.

The ADC can be clocked

Parameters
clkSet to ClockMode::DoNotChange or leave blank if you want to leave this setting untouched.
static bool modm::platform::Adc1::isReady ( )
inheritedinlinestatic

Returns true if the ADRDY bit of the ISR is set

static bool modm::Adc::setChannel ( Channel  channel)
inheritedstatic

Analog channel selection.

Returns
true if the channel exists and was available, false otherwise
static bool modm::Adc::setChannel ( Channel  channel)
inheritedstatic

Analog channel selection.

Returns
true if the channel exists and was available, false otherwise
static bool modm::platform::Adc1::setChannel ( Channel  channel,
SampleTimeGroup  group = SampleTimeGroup::Group1 
)
inheritedinlinestatic

Analog channel selection.

This not for scan mode. The number of channels will be set to 1, the channel selected and the corresponding pin will be set to analog input. If the the channel is modified during a conversion, the current conversion is reset and a new start pulse is sent to the ADC to convert the new chosen channnel / group of channels.

Parameters
channelThe channel which shall be read.
Precondition
The ADC clock must be started and the ADC switched on with initialize()
static void modm::platform::Adc1::setChannels ( ChannelMask_t  channels)
inheritedinlinestatic

Set channel scan sequence mask. All selected channels will be converted sequentially starting from the lowest.

Parameters
channelsMask of channels to convert
static bool modm::platform::Adc1::setChannels ( std::span< const Channel channels)
inheritedinlinestatic

Set channel scan sequence to convert up to 8 channels in arbitrary order.

Warning
The sequence provided must contain at least one but no more than 8 channels. Channels above 15 are not supported due to hardware limitations. If channels 16 to 18 should be sampled the in-order conversion sequence must be used instead.
Parameters
channelsFlag mask of channels to convert
Returns
true if provided channel sequence is valid, false otherwise.
static void modm::platform::Adc1::setDmaMode ( DmaMode  mode)
inheritedinlinestatic

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

The documentation for this class was generated from the following files: