Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AnalogDigitalConverter Class Reference

A driver for the analog-digital converters available on the microcontroller. More...

#include <analog_digital_converter.h>

Public Member Functions

uint8_t add_channel (uint8_t channel)
 Adds a channel to the list that is scanned. More...
 
uint8_t get_current_channel_count () const
 Checks the number of used channels. If this exceeds CHANNEL_COUNT, stuff will break. More...
 
void init (const ADCHardwareStruct *adc_def)
 Initializes the ADC according to the definition struct provided. More...
 
bool is_initialized () const
 Checks if the adc has been initialized, i.e. init has been called. More...
 
uint16_t read (uint8_t index) const
 Reads a single channel. More...
 

Static Public Attributes

static constexpr uint8_t CHANNEL_COUNT {16}
 
static constexpr uint16_t NO_READING {0xFFFF}
 
static constexpr uint16_t RAW_READING_MAX {0xFFF}
 
static constexpr double REFERENCE_VOLTAGE {3.3}
 

Private Member Functions

void init_dma ()
 
void start_dma ()
 

Private Attributes

const ADCHardwareStructadc_def_
 
volatile uint32_t buffer [CHANNEL_COUNT]
 
uint8_t current_channels
 
bool is_initialized_ {false}
 

Static Private Attributes

static constexpr uint32_t SQR1_CHANNEL_COUNT_MASK {~0xFF0FFFFF}
 
static constexpr uint8_t SQR1_CHANNEL_COUNT_OFFSET {20}
 

Detailed Description

A driver for the analog-digital converters available on the microcontroller.

Besides initialization, it is most convenient to work with the ADC with the AnalogPin class, which handles adding channels and reading results.

Definition at line 42 of file analog_digital_converter.h.

Member Function Documentation

uint8_t AnalogDigitalConverter::add_channel ( uint8_t  channel)

Adds a channel to the list that is scanned.

This returns the index assigned to the channel, which is needed to read it later This method does not check for errors. Do not add more than CHANNEL_COUNT channels, by calling add_channel more than CHANNEL_COUNT times

Parameters
channelThe index of the channel to be read
Returns
The index of the added channel

Definition at line 95 of file analog_digital_converter.cpp.

uint8_t AnalogDigitalConverter::get_current_channel_count ( ) const

Checks the number of used channels. If this exceeds CHANNEL_COUNT, stuff will break.

Returns
The number of ADC channels in use for this ADC

Definition at line 124 of file analog_digital_converter.cpp.

void AnalogDigitalConverter::init ( const ADCHardwareStruct adc_def)

Initializes the ADC according to the definition struct provided.

Parameters
Ahardware struct defining the resources for the ADC

Definition at line 34 of file analog_digital_converter.cpp.

void AnalogDigitalConverter::init_dma ( )
private

Definition at line 65 of file analog_digital_converter.cpp.

bool AnalogDigitalConverter::is_initialized ( ) const

Checks if the adc has been initialized, i.e. init has been called.

Returns
if the adc has been initialized

Definition at line 115 of file analog_digital_converter.cpp.

uint16_t AnalogDigitalConverter::read ( uint8_t  index) const

Reads a single channel.

The reading is between 0 and RAW_READING_MAX. 0 represents 0V, and RAW_READING_MAX represents REFERENCE_VOLTAGE (typically 3.3V). Takes the index of the channel as a parameter, which is returned from add_channel

Parameters
indexThe index of the channel to be read.
Returns

Definition at line 119 of file analog_digital_converter.cpp.

void AnalogDigitalConverter::start_dma ( )
private

Definition at line 111 of file analog_digital_converter.cpp.

Member Data Documentation

const ADCHardwareStruct* AnalogDigitalConverter::adc_def_
private

Definition at line 102 of file analog_digital_converter.h.

volatile uint32_t AnalogDigitalConverter::buffer[CHANNEL_COUNT]
private

Definition at line 110 of file analog_digital_converter.h.

constexpr uint8_t AnalogDigitalConverter::CHANNEL_COUNT {16}
static

The maximum number of channels on a single ADC. Hardware-dependent

Definition at line 99 of file analog_digital_converter.h.

uint8_t AnalogDigitalConverter::current_channels
private

Definition at line 104 of file analog_digital_converter.h.

bool AnalogDigitalConverter::is_initialized_ {false}
private

Definition at line 103 of file analog_digital_converter.h.

constexpr uint16_t AnalogDigitalConverter::NO_READING {0xFFFF}
static

A value indicating that the channel value has not yet been read by the ADC. If you get this for more than just the startup time, your channel may not be initialized

Definition at line 95 of file analog_digital_converter.h.

constexpr uint16_t AnalogDigitalConverter::RAW_READING_MAX {0xFFF}
static

The maximum reading from a channel. This reading corresponds to REFERENCE_VOLTAGE volts.

Definition at line 90 of file analog_digital_converter.h.

constexpr double AnalogDigitalConverter::REFERENCE_VOLTAGE {3.3}
static

The reference voltage used for the ADC, which is hardware-dependent. Unit is volts.

Definition at line 86 of file analog_digital_converter.h.

constexpr uint32_t AnalogDigitalConverter::SQR1_CHANNEL_COUNT_MASK {~0xFF0FFFFF}
staticprivate

Definition at line 107 of file analog_digital_converter.h.

constexpr uint8_t AnalogDigitalConverter::SQR1_CHANNEL_COUNT_OFFSET {20}
staticprivate

Definition at line 108 of file analog_digital_converter.h.


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


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Fri Oct 9 2020 03:17:21