SmartSnippets DA1459x SDK
ad_gpadc.h
Go to the documentation of this file.
1 
44 #if (dg_configGPADC_ADAPTER == 1)
45 
46 #ifndef AD_GPADC_H_
47 #define AD_GPADC_H_
48 
49 #include "ad.h"
50 #include "hw_gpadc.h"
51 #include "hw_gpio.h"
52 #include "osal.h"
53 #include "resmgmt.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
67 #ifndef CONFIG_GPADC_USE_ASYNC_TRANSACTIONS
68 #define CONFIG_GPADC_USE_ASYNC_TRANSACTIONS (1)
69 #endif
70 
82 #if dg_configUSE_SYS_ADC
83 #define CONFIG_GPADC_USE_SYNC_TRANSACTIONS (1)
84 #else
85 #ifndef CONFIG_GPADC_USE_SYNC_TRANSACTIONS
86 #define CONFIG_GPADC_USE_SYNC_TRANSACTIONS (1)
87 #endif
88 #endif
89 
96 typedef struct ad_gpadc_io_conf {
100 
110 
114 #define HW_GPADC_1 ((void *)GPADC_BASE)
115 
122 typedef struct ad_gpadc_controller_conf {
123  const HW_GPADC_ID id;
127 
131 typedef void *ad_gpadc_handle_t;
132 
136 typedef enum {
137  AD_GPADC_ERROR_NONE = 0,
138  AD_GPADC_ERROR_HANDLE_INVALID = -1,
139  AD_GPADC_ERROR_CHANGE_NOT_ALLOWED = -2,
140  AD_GPADC_ERROR_ADAPTER_NOT_OPEN = -3,
141  AD_GPADC_ERROR_CONFIG_INVALID = -4,
142  AD_GPADC_ERROR_ASYNC_READ_IN_PROGRESS = -5,
143  AD_GPADC_ERROR_TIMEOUT = -6,
144  AD_GPADC_ERROR_OTHER = -7,
145  AD_GPADC_ERROR_IO_CFG_INVALID = -8,
147 
154 typedef void (*ad_gpadc_user_cb)(void *user_data, int value);
155 
163 void ad_gpadc_init(void);
164 
165 #if (CONFIG_GPADC_USE_SYNC_TRANSACTIONS == 1)
166 
181 int ad_gpadc_read_nof_conv(const ad_gpadc_handle_t handle, int nof_conv, uint16_t *outbuf);
182 #endif /* CONFIG_GPADC_USE_SYNC_TRANSACTIONS */
183 
184 #if (CONFIG_GPADC_USE_ASYNC_TRANSACTIONS == 1)
185 
202 int ad_gpadc_read_nof_conv_async(const ad_gpadc_handle_t handle, int nof_conv, uint16_t *outbuf, ad_gpadc_user_cb read_async_cb, void *user_data);
203 #endif
204 
220 
237 
249 
263 int ad_gpadc_io_config (const HW_GPADC_ID id, const ad_gpadc_io_conf_t *io, AD_IO_CONF_STATE state);
264 
279 int ad_gpadc_close(ad_gpadc_handle_t p, bool force);
280 
290 __STATIC_FORCEINLINE int ad_gpadc_conv_to_temp_x100(const ad_gpadc_driver_conf_t *drv, uint16_t raw_value)
291 {
292  return hw_gpadc_convert_to_celsius_x100_util(drv, raw_value);
293 }
294 
306 uint16_t ad_gpadc_conv_raw_to_batt_mvolt(const ad_gpadc_driver_conf_t *drv, uint32_t raw_value);
307 
319 int ad_gpadc_conv_to_mvolt(const ad_gpadc_driver_conf_t *drv, uint32_t raw_value);
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 
325 #endif /* AD_GPADC_H_ */
326 
327 #endif /* dg_configGPADC_ADAPTER */
328 
hw_gpadc.h
Definition of API for the GPADC Low Level Driver.
ad_gpadc_io_config
int ad_gpadc_io_config(const HW_GPADC_ID id, const ad_gpadc_io_conf_t *io, AD_IO_CONF_STATE state)
Initialize controller pins to on / off io configuration.
hw_gpadc_convert_to_celsius_x100_util
int16_t hw_gpadc_convert_to_celsius_x100_util(const hw_gpadc_config_t *cfg, uint16_t raw_val)
Convert a 16-bit, left-aligned, raw value to temperature. For accurate conversions using this functio...
ad_gpadc_conv_to_mvolt
int ad_gpadc_conv_to_mvolt(const ad_gpadc_driver_conf_t *drv, uint32_t raw_value)
Convert raw value read from GPADC to voltage in mV. The same configuration which was used to obtain t...
ad_gpadc_controller_conf::io
const ad_gpadc_io_conf_t * io
Definition: ad_gpadc.h:124
ad_gpadc_get_source_max
uint16_t ad_gpadc_get_source_max(const ad_gpadc_driver_conf_t *drv)
Return maximum value that can be read for ADC source.
AD_GPADC_ERROR
AD_GPADC_ERROR
enum with return values of API calls
Definition: ad_gpadc.h:136
resmgmt.h
Resource management API.
osal.h
OS abstraction layer API.
ad_gpadc_controller_conf
GPADC controller configuration.
Definition: ad_gpadc.h:122
ad_gpadc_open
ad_gpadc_handle_t ad_gpadc_open(const ad_gpadc_controller_conf_t *conf)
Open GPADC controller.
ad_gpadc_close
int ad_gpadc_close(ad_gpadc_handle_t p, bool force)
Close GPADC controller.
ad_gpadc_user_cb
void(* ad_gpadc_user_cb)(void *user_data, int value)
GPADC adapter callback function.
Definition: ad_gpadc.h:154
ad_gpadc_handle_t
void * ad_gpadc_handle_t
GPADC Handle returned by ad_gpadc_open()
Definition: ad_gpadc.h:131
ad_gpadc_io_conf::input0
ad_io_conf_t input0
Definition: ad_gpadc.h:97
ad.h
Adapters shared definitions.
AD_IO_CONF_STATE
AD_IO_CONF_STATE
Adapters IO configuration state.
Definition: ad.h:65
ad_gpadc_reconfig
int ad_gpadc_reconfig(const ad_gpadc_handle_t p, const ad_gpadc_driver_conf_t *drv)
Reconfigure GPADC controller.
ad_gpadc_init
void ad_gpadc_init(void)
Initialize GPADC adapter and some required variables.
hw_gpadc_config_t
ADC configuration.
Definition: hw_gpadc_v2.h:159
ad_gpadc_io_conf::input1
ad_io_conf_t input1
Definition: ad_gpadc.h:98
ad_gpadc_controller_conf::id
const HW_GPADC_ID id
Definition: ad_gpadc.h:123
ad_gpadc_read_nof_conv
int ad_gpadc_read_nof_conv(const ad_gpadc_handle_t handle, int nof_conv, uint16_t *outbuf)
Read synchronously nof_conv conversions from the selected source.
ad_gpadc_conv_raw_to_batt_mvolt
uint16_t ad_gpadc_conv_raw_to_batt_mvolt(const ad_gpadc_driver_conf_t *drv, uint32_t raw_value)
Convert raw value read from GPADC to battery voltage in mV. The same configuration which was used to ...
hw_gpio.h
Definition of API for the GPIO Low Level Driver.
ad_gpadc_conv_to_temp_x100
__STATIC_FORCEINLINE int ad_gpadc_conv_to_temp_x100(const ad_gpadc_driver_conf_t *drv, uint16_t raw_value)
Convert raw value read from GPADC to temperature value in hundredths of degree Celsius.
Definition: ad_gpadc.h:290
ad_gpadc_controller_conf::drv
const ad_gpadc_driver_conf_t * drv
Definition: ad_gpadc.h:125
ad_io_conf_t
Adapters IO configuration.
Definition: ad.h:104
ad_gpadc_io_conf_t
struct ad_gpadc_io_conf ad_gpadc_io_conf_t
GPADC I/O configuration.
ad_gpadc_io_conf
GPADC I/O configuration.
Definition: ad_gpadc.h:96
ad_gpadc_controller_conf_t
struct ad_gpadc_controller_conf ad_gpadc_controller_conf_t
GPADC controller configuration.
ad_gpadc_read_nof_conv_async
int ad_gpadc_read_nof_conv_async(const ad_gpadc_handle_t handle, int nof_conv, uint16_t *outbuf, ad_gpadc_user_cb read_async_cb, void *user_data)
Read asynchronously nof_conv conversions from the selected source.
ad_gpadc_driver_conf_t
hw_gpadc_config_t ad_gpadc_driver_conf_t
GPADC driver configuration.
Definition: ad_gpadc.h:109