Atmel Software Framework

bma020.c File Reference

Bosch BMA020 3-axis accelerometer.

This file contains functions for initializing and reading data from a Bosch BMA020 3-axis accelerometer.

Copyright (c) 2014-2015 Atmel Corporation. All rights reserved.

#include "bma020.h"
#include "bma_axis.inc.c"

Functions

static bool bma020_device_id (sensor_hal_t *hal, sensor_data_t *data)
 Read accelerometer device ID and revision numbers. More...
 
static bool bma020_get_accel (sensor_hal_t *hal, sensor_data_t *data)
 Read accelerometer vector data. More...
 
bool bma020_init (sensor_t *sensor, int resvd)
 Bosch BMA020 accelerometer driver initialization. More...
 
static bool bma020_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg)
 BMA020 ioctl control entry point. More...
 
static bool bma020_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data)
 Read sensor data. More...
 
static bool bma020_set_bandwidth (sensor_hal_t *hal, int16_t band)
 Set the BMA020 ADC output data bandwidth. More...
 
static bool bma020_set_range (sensor_hal_t *hal, int16_t range)
 Set the BMA020 full scale acceleration range. More...
 

Variables

static const sensor_map_t band_table []
 Bosch BMA020 Bandwidth Table (hertz, register value) More...
 
static const sensor_map_t range_table []
 Bosch BMA020 Range Table (milli-g, register value) More...
 

static bool bma020_device_id ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read accelerometer device ID and revision numbers.

This function reads the accelerometer hardware identification registers and returns these values in the specified data structure.

Parameters
halAddress of an initialized sensor hardware descriptor.
dataAddress of sensor_data_t structure to return values.
Returns
bool true if the call succeeds, else false is returned.

References BMA020_CHIP_ID, BMA020_CHIP_VERSION, sensor_data_t::device, and sensor_bus_get.

Referenced by bma020_read().

static bool bma020_get_accel ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read accelerometer vector data.

This function obtains accelerometer data for all three axes of the Bosch device. The data is read from six device registers using a multi-byte bus transfer. The 10-bit raw results are then assembled from the two register values for each axis, including extending the sign bit, to form a signed 32-bit value.

Along with the actual sensor data, the LSB byte contains a "new" flag indicating if the data for this axis has been updated since the last time the axis data was read. Reading either LSB or MSB data will clear this flag.

Parameters
halAddress of an initialized sensor hardware descriptor.
dataThe address of a vector storing sensor axis data.
Returns
bool true if the call succeeds, else false is returned.

References sensor_hal::burst_addr, and sensor_bus_read.

Referenced by bma020_ioctl(), and bma020_read().

bool bma020_init ( sensor_t sensor,
int  resvd 
)

Bosch BMA020 accelerometer driver initialization.

This is the main initialization function for the BMA020 device. The accelerometer range and bandwidth are set based on user-specified values from the system configuration.

Parameters
sensorAddress of a sensor device descriptor.
resvdReserved value.
Returns
bool true if the call succeeds, else false is returned.

References ARRAYSIZE, band_table, sensor_hal::bandwidth, BMA020_ACC_X_LSB, BMA020_CHIP_ID, BMA020_DATA_RESOLUTION, BMA020_ID_VAL, bma020_ioctl(), bma020_read(), bma020_set_bandwidth(), bma020_set_range(), sensor_hal::burst_addr, sensor_hal::bus, sensor_device_t::func, sensor_hal::range, range_table, sensor_funcs_t::read, sensor_hal::resolution, sensor_bus_get, SENSOR_CAPS_3_AXIS, SENSOR_CAPS_HI_G_EVENT, SENSOR_CAPS_LO_G_EVENT, SENSOR_CAPS_SELFTEST, SENSOR_SCALE_milli, SENSOR_UNITS_g0, SENSOR_VENDOR_BOSCH, status, bus_desc_t::status, and STATUS_OK.

static bool bma020_ioctl ( sensor_t sensor,
sensor_command_t  cmd,
void *  arg 
)
static

BMA020 ioctl control entry point.

Parameters
halAddress of an initialized sensor device descriptor.
cmdCommand to execute
argArgument for command (varies)
Returns
bool true if the call succeeds, else false is returned.

References sensor_data_t::axis, bma020_get_accel(), bma020_set_bandwidth(), bma020_set_range(), sensor_data_t::scaled, SENSOR_ERR_UNSUPPORTED, SENSOR_READ_VECTOR, SENSOR_SET_BANDWIDTH, SENSOR_SET_RANGE, vector3_t::x, vector3_t::y, and vector3_t::z.

Referenced by bma020_init().

static bool bma020_read ( sensor_t sensor,
sensor_read_t  type,
sensor_data_t data 
)
static

Read sensor data.

This routine calls the appropriate internal data function to obtain the specified type of data from the sensor device.

Parameters
sensorAddress of an initialized sensor device descriptor.
typeType of sensor data to read.
dataThe address where data values are returned.
Returns
bool true if the call succeeds, else false is returned.

References bma020_device_id(), bma020_get_accel(), SENSOR_ERR_FUNCTION, SENSOR_READ_ACCELERATION, and SENSOR_READ_ID.

Referenced by bma020_init().

static bool bma020_set_bandwidth ( sensor_hal_t hal,
int16_t  band 
)
static

Set the BMA020 ADC output data bandwidth.

Parameters
halAddress of an initialized sensor hardware descriptor.
bandThe index of a driver-specific bandwidth table entry.
Returns
bool true if the call succeeds, else false is returned.

References BMA020_CTRL4, CTRL4_BANDWIDTH, sensor_bus_get, and sensor_bus_put.

Referenced by bma020_init(), and bma020_ioctl().

static bool bma020_set_range ( sensor_hal_t hal,
int16_t  range 
)
static

Set the BMA020 full scale acceleration range.

Parameters
halAddress of an initialized sensor hardware descriptor.
rangeThe index of a driver-specific range table entry.
Returns
bool true if the call succeeds, else false is returned.

References BMA020_CTRL4, CTRL4_RANGE, sensor_bus_get, and sensor_bus_put.

Referenced by bma020_init(), and bma020_ioctl().

const sensor_map_t band_table[]
static
Initial value:
= {
{{ 25}, BANDWIDTH_25HZ }, {{ 50}, BANDWIDTH_50HZ },
{{ 100}, BANDWIDTH_100HZ }, {{190}, BANDWIDTH_190HZ},
{{ 375}, BANDWIDTH_375HZ }, {{750}, BANDWIDTH_750HZ},
{{1500}, BANDWIDTH_1500HZ}
}
#define BANDWIDTH_25HZ
Definition: bma020.h:138
#define BANDWIDTH_375HZ
Definition: bma020.h:142
#define BANDWIDTH_1500HZ
Definition: bma020.h:144
#define BANDWIDTH_190HZ
Definition: bma020.h:141
#define BANDWIDTH_50HZ
Definition: bma020.h:139
#define BANDWIDTH_750HZ
Definition: bma020.h:143
#define BANDWIDTH_100HZ
Definition: bma020.h:140

Bosch BMA020 Bandwidth Table (hertz, register value)

Referenced by bma020_init().

const sensor_map_t range_table[]
static
Initial value:
= {
{{2000}, RANGE_2G}, {{4000}, RANGE_4G}, {{8000}, RANGE_8G}
}
#define RANGE_2G
Definition: bma220.h:244
#define RANGE_4G
Definition: bma220.h:245
#define RANGE_8G
Definition: bma220.h:246

Bosch BMA020 Range Table (milli-g, register value)

Referenced by bma020_init().