Bosch BMA220 3-axis accelerometer driver.
This file contains functions for initializing and reading data from a Bosch BMA220 3-axis accelerometer.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
Macros | |
#define | BMA220_DATA_RESOLUTION (6) |
#define | BMA220_SPI_MODE (4) |
#define | BMA220_TWI_ADDR (0x0b) |
#define | BMA220_ZERO_G_OFFSET (95) /* +/- 95 mg @ 2g FS resolution */ |
#define | get_field(reg, mask, offset) (((reg) & (mask)) >> (offset)) |
#define | HYSTERESIS_IN_G(hysteresis, grange) (((threshold) * 4) / (grange)) |
convert real G values into hysteresis register values More... | |
#define | set_field(reg, mask, value) ((reg) & ~(mask)) | ((value) & (mask)) |
#define | THRESHOLD_IN_G(threshold, grange) (((threshold) * 16) / (grange)) |
convert real G values into register values More... | |
#define | BMA220_ID_VAL (0xdd) /* BMA220 chip ID (always ddh) */ |
BMA220 Register Bit Definitions. More... | |
#define | HIGH_DUR_FIELD (0x3f) /* high-g duration mask */ |
#define | HIGH_HY_FIELD (0xc0) /* high-g hysteresis mask */ |
#define | HIGH_TH_FIELD (0x0f) /* high-g threshold mask */ |
#define | LOW_TH_FIELD (0xf0) /* low-g threshold mask */ |
#define | LOW_DUR_FIELD (0x3f) /* low-g duration mask */ |
#define | LOW_HY_FIELD (0xc0) /* low-g hysteresis mask */ |
#define | TT_DUR_FIELD (0x07) /* tap duration mask */ |
#define | TT_DUR_50MS (0) |
#define | TT_DUR_105MS (1) |
#define | TT_DUR_150MS (2) |
#define | TT_DUR_219MS (3 |
#define | TT_DUR_250MS (4) |
#define | TT_DUR_375MS (5) |
#define | TT_DUR_500MS (6) |
#define | TT_DUR_700MS (7) |
#define | TT_TH_FIELD (0x78) /* tap threshold mask */ |
#define | TT_FILT_FIELD (0x80) /* tap filter mask */ |
#define | SLOPE_DUR_FIELD (0x03) |
#define | SLOPE_DUR_1 (0) |
#define | SLOPE_DUR_2 (1) |
#define | SLOPE_DUR_3 (2) |
#define | SLOPE_DUR_4 (3) |
#define | SLOPE_TH_FIELD (0x3c) |
#define | SLOPE_FILT_FIELD (0x40) |
#define | ORIENT_EX_FIELD (0x80) |
#define | TT_SAMP_FIELD (0x03) |
#define | ORIENT_BLOCKING_FIELD (0x0c) |
#define | TIP_EN_FIELD (0x10) |
#define | INT_SIGN_FIELD (0x01) |
#define | INT_FIRST_Z_FIELD (0x02) |
#define | INT_FIRST_Y_FIELD (0x04) |
#define | INT_FIRST_X_FIELD (0x08) |
#define | ORIENT_FIELD (0x70) |
#define | ORIENT_INT_FIELD (0x80) |
#define | SLOPE_INT_FIELD (0x01) |
#define | DATA_INT_FIELD (0x02) |
#define | HIGH_INT_FIELD (0x04) |
#define | LOW_INT_FIELD (0x08) |
#define | TT_INT_FIELD (0x10) |
#define | EN_TT_Z_FIELD (0x01) |
#define | EN_TT_Y_FIELD (0x02) |
#define | EN_TT_X_FIELD (0x04) |
#define | EN_SLOPE_Z_FIELD (0x08) |
#define | EN_SLOPE_Y_FIELD (0x10) |
#define | EN_SLOPE_X_FIELD (0x20) |
#define | EN_ORIENT_FIELD (0x40) |
#define | EN_DATA_FIELD (0x80) |
#define | EN_HIGH_Z_FIELD (0x01) |
#define | EN_HIGH_Y_FIELD (0x02) |
#define | EN_HIGH_X_FIELD (0x04) |
#define | EN_LOW_FIELD (0x08) |
#define | LATCH_INT_FIELD (0x70) |
#define | LATCH_INT_OFF (0) /* unlatched */ |
#define | LATCH_INT_250MS (1) /* 0.25s latch time */ |
#define | LATCH_INT_500MS (2) /* 0.5s latch time */ |
#define | LATCH_INT_1000MS (3) /* 1s latch time */ |
#define | LATCH_INT_2000MS (4) /* 2s latch time */ |
#define | LATCH_INT_4000MS (5) /* 4s latch time */ |
#define | LATCH_INT_8000MS (6) /* 8s latch time */ |
#define | LATCH_INT_ON (7) /* permanent latch */ |
#define | RESET_INT (0x80) /* w/o software reset bit */ |
#define | EN_Z_CHANNEL_FIELD (0x01) |
#define | EN_Y_CHANNEL_FIELD (0x02) |
#define | EN_X_CHANNEL_FIELD (0x04) |
#define | SLEEP_DUR_FIELD (0x38) |
#define | SLEEP_DUR_2MS (0) |
#define | SLEEP_DUR_10MS (1) |
#define | SLEEP_DUR_25MS (2) |
#define | SLEEP_DUR_50MS (3) |
#define | SLEEP_DUR_100MS (4) |
#define | SLEEP_DUR_500MS (5) |
#define | SLEEP_DUR_1000MS (6) |
#define | SLEEP_DUR_2000MS (7) |
#define | SLEEP_ENABLE (0x40) |
#define | FILTER_CONFIG_FIELD (0x0f) |
#define | BANDWIDTH_1000HZ (0) |
#define | BANDWIDTH_500HZ (1) |
#define | BANDWIDTH_250HZ (2) |
#define | BANDWIDTH_125HZ (3) |
#define | BANDWIDTH_64HZ (4) |
#define | BANDWIDTH_32HZ (5) |
#define | SERIAL_HIGH_BW_FIELD (0x80) |
#define | RANGE_FIELD (0x03) |
#define | RANGE_2G (0) |
#define | RANGE_4G (1) |
#define | RANGE_8G (2) |
#define | RANGE_16G (3) |
#define | SBIST_FIELD (0x0c) |
#define | SBIST_OFF (0) |
#define | SBIST_X_AXIS (1) |
#define | SBIST_Y_AXIS (2) |
#define | SBIST_Z_AXIS (3) |
#define | SBIST_SIGN_FIELD (0x70) |
#define | SBIST_SIGN_POSITIVE (0) |
#define | SBIST_SIGN_NEGATIVE (1) |
#define | SPI3_FIELD (0x01) /* SPI3 ENABLE */ |
#define | WDT_TO_SEL_FIELD (0x02) /* WATCHDOG TIMEOUT SELECT */ |
#define | WDT_TO_EN_FIELD (0x04) /* WATCHDOG TIMEOUT ENABLE */ |
Functions | |
bool | bma220_init (sensor_t *, int) |
Bosch BMA220 accelerometer driver initialization. More... | |
#define BANDWIDTH_1000HZ (0) |
#define BANDWIDTH_125HZ (3) |
#define BANDWIDTH_250HZ (2) |
#define BANDWIDTH_32HZ (5) |
#define BANDWIDTH_500HZ (1) |
#define BANDWIDTH_64HZ (4) |
#define BMA220_DATA_RESOLUTION (6) |
Referenced by bma220_init().
#define BMA220_ID_VAL (0xdd) /* BMA220 chip ID (always ddh) */ |
BMA220 Register Bit Definitions.
Referenced by bma220_init().
#define BMA220_SPI_MODE (4) |
#define BMA220_TWI_ADDR (0x0b) |
#define BMA220_ZERO_G_OFFSET (95) /* +/- 95 mg @ 2g FS resolution */ |
#define DATA_INT_FIELD (0x02) |
#define EN_DATA_FIELD (0x80) |
Referenced by bma220_event().
#define EN_HIGH_X_FIELD (0x04) |
Referenced by bma220_event().
#define EN_HIGH_Y_FIELD (0x02) |
Referenced by bma220_event().
#define EN_HIGH_Z_FIELD (0x01) |
Referenced by bma220_event().
#define EN_LOW_FIELD (0x08) |
Referenced by bma220_event().
#define EN_ORIENT_FIELD (0x40) |
#define EN_SLOPE_X_FIELD (0x20) |
Referenced by bma220_event().
#define EN_SLOPE_Y_FIELD (0x10) |
Referenced by bma220_event().
#define EN_SLOPE_Z_FIELD (0x08) |
Referenced by bma220_event().
#define EN_TT_X_FIELD (0x04) |
Referenced by bma220_event().
#define EN_TT_Y_FIELD (0x02) |
Referenced by bma220_event().
#define EN_TT_Z_FIELD (0x01) |
Referenced by bma220_event().
#define EN_X_CHANNEL_FIELD (0x04) |
#define EN_Y_CHANNEL_FIELD (0x02) |
#define EN_Z_CHANNEL_FIELD (0x01) |
#define FILTER_CONFIG_FIELD (0x0f) |
Referenced by bma220_set_bandwidth().
#define get_field | ( | reg, | |
mask, | |||
offset | |||
) | (((reg) & (mask)) >> (offset)) |
#define HIGH_DUR_FIELD (0x3f) /* high-g duration mask */ |
#define HIGH_HY_FIELD (0xc0) /* high-g hysteresis mask */ |
#define HIGH_INT_FIELD (0x04) |
#define HIGH_TH_FIELD (0x0f) /* high-g threshold mask */ |
Referenced by bma220_set_threshold().
#define HYSTERESIS_IN_G | ( | hysteresis, | |
grange | |||
) | (((threshold) * 4) / (grange)) |
convert real G values into hysteresis register values
#define INT_FIRST_X_FIELD (0x08) |
#define INT_FIRST_Y_FIELD (0x04) |
#define INT_FIRST_Z_FIELD (0x02) |
#define INT_SIGN_FIELD (0x01) |
#define LATCH_INT_1000MS (3) /* 1s latch time */ |
#define LATCH_INT_2000MS (4) /* 2s latch time */ |
#define LATCH_INT_250MS (1) /* 0.25s latch time */ |
#define LATCH_INT_4000MS (5) /* 4s latch time */ |
#define LATCH_INT_500MS (2) /* 0.5s latch time */ |
#define LATCH_INT_8000MS (6) /* 8s latch time */ |
#define LATCH_INT_FIELD (0x70) |
Referenced by bma220_event().
#define LATCH_INT_OFF (0) /* unlatched */ |
#define LATCH_INT_ON (7) /* permanent latch */ |
#define LOW_DUR_FIELD (0x3f) /* low-g duration mask */ |
#define LOW_HY_FIELD (0xc0) /* low-g hysteresis mask */ |
#define LOW_INT_FIELD (0x08) |
#define LOW_TH_FIELD (0xf0) /* low-g threshold mask */ |
Referenced by bma220_set_threshold().
#define ORIENT_BLOCKING_FIELD (0x0c) |
#define ORIENT_EX_FIELD (0x80) |
#define ORIENT_FIELD (0x70) |
#define ORIENT_INT_FIELD (0x80) |
#define RANGE_16G (3) |
#define RANGE_2G (0) |
#define RANGE_4G (1) |
#define RANGE_8G (2) |
#define RANGE_FIELD (0x03) |
Referenced by bma220_set_range().
#define RESET_INT (0x80) /* w/o software reset bit */ |
Referenced by bma220_event().
#define SBIST_FIELD (0x0c) |
#define SBIST_OFF (0) |
#define SBIST_SIGN_FIELD (0x70) |
#define SBIST_SIGN_NEGATIVE (1) |
#define SBIST_SIGN_POSITIVE (0) |
#define SBIST_X_AXIS (1) |
#define SBIST_Y_AXIS (2) |
#define SBIST_Z_AXIS (3) |
#define SERIAL_HIGH_BW_FIELD (0x80) |
#define set_field | ( | reg, | |
mask, | |||
value | |||
) | ((reg) & ~(mask)) | ((value) & (mask)) |
#define SLEEP_DUR_1000MS (6) |
#define SLEEP_DUR_100MS (4) |
#define SLEEP_DUR_10MS (1) |
#define SLEEP_DUR_2000MS (7) |
#define SLEEP_DUR_25MS (2) |
#define SLEEP_DUR_2MS (0) |
#define SLEEP_DUR_500MS (5) |
#define SLEEP_DUR_50MS (3) |
#define SLEEP_DUR_FIELD (0x38) |
#define SLEEP_ENABLE (0x40) |
Referenced by bma220_sleep_en().
#define SLOPE_DUR_1 (0) |
#define SLOPE_DUR_2 (1) |
#define SLOPE_DUR_3 (2) |
#define SLOPE_DUR_4 (3) |
#define SLOPE_DUR_FIELD (0x03) |
#define SLOPE_FILT_FIELD (0x40) |
#define SLOPE_INT_FIELD (0x01) |
#define SLOPE_TH_FIELD (0x3c) |
Referenced by bma220_set_threshold().
#define SPI3_FIELD (0x01) /* SPI3 ENABLE */ |
#define THRESHOLD_IN_G | ( | threshold, | |
grange | |||
) | (((threshold) * 16) / (grange)) |
convert real G values into register values
Referenced by bma220_set_threshold().
#define TIP_EN_FIELD (0x10) |
#define TT_DUR_105MS (1) |
#define TT_DUR_150MS (2) |
#define TT_DUR_219MS (3 |
#define TT_DUR_250MS (4) |
#define TT_DUR_375MS (5) |
#define TT_DUR_500MS (6) |
#define TT_DUR_50MS (0) |
#define TT_DUR_700MS (7) |
#define TT_DUR_FIELD (0x07) /* tap duration mask */ |
#define TT_FILT_FIELD (0x80) /* tap filter mask */ |
#define TT_INT_FIELD (0x10) |
#define TT_SAMP_FIELD (0x03) |
#define TT_TH_FIELD (0x78) /* tap threshold mask */ |
Referenced by bma220_set_threshold().
#define WDT_TO_EN_FIELD (0x04) /* WATCHDOG TIMEOUT ENABLE */ |
#define WDT_TO_SEL_FIELD (0x02) /* WATCHDOG TIMEOUT SELECT */ |
enum bma220_register_t |
Standard Register Addresses.
The TWI/I2C register address for a particular register is derived by shifting the SPI register address to the left by one bit. In other words, from I2C->SPI the burst address increment is 0x2 steps.
Bosch BMA220 accelerometer driver initialization.
This is the main initialization function for the BMA220 device.
sensor | Address of a sensor device descriptor. |
resvd | Reserved value. |
References ARRAYSIZE, band_table, sensor_hal::bandwidth, BMA220_CHIP_ID, BMA220_DATA_RESOLUTION, bma220_event(), BMA220_ID_VAL, bma220_ioctl(), bma220_isr(), bma220_read(), bma220_selftest(), bma220_set_state(), BMA220_X_AXIS_DATA, sensor_hal::burst_addr, burst_increment, sensor_hal::bus, BUS_TYPE_TWI, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, sensor_hal::mcu_sigint, sensor_hal::range, range_table, sensor_funcs_t::read, REG_ADDR, sensor_hal::resolution, sensor_bus_get, SENSOR_CAPS_3_AXIS, SENSOR_CAPS_HI_G_EVENT, SENSOR_CAPS_LO_G_EVENT, SENSOR_CAPS_SELFTEST, SENSOR_CAPS_TAP_EVENT, SENSOR_CAPS_TILT_EVENT, sensor_irq_connect(), SENSOR_SCALE_milli, SENSOR_STATE_RESET, SENSOR_UNITS_g0, SENSOR_VENDOR_BOSCH, status, bus_desc_t::status, STATUS_OK, and bus_desc_t::type.