Loading...
Searching...
No Matches

Device driver for the QMI8658 6D MEMS inertial measurement unit (IMU) More...

Detailed Description

Device driver for the QMI8658 6D MEMS inertial measurement unit (IMU)

This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.

About

This module provides a device driver for the QMI8658 interial measurement unit (IMU) by QST. This driver exposes accelerometer, gyroscope and temperature sensor data in several operating modes of the device (qmi8658_mode_t). This driver also supports the tap detection feature of the QMI8658. Currently, only the I2C interface is supported (the sensor also has SPI and I3C). Programmable interrupts via the INT1 and INT2 pins are currently also not supported.

Configuration

This driver is configurable via the parameters in qmi8658_params.h:

Usage

Use the qmi8658_init function to initialize the device. This will configure the device but not enable any sensors. Use qmi8658_set_mode to select an operating mode for the device, which enables the corresponding sensors in the chosen power mode. Now the sensor values can be polled using the functions qmi8658_read_acc, qmi8658_read_gyro and qmi8658_read_temp.

Tap detection

Tap detection only works while the accelerometer is enabled. After initializing the device, tap detection can be enabled with qmi8658_enable_tap. Tap data can then be polled using qmi8658_read_tap. See qmi8658_tap_data_t for a description of the tap data fields.

Files

file  qmi8658.h
 
file  qmi8658_constants.h
 Internal addresses, registers and constants.
 
file  qmi8658_params.h
 Default configuration.
 

Data Structures

struct  qmi8658_params_t
 Device initialization parameters. More...
 
struct  qmi8658_t
 Device descriptor for the driver. More...
 
struct  qmi8658_3d_data_t
 3D output data More...
 
struct  qmi8658_tap_data_t
 Tap detection data. More...
 

Enumerations

enum  qmi8658_odr_t {
  QMI8658_DATA_RATE_8KHZ = 0x00 , QMI8658_DATA_RATE_4KHZ = 0x01 , QMI8658_DATA_RATE_2KHZ = 0x02 , QMI8658_DATA_RATE_1KHZ = 0x03 ,
  QMI8658_DATA_RATE_500HZ = 0x04 , QMI8658_DATA_RATE_250HZ = 0x05 , QMI8658_DATA_RATE_125HZ = 0x06 , QMI8658_DATA_RATE_62_5HZ = 0x07 ,
  QMI8658_DATA_RATE_31_25HZ = 0x08
}
 Data rate settings. More...
 
enum  qmi8658_acc_lowpwr_odr_t { QMI8658_ACC_LOWPWR_DATA_RATE_128HZ = 0x0C , QMI8658_ACC_LOWPWR_DATA_RATE_21HZ = 0x0D , QMI8658_ACC_LOWPWR_DATA_RATE_11HZ = 0x0E , QMI8658_ACC_LOWPWR_DATA_RATE_3HZ = 0x0F }
 Accelerometer low power data rate settings. More...
 
enum  qmi8658_acc_fs_t { QMI8658_ACC_FS_2G = 0x00 , QMI8658_ACC_FS_4G = 0x01 , QMI8658_ACC_FS_8G = 0x02 , QMI8658_ACC_FS_16G = 0x03 }
 Accelerometer full scale. More...
 
enum  qmi8658_gyro_fs_t {
  QMI8658_GYRO_FS_16DPS = 0x00 , QMI8658_GYRO_FS_32DPS = 0x01 , QMI8658_GYRO_FS_64DPS = 0x02 , QMI8658_GYRO_FS_128DPS = 0x03 ,
  QMI8658_GYRO_FS_256DPS = 0x04 , QMI8658_GYRO_FS_512DPS = 0x05 , QMI8658_GYRO_FS_1024DPS = 0x06 , QMI8658_GYRO_FS_2048DPS = 0x07
}
 Gyroscope full scale. More...
 
