Skip to content

Commit

Permalink
rearrange LIS2DW functions in data sheet order
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 9, 2024
1 parent e966131 commit d9bee40
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
76 changes: 38 additions & 38 deletions watch-library/shared/driver/lis2dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,6 @@ uint16_t lis2dw_get_temperature(void) {
return watch_i2c_read16(LIS2DW_ADDRESS, LIS2DW_REG_OUT_TEMP_L);
}

void lis2dw_set_range(lis2dw_range_t range) {
uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & ~(LIS2DW_RANGE_16_G << 4);
uint8_t bits = range << 4;

watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6, val | bits);
}

lis2dw_range_t lis2dw_get_range(void) {
uint8_t retval = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & (LIS2DW_RANGE_16_G << 4);
retval >>= 4;
return (lis2dw_range_t)retval;
}

void lis2dw_set_data_rate(lis2dw_data_rate_t dataRate) {
uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & ~(0b1111 << 4);
uint8_t bits = dataRate << 4;
Expand All @@ -125,16 +112,26 @@ 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);
void lis2dw_set_mode(lis2dw_mode_t mode) {
uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & ~(0b1100);
uint8_t bits = (mode << 2) & 0b1100;

watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, 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;
lis2dw_mode_t lis2dw_get_mode(void) {
return (lis2dw_mode_t)(watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & 0b1100) >> 2;
}

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_bandwidth_filtering(lis2dw_bandwidth_filtering_mode_t bwfilter) {
Expand All @@ -149,26 +146,29 @@ lis2dw_bandwidth_filtering_mode_t lis2dw_get_bandwidth_filtering(void) {
return (lis2dw_bandwidth_filtering_mode_t)retval;
}

void lis2dw_set_mode(lis2dw_mode_t mode) {
uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & ~(0b1100);
uint8_t bits = (mode << 2) & 0b1100;
void lis2dw_set_range(lis2dw_range_t range) {
uint8_t val = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & ~(LIS2DW_RANGE_16_G << 4);
uint8_t bits = range << 4;

watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, val | bits);
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6, val | bits);
}

lis2dw_mode_t lis2dw_get_mode(void) {
return (lis2dw_mode_t)(watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & 0b1100) >> 2;
lis2dw_range_t lis2dw_get_range(void) {
uint8_t retval = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL6) & (LIS2DW_RANGE_16_G << 4);
retval >>= 4;
return (lis2dw_range_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;

watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1, val | bits);
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_low_power_mode_t lis2dw_get_low_power_mode(void) {
return watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & 0b11;
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_low_noise_mode(bool on) {
Expand All @@ -182,14 +182,14 @@ bool lis2dw_get_low_noise_mode(void) {
return (watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL1) & LIS2DW_CTRL6_VAL_LOW_NOISE) != 0;
}

inline void lis2dw_disable_fifo(void) {
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_CTRL, LIS2DW_FIFO_CTRL_MODE_OFF);
}

inline void lis2dw_enable_fifo(void) {
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_CTRL, LIS2DW_FIFO_CTRL_MODE_COLLECT_AND_STOP | LIS2DW_FIFO_CTRL_FTH);
}

inline void lis2dw_disable_fifo(void) {
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_CTRL, LIS2DW_FIFO_CTRL_MODE_OFF);
}

bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data) {
uint8_t temp = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_SAMPLE);
bool overrun = !!(temp & LIS2DW_FIFO_SAMPLE_OVERRUN);
Expand Down
24 changes: 12 additions & 12 deletions watch-library/shared/driver/lis2dw.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,38 +299,38 @@ lis2dw_acceleration_measurement_t lis2dw_get_acceleration_measurement(lis2dw_rea

uint16_t lis2dw_get_temperature(void);

void lis2dw_set_range(lis2dw_range_t range);

lis2dw_range_t lis2dw_get_range(void);

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);
void lis2dw_set_mode(lis2dw_mode_t mode);

lis2dw_filter_t lis2dw_get_filter_type(void);
lis2dw_mode_t lis2dw_get_mode(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_bandwidth_filtering(lis2dw_bandwidth_filtering_mode_t bwfilter);

lis2dw_bandwidth_filtering_mode_t lis2dw_get_bandwidth_filtering(void);

void lis2dw_set_mode(lis2dw_mode_t mode);
void lis2dw_set_range(lis2dw_range_t range);

lis2dw_mode_t lis2dw_get_mode(void);
lis2dw_range_t lis2dw_get_range(void);

void lis2dw_set_low_power_mode(lis2dw_low_power_mode_t mode);
void lis2dw_set_filter_type(lis2dw_filter_t filter);

lis2dw_low_power_mode_t lis2dw_get_low_power_mode(void);
lis2dw_filter_t lis2dw_get_filter_type(void);

void lis2dw_set_low_noise_mode(bool on);

bool lis2dw_get_low_noise_mode(void);

void lis2dw_disable_fifo(void);

void lis2dw_enable_fifo(void);

void lis2dw_disable_fifo(void);

bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data);

void lis2dw_clear_fifo(void);
Expand Down

0 comments on commit d9bee40

Please sign in to comment.