mirror of
https://github.com/firewalkwithm3/Sensor-Watch.git
synced 2024-11-22 19:20:30 +08:00
lis2dw: add low power / low noise mode
This commit is contained in:
parent
a102675522
commit
68e792f9b7
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue