diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-09 12:25:56 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-01-09 12:25:56 -0500 |
commit | 68e792f9b71a46474b33d4dc6199522ff70f85d4 (patch) | |
tree | 86111f575ea4379313da51164905ab99c561abde /watch-library | |
parent | a10267552260466d0dd50432faffbdbceec94eb6 (diff) | |
download | Sensor-Watch-68e792f9b71a46474b33d4dc6199522ff70f85d4.tar.gz Sensor-Watch-68e792f9b71a46474b33d4dc6199522ff70f85d4.tar.bz2 Sensor-Watch-68e792f9b71a46474b33d4dc6199522ff70f85d4.zip |
lis2dw: add low power / low noise mode
Diffstat (limited to 'watch-library')
-rw-r--r-- | watch-library/driver/lis2dw.c | 22 | ||||
-rw-r--r-- | watch-library/driver/lis2dw.h | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/watch-library/driver/lis2dw.c b/watch-library/driver/lis2dw.c index 4e506a6d..6e1ac56d 100644 --- a/watch-library/driver/lis2dw.c +++ b/watch-library/driver/lis2dw.c @@ -115,3 +115,25 @@ void lis2dw_set_data_rate(lis2dw_data_rate_t dataRate) { lis2dw_data_rate_t lis2dw_get_data_rate(void) { return watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) >> 4; } + +void lis2dw_set_low_power_mode(lis2dw_low_power_mode_t mode) { + uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & ~(0b11); + uint8_t bits = mode & 0b11; + + watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, val | bits); +} + +lis2dw_low_power_mode_t lis2dw_get_low_power_mode(void) { + return watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & 0b11; +} + +void lis2dw_set_low_noise_mode(bool on) { + uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & ~(LIS2DW_CTRL6_VAL_LOW_NOISE); + uint8_t bits = on ? LIS2DW_CTRL6_VAL_LOW_NOISE : 0; + + watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, val | bits); +} + +bool lis2dw_get_low_noise_mode(void) { + return (watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & LIS2DW_CTRL6_VAL_LOW_NOISE) != 0; +} diff --git a/watch-library/driver/lis2dw.h b/watch-library/driver/lis2dw.h index 7a0e0cbb..22b4484f 100644 --- a/watch-library/driver/lis2dw.h +++ b/watch-library/driver/lis2dw.h @@ -254,4 +254,12 @@ void lis2dw_set_data_rate(lis2dw_data_rate_t dataRate); lis2dw_data_rate_t lis2dw_get_data_rate(void); +void lis2dw_set_low_power_mode(lis2dw_low_power_mode_t mode); + +lis2dw_low_power_mode_t lis2dw_get_low_power_mode(void); + +void lis2dw_set_low_noise_mode(bool on); + +bool lis2dw_get_low_noise_mode(void); + #endif // LIS2DW_H |