201 lines
6.0 KiB
C
201 lines
6.0 KiB
C
/**
|
|
* @file include/di_fw/drv/lsm9ds0.h
|
|
* @brief LSM9DS0 header file
|
|
* @date april 20, 2016
|
|
* @author A.A.W.M. Ruijs
|
|
* @copyright 2016 Dual Inventive Technology Centre B.V.
|
|
*/
|
|
#ifndef INCLUDE_DI_FW_DRV_LSM9DS0_H_
|
|
#define INCLUDE_DI_FW_DRV_LSM9DS0_H_
|
|
|
|
#include <stdint.h>
|
|
#include "di_fw/os.h"
|
|
#include "di/types.h"
|
|
|
|
/* mask for LSM9DS0 address */
|
|
#define LSM9DS0_ADDRESS_MASK 0x3F
|
|
|
|
/* read/write modes for LSM9DS0 */
|
|
#define LSM9DS0_WRITE_MODE 0x00
|
|
#define LSM9DS0_READ_MODE 0x80
|
|
#define LSM9DS0_MULTI_WRITE_MODE 0x40
|
|
#define LSM9DS0_MULTI_READ_MODE 0xC0
|
|
|
|
/* sensor ID for LSM9DS0*/
|
|
#define LSM9DS0_ID_XM (0x49)
|
|
|
|
/* LSM9DS0 magnet output registers */
|
|
#define LSM9DS0_STATUS_REG_M 0x07
|
|
#define LSM9DS0_OUT_X_L_M 0x08
|
|
#define LSM9DS0_OUT_X_H_M 0x09
|
|
#define LSM9DS0_OUT_Y_L_M 0x0A
|
|
#define LSM9DS0_OUT_Y_H_M 0x0B
|
|
#define LSM9DS0_OUT_Z_L_M 0x0C
|
|
#define LSM9DS0_OUT_Z_H_M 0x0D
|
|
|
|
/* LSM9DS0 accelerometer output registers */
|
|
#define LSM9DS0_STATUS_REG_A 0x27
|
|
#define LSM9DS0_OUT_X_L_A 0x28
|
|
#define LSM9DS0_OUT_X_H_A 0x29
|
|
#define LSM9DS0_OUT_Y_L_A 0x2A
|
|
#define LSM9DS0_OUT_Y_H_A 0x2B
|
|
#define LSM9DS0_OUT_Z_L_A 0x2C
|
|
#define LSM9DS0_OUT_Z_H_A 0x2D
|
|
|
|
/* LSM9DS0 offset registers */
|
|
#define LSM9DS0_OFFSET_X_L_M 0x16
|
|
#define LSM9DS0_OFFSET_X_H_M 0x17
|
|
#define LSM9DS0_OFFSET_Y_L_M 0x18
|
|
#define LSM9DS0_OFFSET_Y_H_M 0x19
|
|
#define LSM9DS0_OFFSET_Z_L_M 0x1A
|
|
#define LSM9DS0_OFFSET_Z_H_M 0x1B
|
|
|
|
/* LSM9DS0 accelerometer + magnetometer registers */
|
|
#define LSM9DS0_WHO_AM_I_XM 0x0F
|
|
#define LSM9DS0_CTRL_REG1_XM 0x20
|
|
#define LSM9DS0_CTRL_REG2_XM 0x21
|
|
#define LSM9DS0_CTRL_REG3_XM 0x22
|
|
#define LSM9DS0_CTRL_REG4_XM 0x23
|
|
#define LSM9DS0_CTRL_REG5_XM 0x24
|
|
#define LSM9DS0_CTRL_REG6_XM 0x25
|
|
#define LSM9DS0_CTRL_REG7_XM 0x26
|
|
|
|
/* Linear Acceleration: to make mg per lsb*/
|
|
#define LSM9DS0_ACCEL_BIT_PER_DEGREE_2G 11
|
|
#define LSM9DS0_ACC_SENSITIVITY_2G (0.061F)
|
|
#define LSM9DS0_ACC_SENSITIVITY_4G (0.122F)
|
|
#define LSM9DS0_ACC_SENSITIVITY_6G (0.183F)
|
|
#define LSM9DS0_ACC_SENSITIVITY_8G (0.244F)
|
|
#define LSM9DS0_ACC_SENSITIVITY_16G (0.732F)
|
|
|
|
/* Magnetic Field Strength: gause range */
|
|
#define LSM9DS0_MAGN_SENSITIVITY_2GAUSS (0.08F)
|
|
#define LSM9DS0_MAGN_SENSITIVITY_4GAUSS (0.16F)
|
|
#define LSM9DS0_MAGN_SENSITIVITY_8GAUSS (0.32F)
|
|
#define LSM9DS0_MAGN_SENSITIVITY_12GAUSS (0.48F)
|
|
|
|
/* Scale masks for the sensors */
|
|
#define DI_FW_LSM9DS0_ACCEL_SCALE_MASK 0x38
|
|
#define DI_FW_LSM9DS0_MAGN_SCALE_MASK 0x60
|
|
|
|
/* set of accelerometer full scale settings */
|
|
enum di_fw_lsm9ds0_accel_scale {
|
|
DI_FW_LSM9DS0_ACCEL_SCALE_2G = 0x00 << 3,
|
|
DI_FW_LSM9DS0_ACCEL_SCALE_4G = 0x01 << 3,
|
|
DI_FW_LSM9DS0_ACCEL_SCALE_6G = 0x02 << 3,
|
|
DI_FW_LSM9DS0_ACCEL_SCALE_8G = 0x03 << 3,
|
|
DI_FW_LSM9DS0_ACCEL_SCALE_16G = 0x04 << 3
|
|
};
|
|
|
|
/* set of accelerometer sample rates*/
|
|
enum di_fw_lsm9ds0_accel_samplerate {
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_POWERDOWN = 0X00 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_3_125Hz = 0x01 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_6_25Hz = 0x02 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_12_5Hz = 0x03 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_25Hz = 0x04 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_50Hz = 0x05 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_100Hz = 0x06 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_200Hz = 0x07 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_400Hz = 0x08 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_800Hz = 0x09 << 4,
|
|
DI_FW_LSM9DS0_ACCEL_SAMPLERATE_1600Hz = 0x0A << 4
|
|
};
|
|
|
|
/* set of accelerometer bandwidths */
|
|
enum di_fw_lsm9ds0_accel_bw {
|
|
DI_FW_LSM9DS0_ACCEL_BW_773Hz = 0,
|
|
DI_FW_LSM9DS0_ACCEL_BW_194Hz,
|
|
DI_FW_LSM9DS0_ACCEL_BW_362Hz,
|
|
DI_FW_LSM9DS0_ACCEL_BW_50Hz
|
|
};
|
|
|
|
#define DI_FW_LSM9DS0_ACCEL_BDU 0x8
|
|
|
|
/* set of axes for accelerometer */
|
|
enum di_fw_lsm9ds0_accel_axes {
|
|
DI_FW_LSM9DS0_ACCEL_X_DISABLE = 0x00,
|
|
DI_FW_LSM9DS0_ACCEL_Y_DISABLE = 0x00 << 1,
|
|
DI_FW_LSM9DS0_ACCEL_Z_DISABLE = 0x00 << 2,
|
|
DI_FW_LSM9DS0_ACCEL_X_ENABLE = 0x01,
|
|
DI_FW_LSM9DS0_ACCEL_Y_ENABLE = 0x01 << 1,
|
|
DI_FW_LSM9DS0_ACCEL_Z_ENABLE = 0x01 << 2
|
|
};
|
|
|
|
/* set of magnet full scale settings */
|
|
enum di_fw_lsm9ds0_magn_scale {
|
|
DI_FW_LSM9DS0_MAGN_SCALE_2G = 0x00 << 5,
|
|
DI_FW_LSM9DS0_MAGN_SCALE_4G = 0x01 << 5,
|
|
DI_FW_LSM9DS0_MAGN_SCALE_8G = 0x02 << 5,
|
|
DI_FW_LSM9DS0_MAGN_SCALE_12G = 0x03 << 5
|
|
};
|
|
|
|
/* set of magnet sample rates*/
|
|
enum di_fw_lsm9ds0_magn_samplerate {
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_3_125Hz = 0x00 << 2,
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_6_25Hz = 0x01 << 2,
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_12_5Hz = 0x02 << 2,
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_25Hz = 0x03 << 2,
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_50Hz = 0x04 << 2,
|
|
DI_FW_LSM9DS0_MAGN_SAMPLERATE_100Hz = 0x05 << 2
|
|
};
|
|
|
|
/* set of magnet resolutions */
|
|
enum di_fw_lsm9ds0_magn_res {
|
|
DI_FW_LSM9DS0_MAGN_RES_LOW = 0x00 << 5,
|
|
DI_FW_LSM9DS0_MAGN_RES_HIGH = 0x03 << 5
|
|
};
|
|
|
|
/* set of magnet mode */
|
|
enum di_fw_lsm9ds0_magn_mode {
|
|
DI_FW_LSM9DS0_MAGN_MODE_CONTINUOUS = 0x00
|
|
};
|
|
|
|
/* set of accelerometer position struct */
|
|
struct lsm9ds0_vector {
|
|
int16_t x;
|
|
int16_t y;
|
|
int16_t z;
|
|
};
|
|
|
|
/* set of magnet position struct */
|
|
struct lsm9ds0_vector_magnet {
|
|
int8_t x;
|
|
int8_t y;
|
|
int8_t z;
|
|
};
|
|
|
|
/**
|
|
* Setup for the accelerometer
|
|
* @param scale the scale that the accelerometer needs to be set to
|
|
*/
|
|
void di_fw_lsm9ds0_setup_accel(enum di_fw_lsm9ds0_accel_scale scale);
|
|
|
|
/**
|
|
* Setup for the magnetometer
|
|
* @param scale the scale that the magnetometer needs to be set to
|
|
*/
|
|
void di_fw_lsm9ds0_setup_magnet(enum di_fw_lsm9ds0_magn_scale scale);
|
|
|
|
/**
|
|
* Read the Registers for the accelerometer
|
|
* @param val pointer to where the value needs to be written
|
|
*/
|
|
void di_fw_lsm9ds0_read_accel(struct lsm9ds0_vector *val);
|
|
|
|
/**
|
|
* Read the Registers for the magnetometer
|
|
* @param val pointer to where the value needs to be written
|
|
*/
|
|
void di_fw_lsm9ds0_read_magnet(struct lsm9ds0_vector_magnet *val);
|
|
|
|
/**
|
|
* Initiate the LSM9DS0 registers to the right values
|
|
* @param accel_rate sample rate of accelerometer
|
|
* @param magn_rate sample rate of magnetometer
|
|
*/
|
|
di_errno_t di_fw_lsm9ds0_init(enum di_fw_lsm9ds0_accel_samplerate accel_rate,
|
|
enum di_fw_lsm9ds0_magn_samplerate magn_rate);
|
|
|
|
#endif /* INCLUDE_DI_FW_DRV_LSM9DS0_H_ */
|