ADC Driver

The ADC driver is used for reading analog voltage and interacting with an end device’s ADC functionality.

Data Structures

ATMO_ADC_Peripheral_t

ADC peripheral configuration structure.

Member Name Type
resolution ATMO_ADC_Resolution_t
conversionMode ATMO_ADC_ConversionMode_t
sampleRate uint32_t
vref_mV int32_t
vrefSource ATMO_ADC_VrefSource_t

ATMO_ADC_Channel_t

ADC single channel configuration.

Member Name Type
inputMode ATMO_ADC_InputMode_t

Type Definitions

Name Definition
ATMO_ADC_DriverInstance_t typedef struct ATMO_ADC_DriverInstance_t

Enumerations

enum ATMO_ADC_Status_t

ADC driver return enumerations.

Name Value Description
ATMO_ADC_Status_Success 0x00u Operation was successful
ATMO_ADC_Status_Fail 0x01u Operation failed
ATMO_ADC_Status_Initialized 0x02u Peripheral already initialized
ATMO_ADC_Status_Invalid 0x03u Invalid operation
ATMO_ADC_Status_NotSupported 0x04u Feature not supported by platform
ATMO_ADC_Status_Unknown 0x05u Some other status not defined
ATMO_ADC_Status_Busy 0x20u Conversion in progress
ATMO_ADC_Status_Timeout 0x21u Conversion timed out

enum ATMO_ADC_ConversionMode_t

Name Value
ATMO_ADC_ConversionMode_Single 0x0001u
ATMO_ADC_ConversionMode_Continuous 0x0002u

enum ATMO_ADC_InputMode_t

Name Value
ATMO_ADC_InputMode_SingleEnded 0x0001u
ATMO_ADC_InputMode_Differential 0x0002u

enum ATMO_ADC_VrefSource_t

Name Value
ATMO_ADC_vrefSource_ExternalVref 0x0001u
ATMO_ADC_vrefSource_InternalVref 0x0002u
ATMO_ADC_vrefSource_InternalBandgap 0x0003u
ATMO_ADC_vrefSource_InternalVDD 0x0004u
ATMO_ADC_vrefSource_InternalVDDIO 0x0005u

enum ATMO_ADC_Resolution_t

Name Value
ATMO_ADC_Resolution_8bit 0x0008u
ATMO_ADC_Resolution_9bit 0x0009u
ATMO_ADC_Resolution_10bit 0x000Au
ATMO_ADC_Resolution_11bit 0x000Bu
ATMO_ADC_Resolution_12bit 0x000Cu
ATMO_ADC_Resolution_13bit 0x000Du
ATMO_ADC_Resolution_14bit 0x000Eu
ATMO_ADC_Resolution_15bit 0x000Fu
ATMO_ADC_Resolution_16bit 0x0010u
ATMO_ADC_Resolution_17bit 0x0011u
ATMO_ADC_Resolution_18bit 0x0012u
ATMO_ADC_Resolution_19bit 0x0013u
ATMO_ADC_Resolution_20bit 0x0014u
ATMO_ADC_Resolution_21bit 0x0015u
ATMO_ADC_Resolution_22bit 0x0016u
ATMO_ADC_Resolution_23bit 0x0017u
ATMO_ADC_Resolution_24bit 0x0018u

enum ATMO_ADC_VoltageUnits_t

Name Value
ATMO_ADC_VoltageUnits_Volts 0x0001u
ATMO_ADC_VoltageUnits_MilliVolts 0x0002u
ATMO_ADC_VoltageUnits_MicroVolts 0x0003u
ATMO_ADC_VoltageUnits_NanoVolts 0x0004u

Functions

ATMO_Status_t ATMO_ADC_AddDriverInstance(const ATMO_ADC_DriverInstance_t *driverInstance, ATMO_DriverInstanceData_t *driverInstanceData, ATMO_DriverInstanceHandle_t *instanceNumber)

