lis2dw: add low power / low noise mode

This commit is contained in:
Joey Castillo 2022-01-09 12:25:56 -05:00
parent a102675522
commit 68e792f9b7
2 changed files with 30 additions and 0 deletions

View file

@ -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;
}

View file

@ -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