accelrometer: add tap event, test by adding tap to set countdown
This commit is contained in:
@@ -253,6 +253,24 @@ void lis2dw_configure_6d_threshold(uint8_t threshold) {
|
||||
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_TAP_THS_X, configuration | ((threshold & 0b11) << 5));
|
||||
}
|
||||
|
||||
void lis2dw_configure_tap_threshold(uint8_t threshold_x, uint8_t threshold_y, uint8_t threshold_z, uint8_t axes_to_enable) {
|
||||
uint8_t configuration;
|
||||
// if (axes_to_enable & LIS2DW_REG_TAP_THS_Z_X_AXIS_ENABLE); // X axis tap not implemented
|
||||
// if (axes_to_enable & LIS2DW_REG_TAP_THS_Z_Y_AXIS_ENABLE); // Y axis tap not implemented
|
||||
// tap enable bitmask is the high bits of LIS2DW_REG_TAP_THS_Z
|
||||
configuration = axes_to_enable & 0b00100000; // NOTE: should be 0b11100000 to allow use of all three axes, but we're not using X or Y.
|
||||
if (axes_to_enable & LIS2DW_REG_TAP_THS_Z_Z_AXIS_ENABLE) {
|
||||
// mask out high bits if set
|
||||
configuration |= (threshold_z & 0b00011111);
|
||||
}
|
||||
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_TAP_THS_Z, configuration);
|
||||
}
|
||||
|
||||
void lis2dw_configure_tap_duration(uint8_t latency, uint8_t quiet, uint8_t shock) {
|
||||
uint8_t configuration = (latency << 4) | ((quiet & 0b11) << 2) | (shock & 0b11);
|
||||
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_INT1_DUR, configuration);
|
||||
}
|
||||
|
||||
void lis2dw_configure_int1(uint8_t sources) {
|
||||
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1, sources);
|
||||
}
|
||||
|
||||
@@ -227,8 +227,14 @@ typedef enum {
|
||||
#define LIS2DW_FIFO_SAMPLE_COUNT (0b00111111)
|
||||
|
||||
#define LIS2DW_REG_TAP_THS_X 0x30
|
||||
|
||||
#define LIS2DW_REG_TAP_THS_Y 0x31
|
||||
|
||||
#define LIS2DW_REG_TAP_THS_Z 0x32
|
||||
#define LIS2DW_REG_TAP_THS_Z_X_AXIS_ENABLE 0b10000000
|
||||
#define LIS2DW_REG_TAP_THS_Z_Y_AXIS_ENABLE 0b01000000
|
||||
#define LIS2DW_REG_TAP_THS_Z_Z_AXIS_ENABLE 0b00100000
|
||||
|
||||
#define LIS2DW_REG_INT1_DUR 0x33
|
||||
|
||||
#define LIS2DW_REG_WAKE_UP_THS 0x34
|
||||
@@ -353,6 +359,10 @@ void lis2dw_configure_wakeup_threshold(uint8_t threshold);
|
||||
|
||||
void lis2dw_configure_6d_threshold(uint8_t threshold);
|
||||
|
||||
void lis2dw_configure_tap_threshold(uint8_t threshold_x, uint8_t threshold_y, uint8_t threshold_z, uint8_t axes_to_enable);
|
||||
|
||||
void lis2dw_configure_tap_duration(uint8_t latency, uint8_t quiet, uint8_t shock);
|
||||
|
||||
void lis2dw_configure_int1(uint8_t sources);
|
||||
|
||||
void lis2dw_configure_int2(uint8_t sources);
|
||||
|
||||
Reference in New Issue
Block a user