Exemple #1
0
enum error_t accelEnableFreefall(void (* event_cb)(void))
{
    if (!event_cb) {
        return ERR_ACCEL_INVALID_ARG;
    }

    m_freefall_event_cb = event_cb;

    /* Enable freefall detect on y; Event latch disable */
    accelWriteReg(ACCEL_REG_FF_MT_CFG, 0x10u);

    /* Enable freefall detect */
    accelWriteReg(ACCEL_REG_CTRL_4, 0x04u);

    /* Freefall interrupt to INT2 pin */
    accelWriteReg(ACCEL_REG_INT_PIN_MAP, 0x04u);

    /* Push pull, active high */
    accelWriteReg(ACCEL_REG_CTRL_3, 0x00u);

    /* Set threshold. Max = 0x7f, which equals 8 G */
    accelWriteReg(ACCEL_REG_FF_MT_THS, 0x13u);

	/* Set freefall debounce timeout */
	accelWriteReg(ACCEL_REG_FF_MT_COUNT, 0X00);

    /* Set ACTIVE bit to wake chip */
    accelWriteReg(ACCEL_REG_CTRL_1, 0x01u);

	/* Interrupt on INT1. Rising edge. */
	EICRA |= _BV(ISC11) | _BV(ISC10);
	EIMSK |= _BV(INT1);

    return ERR_NONE;
}
Exemple #2
0
enum error_t accelDisable(void)
{
    /* Put the accelerometer into standby mode */
    accelWriteReg(ACCEL_REG_CTRL_1, 0x00);

    /* Disable the interrupt */
	EIMSK &= ~_BV(INT1);
    return ERR_NONE;
}
Exemple #3
0
/*
 Initializes the accelerometer and it's I2C channel
 */
void initI2CAccel(Accel *a, I2C_MODULE i2c){
    a->read = 0x3b;                     // read accel device value
    a->write = 0x3a;                    // write accel device value

    a->I2C = i2c;                       // I2C channel for accel device

    I2CSetFrequency(a->I2C,             //100 Hz
                    10*1000*1000, 100);
    I2CEnable(a->I2C, 1);               // turn on
    accelWriteReg(a, 0x2d, 0x8);        // set to measure mode
}