From 4ae46f907b2c6f54f87c350920d7f297967764fe Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Tue, 30 Nov 2021 18:53:43 -0500 Subject: lis2dh driver: add basic interrupt functionality --- watch-library/driver/lis2dh.c | 11 +++++++++++ watch-library/driver/lis2dh.h | 27 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'watch-library') diff --git a/watch-library/driver/lis2dh.c b/watch-library/driver/lis2dh.c index 2593fc69..2ebf53fb 100644 --- a/watch-library/driver/lis2dh.c +++ b/watch-library/driver/lis2dh.c @@ -114,3 +114,14 @@ void lis2dh_set_data_rate(lis2dh_data_rate_t dataRate) { lis2dh_data_rate_t lis2dh_get_data_rate() { return watch_i2c_read8(LIS2DH_ADDRESS, LIS2DH_REG_CTRL1) >> 4; } + +void lis2dh_configure_aoi_int1(lis2dh_interrupt_configuration configuration, uint8_t threshold, uint8_t duration) { + watch_i2c_write8(LIS2DH_ADDRESS, LIS2DH_REG_CTRL3, LIS2DH_CTRL3_VAL_I1_AOI1); + watch_i2c_write8(LIS2DH_ADDRESS, LIS2DH_REG_INT1_CFG, configuration); + watch_i2c_write8(LIS2DH_ADDRESS, LIS2DH_REG_INT1_THS, threshold); + watch_i2c_write8(LIS2DH_ADDRESS, LIS2DH_REG_INT1_DUR, duration); +} + +lis2dh_interrupt_state lis2dh_get_int1_state() { + return (lis2dh_interrupt_state) watch_i2c_read8(LIS2DH_ADDRESS, LIS2DH_REG_INT1_SRC); +} diff --git a/watch-library/driver/lis2dh.h b/watch-library/driver/lis2dh.h index 57ea85ee..b8162a4c 100644 --- a/watch-library/driver/lis2dh.h +++ b/watch-library/driver/lis2dh.h @@ -61,6 +61,29 @@ typedef enum { } lis2dh_data_rate_t; +typedef enum { + LIS2DH_INTERRUPT_CONFIGURATION_OR = 0b00000000, + LIS2DH_INTERRUPT_CONFIGURATION_AND = 0b10000000, + LIS2DH_INTERRUPT_CONFIGURATION_6D_MOVEMENT = 0b01000000, + LIS2DH_INTERRUPT_CONFIGURATION_6D_POSITION = 0b11000000, // in 6D mode, these have an alternate meaning: + LIS2DH_INTERRUPT_CONFIGURATION_Z_HIGH_ENABLE = 0b00100000, // Z up enable + LIS2DH_INTERRUPT_CONFIGURATION_Z_LOW_ENABLE = 0b00010000, // Z down enable + LIS2DH_INTERRUPT_CONFIGURATION_Y_HIGH_ENABLE = 0b00001000, // Y up enable + LIS2DH_INTERRUPT_CONFIGURATION_Y_LOW_ENABLE = 0b00000100, // Y down enable + LIS2DH_INTERRUPT_CONFIGURATION_X_HIGH_ENABLE = 0b00000010, // X up enable + LIS2DH_INTERRUPT_CONFIGURATION_X_LOW_ENABLE = 0b00000001, // X down enable +} lis2dh_interrupt_configuration; + +typedef enum { + LIS2DH_INTERRUPT_STATE_ACTIVE = 0b01000000, + LIS2DH_INTERRUPT_STATE_Z_HIGH = 0b00100000, // Z up + LIS2DH_INTERRUPT_STATE_Z_LOW = 0b00010000, // Z down + LIS2DH_INTERRUPT_STATE_Y_HIGH = 0b00001000, // Y up + LIS2DH_INTERRUPT_STATE_Y_LOW = 0b00000100, // Y down + LIS2DH_INTERRUPT_STATE_X_HIGH = 0b00000010, // X up + LIS2DH_INTERRUPT_STATE_X_LOW = 0b00000001, // X down +} lis2dh_interrupt_state; + bool lis2dh_begin(); uint8_t lis2dh_get_device_id(); @@ -79,6 +102,10 @@ void lis2dh_set_data_rate(lis2dh_data_rate_t dataRate); lis2dh_data_rate_t lis2dh_get_data_rate(); +void lis2dh_configure_aoi_int1(lis2dh_interrupt_configuration configuration, uint8_t threshold, uint8_t duration); + +lis2dh_interrupt_state lis2dh_get_int1_state(); + // Assumes SA0 is high; if low, its 0x18 #define LIS2DH_ADDRESS (0x19) -- cgit v1.2.3