48#include "isr_compat.h"
49#include "lib/sensors.h"
53#define PRINTF(...) printf(__VA_ARGS__)
58static uint8_t enabled;
61void (*accm_int1_cb)(uint8_t reg);
62void (*accm_int2_cb)(uint8_t reg);
65static uint16_t int1_mask = 0, int2_mask = 0;
72static uint8_t adxl345_default_settings[] = {
79 ADXL345_THRESH_TAP_DEFAULT,
84 ADXL345_LATENT_DEFAULT,
85 ADXL345_WINDOW_DEFAULT,
86 ADXL345_THRESH_ACT_DEFAULT,
87 ADXL345_THRESH_INACT_DEFAULT,
88 ADXL345_TIME_INACT_DEFAULT,
89 ADXL345_ACT_INACT_CTL_DEFAULT,
90 ADXL345_THRESH_FF_DEFAULT,
91 ADXL345_TIME_FF_DEFAULT,
92 ADXL345_TAP_AXES_DEFAULT,
97 ADXL345_BW_RATE_DEFAULT,
98 ADXL345_POWER_CTL_DEFAULT,
99 ADXL345_INT_ENABLE_DEFAULT,
100 ADXL345_INT_MAP_DEFAULT,
103 ADXL345_DATA_FORMAT_DEFAULT,
104 ADXL345_FIFO_CTL_DEFAULT
107PROCESS(accmeter_process,
"Accelerometer process");
110accm_write_reg(uint8_t reg, uint8_t val)
112 uint8_t tx_buf[] = {reg, val};
114 i2c_transmitinit(ADXL345_ADDR);
116 PRINTF(
"ADXL345: I2C Ready to TX\n");
118 i2c_transmit_n(2, tx_buf);
120 PRINTF(
"ADXL345: WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
127accm_write_stream(uint8_t len, uint8_t *data)
129 i2c_transmitinit(ADXL345_ADDR);
131 PRINTF(
"ADXL345: I2C Ready to TX(stream)\n");
133 i2c_transmit_n(len, data);
135 PRINTF(
"ADXL345: WRITE_STR %u B to 0x%02X\n", len, data[0]);
140accm_read_reg(uint8_t reg)
144 PRINTF(
"ADXL345: READ_REG 0x%02X\n", reg);
147 i2c_transmitinit(ADXL345_ADDR);
149 i2c_transmit_n(1, &rtx);
153 i2c_receiveinit(ADXL345_ADDR);
155 i2c_receive_n(1, &retVal);
162accm_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
165 PRINTF(
"ADXL345: READ_STR %u B from 0x%02X\n", len, reg);
168 i2c_transmitinit(ADXL345_ADDR);
170 i2c_transmit_n(1, &rtx);
174 i2c_receiveinit(ADXL345_ADDR);
176 i2c_receive_n(len, whereto);
188accm_read_axis(
enum ADXL345_AXIS axis)
195 accm_read_stream(ADXL345_DATAX0 + axis, 2, &tmp[0]);
196 rd = (int16_t)(tmp[0] | (tmp[1]<<8));
201accm_set_grange(uint8_t grange)
205 if(grange > ADXL345_RANGE_16G) {
206 PRINTF(
"ADXL345: grange invalid: %u\n", grange);
207 return ADXL345_ERROR;
211 return ADXL345_ERROR;
215 tempreg = (accm_read_reg(ADXL345_DATA_FORMAT) & 0xFC);
217 accm_write_reg(ADXL345_DATA_FORMAT, tempreg);
218 return ADXL345_SUCCESS;
225 PRINTF(
"ADXL345: init\n");
230 ADXL345_DIR &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
231 ADXL345_SEL &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
232 ADXL345_SEL2 &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
238 accm_write_stream(15, &adxl345_default_settings[0]);
239 accm_write_stream(5, &adxl345_default_settings[15]);
240 accm_write_reg(ADXL345_DATA_FORMAT, adxl345_default_settings[20]);
241 accm_write_reg(ADXL345_FIFO_CTL, adxl345_default_settings[21]);
248 ADXL345_IES &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
250 ADXL345_IE |= (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
260 ADXL345_IE &= ~(ADXL345_INT1_PIN | ADXL345_INT2_PIN);
261 accm_write_reg(ADXL345_INT_ENABLE, ~(int1_mask | int2_mask));
262 accm_write_reg(ADXL345_INT_MAP, ~int2_mask);
268accm_set_irq(uint8_t int1, uint8_t int2)
271 return ADXL345_ERROR;
275 PRINTF(
"ADXL345: IRQs set to INT1: 0x%02X IRQ2: 0x%02X\n", int1, int2);
280 accm_write_reg(ADXL345_INT_ENABLE, (int1 | int2));
282 accm_write_reg(ADXL345_INT_MAP, int2);
283 return ADXL345_SUCCESS;
295 ireg = accm_read_reg(ADXL345_INT_SOURCE);
298 if(ireg & int1_mask){
299 if(accm_int1_cb != NULL){
300 PRINTF(
"ADXL345: INT1 cb invoked\n");
303 }
else if(ireg & int2_mask){
304 if(accm_int2_cb != NULL){
305 PRINTF(
"ADXL345: INT2 cb invoked\n");
327static struct timer suppressTimer1, suppressTimer2;
334 if((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
337 timer_set(&suppressTimer1, SUPPRESS_TIME_INT1);
338 ADXL345_IFG &= ~ADXL345_INT1_PIN;
342 }
else if((ADXL345_IFG & ADXL345_INT2_PIN) &&
343 !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
346 timer_set(&suppressTimer2, SUPPRESS_TIME_INT2);
348 ADXL345_IFG &= ~ADXL345_INT2_PIN;
361configure(
int type,
int value)
363 if(type != SENSORS_ACTIVE) {
364 return ADXL345_ERROR;
373 return ADXL345_SUCCESS;
384 return ADXL345_SUCCESS;
391 return ADXL345_ERROR;
394 if((type != X_AXIS) && (type != Y_AXIS) && (type != Z_AXIS)) {
395 return ADXL345_ERROR;
400 return accm_read_axis(X_AXIS);
402 return accm_read_axis(Y_AXIS);
404 return accm_read_axis(Z_AXIS);
406 return ADXL345_ERROR;
410SENSORS_SENSOR(adxl345, ADXL345_SENSOR, value, configure, status);
Device drivers header file for adxl345 accelerometer in Zolertia Z1.
CC2420 driver header file.
int cc2420_interrupt(void)
Interrupt function, called from the simple-cc2420-arch driver.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_EXITHANDLER(handler)
Specify an action when a process exits.
#define PROCESS_POLLHANDLER(handler)
Specify an action when a process is polled.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
void process_poll(struct process *p)
Request a process to be polled.
void timer_set(struct timer *t, clock_time_t interval)
Set a timer.
int timer_expired(struct timer *t)
Check if a timer has expired.
I2C communication device driver header file for Zolertia Z1 sensor node.