Analog to Digital Conversion (ADC) Input Driver.
The ADC driver allows you to manage an Analog to Digital peripheral via simple and portable APIs. This driver supports sampling and converting raw values into microvolts.
This documentation provides a basic usage summary and a set of examples in the form of commented code fragments. Detailed descriptions of the APIs are provided in subsequent sections.
An ADC conversion with an ADC peripheral is started by calling ADC_convert(). The result value is returned by ADC_convert() once the conversion is finished.
The result value returned by ADC_convert() is a raw value. The following uses ADC_convertToMicroVolts() to convert the raw value into microvolts.
Refer to the Driver's Configuration section for driver configuration information.
#include <stdbool.h>
#include <stdint.h>
Go to the source code of this file.
Data Structures | |
struct | ADC_Params |
ADC Parameters used with ADC_open(). More... | |
struct | ADC_FxnTable |
The definition of an ADC function table that contains the required set of functions to control a specific ADC driver implementation. More... | |
struct | ADC_Config |
ADC driver's custom configuration structure. More... | |
Macros | |
#define | ADC_convertRawToMicroVolts ADC_convertToMicroVolts |
#define | ADC_CMD_RESERVED |
#define | ADC_STATUS_RESERVED |
#define | ADC_STATUS_SUCCESS (0) |
Successful status code returned by ADC_control(). More... | |
#define | ADC_STATUS_ERROR (-1) |
Generic error status code returned by ADC_control(). More... | |
#define | ADC_STATUS_UNDEFINEDCMD (-2) |
An error status code returned by ADC_control() for undefined command codes. More... | |
Typedefs | |
typedef struct ADC_Config * | ADC_Handle |
A handle that is returned from an ADC_open() call. More... | |
typedef struct ADC_Config | ADC_Config |
ADC driver's custom configuration structure. More... | |
Functions | |
void | ADC_close (ADC_Handle handle) |
Function to close an ADC driver instance. More... | |
int_fast16_t | ADC_control (ADC_Handle handle, uint_fast16_t cmd, void *arg) |
Function performs implementation specific features on a driver instance. More... | |
int_fast16_t | ADC_convert (ADC_Handle handle, uint16_t *value) |
Function to perform an ADC conversion. More... | |
uint32_t | ADC_convertToMicroVolts (ADC_Handle handle, uint16_t adcValue) |
Function to convert a raw ADC sample into microvolts. More... | |
void | ADC_init (void) |
Function to initialize the ADC driver. More... | |
ADC_Handle | ADC_open (uint_least8_t index, ADC_Params *params) |
Function to initialize the ADC peripheral. More... | |
void | ADC_Params_init (ADC_Params *params) |
Initialize an ADC_Params structure to its default values. More... | |
#define ADC_convertRawToMicroVolts ADC_convertToMicroVolts |
typedef struct ADC_Config* ADC_Handle |
A handle that is returned from an ADC_open() call.
typedef struct ADC_Config ADC_Config |
ADC driver's custom configuration structure.
void ADC_close | ( | ADC_Handle | handle | ) |
Function to close an ADC driver instance.
[in] | handle | An ADC_Handle returned from ADC_open() |
int_fast16_t ADC_control | ( | ADC_Handle | handle, |
uint_fast16_t | cmd, | ||
void * | arg | ||
) |
Function performs implementation specific features on a driver instance.
[in] | handle | An ADC_Handle returned from ADC_open() |
[in] | cmd | A command value defined by the device specific implementation |
[in] | arg | An optional R/W (read/write) argument that is accompanied with cmd |
ADC_STATUS_SUCCESS | The call was successful. |
ADC_STATUS_UNDEFINEDCMD | The cmd value is not supported by the device specific implementation. |
int_fast16_t ADC_convert | ( | ADC_Handle | handle, |
uint16_t * | value | ||
) |
Function to perform an ADC conversion.
Function to perform a single channel sample conversion.
[in] | handle | An ADC_Handle returned from ADC_open() |
[in,out] | value | A pointer to a uint16_t to store the conversion result |
ADC_STATUS_SUCCESS | The conversion was successful. |
ADC_STATUS_ERROR | The conversion failed and value is invalid. |
uint32_t ADC_convertToMicroVolts | ( | ADC_Handle | handle, |
uint16_t | adcValue | ||
) |
Function to convert a raw ADC sample into microvolts.
[in] | handle | An ADC_Handle returned from ADC_open() |
[in] | adcValue | A sampling result return from ADC_convert() |
adcValue
converted into microvoltsvoid ADC_init | ( | void | ) |
Function to initialize the ADC driver.
This function must also be called before any other ADC driver APIs.
ADC_Handle ADC_open | ( | uint_least8_t | index, |
ADC_Params * | params | ||
) |
Function to initialize the ADC peripheral.
Function to initialize the ADC peripheral specified by the particular index value.
[in] | index | Index in the ADC_Config [] array. |
[in] | params | Pointer to an initialized ADC_Params structure. If NULL, the default ADC_Params values are used. |
void ADC_Params_init | ( | ADC_Params * | params | ) |
Initialize an ADC_Params structure to its default values.
[in] | params | A pointer to an ADC_Params structure. |
Default values are: