Skip to content

File ADC.h

FileList > bsp > Inc > ADC.h

Go to the source code of this file

Provides functions for initializing, reading, and managing ADC peripherals. More...

  • #include "stm32xx_hal.h"
  • #include "FreeRTOS.h"
  • #include "queue.h"
  • #include "semphr.h"

Public Types

Type Name
enum adc_status_t

Public Functions

Type Name
adc_status_t adc_deinit (ADC_HandleTypeDef * h)
Deinitializes the ADC peripheral.
adc_status_t adc_init (ADC_InitTypeDef * init, ADC_HandleTypeDef * hadc)
Initializes the ADC peripheral with the specified configuration.
adc_status_t adc_read (uint32_t channel, uint32_t samplingTime, ADC_HandleTypeDef * h, QueueHandle_t * q)
Reads a value from the specified ADC channel.

Detailed Description

This file contains the API for working with ADC (Analog-to-Digital Converter) peripherals in an embedded system, including initialization, reading channels, and queue-based data handling (e.g., with FreeRTOS). The functions support flexible configuration of ADC instances, sampling times, and data storage mechanisms.

Initialization:

  • Call adc_init() to configure and initialize a specific ADC instance.
  • Provide the ADC configuration structure and handle for the target peripheral.
  • Returns a status code indicating success or failure.

Reading ADC Values:

  • Call adc_read() to sample a channel on the ADC.
  • Provide the channel number, sampling time, ADC handle, and storage/queue reference.
  • Returns a status code indicating success or failure.

Data Retrieval:

  • If using queues, use standard FreeRTOS queue functions (e.g., xQueueReceive()) to retrieve ADC readings.
  • Supports both blocking and non-blocking behavior depending on the chosen timeout.

Note:

This driver is designed to work with multiple ADC instances and supports integration with an RTOS for asynchronous data handling.

Public Types Documentation

enum adc_status_t

enum adc_status_t {
    ADC_OK,
    ADC_INIT_FAIL,
    ADC_DEINIT_FAIL,
    ADC_CHANNEL_CONFIG_FAIL,
    ADC_INTERRUPT_BUSY,
    ADC_INTERRUPT_TIMEOUT,
    ADC_INTERRUPT_ERROR,
    ADC_QUEUE_FULL
};

Public Functions Documentation

function adc_deinit

Deinitializes the ADC peripheral.

adc_status_t adc_deinit (
    ADC_HandleTypeDef * h
) 

This function releases resources used by the ADC and resets it to its default uninitialized state.

Parameters:

  • h Pointer to the ADC handle structure.

Returns:

adc_status_t Returns ADC_OK on success or an appropriate error code.


function adc_init

Initializes the ADC peripheral with the specified configuration.

adc_status_t adc_init (
    ADC_InitTypeDef * init,
    ADC_HandleTypeDef * hadc
) 

This function sets up the ADC hardware according to the parameters in the initialization structure and prepares it for subsequent conversions.

Parameters:

  • init ADC initialization structure containing configuration parameters.
  • hadc Pointer to the ADC handle structure.

Returns:

adc_status_t Returns ADC_OK on success or an appropriate error code.


function adc_read

Reads a value from the specified ADC channel.

adc_status_t adc_read (
    uint32_t channel,
    uint32_t samplingTime,
    ADC_HandleTypeDef * h,
    QueueHandle_t * q
) 

This function triggers a conversion on the given channel and stores the converted result in the provided queue. It supports both blocking and non-blocking operation depending on configuration.

Parameters:

  • channel ADC channel to read from.
  • samplingTime ADC sampling time (in ADC clock cycles).
  • h Pointer to the ADC handle structure.
  • q Pointer to the user-provided queue handle for result storage.

Returns:

adc_status_t Returns ADC_OK on success or an appropriate error code.



The documentation for this class was generated from the following file bsp/Inc/ADC.h