objc

Data Structures | Typedefs | Functions

Analog-to-Digital Converter (ADC) interface for hardware platforms. More...

Collaboration diagram for ADC:

Data Structures

struct  hw_adc_t
 ADC channel. More...
 

Typedefs

typedef struct hw_adc_t hw_adc_t
 ADC channel.
 

Functions

uint8_t hw_adc_count (void)
 Get the total number of available ADC channels. More...
 
hw_adc_t hw_adc_init_pin (uint8_t pin)
 Initialize an ADC interface for a specific pin. More...
 
hw_adc_t hw_adc_init_temperature ()
 Initialize an ADC interface on which the temperature sensor is connected. More...
 
void hw_adc_finalize (hw_adc_t *adc)
 Finalize and release an ADC interface. More...
 
uint8_t hw_adc_gpio_channel (uint8_t gpio)
 Get the ADC channel number for a specific GPIO pin. More...
 
static bool hw_adc_valid (hw_adc_t *adc)
 Check if an ADC handle is valid and usable. More...
 
uint16_t hw_adc_read (hw_adc_t *adc)
 Read the current value from an ADC channel. More...
 
float hw_adc_read_voltage (hw_adc_t *adc)
 Read the current value from an ADC channel as a voltage. More...
 
float hw_adc_read_temperature (hw_adc_t *adc)
 Read the current value from an ADC channel as a temperature. More...
 

Detailed Description

Analog-to-Digital Converter (ADC) interface for hardware platforms.

This module provides functions to initialize and read from ADC peripherals.

Function Documentation

◆ hw_adc_count()

uint8_t hw_adc_count ( void  )

Get the total number of available ADC channels.

Returns
The number of ADC channels available on the hardware platform.

Returns the number of logical ADC channels that can be used in the system. These are usually numbered from 0 to hw_adc_count() - 1. If zero is returned, it indicates that ADC functionality is not available.

◆ hw_adc_finalize()

void hw_adc_finalize ( hw_adc_t adc)

Finalize and release an ADC interface.

Parameters
adcPointer to the ADC structure to finalize.

This function releases the ADC interface and frees any associated resources. After calling this function, the ADC interface should not be used for further operations.

◆ hw_adc_gpio_channel()

uint8_t hw_adc_gpio_channel ( uint8_t  gpio)

Get the ADC channel number for a specific GPIO pin.

Parameters
gpioThe GPIO pin number.
Returns
The corresponding ADC channel number, or 0xFF if not found.

◆ hw_adc_init_pin()

hw_adc_t hw_adc_init_pin ( uint8_t  pin)

Initialize an ADC interface for a specific pin.

Returns
An ADC structure representing the initialized interface.

This function initializes the ADC interface for a specific channel and pin, allowing for flexible configuration of the ADC hardware.

◆ hw_adc_init_temperature()

hw_adc_t hw_adc_init_temperature ( )

Initialize an ADC interface on which the temperature sensor is connected.

Returns
An ADC structure representing the initialized interface.

This function initializes the ADC interface which is used for measuring the temperature sensor.

◆ hw_adc_read()

uint16_t hw_adc_read ( hw_adc_t adc)

Read the current value from an ADC channel.

Parameters
adcPointer to the ADC structure.
Returns
The raw ADC value (0-4095 for 12-bit ADC).

This function reads the current value from the specified ADC channel and returns the raw digital value corresponding to the analog input voltage.

◆ hw_adc_read_temperature()

float hw_adc_read_temperature ( hw_adc_t adc)

Read the current value from an ADC channel as a temperature.

Parameters
adcPointer to the ADC structure configured for temperature sensing.
Returns
The temperature value in degrees Celsius.

This function reads the current value from an ADC channel that is connected to a temperature sensor and converts the reading to a temperature value. This function is typically used with the ADC channel initialized by hw_adc_init_temperature().

◆ hw_adc_read_voltage()

float hw_adc_read_voltage ( hw_adc_t adc)

Read the current value from an ADC channel as a voltage.

Parameters
adcPointer to the ADC structure.
Returns
The voltage value in volts (typically 0.0 to 3.3V range).

This function reads the current value from the specified ADC channel and converts the raw digital value to a voltage measurement.

The conversion is based on the reference voltage of the ADC (typically 3.3V for most microcontrollers), except for the battery voltage pin which uses a voltage divider to scale the input.

◆ hw_adc_valid()

static bool hw_adc_valid ( hw_adc_t adc)
inlinestatic

Check if an ADC handle is valid and usable.

Parameters
adcPointer to the ADC structure to validate.
Returns
True if the ADC handle is valid and can be used; false otherwise.

Definition at line 92 of file adc.h.

92  {
93  return adc && adc->channel < hw_adc_count();
94 }
uint8_t channel
ADC channel number (0, 1, etc.)
Definition: adc.h:25
uint8_t hw_adc_count(void)
Get the total number of available ADC channels.