Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for LIS3DH without INT1 pin connected #128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion inc/drivers/LIS3DH.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ 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
{
I2C& i2c; // The I2C interface to use.
Pin &int1; // Data ready interrupt.
uint16_t address; // I2C address of this accelerometer.
uint32_t lastUpdate;

public:

Expand Down
19 changes: 17 additions & 2 deletions source/drivers/LIS3DH.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ 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"
#include "LIS3DH.h"
#include "ErrorNo.h"
#include "CodalCompat.h"
#include "CodalFiber.h"
#include "Timer.h"

#define UPDATE_DONE 0x0040

using namespace codal;

Expand Down Expand Up @@ -177,12 +180,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 & UPDATE_DONE))
{
int8_t data[6];
uint8_t src;
int result;

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!)
result = i2c.readRegister(address, 0x80 | LIS3DH_OUT_X_L, (uint8_t *)data, 6);
Expand Down Expand Up @@ -232,6 +238,15 @@ int LIS3DH::requestUpdate()
*/
void LIS3DH::idleCallback()
{
if (!&int1)
{
uint32_t now = codal::system_timer_current_time();
if (!lastUpdate || now - lastUpdate > this->samplePeriod)
{
status &= ~UPDATE_DONE;
lastUpdate = now;
}
}
requestUpdate();
}

Expand Down