2010-11-07 08:38:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
2016-02-22 10:24:50 +00:00
|
|
|
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
2010-11-07 08:38:51 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the Institute nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the Contiki operating system.
|
|
|
|
*
|
|
|
|
*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-07 08:38:51 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Device drivers for adxl345 accelerometer in Zolertia Z1.
|
|
|
|
* \author
|
|
|
|
* Marcus Lundén, SICS <mlunden@sics.se>
|
|
|
|
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
2016-02-22 10:24:50 +00:00
|
|
|
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
2010-11-07 08:38:51 +00:00
|
|
|
*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-07 08:38:51 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "contiki.h"
|
|
|
|
#include "adxl345.h"
|
2011-03-16 12:56:29 +00:00
|
|
|
#include "cc2420.h"
|
2010-11-07 08:38:51 +00:00
|
|
|
#include "i2cmaster.h"
|
2012-03-07 00:14:54 +00:00
|
|
|
#include "isr_compat.h"
|
2016-02-22 11:06:38 +00:00
|
|
|
#include "lib/sensors.h"
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
#define DEBUG 0
|
|
|
|
#if DEBUG
|
|
|
|
#define PRINTF(...) printf(__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define PRINTF(...)
|
|
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static uint8_t enabled;
|
2016-02-22 10:24:50 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-07 08:38:51 +00:00
|
|
|
/* Callback pointers when interrupt occurs */
|
2012-02-20 19:32:05 +00:00
|
|
|
void (*accm_int1_cb)(uint8_t reg);
|
|
|
|
void (*accm_int2_cb)(uint8_t reg);
|
2016-02-22 10:24:50 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
2010-11-07 08:38:51 +00:00
|
|
|
/* Bitmasks for the interrupts */
|
|
|
|
static uint16_t int1_mask = 0, int2_mask = 0;
|
|
|
|
|
2016-02-22 10:24:50 +00:00
|
|
|
/* Default values for adxl345 at startup.
|
|
|
|
* This will be sent to the adxl345 in a
|
|
|
|
* stream at init to set it up in a default state
|
|
|
|
*/
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
static uint8_t adxl345_default_settings[] = {
|
|
|
|
/* Note, as the two first two bulks are to be written in a stream, they contain
|
2016-02-22 10:24:50 +00:00
|
|
|
* the register address as first byte in that section.
|
|
|
|
* 0--14 are in one stream, start at ADXL345_THRESH_TAP
|
|
|
|
*/
|
|
|
|
/* XXX NB Register address, not register value!! */
|
|
|
|
ADXL345_THRESH_TAP,
|
2010-11-07 08:38:51 +00:00
|
|
|
ADXL345_THRESH_TAP_DEFAULT,
|
|
|
|
ADXL345_OFSX_DEFAULT,
|
|
|
|
ADXL345_OFSY_DEFAULT,
|
|
|
|
ADXL345_OFSZ_DEFAULT,
|
|
|
|
ADXL345_DUR_DEFAULT,
|
|
|
|
ADXL345_LATENT_DEFAULT,
|
|
|
|
ADXL345_WINDOW_DEFAULT,
|
|
|
|
ADXL345_THRESH_ACT_DEFAULT,
|
|
|
|
ADXL345_THRESH_INACT_DEFAULT,
|
|
|
|
ADXL345_TIME_INACT_DEFAULT,
|
|
|
|
ADXL345_ACT_INACT_CTL_DEFAULT,
|
|
|
|
ADXL345_THRESH_FF_DEFAULT,
|
|
|
|
ADXL345_TIME_FF_DEFAULT,
|
|
|
|
ADXL345_TAP_AXES_DEFAULT,
|
|
|
|
|
|
|
|
/* 15--19 start at ADXL345_BW_RATE */
|
2016-02-22 10:24:50 +00:00
|
|
|
/* XXX NB Register address, not register value!! */
|
|
|
|
ADXL345_BW_RATE,
|
2010-11-07 08:38:51 +00:00
|
|
|
ADXL345_BW_RATE_DEFAULT,
|
|
|
|
ADXL345_POWER_CTL_DEFAULT,
|
|
|
|
ADXL345_INT_ENABLE_DEFAULT,
|
|
|
|
ADXL345_INT_MAP_DEFAULT,
|
|
|
|
|
|
|
|
/* These two: 20, 21 write separately */
|
|
|
|
ADXL345_DATA_FORMAT_DEFAULT,
|
|
|
|
ADXL345_FIFO_CTL_DEFAULT
|
|
|
|
};
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
PROCESS(accmeter_process, "Accelerometer process");
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
static void
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_write_reg(uint8_t reg, uint8_t val)
|
|
|
|
{
|
2012-02-20 19:32:05 +00:00
|
|
|
uint8_t tx_buf[] = {reg, val};
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
i2c_transmitinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: I2C Ready to TX\n");
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
i2c_transmit_n(2, tx_buf);
|
|
|
|
while (i2c_busy());
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/* First byte in stream must be the register address to begin writing to.
|
|
|
|
* The data is then written from second byte and increasing.
|
|
|
|
*/
|
|
|
|
static void
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_write_stream(uint8_t len, uint8_t *data)
|
|
|
|
{
|
2010-11-07 08:38:51 +00:00
|
|
|
i2c_transmitinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: I2C Ready to TX(stream)\n");
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
i2c_transmit_n(len, data); // start tx and send conf reg
|
|
|
|
while (i2c_busy());
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: WRITE_STR %u B to 0x%02X\n", len, data[0]);
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
static uint8_t
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_read_reg(uint8_t reg)
|
|
|
|
{
|
2012-02-20 19:32:05 +00:00
|
|
|
uint8_t retVal = 0;
|
|
|
|
uint8_t rtx = reg;
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: READ_REG 0x%02X\n", reg);
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
/* transmit the register to read */
|
|
|
|
i2c_transmitinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
|
|
|
i2c_transmit_n(1, &rtx);
|
|
|
|
while (i2c_busy());
|
|
|
|
|
|
|
|
/* receive the data */
|
|
|
|
i2c_receiveinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
|
|
|
i2c_receive_n(1, &retVal);
|
|
|
|
while (i2c_busy());
|
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
static void
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
|
|
|
|
{
|
2012-02-20 19:32:05 +00:00
|
|
|
uint8_t rtx = reg;
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: READ_STR %u B from 0x%02X\n", len, reg);
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
/* transmit the register to start reading from */
|
|
|
|
i2c_transmitinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
|
|
|
i2c_transmit_n(1, &rtx);
|
|
|
|
while (i2c_busy());
|
|
|
|
|
|
|
|
/* receive the data */
|
|
|
|
i2c_receiveinit(ADXL345_ADDR);
|
|
|
|
while (i2c_busy());
|
|
|
|
i2c_receive_n(len, whereto);
|
|
|
|
while (i2c_busy());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/* Read an axis of the accelerometer (x, y or z). Return value is a signed
|
|
|
|
* 10 bit int.
|
|
|
|
* The resolution of the acceleration measurement can be increased up to 13 bit,
|
|
|
|
* but will change the data format of this read out. Refer to the data sheet if
|
|
|
|
* so is wanted/needed.
|
|
|
|
*/
|
2010-11-07 08:38:51 +00:00
|
|
|
int16_t
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_read_axis(enum ADXL345_AXIS axis)
|
|
|
|
{
|
2010-11-07 08:38:51 +00:00
|
|
|
int16_t rd = 0;
|
2012-02-20 19:32:05 +00:00
|
|
|
uint8_t tmp[2];
|
2010-11-07 08:38:51 +00:00
|
|
|
if(axis > Z_AXIS){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
accm_read_stream(ADXL345_DATAX0 + axis, 2, &tmp[0]);
|
|
|
|
rd = (int16_t)(tmp[0] | (tmp[1]<<8));
|
|
|
|
return rd;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 11:06:38 +00:00
|
|
|
int
|
|
|
|
accm_set_grange(uint8_t grange)
|
|
|
|
{
|
|
|
|
uint8_t tempreg = 0;
|
|
|
|
|
2010-11-07 08:38:51 +00:00
|
|
|
if(grange > ADXL345_RANGE_16G) {
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: grange invalid: %u\n", grange);
|
|
|
|
return ADXL345_ERROR;
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
2016-02-22 10:24:50 +00:00
|
|
|
|
2016-02-22 11:06:38 +00:00
|
|
|
if(!enabled) {
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
2010-11-07 08:38:51 +00:00
|
|
|
|
2016-02-22 10:24:50 +00:00
|
|
|
/* Keep the previous contents of the register, zero out the last two bits */
|
|
|
|
tempreg = (accm_read_reg(ADXL345_DATA_FORMAT) & 0xFC);
|
|
|
|
tempreg |= grange;
|
2010-11-07 08:38:51 +00:00
|
|
|
accm_write_reg(ADXL345_DATA_FORMAT, tempreg);
|
2016-02-22 11:06:38 +00:00
|
|
|
return ADXL345_SUCCESS;
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_init(void)
|
|
|
|
{
|
|
|
|
PRINTF("ADXL345: init\n");
|
2016-02-22 10:24:50 +00:00
|
|
|
accm_int1_cb = NULL;
|
|
|
|
accm_int2_cb = NULL;
|
|
|
|
|
|
|
|
/* Set up ports and pins for interrups. */
|
|
|
|
ADXL345_DIR &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
ADXL345_SEL &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
ADXL345_SEL2 &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
|
|
|
|
/* Set up ports and pins for I2C communication */
|
|
|
|
i2c_enable();
|
|
|
|
|
|
|
|
/* set default register values. */
|
|
|
|
accm_write_stream(15, &adxl345_default_settings[0]);
|
|
|
|
accm_write_stream(5, &adxl345_default_settings[15]);
|
|
|
|
accm_write_reg(ADXL345_DATA_FORMAT, adxl345_default_settings[20]);
|
|
|
|
accm_write_reg(ADXL345_FIFO_CTL, adxl345_default_settings[21]);
|
|
|
|
|
|
|
|
process_start(&accmeter_process, NULL);
|
|
|
|
|
|
|
|
/* Enable msp430 interrupts on the two interrupt pins. */
|
|
|
|
dint();
|
|
|
|
/* low to high transition interrupts */
|
|
|
|
ADXL345_IES &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
/* enable interrupts */
|
|
|
|
ADXL345_IE |= (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
eint();
|
2010-11-07 08:38:51 +00:00
|
|
|
|
2016-02-22 11:06:38 +00:00
|
|
|
enabled = 1;
|
|
|
|
}
|
2010-11-07 08:38:51 +00:00
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
void
|
2016-02-22 11:06:38 +00:00
|
|
|
accm_stop(void)
|
|
|
|
{
|
|
|
|
dint();
|
|
|
|
ADXL345_IE &= ~(ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
|
|
|
accm_write_reg(ADXL345_INT_ENABLE, ~(int1_mask | int2_mask));
|
|
|
|
accm_write_reg(ADXL345_INT_MAP, ~int2_mask);
|
|
|
|
eint();
|
|
|
|
enabled = 0;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
int
|
|
|
|
accm_set_irq(uint8_t int1, uint8_t int2)
|
|
|
|
{
|
|
|
|
if(!enabled) {
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-11-07 08:38:51 +00:00
|
|
|
/* Set the corresponding interrupt mapping to INT1 or INT2 */
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: IRQs set to INT1: 0x%02X IRQ2: 0x%02X\n", int1, int2);
|
2010-11-07 08:38:51 +00:00
|
|
|
|
|
|
|
int1_mask = int1;
|
|
|
|
int2_mask = int2;
|
|
|
|
|
|
|
|
accm_write_reg(ADXL345_INT_ENABLE, (int1 | int2));
|
2016-02-22 11:06:38 +00:00
|
|
|
/* int1 bits are zeroes in the map register so this is for both ints */
|
|
|
|
accm_write_reg(ADXL345_INT_MAP, int2);
|
|
|
|
return ADXL345_SUCCESS;
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/* Invoked after an interrupt happened. Reads the interrupt source reg at the
|
2016-02-22 10:24:50 +00:00
|
|
|
* accelerometer, which resets the interrupts, and invokes the corresponding
|
|
|
|
* callback. It passes the source register value so the callback can determine
|
|
|
|
* what interrupt happened, if several interrupts are mapped to the same pin.
|
|
|
|
*/
|
2010-11-07 08:38:51 +00:00
|
|
|
static void
|
2016-02-22 11:06:38 +00:00
|
|
|
poll_handler(void)
|
|
|
|
{
|
2010-11-07 08:38:51 +00:00
|
|
|
uint8_t ireg = 0;
|
|
|
|
ireg = accm_read_reg(ADXL345_INT_SOURCE);
|
|
|
|
|
|
|
|
/* Invoke callbacks for the corresponding interrupts */
|
|
|
|
if(ireg & int1_mask){
|
|
|
|
if(accm_int1_cb != NULL){
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: INT1 cb invoked\n");
|
2010-11-07 08:38:51 +00:00
|
|
|
accm_int1_cb(ireg);
|
|
|
|
}
|
|
|
|
} else if(ireg & int2_mask){
|
|
|
|
if(accm_int2_cb != NULL){
|
2016-02-22 11:06:38 +00:00
|
|
|
PRINTF("ADXL345: INT2 cb invoked\n");
|
2010-11-07 08:38:51 +00:00
|
|
|
accm_int2_cb(ireg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/* This process is sleeping until an interrupt from the accelerometer occurs,
|
|
|
|
* which polls this process from the interrupt service routine. */
|
2016-02-22 11:06:38 +00:00
|
|
|
PROCESS_THREAD(accmeter_process, ev, data)
|
|
|
|
{
|
2010-11-07 08:38:51 +00:00
|
|
|
PROCESS_POLLHANDLER(poll_handler());
|
|
|
|
PROCESS_EXITHANDLER();
|
|
|
|
PROCESS_BEGIN();
|
|
|
|
while(1){
|
2016-02-22 10:24:50 +00:00
|
|
|
PROCESS_WAIT_EVENT_UNTIL(0);
|
2010-11-07 08:38:51 +00:00
|
|
|
}
|
|
|
|
PROCESS_END();
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 10:24:50 +00:00
|
|
|
/* This interrupt vector is shared with the interrupts from CC2420, so that
|
|
|
|
* was moved here
|
|
|
|
*/
|
2010-11-07 08:38:51 +00:00
|
|
|
static struct timer suppressTimer1, suppressTimer2;
|
|
|
|
|
2012-03-07 00:14:54 +00:00
|
|
|
ISR(PORT1, port1_isr)
|
|
|
|
{
|
2010-11-07 08:38:51 +00:00
|
|
|
ENERGEST_ON(ENERGEST_TYPE_IRQ);
|
2016-02-22 10:24:50 +00:00
|
|
|
|
|
|
|
/* ADXL345_IFG.x goes high when interrupt occurs, use to check what
|
|
|
|
* interrupted
|
|
|
|
*/
|
|
|
|
if((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
2010-11-07 08:38:51 +00:00
|
|
|
/* Check if this should be suppressed or not */
|
|
|
|
if(timer_expired(&suppressTimer1)) {
|
|
|
|
timer_set(&suppressTimer1, SUPPRESS_TIME_INT1);
|
|
|
|
ADXL345_IFG &= ~ADXL345_INT1_PIN; // clear interrupt flag
|
|
|
|
process_poll(&accmeter_process);
|
|
|
|
LPM4_EXIT;
|
|
|
|
}
|
2016-02-22 10:24:50 +00:00
|
|
|
} else if((ADXL345_IFG & ADXL345_INT2_PIN) &&
|
|
|
|
!(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
2010-11-07 08:38:51 +00:00
|
|
|
/* Check if this should be suppressed or not */
|
|
|
|
if(timer_expired(&suppressTimer2)) {
|
|
|
|
timer_set(&suppressTimer2, SUPPRESS_TIME_INT2);
|
2016-02-22 10:24:50 +00:00
|
|
|
/* clear interrupt flag */
|
|
|
|
ADXL345_IFG &= ~ADXL345_INT2_PIN;
|
2010-11-07 08:38:51 +00:00
|
|
|
process_poll(&accmeter_process);
|
|
|
|
LPM4_EXIT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* CC2420 interrupt */
|
|
|
|
if(cc2420_interrupt()) {
|
|
|
|
LPM4_EXIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
2016-02-22 11:06:38 +00:00
|
|
|
static int
|
|
|
|
configure(int type, int value)
|
|
|
|
{
|
|
|
|
if(type != SENSORS_ACTIVE) {
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(value) {
|
|
|
|
accm_init();
|
|
|
|
} else {
|
|
|
|
accm_stop();
|
|
|
|
}
|
|
|
|
enabled = value;
|
|
|
|
return ADXL345_SUCCESS;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
status(int type)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case SENSORS_ACTIVE:
|
|
|
|
case SENSORS_READY:
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
return ADXL345_SUCCESS;
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
static int
|
|
|
|
value(int type)
|
|
|
|
{
|
|
|
|
if(!enabled) {
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((type != X_AXIS) && (type != Y_AXIS) && (type != Z_AXIS)) {
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case X_AXIS:
|
|
|
|
return accm_read_axis(X_AXIS);
|
|
|
|
case Y_AXIS:
|
|
|
|
return accm_read_axis(Y_AXIS);
|
|
|
|
case Z_AXIS:
|
|
|
|
return accm_read_axis(Z_AXIS);
|
|
|
|
default:
|
|
|
|
return ADXL345_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
SENSORS_SENSOR(adxl345, ADXL345_SENSOR, value, configure, status);
|
|
|
|
/*---------------------------------------------------------------------------*/
|