Skip to content

Commit 1f96022

Browse files
committed
drivers/ads1x1x: add undef params, store bits res in struct
1 parent b6ab944 commit 1f96022

File tree

4 files changed

+84
-45
lines changed

4 files changed

+84
-45
lines changed

drivers/ads1x1x/Makefile.dep

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ FEATURES_REQUIRED += periph_i2c
33
USEMODULE += ztimer
44
USEMODULE += ztimer_msec
55

6-
ifeq (,$(filter ads111% ads101%,$(USEMODULE)))
7-
# enable ads101x as default if no other module is enabled
8-
USEMODULE += ads101x
9-
endif
10-
116
ifneq (,$(filter ads101%,$(USEMODULE)))
127
USEMODULE += ads1x1x
138
endif

drivers/ads1x1x/ads1x1x.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#define ENABLE_DEBUG 0
3232
#include "debug.h"
3333

34-
#ifndef ADS1X1X_READ_DELAY_MS
34+
#ifndef ADS1X1X_READ_DELAY_MS //TODO: optim
3535
#define ADS1X1X_READ_DELAY_MS 8 /* compatible with 128SPS */
3636
#endif
3737

@@ -200,6 +200,7 @@ int ads1x1x_init(ads1x1x_t *dev, const ads1x1x_params_t *params)
200200
int ads1x1x_set_parameters(ads1x1x_t *dev, const ads1x1x_params_t *params)
201201
{
202202
assert(dev && params);
203+
assert(params->bits_res != ADS1X1X_BITS_RES_UNDEF && params->dr != ADS1X1X_DATAR_UNDEF);
203204

204205
i2c_acquire(params->i2c);
205206

drivers/ads1x1x/include/ads1x1x_internal.h

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,45 @@ extern "C" {
8585
/** @} */
8686

8787
/**
88-
* @name ADS101x/111x data rate settings
89-
* Configures the data rate (samples per second).
88+
* @name ADS101x/ADS111x Data Rate Settings
89+
* @brief Register bit definitions for configuring data rate (samples per second).
9090
* @{
9191
*/
92-
#define ADS1X1X_DATAR_MASK ((1 << 7) | (1 << 6) | (1 << 5)) /**< Mask for data rate bits */
93-
#define ADS1X1X_DATAR_8 ((0 << 7) | (0 << 6) | (0 << 5)) /**< 8 SPS */
94-
#define ADS1X1X_DATAR_16 ((0 << 7) | (0 << 6) | (1 << 5)) /**< 16 SPS */
95-
#define ADS1X1X_DATAR_32 ((0 << 7) | (1 << 6) | (0 << 5)) /**< 32 SPS */
96-
#define ADS1X1X_DATAR_64 ((0 << 7) | (1 << 6) | (1 << 5)) /**< 64 SPS */
97-
#define ADS1X1X_DATAR_128 ((1 << 7) | (0 << 6) | (0 << 5)) /**< 128 SPS (default) */
98-
#define ADS1X1X_DATAR_250 ((1 << 7) | (0 << 6) | (1 << 5)) /**< 250 SPS */
99-
#define ADS1X1X_DATAR_475 ((1 << 7) | (1 << 6) | (0 << 5)) /**< 475 SPS */
100-
#define ADS1X1X_DATAR_490 ((0 << 7) | (1 << 6) | (0 << 5)) /**< 490 SPS */
101-
#define ADS1X1X_DATAR_860 ((1 << 7) | (1 << 6) | (1 << 5)) /**< 860 SPS */
102-
#define ADS1X1X_DATAR_920 ((0 << 7) | (1 << 6) | (1 << 5)) /**< 920 SPS */
103-
#define ADS1X1X_DATAR_1600 ((1 << 7) | (0 << 6) | (0 << 5)) /**< 1600 SPS */
104-
#define ADS1X1X_DATAR_2400 ((1 << 7) | (0 << 6) | (1 << 5)) /**< 2400 SPS */
105-
#define ADS1X1X_DATAR_3300 ((1 << 7) | (1 << 6) | (0 << 5)) /**< 3300 SPS */
92+
93+
#define ADS1X1X_DATAR_UNDEF (-1) /**< Undefined / invalid data rate */
94+
#define ADS1X1X_DATAR_MASK ((1 << 7) | (1 << 6) | (1 << 5)) /**< Bit mask for data rate field */
95+
96+
/**
97+
* @name ADS111x Data Rates
98+
* @brief Valid data rates for ADS111x (in SPS).
99+
* @{
100+
*/
101+
#if MODULE_ADS111X
102+
# define ADS111X_DATAR_8 ((0 << 7) | (0 << 6) | (0 << 5)) /**< 8 SPS */
103+
# define ADS111X_DATAR_16 ((0 << 7) | (0 << 6) | (1 << 5)) /**< 16 SPS */
104+
# define ADS111X_DATAR_64 ((0 << 7) | (1 << 6) | (0 << 5)) /**< 64 SPS */
105+
# define ADS111X_DATAR_128 ((0 << 7) | (1 << 6) | (1 << 5)) /**< 128 SPS (default) */
106+
# define ADS111X_DATAR_250 ((1 << 7) | (0 << 6) | (0 << 5)) /**< 250 SPS */
107+
# define ADS111X_DATAR_475 ((1 << 7) | (0 << 6) | (1 << 5)) /**< 475 SPS */
108+
# define ADS111X_DATAR_860 ((1 << 7) | (1 << 6) | (0 << 5)) /**< 860 SPS (max) */
109+
#endif
110+
/** @} */
111+
112+
/**
113+
* @name ADS101x Data Rates
114+
* @brief Valid data rates for ADS101x (in SPS).
115+
* @{
116+
*/
117+
#if MODULE_ADS101X
118+
# define ADS101X_DATAR_128 ((0 << 7) | (0 << 6) | (0 << 5)) /**< 128 SPS */
119+
# define ADS101X_DATAR_250 ((0 << 7) | (0 << 6) | (1 << 5)) /**< 250 SPS */
120+
# define ADS101X_DATAR_490 ((0 << 7) | (1 << 6) | (0 << 5)) /**< 490 SPS */
121+
# define ADS101X_DATAR_920 ((0 << 7) | (1 << 6) | (1 << 5)) /**< 920 SPS */
122+
# define ADS101X_DATAR_1600 ((1 << 7) | (0 << 6) | (0 << 5)) /**< 1600 SPS (default) */
123+
# define ADS101X_DATAR_2400 ((1 << 7) | (0 << 6) | (1 << 5)) /**< 2400 SPS */
124+
# define ADS101X_DATAR_3300 ((1 << 7) | (1 << 6) | (0 << 5)) /**< 3300 SPS (max) */
125+
#endif
126+
/** @} */
106127
/** @} */
107128

108129
/**
@@ -147,6 +168,27 @@ extern "C" {
147168
#define ADS1X1X_COMP_QUEUE_DISABLE ((1 << 1) | (1 << 0)) /**< Disable comparator (default) */
148169
/** @} */
149170

171+
/**
172+
* @name ADS101x/111x bit resolution
173+
* @{
174+
*/
175+
#define ADS1X1X_BITS_RES_UNDEF (0) /**< Undefined resolution */
176+
177+
/**
178+
* @brief ADS101x 12-bit resolution
179+
*/
180+
#if MODULE_ADS101X
181+
# define ADS101X_BITS_RES (12) /**< 12-bit resolution */
182+
#endif
183+
184+
/**
185+
* @brief ADS111x 16-bit resolution
186+
*/
187+
#if MODULE_ADS111X
188+
# define ADS111X_BITS_RES (16) /**< 16-bit resolution */
189+
#endif
190+
/** @} */
191+
150192
/**
151193
* @brief Mask for all alert-related configuration bits
152194
* (comparator mode, polarity, latch, queue).

drivers/ads1x1x/include/ads1x1x_params.h

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,11 @@ extern "C" {
9090
#endif
9191

9292
/**
93-
* @brief Default data rate configuration
93+
* @def ADS1X1X_PARAM_DATAR
94+
* @brief Default data rate configuration set to undefined
9495
*/
95-
#if MODULE_ADS111X
96-
# define ADS111X_PARAM_DATAR (ADS1X1X_DATAR_128)
97-
# define ADS1X1X_PARAM_DATAR (ADS111X_PARAM_DATAR)
98-
#elif defined(MODULE_ADS101X)
99-
# define ADS101X_PARAM_DATAR (ADS1X1X_DATAR_1600)
100-
# define ADS1X1X_PARAM_DATAR (ADS101X_PARAM_DATAR)
96+
#ifndef ADS1X1X_PARAM_DATAR
97+
# define ADS1X1X_PARAM_DATAR ADS1X1X_DATAR_UNDEF
10198
#endif
10299

103100
/**
@@ -142,29 +139,33 @@ extern "C" {
142139

143140
/**
144141
* @def ADS1X1X_PARAM_BITS_RES
145-
* @brief Resolution in bits of the ADC
142+
* @brief Default bit resolution set to undefined
146143
*/
147-
#if MODULE_ADS101X
148-
# define ADS101X_PARAM_BITS_RES (12)
149-
# define ADS1X1X_PARAM_BITS_RES ADS101X_PARAM_BITS_RES
150-
#elif defined(MODULE_ADS111X)
151-
# define ADS111X_PARAM_BITS_RES (16)
152-
# define ADS1X1X_PARAM_BITS_RES ADS111X_PARAM_BITS_RES
144+
#ifndef ADS1X1X_PARAM_BITS_RES
145+
# define ADS1X1X_PARAM_BITS_RES (ADS1X1X_BITS_RES_UNDEF)
153146
#endif
154147

155148
/**
156149
* @def ADS1X1X_PARAMS
157-
* @brief Default ADS1X1X parameters structure
150+
* @brief Default configuration parameters structure for ADS1X1X ADC devices
158151
*
159-
* @note The default parameter set defined here can only be used if a single type of
160-
* ADS101x/111x device is used. If devices of both types are used together, a
161-
* user-defined parameter set must be provided via @ref ADS1X1X_PARAMS.
152+
* This macro defines the default parameter structure used to initialize ADS1X1X
153+
* analog-to-digital converter devices. The structure contains all necessary
154+
* configuration options including resolution, data rate, gain, and operational modes.
162155
*
163-
* In this case, you must configure the parameters according to the device type:
164-
* - @ref ads1x1x_params_t::bits_res must be set to either
165-
* ADS101X_PARAM_BITS_RES or ADS111X_PARAM_BITS_RES.
166-
* - @ref ads1x1x_params_t::dr must also be set to either
167-
* ADS101X_PARAM_DATAR or ADS111X_PARAM_DATAR.
156+
* @warning The following parameters are mandatory and must be explicitly configured:
157+
* - @ref ads1x1x_params_t::bits_res - ADC resolution, must be set to either:
158+
* * ADS101X_BITS_RES for 12-bit resolution (ADS101x series)
159+
* * ADS111X_BITS_RES for 16-bit resolution (ADS111x series)
160+
* - @ref ads1x1x_params_t::dr - Data rate configuration, must be set to a
161+
* valid sampling rate value appropriate for the selected device variant
162+
*
163+
* @note Other parameters in the structure have sensible defaults but can be
164+
* customized based on application requirements such as input multiplexer
165+
* configuration, programmable gain amplifier settings, and comparator modes.
166+
*
167+
* @see ads1x1x_params_t for detailed parameter structure definition
168+
* @see ads1x1x_init() for device initialization using these parameters
168169
*/
169170
#ifndef ADS1X1X_PARAMS
170171
# define ADS1X1X_PARAMS { .i2c = ADS1X1X_PARAM_I2C, \

0 commit comments

Comments
 (0)