Skip to content

Commit

Permalink
update all lib to last rev
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryBorisenko33 committed May 20, 2020
1 parent b2dccc7 commit 76c845f
Show file tree
Hide file tree
Showing 1,278 changed files with 775,191 additions and 26,758 deletions.
460 changes: 460 additions & 0 deletions Adafruit_ADXL343/Adafruit_ADXL343.cpp

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions Adafruit_ADXL343/Adafruit_ADXL343.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**************************************************************************/
/*!
@file Adafruit_ADXL343.h
@author K. Townsend (Adafruit Industries)
BSD license (see license.txt)
This is a library for the Adafruit ADS1015 breakout board
----> https://www.adafruit.com/products/???
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
v1.0 - First release
*/
/**************************************************************************/
#ifndef _ADAFRUIT_SENSOR_ADXL343_H
#define _ADAFRUIT_SENSOR_ADXL343_H

#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <Adafruit_Sensor.h>
#include <Wire.h>

/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define ADXL343_ADDRESS (0x53) /**< Assumes ALT address pin low */
/*=========================================================================*/

/*=========================================================================
REGISTERS
-----------------------------------------------------------------------*/
#define ADXL343_REG_DEVID (0x00) /**< Device ID */
#define ADXL343_REG_THRESH_TAP (0x1D) /**< Tap threshold */
#define ADXL343_REG_OFSX (0x1E) /**< X-axis offset */
#define ADXL343_REG_OFSY (0x1F) /**< Y-axis offset */
#define ADXL343_REG_OFSZ (0x20) /**< Z-axis offset */
#define ADXL343_REG_DUR (0x21) /**< Tap duration */
#define ADXL343_REG_LATENT (0x22) /**< Tap latency */
#define ADXL343_REG_WINDOW (0x23) /**< Tap window */
#define ADXL343_REG_THRESH_ACT (0x24) /**< Activity threshold */
#define ADXL343_REG_THRESH_INACT (0x25) /**< Inactivity threshold */
#define ADXL343_REG_TIME_INACT (0x26) /**< Inactivity time */
#define ADXL343_REG_ACT_INACT_CTL \
(0x27) /**< Axis enable control for activity and inactivity detection */
#define ADXL343_REG_THRESH_FF (0x28) /**< Free-fall threshold */
#define ADXL343_REG_TIME_FF (0x29) /**< Free-fall time */
#define ADXL343_REG_TAP_AXES (0x2A) /**< Axis control for single/double tap */
#define ADXL343_REG_ACT_TAP_STATUS (0x2B) /**< Source for single/double tap */
#define ADXL343_REG_BW_RATE (0x2C) /**< Data rate and power mode control */
#define ADXL343_REG_POWER_CTL (0x2D) /**< Power-saving features control */
#define ADXL343_REG_INT_ENABLE (0x2E) /**< Interrupt enable control */
#define ADXL343_REG_INT_MAP (0x2F) /**< Interrupt mapping control */
#define ADXL343_REG_INT_SOURCE (0x30) /**< Source of interrupts */
#define ADXL343_REG_DATA_FORMAT (0x31) /**< Data format control */
#define ADXL343_REG_DATAX0 (0x32) /**< X-axis data 0 */
#define ADXL343_REG_DATAX1 (0x33) /**< X-axis data 1 */
#define ADXL343_REG_DATAY0 (0x34) /**< Y-axis data 0 */
#define ADXL343_REG_DATAY1 (0x35) /**< Y-axis data 1 */
#define ADXL343_REG_DATAZ0 (0x36) /**< Z-axis data 0 */
#define ADXL343_REG_DATAZ1 (0x37) /**< Z-axis data 1 */
#define ADXL343_REG_FIFO_CTL (0x38) /**< FIFO control */
#define ADXL343_REG_FIFO_STATUS (0x39) /**< FIFO status */
/*=========================================================================*/

/*=========================================================================
REGISTERS
-----------------------------------------------------------------------*/
#define ADXL343_MG2G_MULTIPLIER (0.004) /**< 4mg per lsb */
/*=========================================================================*/

