fxos8700.h

Interface definition for the FXOS8700 sensor driver.

FXOS8700_USE_ACC_RAW_VALUES

Default raw value mode for accelerator.

1
(0)

If set to 0, measurements will be converted to mg. If set to 1, raw adc readings will be returned.

enum @121
FXOS8700_OK = 0
everything went as expected
FXOS8700_ADDRERR = -1
no FXOS8700 device found on the bus
FXOS8700_NOBUS = -2
errors while initializing the I2C bus
FXOS8700_NODEV = -3
no FXOS8700 device found on the bus
FXOS8700_BUSERR = -4
error during I2C communication
int fxos8700_init(fxos8700_t * dev, const fxos8700_params_t * params)

Initialize an FXOS8700 device.

Parameters

dev:device descriptor
params:parameters for device

Return values

  • FXOS8700_OK on success
  • FXOS8700_NOBUS on I2C initialization error
  • FXOS8700_BUSERR on I2C communication error
  • FXOS8700_ADDRERR on invalid address
  • FXOS8700_NODEV if no FXOS8700 device found on bus
int fxos8700_set_active(const fxos8700_t * dev)

Convenience function for turning on the FXOS8700.

This function will trigger a new conversion, wait for the conversion to be finished and the get the results from the device.

Parameters

dev:device descriptor of sensor

Return values

  • FXOS8700_OK on success
  • FXOS8700_BUSERR on I2C communication failures
int fxos8700_set_idle(const fxos8700_t * dev)

Convenience function for turning off the FXOS8700.

This function will trigger a new conversion, wait for the conversion to be finished and the get the results from the device.

Parameters

dev:device descriptor of sensor

Return values

  • FXOS8700_OK on success
  • FXOS8700_BUSERR on I2C communication failures
int fxos8700_read(const fxos8700_t * dev, fxos8700_measurement_t * acc, fxos8700_measurement_t * mag)

Convenience function for reading acceleration and magnetic field.

This function will trigger a new conversion, wait for the conversion to be finished and the get the results from the device.

Parameters

dev:device descriptor of sensor
acc:3-axis acceleration [in milli grativy acceleration (mg) ]
mag:3-axis magnetic field [in degree milli Gauss (mGs) ]

Return values

  • FXOS8700_OK on success
  • FXOS8700_BUSERR on I2C communication failures
int fxos8700_read_cached(const void * dev, fxos8700_measurement_t * acc, fxos8700_measurement_t * mag)

Extended read function including caching capability.

This function will return cached values if they are within the sampling period (FXOS8700_RENEW_INTERVAL), or will trigger a new conversion, wait for the conversion to be finished and the get the results from the device.

Parameters

dev:device descriptor of sensor
acc:3-axis acceleration [in milli grativy acceleration (mg) ]
mag:3-axis magnetic field [in degree milli Gauss (mGs) ]

Return values

  • FXOS8700_OK on success
  • FXOS8700_BUSERR on I2C communication failures
struct fxos8700_params_t

Parameters needed for device initialization.

i2c.h::i2c_t i2c

I2C device that sensor is connected to.

uint8_t addr

I2C address of this particular sensor.

uint8_t acc_range

Accelerator full-scale range.

uint32_t renew_interval

Interval for cache renewal.

struct fxos8700_measurement_t

Individual 3-axis measurement.

int16_t x

x axis of 3-axis measurement

int16_t y

y axis of 3-axis measurement

int16_t z

z axis of 3-axis measurement

struct fxos8700_t

Device descriptor for a FXOS8700 device.

uint8_t config

sensor configuration including active mode

fxos8700_measurement_t acc_cached

cached 3-axis acceleration

fxos8700_measurement_t mag_cached

cached 3-axis magnetic field

uint32_t last_read_time

last time when cached data was refreshed

fxos8700_params_t p

configuration parameters