Atmel Software Framework

bma180.c File Reference

Bosch BMA180 3-axis accelerometer driver.

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

Copyright (c) 2012 Atmel Corporation. All rights reserved.

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

Functions

static bool bma180_device_id (sensor_hal_t *hal, sensor_data_t *data)
 Read BMA180 device ID and revision numbers. More...
 
static bool bma180_get_accel (sensor_hal_t *hal, sensor_data_t *data)
 Read accelerometer data. More...
 
static bool bma180_get_temperature (sensor_hal_t *hal, sensor_data_t *data)
 Read BMA180 integrated temperature sensor data. More...
 
bool bma180_init (sensor_t *sensor, int resvd)
 Bosch BMA180 accelerometer driver initialization. More...
 
static bool bma180_ioctl (sensor_t *sensor, sensor_command_t cmd, void *arg)
 BMA180 ioctl control entry point. More...
 
static bool bma180_read (sensor_t *sensor, sensor_read_t type, sensor_data_t *data)
 Read sensor data. More...
 
static bool bma180_set_bandwidth (sensor_hal_t *hal, int16_t band)
 Set the BMA180 ADC output data bandwidth. More...
 
static bool bma180_set_range (sensor_hal_t *hal, int16_t range)
 Set the BMA180 full scale acceleration range. More...
 
static bool bma180_set_state (sensor_hal_t *hal, sensor_state_t state)
 Set the BMA180 execution mode. More...
 

Variables

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

static bool bma180_device_id ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read BMA180 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 BMA180_CHIP_ID, BMA180_CHIP_VERSION, sensor_data_t::device, and sensor_bus_get.

Referenced by bma180_read().

static bool bma180_get_accel ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read accelerometer 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, count, and sensor_bus_read.

Referenced by bma180_ioctl(), and bma180_read().

static bool bma180_get_temperature ( sensor_hal_t hal,
sensor_data_t data 
)
static

Read BMA180 integrated temperature sensor data.

Parameters
halAddress of an initialized sensor hardware descriptor.
dataThe address where temperature samples are returned.
Returns
bool true if the call succeeds, else false is returned.

References BMA180_TEMP, BMA180_TEMP_OFFSET, sensor_hal::bus, sensor_data_t::scaled, sensor_bus_get, bus_desc_t::status, STATUS_OK, and sensor_data_t::temperature.

Referenced by bma180_read().

bool bma180_init ( sensor_t sensor,
int  resvd 
)

Bosch BMA180 accelerometer driver initialization.

This is the main initialization function for the BMA180 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, BMA180_ACC_X_LSB, BMA180_CHIP_ID, BMA180_DATA_RESOLUTION, BMA180_ID_VAL, bma180_ioctl(), bma180_read(), bma180_set_bandwidth(), bma180_set_range(), sensor_hal::burst_addr, sensor_hal::bus, sensor_desc::drv, sensor_device_t::func, sensor_desc::hal, sensor_hal::range, range_table, sensor_funcs_t::read, sensor_hal::resolution, sensor_bus_get, SENSOR_CAPS_3_AXIS, SENSOR_CAPS_AUX_TEMP, SENSOR_CAPS_HI_G_EVENT, SENSOR_CAPS_LO_G_EVENT, SENSOR_CAPS_SELFTEST, SENSOR_SCALE_milli, SENSOR_UNITS_g0, SENSOR_VENDOR_BOSCH, bus_desc_t::status, status, and STATUS_OK.

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

BMA180 ioctl control entry point.

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

References sensor_data_t::axis, bma180_get_accel(), bma180_set_bandwidth(), bma180_set_range(), bma180_set_state(), sensor_desc::err, sensor_desc::hal, sensor_data_t::scaled, SENSOR_ERR_UNSUPPORTED, SENSOR_READ_VECTOR, SENSOR_SET_BANDWIDTH, SENSOR_SET_RANGE, SENSOR_SET_STATE, vector3_t::x, vector3_t::y, and vector3_t::z.

Referenced by bma180_init().

static bool bma180_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 bma180_device_id(), bma180_get_accel(), bma180_get_temperature(), sensor_desc::err, sensor_desc::hal, SENSOR_ERR_FUNCTION, SENSOR_READ_ACCELERATION, SENSOR_READ_ID, and SENSOR_READ_TEMPERATURE.

Referenced by bma180_init().

static bool bma180_set_bandwidth ( sensor_hal_t hal,
int16_t  band 
)
static

Set the BMA180 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 BMA180_BW_TCS, BW, sensor_bus_get, and sensor_bus_put.

Referenced by bma180_init(), and bma180_ioctl().

static bool bma180_set_range ( sensor_hal_t hal,
int16_t  range 
)
static

Set the BMA180 full scale acceleration range.

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

References BMA180_OFFSET_LSB1, RANGE, sensor_bus_get, and sensor_bus_put.

Referenced by bma180_init(), and bma180_ioctl().

static bool bma180_set_state ( sensor_hal_t hal,
sensor_state_t  state 
)
static

Set the BMA180 execution mode.

Parameters
halAddress of an initialized sensor hardware descriptor.
stateA specified sensor operational state.
Returns
bool true if the call succeeds, else false is returned.

Referenced by bma180_ioctl().

const sensor_map_t band_table[]
static
Initial value:
= {
{{ 10}, BW_10HZ }, {{ 20}, BW_20HZ },
{{ 40}, BW_40HZ }, {{ 75}, BW_75HZ },
{{150}, BW_150HZ}, {{ 300}, BW_300HZ },
{{600}, BW_600HZ}, {{1200}, BW_1200HZ}
}
#define BW_1200HZ
Definition: bma180.h:255
#define BW_20HZ
Definition: bma180.h:249
#define BW_600HZ
Definition: bma180.h:254
#define BW_10HZ
Definition: bma180.h:248
#define BW_150HZ
Definition: bma180.h:252
#define BW_40HZ
Definition: bma180.h:250
#define BW_75HZ
Definition: bma180.h:251
#define BW_300HZ
Definition: bma180.h:253

Bosch BMA180 Bandwidth Table (hertz, register value)

Referenced by bma180_init().

const sensor_map_t range_table[]
static
Initial value:
= {
{{ 1000}, BMA180_RANGE_1G}, {{1500}, BMA180_RANGE_1_5G},
{{ 2000}, BMA180_RANGE_2G}, {{3000}, BMA180_RANGE_3G},
{{ 4000}, BMA180_RANGE_4G}, {{8000}, BMA180_RANGE_8G},
{{16000}, BMA180_RANGE_16G}
}
#define BMA180_RANGE_2G
Definition: bma180.h:359
#define BMA180_RANGE_3G
Definition: bma180.h:360
#define BMA180_RANGE_8G
Definition: bma180.h:362
#define BMA180_RANGE_4G
Definition: bma180.h:361
#define BMA180_RANGE_1_5G
Definition: bma180.h:358
#define BMA180_RANGE_1G
Definition: bma180.h:357
#define BMA180_RANGE_16G
Definition: bma180.h:363

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

Referenced by bma180_init().