/** Used with register 0x2C (ADXL343_REG_BW_RATE) to set bandwidth */
typedef enum {
ADXL343_DATARATE_3200_HZ = 0b1111, /**< 3200Hz Bandwidth */
ADXL343_DATARATE_1600_HZ = 0b1110, /**< 1600Hz Bandwidth */
ADXL343_DATARATE_800_HZ = 0b1101, /**< 800Hz Bandwidth */
ADXL343_DATARATE_400_HZ = 0b1100, /**< 400Hz Bandwidth */
ADXL343_DATARATE_200_HZ = 0b1011, /**< 200Hz Bandwidth */
ADXL343_DATARATE_100_HZ = 0b1010, /**< 100Hz Bandwidth */
ADXL343_DATARATE_50_HZ = 0b1001, /**< 50Hz Bandwidth */
ADXL343_DATARATE_25_HZ = 0b1000, /**< 25Hz Bandwidth */
ADXL343_DATARATE_12_5_HZ = 0b0111, /**< 12.5Hz Bandwidth */
ADXL343_DATARATE_6_25HZ = 0b0110, /**< 6.25Hz Bandwidth */
ADXL343_DATARATE_3_13_HZ = 0b0101, /**< 3.13Hz Bandwidth */
ADXL343_DATARATE_1_56_HZ = 0b0100, /**< 1.56Hz Bandwidth */
ADXL343_DATARATE_0_78_HZ = 0b0011, /**< 0.78Hz Bandwidth */
ADXL343_DATARATE_0_39_HZ = 0b0010, /**< 0.39Hz Bandwidth */
ADXL343_DATARATE_0_20_HZ = 0b0001, /**< 0.20Hz Bandwidth */
ADXL343_DATARATE_0_10_HZ = 0b0000 /**< 0.10Hz Bandwidth (default value) */
} dataRate_t;

/** Used with register 0x31 (ADXL343_REG_DATA_FORMAT) to set g range */
typedef enum {
ADXL343_RANGE_16_G = 0b11, /**< +/- 16g */
ADXL343_RANGE_8_G = 0b10, /**< +/- 8g */
ADXL343_RANGE_4_G = 0b01, /**< +/- 4g */
ADXL343_RANGE_2_G = 0b00 /**< +/- 2g (default value) */
} range_t;

/** Possible interrupts sources on the ADXL343. */
union int_config {
uint8_t value; /**< Composite 8-bit value of the bitfield.*/
struct {
uint8_t overrun : 1; /**< Bit 0 */
uint8_t watermark : 1; /**< Bit 1 */
uint8_t freefall : 1; /**< Bit 2 */
uint8_t inactivity : 1; /**< Bit 3 */
uint8_t activity : 1; /**< Bit 4 */
uint8_t double_tap : 1; /**< Bit 5 */
uint8_t single_tap : 1; /**< Bit 6 */
uint8_t data_ready : 1; /**< Bit 7 */
} bits; /**< Individual bits in the bitfield. */
};

/** Possible interrupt pin outputs on the ADXL343. */
typedef enum { ADXL343_INT1 = 0, ADXL343_INT2 = 1 } int_pin;

/**
* Driver for the Adafruit ADXL343 breakout.
*/
class Adafruit_ADXL343 : public Adafruit_Sensor {
public:
Adafruit_ADXL343(int32_t sensorID);
Adafruit_ADXL343(int32_t sensorID, TwoWire *wireBus);
Adafruit_ADXL343(uint8_t clock, uint8_t miso, uint8_t mosi, uint8_t cs,
int32_t sensorID = -1);

bool begin(uint8_t i2caddr = ADXL343_ADDRESS);
void setRange(range_t range);
range_t getRange(void);
void setDataRate(dataRate_t dataRate);
dataRate_t getDataRate(void);
bool getEvent(sensors_event_t *);
void getSensor(sensor_t *);

uint8_t getDeviceID(void);
void writeRegister(uint8_t reg, uint8_t value);
uint8_t readRegister(uint8_t reg);
int16_t read16(uint8_t reg);

bool enableInterrupts(int_config cfg);
bool mapInterrupts(int_config cfg);
uint8_t checkInterrupts(void);

int16_t getX(void);
int16_t getY(void);
int16_t getZ(void);

private:
inline uint8_t i2cread(void);
inline void i2cwrite(uint8_t x);
uint8_t _i2caddr;

TwoWire *_wire;
int32_t _sensorID;
range_t _range;
uint8_t _clk, _do, _di, _cs;
bool _i2c;
};