Register low level driver instance with main ADC driver.

Parameter Direction Type
instanceNumber N/A ATMO_DriverInstanceHandle_t *
driverInstanceData N/A ATMO_DriverInstanceData_t *
driverInstance N/A const ATMO_ADC_DriverInstance_t *
Return Type
ATMO_Status_t

ATMO_ADC_Status_t ATMO_ADC_Init(ATMO_DriverInstanceHandle_t instance)

This routine initializes data structures needed for the ADC driver.

Parameter Direction Type
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_Status_t

ATMO_ADC_Status_t ATMO_ADC_SetConfiguration(ATMO_DriverInstanceHandle_t instance, ATMO_ADC_Peripheral_t *config)

This routine configures the specified ADC peripheral instance.

Parameter Direction Type
config N/A ATMO_ADC_Peripheral_t *
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_Status_t

ATMO_ADC_Status_t ATMO_ADC_GetConfiguration(ATMO_DriverInstanceHandle_t instance, ATMO_ADC_Peripheral_t *config)

This routine retrieves the current configuration of the specified ADC peripheral instance.

Parameter Direction Type
config N/A ATMO_ADC_Peripheral_t *
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_SetPinConfiguration(ATMO_DriverInstanceHandle_t instance, ATMO_GPIO_Device_Pin_t pin, ATMO_ADC_Channel_t *config)

This routine configures the specified ADC peripheral pin.

Parameter Direction Type
config N/A ATMO_ADC_Channel_t *
pin N/A ATMO_GPIO_Device_Pin_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_DeInit(ATMO_DriverInstanceHandle_t instance)

This routine de-initializes the specified ADC peripheral instance.

Parameter Direction Type
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_Enable(ATMO_DriverInstanceHandle_t instance, ATMO_GPIO_Device_Pin_t pin)

This routine enables the specified ADC peripheral instance. Setting pin to 0xFFFFFFFF enables all channels.

Parameter Direction Type
pin N/A ATMO_GPIO_Device_Pin_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_Disable(ATMO_DriverInstanceHandle_t instance, ATMO_GPIO_Device_Pin_t pin)

This routine disables the specified ADC peripheral instance. Setting pin to 0xFFFFFFFF disables all channels.

Parameter Direction Type
pin N/A ATMO_GPIO_Device_Pin_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_ReadRaw(ATMO_DriverInstanceHandle_t instance, ATMO_GPIO_Device_Pin_t pin, int32_t *value, uint32_t numSamplesToAverage, uint16_t timeout_ms)

This routine initiates an ADC conversion and reads the raw data. The value is formated as signed 2s complement with ‘precision’ data bits plus sign bit (sign extended). The precision is set during initialization. This is a blocking function and will not return until all samples have been taken or a timeout occurs.

Parameter Direction Type
timeout_ms N/A uint16_t
numSamplesToAverage N/A uint32_t
value N/A int32_t *
pin N/A ATMO_GPIO_Device_Pin_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t

ATMO_ADC_Status_t ATMO_ADC_Read(ATMO_DriverInstanceHandle_t instance, ATMO_GPIO_Device_Pin_t pin, ATMO_ADC_VoltageUnits_t units, int32_t *voltage, uint32_t numSamplesToAverage, uint16_t timeout_ms)

This routine initiates an ADC conversion and converts the raw data to voltage. The calculated voltage is returned as an integer where 1 lsb = the specified unit (e.g. volts, millivolts, microvolts). This is a blocking function and will not return until all samples have been taken or a timeout occurs.

Parameter Direction Type
timeout_ms N/A uint16_t
numSamplesToAverage N/A uint32_t
voltage N/A int32_t *
units N/A ATMO_ADC_VoltageUnits_t
pin N/A ATMO_GPIO_Device_Pin_t
instance N/A ATMO_DriverInstanceHandle_t
Return Type
ATMO_ADC_Status_t