caffeine-hal 0.6.6
A Header-Defined Interface c library, it provides the hal layer for the Caffeine framework
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
cfn_hal_adc.h File Reference

Analog-to-Digital Converter (ADC) HAL API. More...

#include "cfn_hal.h"
#include "cfn_hal_base.h"
#include "cfn_hal_gpio.h"
#include "cfn_hal_types.h"

Go to the source code of this file.

Data Structures

struct  cfn_hal_adc_phy_t
 
struct  cfn_hal_adc_config_t
 
struct  cfn_hal_adc_api_s
 ADC Virtual Method Table (VMT). More...
 

Typedefs

typedef struct cfn_hal_adc_s cfn_hal_adc_t
 
typedef struct cfn_hal_adc_api_s cfn_hal_adc_api_t
 
typedef void(* cfn_hal_adc_callback_t) (cfn_hal_adc_t *driver, uint32_t event_mask, uint32_t error_mask, uint32_t value, void *user_arg)
 ADC callback signature.
 

Enumerations

enum  cfn_hal_adc_event_t { CFN_HAL_ADC_EVENT_NONE = 0 , CFN_HAL_ADC_EVENT_EOC = CFN_HAL_BIT(0) }
 ADC nominal event flags. More...
 
enum  cfn_hal_adc_error_t { CFN_HAL_ADC_ERROR_NONE = 0 , CFN_HAL_ADC_ERROR_OVERRUN = CFN_HAL_BIT(0) , CFN_HAL_ADC_ERROR_GENERAL = CFN_HAL_BIT(1) }
 ADC exception error flags. More...
 
enum  cfn_hal_adc_resolution_t {
  CFN_HAL_ADC_RESOLUTION_BIT_4 = 0 , CFN_HAL_ADC_RESOLUTION_BIT_6 , CFN_HAL_ADC_RESOLUTION_BIT_8 , CFN_HAL_ADC_RESOLUTION_BIT_10 ,
  CFN_HAL_ADC_RESOLUTION_BIT_12 , CFN_HAL_ADC_RESOLUTION_BIT_14 , CFN_HAL_ADC_RESOLUTION_BIT_16 , CFN_HAL_ADC_RESOLUTION_BIT_24 ,
  CFN_HAL_ADC_RESOLUTION_BIT_MAX
}
 
enum  cfn_hal_adc_align_t { CFN_HAL_ADC_ALIGN_RIGHT = 0 , CFN_HAL_ADC_ALIGN_LEFT , CFN_HAL_ADC_ALIGN_MAX }
 
enum  cfn_hal_adc_scan_t { CFN_HAL_SCAN_ENABLED = 0 , CFN_HAL_SCAN_DISABLED , CFN_HAL_SCAN_MAX }
 
enum  cfn_hal_adc_mode_t { CFN_HAL_ADC_MODE_SINGLE = 0 , CFN_HAL_ADC_MODE_CONTINUOUS , CFN_HAL_ADC_MODE_MAX }
 
enum  cfn_hal_adc_eoc_t { CFN_HAL_ADC_EOC_SINGLE = CFN_HAL_BIT(0) , CFN_HAL_ADC_EOC_SEQUENCE = CFN_HAL_BIT(1) }
 

Functions

 CFN_HAL_VMT_CHECK (struct cfn_hal_adc_api_s)
 
 CFN_HAL_CREATE_DRIVER_TYPE (adc, cfn_hal_adc_config_t, cfn_hal_adc_api_t, cfn_hal_adc_phy_t, cfn_hal_adc_callback_t)
 
CFN_HAL_INLINE void cfn_hal_adc_populate (cfn_hal_adc_t *driver, uint32_t peripheral_id, struct cfn_hal_clock_s *clock, void *dependency, const cfn_hal_adc_api_t *api, const cfn_hal_adc_phy_t *phy, const cfn_hal_adc_config_t *config, cfn_hal_adc_callback_t callback, void *user_arg)
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_validate (const cfn_hal_adc_t *driver, const cfn_hal_adc_config_t *config)
 Validates the ADC configuration.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_init (cfn_hal_adc_t *driver)
 Initializes the ADC driver.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_deinit (cfn_hal_adc_t *driver)
 Deinitializes the ADC driver.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_set (cfn_hal_adc_t *driver, const cfn_hal_adc_config_t *config)
 Sets the ADC configuration.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_get (cfn_hal_adc_t *driver, cfn_hal_adc_config_t *config)
 Gets the current ADC configuration.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_callback_register (cfn_hal_adc_t *driver, const cfn_hal_adc_callback_t callback, void *user_arg)
 Registers a callback for ADC events and errors.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_power_state_set (cfn_hal_adc_t *driver, cfn_hal_power_state_t state)
 Sets the ADC power state.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_enable (cfn_hal_adc_t *driver, uint32_t event_mask)
 Enables one or more ADC nominal events.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_disable (cfn_hal_adc_t *driver, uint32_t event_mask)
 Disables one or more ADC nominal events.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_get (cfn_hal_adc_t *driver, uint32_t *event_mask)
 Retrieves the current ADC nominal event status.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_enable (cfn_hal_adc_t *driver, uint32_t error_mask)
 Enables one or more ADC exception errors.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_disable (cfn_hal_adc_t *driver, uint32_t error_mask)
 Disables one or more ADC exception errors.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_get (cfn_hal_adc_t *driver, uint32_t *error_mask)
 Retrieves the current ADC exception error status.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_read (cfn_hal_adc_t *driver, uint32_t *value, uint32_t timeout)
 Reads a single ADC value (polling).
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_start (cfn_hal_adc_t *driver)
 Starts continuous ADC conversion.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_stop (cfn_hal_adc_t *driver)
 Stops continuous ADC conversion.
 
CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_read_dma (cfn_hal_adc_t *driver, uint32_t *data, size_t nbr_of_samples)
 Reads multiple ADC values using DMA.
 
cfn_hal_error_code_t cfn_hal_adc_construct (cfn_hal_adc_t *driver, const cfn_hal_adc_config_t *config, const cfn_hal_adc_phy_t *phy, struct cfn_hal_clock_s *clock, void *dependency, cfn_hal_adc_callback_t callback, void *user_arg)
 
cfn_hal_error_code_t cfn_hal_adc_destruct (cfn_hal_adc_t *driver)
 

Detailed Description

Analog-to-Digital Converter (ADC) HAL API.

Copyright (c) 2026 Hisham Moussa Daou https://www.whileone.me

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Typedef Documentation

◆ cfn_hal_adc_api_t

◆ cfn_hal_adc_callback_t

typedef void(* cfn_hal_adc_callback_t) (cfn_hal_adc_t *driver, uint32_t event_mask, uint32_t error_mask, uint32_t value, void *user_arg)

ADC callback signature.

Parameters
driverPointer to the ADC driver instance.
event_maskMask of triggered nominal events.
error_maskMask of triggered exception errors.
valueLast conversion result (if applicable).
user_argUser-defined argument passed during registration.

◆ cfn_hal_adc_t

typedef struct cfn_hal_adc_s cfn_hal_adc_t

Enumeration Type Documentation

◆ cfn_hal_adc_align_t

Enumerator
CFN_HAL_ADC_ALIGN_RIGHT 
CFN_HAL_ADC_ALIGN_LEFT 
CFN_HAL_ADC_ALIGN_MAX 

◆ cfn_hal_adc_eoc_t

Enumerator
CFN_HAL_ADC_EOC_SINGLE 
CFN_HAL_ADC_EOC_SEQUENCE 

◆ cfn_hal_adc_error_t

ADC exception error flags.

Enumerator
CFN_HAL_ADC_ERROR_NONE 
CFN_HAL_ADC_ERROR_OVERRUN 

Data Overrun

CFN_HAL_ADC_ERROR_GENERAL 

General Hardware Error

◆ cfn_hal_adc_event_t

ADC nominal event flags.

Enumerator
CFN_HAL_ADC_EVENT_NONE 
CFN_HAL_ADC_EVENT_EOC 

End of Conversion

◆ cfn_hal_adc_mode_t

Enumerator
CFN_HAL_ADC_MODE_SINGLE 
CFN_HAL_ADC_MODE_CONTINUOUS 
CFN_HAL_ADC_MODE_MAX 

◆ cfn_hal_adc_resolution_t

Enumerator
CFN_HAL_ADC_RESOLUTION_BIT_4 
CFN_HAL_ADC_RESOLUTION_BIT_6 
CFN_HAL_ADC_RESOLUTION_BIT_8 
CFN_HAL_ADC_RESOLUTION_BIT_10 
CFN_HAL_ADC_RESOLUTION_BIT_12 
CFN_HAL_ADC_RESOLUTION_BIT_14 
CFN_HAL_ADC_RESOLUTION_BIT_16 
CFN_HAL_ADC_RESOLUTION_BIT_24 
CFN_HAL_ADC_RESOLUTION_BIT_MAX 

◆ cfn_hal_adc_scan_t

Enumerator
CFN_HAL_SCAN_ENABLED 
CFN_HAL_SCAN_DISABLED 
CFN_HAL_SCAN_MAX 

Function Documentation

◆ cfn_hal_adc_callback_register()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_callback_register ( cfn_hal_adc_t driver,
const cfn_hal_adc_callback_t  callback,
void *  user_arg 
)

Registers a callback for ADC events and errors.

Parameters
driverPointer to the ADC driver instance.
callbackThe callback function to register.
user_argUser-defined argument passed to the callback.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_config_get()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_get ( cfn_hal_adc_t driver,
cfn_hal_adc_config_t config 
)

Gets the current ADC configuration.

Parameters
driverPointer to the ADC driver instance.
config[out] Pointer to store the configuration.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_config_set()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_set ( cfn_hal_adc_t driver,
const cfn_hal_adc_config_t config 
)