#endif
29 changes: 29 additions & 0 deletions Adafruit_ADXL343/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Adafruit ADXL343 Accelerometer Driver ![Build Status](https://github.com/adafruit/Adafruit_ADXL343/workflows/Arduino%20Library%20CI/badge.svg)

This driver is for the Adafruit ADXL343 Breakout (http://www.adafruit.com/products/), and is based on Adafruit's Unified Sensor Library (Adafruit_Sensor).

## About the ADXL343 ##

The ADXL343 is a digital accelerometer that supports both SPI and I2C mode, with adjustable data rata and 'range' (+/-2/4/8/16g). The Adafruit_ADXL343 driver takes advantage of I2C mode to reduce the total pin count required to use the sensor.

More information on the ADXL345 can be found in the datasheet: http://www.analog.com/static/imported-files/data_sheets/ADXL343.pdf

## What is the Adafruit Unified Sensor Library? ##

The Adafruit Unified Sensor Library (https://github.com/adafruit/Adafruit_Sensor) provides a common interface and data type for any supported sensor. It defines some basic information about the sensor (sensor limits, etc.), and returns standard SI units of a specific type and scale for each supported sensor type.

It provides a simple abstraction layer between your application and the actual sensor HW, allowing you to drop in any comparable sensor with only one or two lines of code to change in your project (essentially the constructor since the functions to read sensor data and get information about the sensor are defined in the base Adafruit_Sensor class).

This is imporant useful for two reasons:

1.) You can use the data right away because it's already converted to SI units that you understand and can compare, rather than meaningless values like 0..1023.

2.) Because SI units are standardised in the sensor library, you can also do quick sanity checks working with new sensors, or drop in any comparable sensor if you need better sensitivity or if a lower cost unit becomes available, etc.

Light sensors will always report units in lux, gyroscopes will always report units in rad/s, etc. ... freeing you up to focus on the data, rather than digging through the datasheet to understand what the sensor's raw numbers really mean.

## About this Driver ##

Adafruit invests time and resources providing this open source code. Please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Kevin (KTOWN) Townsend for Adafruit Industries.
149 changes: 149 additions & 0 deletions Adafruit_ADXL343/examples/interrupts/interrupts.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL343.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_ADXL343 accel = Adafruit_ADXL343(12345);

/** The input pins to enable the interrupt on, connected to INT1 and INT2 on the ADXL. */
#define INPUT_PIN_INT1 (5) // Uno = (2)
#define INPUT_PIN_INT2 (6) // Uno = (3)

/**
* This struct is used to count the number of times that specific interrutps
* have been fired by the ADXL and detected on the MCU. They will increment
* by one for each event associated with the specified interrupt 'bit'.
*/
struct adxl_int_stats {
uint32_t data_ready;
uint32_t single_tap;
uint32_t double_tap;
uint32_t activity;
uint32_t inactivity;
uint32_t freefall;
uint32_t watermark;
uint32_t overrun;
uint32_t total;
};

/** Global stats block, incremented inside the interrupt handler(s). */
struct adxl_int_stats g_int_stats = { 0 };

/** Global counter to track the numbers of unused interrupts fired. */
uint32_t g_ints_fired = 0;

/** Global variable to determine which interrupt(s) are enabled on the ADXL343. */
int_config g_int_config_enabled = { 0 };

/** Global variables to determine which INT pin interrupt(s) are mapped to on the ADXL343. */
int_config g_int_config_map = { 0 };

/** Interrupt service routine for INT1 events. */
void int1_isr(void)
{
/* By default, this sketch routes the OVERRUN interrupt to INT1. */
g_int_stats.overrun++;
g_int_stats.total++;
g_ints_fired++;

/* TODO: Toggle an LED! */
}

/** Interrupt service routine for INT2 events. */
void int2_isr(void)
{
/* By default, this sketch routes the DATA_READY interrupt to INT2. */
g_int_stats.data_ready++;
g_int_stats.total++;
g_ints_fired++;

/* TODO: Toggle an LED! */
}

/** Configures the HW interrupts on the ADXL343 and the target MCU. */
void config_interrupts(void)
{
/* NOTE: Once an interrupt fires on the ADXL you can read a register
* to know the source of the interrupt, but since this would likely
* happen in the 'interrupt context' performing an I2C read is a bad
* idea since it will block the device from handling other interrupts
* in a timely manner.
*
* The best approach is to try to make use of only two interrupts on
* two different interrupt pins, so that when an interrupt fires, based
* on the 'isr' function that is called, you already know the int source.
*/

/* Attach interrupt inputs on the MCU. */
pinMode(LED_BUILTIN, OUTPUT);
pinMode(INPUT_PIN_INT1, INPUT);
pinMode(INPUT_PIN_INT2, INPUT);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN_INT1), int1_isr, RISING);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN_INT2), int2_isr, RISING);