enum  qmi8658_tap_prio_t {
  QMI8658_TAP_PRIO_XYZ = 0 , QMI8658_TAP_PRIO_XZY = 1 , QMI8658_TAP_PRIO_YXZ = 2 , QMI8658_TAP_PRIO_YZX = 3 ,
  QMI8658_TAP_PRIO_ZXY = 4 , QMI8658_TAP_PRIO_ZYX = 5
}
 Tap axis priorities. More...
 
enum  qmi8658_mode_t {
  QMI8658_POWER_DOWN , QMI8658_NORMAL_ACC , QMI8658_NORMAL_GYRO , QMI8658_NORMAL_ACC_GYRO ,
  QMI8658_LOWPWR_ACC
}
 QMI8658 operating modes. More...
 
enum  qmi8658_axis_t { QMI8658_X_AXIS = 1 , QMI8658_Y_AXIS = 2 , QMI8658_Z_AXIS = 3 }
 QMI8658 axis identifiers. More...
 
enum  qmi8658_enable_flag_t { QMI8658_DISABLE_ALL = 0 , QMI8658_ENABLE_ACC = 1 , QMI8658_ENABLE_GYRO = 2 }
 Enable sensor flags. More...
 

Functions

int qmi8658_init (qmi8658_t *dev, const qmi8658_params_t *params)
 Initialize the given device.
 
int qmi8658_set_mode (qmi8658_t *dev, qmi8658_mode_t mode)
 Set the operating mode of the device.
 
int qmi8658_enable_tap (const qmi8658_t *dev)
 Enable the tap detection engine.
 
int qmi8658_disable_tap (const qmi8658_t *dev)
 Disable the tap detection engine.
 
int qmi8658_read_acc (const qmi8658_t *dev, qmi8658_3d_data_t *data)
 Read accelerometer data in mg.
 
int qmi8658_read_gyro (const qmi8658_t *dev, qmi8658_3d_data_t *data)
 Read gyroscope data in dps.
 
int qmi8658_read_temp (const qmi8658_t *dev, int16_t *data)
 Read temperature data in degC x 100.
 
int qmi8658_read_tap (const qmi8658_t *dev, qmi8658_tap_data_t *data)
 Read tap detection data.
 
#define CONFIG_QMI8658_PARAM_I2C   0x6B
 QMI8658 IMU driver compile configuration.
 

Macro Definition Documentation

◆ CONFIG_QMI8658_PARAM_I2C

#define CONFIG_QMI8658_PARAM_I2C   0x6B

QMI8658 IMU driver compile configuration.

Definition at line 65 of file qmi8658.h.

Enumeration Type Documentation

◆ qmi8658_acc_fs_t

Accelerometer full scale.

Definition at line 104 of file qmi8658.h.

◆ qmi8658_acc_lowpwr_odr_t

Accelerometer low power data rate settings.

Available Accelerometer ODRs when low power mode is activated.

Definition at line 94 of file qmi8658.h.

◆ qmi8658_axis_t

QMI8658 axis identifiers.

Enumerator
QMI8658_X_AXIS 

Sensor X axis.

QMI8658_Y_AXIS 

Sensor Y axis.

QMI8658_Z_AXIS 

Sensor Z axis.

Definition at line 153 of file qmi8658.h.

◆ qmi8658_enable_flag_t

Enable sensor flags.

Definition at line 162 of file qmi8658.h.

◆ qmi8658_gyro_fs_t

Gyroscope full scale.

Definition at line 114 of file qmi8658.h.

◆ qmi8658_mode_t

QMI8658 operating modes.

Enumerator
QMI8658_POWER_DOWN 

All functional blocks off, minimal power consumption.

QMI8658_NORMAL_ACC 

Accelerometer only mode (if ODR <= 1kHz, otherwise Gyro is also enabled)

QMI8658_NORMAL_GYRO 

Gyroscope only mode.

QMI8658_NORMAL_ACC_GYRO 

