-
Notifications
You must be signed in to change notification settings - Fork 4
Added support for ADS1119 and updated documentation with new section #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
build/ | ||
deps/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ enum mgos_ads1x1x_type { | |
ADC_ADS1015, | ||
ADC_ADS1113, | ||
ADC_ADS1114, | ||
ADC_ADS1115 | ||
ADC_ADS1115, | ||
ADC_ADS1119 | ||
}; | ||
|
||
enum mgos_ads1x1x_fsr { | ||
|
@@ -50,19 +51,41 @@ enum mgos_ads1x1x_dr { | |
MGOS_ADS1X1X_SPS_MIN = 0, // 8SPS for ADS111X, 128SPS for ADS101X | ||
MGOS_ADS1X1X_SPS_8, // 8SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_16, // 16SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_20, // 20SPS, ADS1119 only (default) | ||
MGOS_ADS1X1X_SPS_32, // 32SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_64, // 64SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_90, // 90SPS, ADS1119 only | ||
MGOS_ADS1X1X_SPS_128, // 128SPS, both ADS111X and ADS101X | ||
MGOS_ADS1X1X_SPS_250, // 250SPS, both ADS111X and ADS101X | ||
MGOS_ADS1X1X_SPS_330, // 330SPS, ADS1119 only | ||
MGOS_ADS1X1X_SPS_475, // 475SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_490, // 490SPS, ADS101X only | ||
MGOS_ADS1X1X_SPS_860, // 860SPS, ADS111X only | ||
MGOS_ADS1X1X_SPS_920, // 920SPS, ADS101X only | ||
MGOS_ADS1X1X_SPS_1000, // 1000SPS, ADS1119 only | ||
MGOS_ADS1X1X_SPS_1600, // 1600SPS, ADS101X only | ||
MGOS_ADS1X1X_SPS_2400, // 2400SPS, ADS101X only | ||
MGOS_ADS1X1X_SPS_3300, // 3300SPS, ADS101X only | ||
MGOS_ADS1X1X_SPS_DEFAULT, // 128SPS for ADS111X, 1600SPS for ADS101X | ||
MGOS_ADS1X1X_SPS_MAX, // 860SPS for ADS111X, 3300SPS for ADS101X | ||
MGOS_ADS1X1X_SPS_DEFAULT, // 128SPS for ADS111X, 1600SPS for ADS101X, 20SPS for ADS1119 | ||
MGOS_ADS1X1X_SPS_MAX, // 860SPS for ADS111X, 3300SPS for ADS101X, 1000SPS for ADS1119 | ||
}; | ||
|
||
enum mgos_ads1119_gain | ||
{ | ||
MGOS_ADS1119_GAIN_1 = 0, | ||
MGOS_ADS1119_GAIN_4 | ||
}; | ||
|
||
enum mgos_ads1119_conversion_mode | ||
{ | ||
MGOS_ADS1119_CM_SS = 0, | ||
MGOS_ADS1119_CM_CONT | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. singleshot vs continuous mode exists also in some other versions in the ads1x1x family, so this can be a shared enum, probably hidden behind an |
||
|
||
enum mgos_ads1119_vref | ||
{ | ||
MGOS_ADS1119_VREF_INT = 0, // Internal 2.048v | ||
MGOS_ADS1119_VREF_EXT | ||
}; | ||
|
||
/* | ||
|
@@ -71,7 +94,20 @@ enum mgos_ads1x1x_dr { | |
* validity, upon success a new `struct mgos_ads1x1x` is allocated and | ||
* returned. If the device could not be found, NULL is returned. | ||
*/ | ||
struct mgos_ads1x1x *mgos_ads1x1x_create(struct mgos_i2c *i2c, uint8_t i2caddr, enum mgos_ads1x1x_type type); | ||
struct mgos_ads1x1x* | ||
mgos_ads1x1x_create(struct mgos_i2c* i2c, uint8_t i2caddr, enum mgos_ads1x1x_type type); | ||
|
||
/* | ||
* Initialize a ADS1119 on the I2C bus `i2c` at address specified in `i2caddr` | ||
* parameter (default ADS1X1X is on address 0x48). The device will be polled for | ||
* validity, upon success a new `struct mgos_ads1x1x` is allocated and | ||
* returned. If the device could not be found, NULL is returned. | ||
* Refer to TI product PDF, Configuration Register, for information on what to use for mux/gain/DR/CM/VREF. | ||
* Note, use the decimal value for each, ie AinP = AIN2, AinN=AGND is decimal 5 (101 binary). | ||
* Mux is provided at read time | ||
*/ | ||
//struct mgos_ads1x1x* mgos_ads1119_create(struct mgos_i2c* i2c, uint8_t i2caddr, enum mgos_ads1x1x_type type, enum mgos_ads1119_gain gain = MGOS_ADS1119_GAIN_1, enum mgos_ads1x1x_dr dataRate = MGOS_ADS1X1X_SPS_20, enum mgos_ads1119_conversion_mode conversionMode = MGOS_ADS1119_CM_SS, enum mgos_ads1119_vref vRef = MGOS_ADS1119_VREF_INT); | ||
struct mgos_ads1x1x* mgos_ads1119_create(struct mgos_i2c* i2c, uint8_t i2caddr, enum mgos_ads1x1x_type type, enum mgos_ads1119_gain gain, enum mgos_ads1x1x_dr dataRate, enum mgos_ads1119_conversion_mode conversionMode, enum mgos_ads1119_vref vRef); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (see my comment on abstraction leak in #1) |
||
|
||
/* | ||
* Destroy the data structure associated with a ADS1X1X device. The reference | ||
|
@@ -108,6 +144,8 @@ bool mgos_ads1x1x_get_dr(struct mgos_ads1x1x *dev, enum mgos_ads1x1x_dr *dr); | |
*/ | ||
bool mgos_ads1x1x_read(struct mgos_ads1x1x *dev, uint8_t chan, int16_t *result); | ||
|
||
bool mgos_ads1119_read(struct mgos_ads1x1x* dev, uint8_t mux, int16_t* result); | ||
|
||
/* Read a 2-channel differential from the ADC and return the read value in `result`. | ||
* If the channel pair invalid, or an error occurred, false is returned and the | ||
* result cannot be relied upon. Upon success, true is returned. | ||
|
@@ -119,6 +157,11 @@ bool mgos_ads1x1x_read(struct mgos_ads1x1x *dev, uint8_t chan, int16_t *result); | |
*/ | ||
bool mgos_ads1x1x_read_diff(struct mgos_ads1x1x *dev, uint8_t chanP, uint8_t chanN, int16_t *result); | ||
|
||
/* Centralised helper function to write configuration to an ADS1119 | ||
* Sends the command for WREG first | ||
*/ | ||
bool mgos_ads1119_write_conf(struct mgos_ads1x1x * dev, uint8_t value); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. helpers do not go into the public API, as they are not meant to be called by users. This should go into a src/*_internal.h file. |
||
#ifdef __cplusplus | ||
} | ||
#endif |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, gain exists also in the other chips, so this can be a shared enum, probably hidden behind an
ads1x1x_{get,set}_gain()
API.