/* Enable interrupts on the accelerometer. */
g_int_config_enabled.bits.overrun = true; /* Set the INT1 */
g_int_config_enabled.bits.watermark = false;
g_int_config_enabled.bits.freefall = false;
g_int_config_enabled.bits.inactivity = false;
g_int_config_enabled.bits.activity = false;
g_int_config_enabled.bits.double_tap = false;
g_int_config_enabled.bits.single_tap = false;
g_int_config_enabled.bits.data_ready = true; /* Set to INT2 */
accel.enableInterrupts(g_int_config_enabled);

/* Map specific interrupts to one of the two INT pins. */
g_int_config_map.bits.overrun = ADXL343_INT1;
g_int_config_map.bits.watermark = ADXL343_INT1;
g_int_config_map.bits.freefall = ADXL343_INT1;
g_int_config_map.bits.inactivity = ADXL343_INT1;
g_int_config_map.bits.activity = ADXL343_INT1;
g_int_config_map.bits.double_tap = ADXL343_INT1;
g_int_config_map.bits.single_tap = ADXL343_INT1;
g_int_config_map.bits.data_ready = ADXL343_INT2;
accel.mapInterrupts(g_int_config_map);
}

void setup(void)
{
Serial.begin(9600);
while (!Serial);
Serial.println("ADXL343 Interrupt Tester"); Serial.println("");

/* Initialise the sensor */
if(!accel.begin())
{
/* There was a problem detecting the ADXL343 ... check your connections */
Serial.println("Ooops, no ADXL343 detected ... Check your wiring!");
while(1);
}

/* Set the range to whatever is appropriate for your project */
accel.setRange(ADXL343_RANGE_16_G);
// displaySetRange(ADXL343_RANGE_8_G);
// displaySetRange(ADXL343_RANGE_4_G);
// displaySetRange(ADXL343_RANGE_2_G);


/* Configure the HW interrupts. */
config_interrupts();

Serial.println("ADXL343 init complete. Waiting for INT activity.");
}

void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
accel.getEvent(&event);
delay(10);

while (g_ints_fired) {
Serial.println("INT detected!");
Serial.print("\tOVERRUN Count: "); Serial.println(g_int_stats.overrun, DEC);
Serial.print("\tDATA_READY Count: "); Serial.println(g_int_stats.data_ready, DEC);

/* Decrement the unhandled int counter. */
g_ints_fired--;
}
}
Loading

0 comments on commit 76c845f

Please sign in to comment.