diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-02-19 12:53:42 -0500 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-02-19 12:53:42 -0500 |
commit | b1bec8f18740486383ce3c8dfcf1b697f00a67f6 (patch) | |
tree | 9900d2327957accd9754ff9e1701082e2ffa7332 /watch-library | |
parent | efde4190f1c1d989530d1bd555739dffa1664da5 (diff) | |
download | Sensor-Watch-b1bec8f18740486383ce3c8dfcf1b697f00a67f6.tar.gz Sensor-Watch-b1bec8f18740486383ce3c8dfcf1b697f00a67f6.tar.bz2 Sensor-Watch-b1bec8f18740486383ce3c8dfcf1b697f00a67f6.zip |
lis2dw: add support for bandwidth filtering
Diffstat (limited to 'watch-library')
-rw-r--r-- | watch-library/shared/driver/lis2dw.c | 24 | ||||
-rw-r--r-- | watch-library/shared/driver/lis2dw.h | 16 |
2 files changed, 39 insertions, 1 deletions
diff --git a/watch-library/shared/driver/lis2dw.c b/watch-library/shared/driver/lis2dw.c index b2c93d85..1b1ecf11 100644 --- a/watch-library/shared/driver/lis2dw.c +++ b/watch-library/shared/driver/lis2dw.c @@ -115,6 +115,30 @@ lis2dw_data_rate_t lis2dw_get_data_rate(void) { return watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) >> 4; } +void lis2dw_set_filter_type(lis2dw_filter_t bwfilter) { + uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & ~(LIS2DW_CTRL6_VAL_FDS_HIGH); + uint8_t bits = bwfilter << 3; + watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6, val | bits); +} + +lis2dw_filter_t lis2dw_get_filter_type(void) { + uint8_t retval = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & (LIS2DW_CTRL6_VAL_FDS_HIGH); + retval >>= 3; + return (lis2dw_filter_t)retval; +} + +void lis2dw_set_bandwidth_filtering(lis2dw_bandwidth_filtering_mode_t bwfilter) { + uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & ~(LIS2DW_CTRL6_VAL_BANDWIDTH_DIV20); + uint8_t bits = bwfilter << 6; + watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6, val | bits); +} + +lis2dw_bandwidth_filtering_mode_t lis2dw_get_filtering(void) { + uint8_t retval = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & (LIS2DW_CTRL6_VAL_BANDWIDTH_DIV20); + retval >>= 6; + return (lis2dw_bandwidth_filtering_mode_t)retval; +} + 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; diff --git a/watch-library/shared/driver/lis2dw.h b/watch-library/shared/driver/lis2dw.h index 41611172..83b0cfb1 100644 --- a/watch-library/shared/driver/lis2dw.h +++ b/watch-library/shared/driver/lis2dw.h @@ -88,6 +88,11 @@ typedef enum { } lis2dw_bandwidth_filtering_mode_t; typedef enum { + LIS2DW_FILTER_LOW_PASS = 0, + LIS2DW_FILTER_HIGH_PASS = 1, +} lis2dw_filter_t; + +typedef enum { LIS2DW_RANGE_16_G = 0b11, // +/- 16g LIS2DW_RANGE_8_G = 0b10, // +/- 8g LIS2DW_RANGE_4_G = 0b01, // +/- 4g @@ -167,7 +172,8 @@ typedef enum { #define LIS2DW_CTRL6_VAL_RANGE_4G (LIS2DW_RANGE_4_G << 4) #define LIS2DW_CTRL6_VAL_RANGE_8G (LIS2DW_RANGE_8_G << 4) #define LIS2DW_CTRL6_VAL_RANGE_16G (LIS2DW_RANGE_16_G << 4) -#define LIS2DW_CTRL6_VAL_FDS 0b00001000 +#define LIS2DW_CTRL6_VAL_FDS_LOW (LIS2DW_FILTER_LOW_PASS << 3) +#define LIS2DW_CTRL6_VAL_FDS_HIGH (LIS2DW_FILTER_HIGH_PASS << 3) #define LIS2DW_CTRL6_VAL_LOW_NOISE 0b00000100 #define LIS2DW_REG_OUT_TEMP 0x26 @@ -277,6 +283,14 @@ void lis2dw_set_data_rate(lis2dw_data_rate_t dataRate); lis2dw_data_rate_t lis2dw_get_data_rate(void); +void lis2dw_set_filter_type(lis2dw_filter_t filter); + +lis2dw_filter_t lis2dw_get_filter_type(void); + +void lis2dw_set_bandwidth_filtering(lis2dw_bandwidth_filtering_mode_t bwfilter); + +lis2dw_bandwidth_filtering_mode_t lis2dw_get_filtering(void); + void lis2dw_set_low_power_mode(lis2dw_low_power_mode_t mode); lis2dw_low_power_mode_t lis2dw_get_low_power_mode(void); |