From 02159013093333c5a4fff036ad7e34257d75ba11 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Wed, 25 Nov 2020 18:27:36 +0100 Subject: [PATCH 1/5] Add hack for int-less LIS3DH --- source/drivers/LIS3DH.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/source/drivers/LIS3DH.cpp b/source/drivers/LIS3DH.cpp index fb8eb6aa..ffaaffd7 100644 --- a/source/drivers/LIS3DH.cpp +++ b/source/drivers/LIS3DH.cpp @@ -158,6 +158,8 @@ int LIS3DH::whoAmI() return (int)data; } +#define HAD_IDLE 0x0040 + /** * Reads the acceleration data from the accelerometer, and stores it in our buffer. * This only happens if the accelerometer indicates that it has new data via int1. @@ -177,12 +179,15 @@ int LIS3DH::requestUpdate() status |= DEVICE_COMPONENT_STATUS_IDLE_TICK; // Poll interrupt line from accelerometer. - if(int1.getDigitalValue() == 1) + if((&int1 && int1.getDigitalValue() == 1) || + (status & HAD_IDLE) == 0) { int8_t data[6]; uint8_t src; int result; + status |= HAD_IDLE; + // read the XYZ data (16 bit) // n.b. we need to set the MSB bit to enable multibyte transfers from this device (WHY? Who Knows!) result = i2c.readRegister(address, 0x80 | LIS3DH_OUT_X_L, (uint8_t *)data, 6); @@ -232,6 +237,7 @@ int LIS3DH::requestUpdate() */ void LIS3DH::idleCallback() { + status &= ~HAD_IDLE; requestUpdate(); } From 423fd69c710ed57eadb3ca8e85a9151091d30f13 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 30 Nov 2020 13:59:59 +0100 Subject: [PATCH 2/5] Idle fix --- source/drivers/LIS3DH.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/drivers/LIS3DH.cpp b/source/drivers/LIS3DH.cpp index ffaaffd7..ca929c90 100644 --- a/source/drivers/LIS3DH.cpp +++ b/source/drivers/LIS3DH.cpp @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE. #include "ErrorNo.h" #include "CodalCompat.h" #include "CodalFiber.h" +#include "Timer.h" using namespace codal; @@ -237,7 +238,14 @@ int LIS3DH::requestUpdate() */ void LIS3DH::idleCallback() { - status &= ~HAD_IDLE; + static uint32_t lastTime; + if (!&int1) { + uint32_t now = codal::system_timer_current_time(); + if (!lastTime || now-lastTime>20) { + status &= ~HAD_IDLE; + lastTime = now; + } + } requestUpdate(); } From 34781fdbe940a32d7bab9228e81f8049968a8254 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 30 Nov 2020 14:05:55 +0100 Subject: [PATCH 3/5] Cleanup --- inc/drivers/LIS3DH.h | 3 ++- source/drivers/LIS3DH.cpp | 15 +++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/inc/drivers/LIS3DH.h b/inc/drivers/LIS3DH.h index bf4270ae..cf8c4f09 100644 --- a/inc/drivers/LIS3DH.h +++ b/inc/drivers/LIS3DH.h @@ -84,7 +84,7 @@ namespace codal /** * Class definition for Accelerometer. * - * Represents an implementation of the Freescale MMA8653 3 axis accelerometer + * Represents an implementation of the ST LIS3DH 3 axis accelerometer * Also includes basic data caching and on demand activation. */ class LIS3DH : public Accelerometer @@ -92,6 +92,7 @@ namespace codal I2C& i2c; // The I2C interface to use. Pin &int1; // Data ready interrupt. uint16_t address; // I2C address of this accelerometer. + uint32_t lastUpdate; public: diff --git a/source/drivers/LIS3DH.cpp b/source/drivers/LIS3DH.cpp index ca929c90..b243ed6d 100644 --- a/source/drivers/LIS3DH.cpp +++ b/source/drivers/LIS3DH.cpp @@ -35,6 +35,8 @@ DEALINGS IN THE SOFTWARE. #include "CodalFiber.h" #include "Timer.h" +#define UPDATE_DONE 0x0040 + using namespace codal; // @@ -159,8 +161,6 @@ int LIS3DH::whoAmI() return (int)data; } -#define HAD_IDLE 0x0040 - /** * Reads the acceleration data from the accelerometer, and stores it in our buffer. * This only happens if the accelerometer indicates that it has new data via int1. @@ -181,13 +181,13 @@ int LIS3DH::requestUpdate() // Poll interrupt line from accelerometer. if((&int1 && int1.getDigitalValue() == 1) || - (status & HAD_IDLE) == 0) + !(status & UPDATE_DONE)) { int8_t data[6]; uint8_t src; int result; - status |= HAD_IDLE; + status |= UPDATE_DONE; // read the XYZ data (16 bit) // n.b. we need to set the MSB bit to enable multibyte transfers from this device (WHY? Who Knows!) @@ -238,12 +238,11 @@ int LIS3DH::requestUpdate() */ void LIS3DH::idleCallback() { - static uint32_t lastTime; if (!&int1) { uint32_t now = codal::system_timer_current_time(); - if (!lastTime || now-lastTime>20) { - status &= ~HAD_IDLE; - lastTime = now; + if (!lastUpdate || now - lastUpdate > this->samplePeriod) { + status &= ~UPDATE_DONE; + lastUpdate = now; } } requestUpdate(); From f83b90471ddc560ee97e938823a82e084d7add74 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 30 Nov 2020 14:07:02 +0100 Subject: [PATCH 4/5] Fix comment --- source/drivers/LIS3DH.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/drivers/LIS3DH.cpp b/source/drivers/LIS3DH.cpp index b243ed6d..238ed5ec 100644 --- a/source/drivers/LIS3DH.cpp +++ b/source/drivers/LIS3DH.cpp @@ -25,7 +25,7 @@ DEALINGS IN THE SOFTWARE. /** * Class definition for an LIS3DH 3 axis accelerometer. * - * Represents an implementation of the Freescale LIS3DH 3 axis accelerometer + * Represents an implementation of the ST LIS3DH 3 axis accelerometer * Also includes basic data caching and on demand activation. */ #include "CodalConfig.h" From cb109768ef084dea1cfac92ae390b424fbf68b12 Mon Sep 17 00:00:00 2001 From: Michal Moskal Date: Mon, 30 Nov 2020 14:07:41 +0100 Subject: [PATCH 5/5] Formatting --- source/drivers/LIS3DH.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/drivers/LIS3DH.cpp b/source/drivers/LIS3DH.cpp index 238ed5ec..8f815a6d 100644 --- a/source/drivers/LIS3DH.cpp +++ b/source/drivers/LIS3DH.cpp @@ -238,9 +238,11 @@ int LIS3DH::requestUpdate() */ void LIS3DH::idleCallback() { - if (!&int1) { + if (!&int1) + { uint32_t now = codal::system_timer_current_time(); - if (!lastUpdate || now - lastUpdate > this->samplePeriod) { + if (!lastUpdate || now - lastUpdate > this->samplePeriod) + { status &= ~UPDATE_DONE; lastUpdate = now; }