Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
driver.hpp File Reference

ADC driver interface - canonical types for MCU driver implementations. More...

Detailed Description

ADC driver interface - canonical types for MCU driver implementations.

This header provides everything an ADC driver needs:

  • AdcHandle: Channel reference with peripheral and channel number
  • SampleTime: Sampling duration configuration

Low-Level Driver Interface

Drivers implement the following static interface:

// Initialize the ADC peripheral static void init();

// Configure channel for conversion static void configure_channel(const sbl::AdcHandle& handle, sbl::adc::SampleTime sample_time);

// Start single conversion static void start_conversion(const sbl::AdcHandle& handle);

// Check if conversion is complete static bool is_conversion_complete();

// Read raw conversion result static uint16_t read_raw();

// Get ADC resolution (compile-time constant) static constexpr uint8_t resolution_bits();

Convenience Helpers

The core library provides convenience functions that compose the low-level primitives:

// Single blocking read uint16_t value = sbl::adc::read<sbl::driver::Adc>(handle);

Usage in driver: #include <sbl/hw/hal/adc/driver.hpp> using sbl::adc::SampleTime;

Definition in file driver.hpp.

#include "handle.hpp"
#include "types.hpp"

Go to the source code of this file.

Namespaces

namespace  sbl
 Root namespace for all Sound Byte Libs code.
 
namespace  sbl::adc
 Convenience layer: read a channel, start and stop a scan.
 

Typedefs

using sbl::adc::SampleTime = sbl::hal::adc::SampleTime
 
using sbl::adc::Resolution = sbl::hal::adc::Resolution
 

Functions

template<typename Driver >
uint16_t sbl::adc::read (const AdcHandle &handle, SampleTime sample_time=SampleTime::Medium)
 Blocking single-channel ADC read.
 
template<typename Driver >
uint32_t sbl::adc::to_millivolts (uint16_t raw_value, uint32_t vref_mv=3300)
 Convert raw ADC value to voltage (millivolts)