Sets the ADC configuration.

Parameters
driverPointer to the ADC driver instance.
configPointer to the configuration structure.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_config_validate()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_config_validate ( const cfn_hal_adc_t driver,
const cfn_hal_adc_config_t config 
)

Validates the ADC configuration.

Parameters
driverPointer to the ADC driver instance.
configPointer to the configuration structure.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_construct()

cfn_hal_error_code_t cfn_hal_adc_construct ( cfn_hal_adc_t driver,
const cfn_hal_adc_config_t config,
const cfn_hal_adc_phy_t phy,
struct cfn_hal_clock_s *  clock,
void *  dependency,
cfn_hal_adc_callback_t  callback,
void *  user_arg 
)

◆ cfn_hal_adc_deinit()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_deinit ( cfn_hal_adc_t driver)

Deinitializes the ADC driver.

Parameters
driverPointer to the ADC driver instance.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_destruct()

cfn_hal_error_code_t cfn_hal_adc_destruct ( cfn_hal_adc_t driver)

◆ cfn_hal_adc_error_disable()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_disable ( cfn_hal_adc_t driver,
uint32_t  error_mask 
)

Disables one or more ADC exception errors.

Parameters
driverPointer to the ADC driver instance.
error_maskMask of errors to disable.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_error_enable()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_enable ( cfn_hal_adc_t driver,
uint32_t  error_mask 
)

Enables one or more ADC exception errors.

Parameters
driverPointer to the ADC driver instance.
error_maskMask of errors to enable.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_error_get()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_error_get ( cfn_hal_adc_t driver,
uint32_t *  error_mask 
)

Retrieves the current ADC exception error status.

Parameters
driverPointer to the ADC driver instance.
error_mask[out] Pointer to store the error mask.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_event_disable()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_disable ( cfn_hal_adc_t driver,
uint32_t  event_mask 
)

Disables one or more ADC nominal events.

Parameters
driverPointer to the ADC driver instance.
event_maskMask of events to disable.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_event_enable()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_enable ( cfn_hal_adc_t driver,
uint32_t  event_mask 
)

Enables one or more ADC nominal events.

Parameters
driverPointer to the ADC driver instance.
event_maskMask of events to enable.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_event_get()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_event_get ( cfn_hal_adc_t driver,
uint32_t *  event_mask 
)

Retrieves the current ADC nominal event status.

Parameters
driverPointer to the ADC driver instance.
event_mask[out] Pointer to store the event mask.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_init()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_init ( cfn_hal_adc_t driver)

Initializes the ADC driver.

Parameters
driverPointer to the ADC driver instance.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_populate()

CFN_HAL_INLINE void cfn_hal_adc_populate ( cfn_hal_adc_t driver,
uint32_t  peripheral_id,
struct cfn_hal_clock_s *  clock,
void *  dependency,
const cfn_hal_adc_api_t api,
const cfn_hal_adc_phy_t phy,
const cfn_hal_adc_config_t config,
cfn_hal_adc_callback_t  callback,
void *  user_arg 
)

◆ cfn_hal_adc_power_state_set()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_power_state_set ( cfn_hal_adc_t driver,
cfn_hal_power_state_t  state 
)

Sets the ADC power state.

Parameters
driverPointer to the ADC driver instance.
stateTarget power state.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_read()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_read ( cfn_hal_adc_t driver,
uint32_t *  value,
uint32_t  timeout 
)

Reads a single ADC value (polling).

Parameters
driverPointer to the ADC driver instance.
value[out] Pointer to store the read value.
timeoutTimeout duration in milliseconds.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_read_dma()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_read_dma ( cfn_hal_adc_t driver,
uint32_t *  data,
size_t  nbr_of_samples 
)

Reads multiple ADC values using DMA.

Parameters
driverPointer to the ADC driver instance.
data[out] Pointer to the buffer where samples will be stored.
nbr_of_samplesNumber of samples to read.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_start()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_start ( cfn_hal_adc_t driver)

Starts continuous ADC conversion.

Parameters
driverPointer to the ADC driver instance.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ cfn_hal_adc_stop()

CFN_HAL_INLINE cfn_hal_error_code_t cfn_hal_adc_stop ( cfn_hal_adc_t driver)

Stops continuous ADC conversion.

Parameters
driverPointer to the ADC driver instance.
Returns
CFN_HAL_ERROR_OK on success, or a specific error code on failure.

◆ CFN_HAL_CREATE_DRIVER_TYPE()

CFN_HAL_CREATE_DRIVER_TYPE ( adc  ,
cfn_hal_adc_config_t  ,
cfn_hal_adc_api_t  ,
cfn_hal_adc_phy_t  ,
cfn_hal_adc_callback_t   
)

◆ CFN_HAL_VMT_CHECK()

CFN_HAL_VMT_CHECK ( struct cfn_hal_adc_api_s  )