IMU mode (Accelerometer + Gyroscope)

QMI8658_LOWPWR_ACC 

Low power mode (Accelerometer only)

Definition at line 142 of file qmi8658.h.

◆ qmi8658_odr_t

Data rate settings.

Actual data rates are slightly lower when gyroscope is enabled. If the selected accelerometer ODR is higher than 1kHz, enabling the accelerometer will implicitly enable the gyroscope as required by hardware design.

Definition at line 77 of file qmi8658.h.

◆ qmi8658_tap_prio_t

Tap axis priorities.

Which axis to prefer in case of an ambiguous tap.

Enumerator
QMI8658_TAP_PRIO_XYZ 

X > Y > Z.

QMI8658_TAP_PRIO_XZY 

X > Z > Y.

QMI8658_TAP_PRIO_YXZ 

Y > X > Z.

QMI8658_TAP_PRIO_YZX 

Y > Z > >

QMI8658_TAP_PRIO_ZXY 

Z > X > Y.

QMI8658_TAP_PRIO_ZYX 

Z > Y > X.

Definition at line 130 of file qmi8658.h.

Function Documentation

◆ qmi8658_disable_tap()

int qmi8658_disable_tap ( const qmi8658_t * dev)

Disable the tap detection engine.

Parameters
[in]devDevice descriptor of the driver
Return values
0on success
-EIOon i2c communication error

◆ qmi8658_enable_tap()

int qmi8658_enable_tap ( const qmi8658_t * dev)

Enable the tap detection engine.

Note
Tap detection requires the accelerometer to be enabled in normal mode (QMI8658_NORMAL_ACC or QMI8658_NORMAL_ACC_GYRO).
This function can be called before or after qmi8658_set_mode, tap data is only generated once the accelerometer is active.
Accelerometer ODR is recommended to be set higher than 200Hz.
Parameters
[in]devDevice descriptor of the driver
Return values
0on success
-EPERMif driver was never initialized
-EIOon i2c communication error

◆ qmi8658_init()

int qmi8658_init ( qmi8658_t * dev,
const qmi8658_params_t * params )

Initialize the given device.

Parameters
[in,out]devDevice descriptor of the driver
[in]paramsInitialization parameters
Return values
0on success
-EIOon error

◆ qmi8658_read_acc()

int qmi8658_read_acc ( const qmi8658_t * dev,
qmi8658_3d_data_t * data )

Read accelerometer data in mg.

Parameters
[in]devDevice descriptor of the driver
[out]dataAccelerometer data buffer
Return values
0on success
-EIOon i2c communication error

◆ qmi8658_read_gyro()

int qmi8658_read_gyro ( const qmi8658_t * dev,
qmi8658_3d_data_t * data )

Read gyroscope data in dps.

Parameters
[in]devDevice descriptor of the driver
[out]dataGyroscope data buffer
Return values
0on success
-EIOon i2c communication error

◆ qmi8658_read_tap()

int qmi8658_read_tap ( const qmi8658_t * dev,
qmi8658_tap_data_t * data )

Read tap detection data.

Parameters
[in]devDevice descriptor of the driver
[out]dataTap detection data buffer
Return values
0on success
-EIOon i2c communication error

◆ qmi8658_read_temp()

int qmi8658_read_temp ( const qmi8658_t * dev,
int16_t * data )

Read temperature data in degC x 100.

Parameters
[in]devDevice descriptor of the driver
[out]dataTemperature data buffer
Return values
0on success
-EIOon i2c communication error

◆ qmi8658_set_mode()

int qmi8658_set_mode ( qmi8658_t * dev,
qmi8658_mode_t mode )

Set the operating mode of the device.

Parameters
[in,out]devDevice descriptor of the driver
[in]modeNew mode
Return values
0on success
-EPERMif driver was never initialized
-EINVALif invalid mode is given
-EIOon i2c communication error