Skip to content

Analog Read

Simplified API for reading analog values from external voltage sources.

While a possible future version of the OS will have a more complex analog API, at the moment the analog APIs are only meant to provide a quick means for reading e.g. a battery voltage or providing a controllable voltage reference for an external analog circuitry. If your application needs to e.g. gather high frequency analog samples from a microphone a vendor-specific implementation for the analog peripheral has to be written in application code.

Sysprops

Sysprops for the ADC are driver dependent. Please refer to the documentation of the specific hardware driver you're using.

Functions Overview

Name
CW_DRIVER_FUNCadc_read(int hdev, uint8_t channel)
CW_DRIVER_FUNCadc_read_buf(int hdev, uint8_t channel, uint32_t * buf)

Function Details

function adc_read

cpp
CW_DRIVER_FUNC adc_read(
    int hdev,
    uint8_t channel
)

Parameters:

  • hdev device handle as returned by open(const char*)
  • channel some analog peripheral drivers differentiate different pin outputs via channels. if this is not required by the HAL driver, simply pass 0 here.

Return:

  • the value returned by the driver
  • -ENODEV if the device handle is invalid

function adc_read_buf

cpp
CW_DRIVER_FUNC adc_read_buf(
    int hdev,
    uint8_t channel,
    uint32_t * buf
)