Loading...
Searching...
No Matches

Driver for the QMA6100P 3-Axis accelerometer. More...

Detailed Description

Driver for the QMA6100P 3-Axis accelerometer.

The driver will initialize the accelerometer for best resolution. After the initialization the accelerometer will make measurements at periodic times. The measurements period and scale range can be determined by accelerometer initialization. This driver only implements basic functionality: data-ready interrupt support only (no tap, motion, step, or FIFO interrupts).

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

Files

file  qma6100p.h
 Interface definition for the QMA6100P accelerometer driver.
 
file  qma6100p_params.h
 Default configuration for the QST QMA6100P accelerometer.
 
file  qma6100p_regs.h
 Register definitions for the QST QMA6100P accelerometer.
 

Data Structures

struct  qma6100p_params_t
 Configuration parameters. More...
 
struct  qma6100p_t
 Device descriptor for QMA6100P accelerometer. More...
 
struct  qma6100p_raw_data_t
 Raw 14-bit acceleration data (ADC counts) More...
 
struct  qma6100p_data_t
 Converted acceleration data in µg. More...
 

Typedefs

typedef void(* qma6100p_int_cb_t) (void *)
 QMA6100P interrupt callback.
 

Enumerations

enum  {
  QMA6100P_OK = 0 , QMA6100P_DATA_READY = 1 , QMA6100P_NO_NEW_DATA = 2 , QMA6100P_NOI2C = -1 ,
  QMA6100P_NODEV = -2 , QMA6100P_INVALID_ARG = -3 , QMA6100P_GPIO_ERROR = -4 , QMA6100P_TIMEOUT = -5
}
 Named return values. More...
 
enum  qma6100p_range_t {
  QMA6100P_RANGE_2G = 0x01 , QMA6100P_RANGE_4G = 0x02 , QMA6100P_RANGE_8G = 0x04 , QMA6100P_RANGE_16G = 0x08 ,
  QMA6100P_RANGE_32G = 0x0F
}
 Full-scale range selection for the QMA6100P accelerometer. More...
 
enum  qma6100p_odr_t {
  QMA6100P_ODR_100HZ = 0x00 , QMA6100P_ODR_200HZ = 0x01 , QMA6100P_ODR_400HZ = 0x02 , QMA6100P_ODR_800HZ = 0x03 ,
  QMA6100P_ODR_1600HZ = 0x04 , QMA6100P_ODR_50HZ = 0x05 , QMA6100P_ODR_25HZ = 0x06 , QMA6100P_ODR_12HZ5 = 0x07
}
 Output data rate selection. More...
 
enum  qma6100p_mclk_t { QMA6100P_PM_MCLK_51K2 = 4 , QMA6100P_PM_MCLK_25K6 = 5 , QMA6100P_PM_MCLK_12K8 = 6 , QMA6100P_PM_MCLK_6K4 = 7 }
 Master Clock selection. More...
 
enum  qma6100p_int_pin_mode_t { QMA6100P_INTPIN_PUSH_PULL = 0 , QMA6100P_INTPIN_OPEN_DRAIN = 1 }
 INT pin output mode (INTPIN_CONF, 0x20) More...
 
enum  qma6100p_int_active_level_t { QMA6100P_INTPIN_ACTIVE_LOW = 0 , QMA6100P_INTPIN_ACTIVE_HIGH = 1 }
 INT pin active level (INTPIN_CONF, 0x20) More...
 
enum  qma6100p_int_shadow_t { QMA6100P_INT_CFG_SHADOW_EN = 0 , QMA6100P_INT_CFG_SHADOW_DIS = 1 }
 Data shadowing mode (INT_CFG, 0x21) More...
 
enum  qma6100p_int_pin_num_t { QMA6100P_INT1 = 1 , QMA6100P_INT2 = 2 }
 Interrupt pin number selection (INT1_MAP1 0x1A / INT2_MAP1 0x1C) More...
 

Functions

int qma6100p_init (qma6100p_t *dev, const qma6100p_params_t *params)
 Initialize the QMA6100P accelerometer driver.
 
int qma6100p_set_low_power (qma6100p_t *dev)
 Enter Ultra-Low Power State (ULPS)
 
int qma6100p_set_active_mode (qma6100p_t *dev)
 Enter active mode.
 
int qma6100p_read_raw (const qma6100p_t *dev, qma6100p_raw_data_t *data)
 Read raw accelerometer data (ADC counts)
 
int qma6100p_read (const qma6100p_t *dev, qma6100p_data_t *data)
 Read accelerometer data converted to ug.
 
int qma6100p_set_data_ready_int (qma6100p_t *dev, qma6100p_int_pin_num_t line, qma6100p_int_cb_t cb, void *arg)
 Configure data-ready interrupt.
 

Typedef Documentation

◆ qma6100p_int_cb_t

typedef void(* qma6100p_int_cb_t) (void *)

QMA6100P interrupt callback.

Definition at line 104 of file qma6100p.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Named return values.

Enumerator
QMA6100P_OK 

everything was fine

QMA6100P_DATA_READY 

new data ready to be read

QMA6100P_NO_NEW_DATA 

no new data available (normal polling state)

QMA6100P_NOI2C 

I2C communication failed.

QMA6100P_NODEV 

no QMA6100P device found on the bus

QMA6100P_INVALID_ARG 

invalid argument

QMA6100P_GPIO_ERROR 

GPIO error.

QMA6100P_TIMEOUT 

operation timed out

Definition at line 45 of file qma6100p.h.

◆ qma6100p_int_active_level_t

INT pin active level (INTPIN_CONF, 0x20)

Enumerator
QMA6100P_INTPIN_ACTIVE_LOW 

INT pin active LOW on interrupt.

QMA6100P_INTPIN_ACTIVE_HIGH 

INT pin active HIGH on interrupt.

Definition at line 117 of file qma6100p.h.

◆ qma6100p_int_pin_mode_t

INT pin output mode (INTPIN_CONF, 0x20)

Enumerator
QMA6100P_INTPIN_PUSH_PULL 

INT pin push-pull mode.

QMA6100P_INTPIN_OPEN_DRAIN 

INT pin open-drain mode.

Definition at line 109 of file qma6100p.h.

◆ qma6100p_int_pin_num_t

Interrupt pin number selection (INT1_MAP1 0x1A / INT2_MAP1 0x1C)

Enumerator
QMA6100P_INT1 

Use INT1 pin for interrupt output.

QMA6100P_INT2 

Use INT2 pin for interrupt output.

Definition at line 137 of file qma6100p.h.

◆ qma6100p_int_shadow_t

Data shadowing mode (INT_CFG, 0x21)

Enumerator
QMA6100P_INT_CFG_SHADOW_EN 

shadowing enabled: lock the MSB content while the LSB is read so both bytes belong to the same sample, preserving acceleration data integrity (default)

QMA6100P_INT_CFG_SHADOW_DIS 

shadowing disabled: no lock, MSB/LSB may come from different samples

Definition at line 125 of file qma6100p.h.

◆ qma6100p_mclk_t

Master Clock selection.

Master clock is controlled by PM_REGISTER (0x11) and can be set through I2C commands.

Note
By default, QMA6100P has a 51.2kHz clock rate after init sequence.
Enumerator
QMA6100P_PM_MCLK_51K2 

51.2 kHz (default)

QMA6100P_PM_MCLK_25K6 

25.6 kHz

QMA6100P_PM_MCLK_12K8 

12.8 kHz

QMA6100P_PM_MCLK_6K4 

6.4 kHz

Definition at line 94 of file qma6100p.h.

◆ qma6100p_odr_t

Output data rate selection.

Values map directly to bits[4:0] of the ODR register (0x10) Assumes MCLK=51.2kHz (default after init sequence)

Enumerator
QMA6100P_ODR_100HZ 

100 Hz (default)

QMA6100P_ODR_200HZ 

200 Hz

QMA6100P_ODR_400HZ 

400 Hz

QMA6100P_ODR_800HZ 

800 Hz

QMA6100P_ODR_1600HZ 

1600 Hz

QMA6100P_ODR_50HZ 

50 Hz

QMA6100P_ODR_25HZ 

25 Hz

QMA6100P_ODR_12HZ5 

12.5 Hz

Definition at line 76 of file qma6100p.h.

◆ qma6100p_range_t

Full-scale range selection for the QMA6100P accelerometer.

Values map directly to bits[3:0] of the RANGE register (0x0F) Higher range = lower sensitivity

Enumerator
QMA6100P_RANGE_2G 

±2g - sensitivity 4096 LSB/g

QMA6100P_RANGE_4G 

±4g - sensitivity 2048 LSB/g

QMA6100P_RANGE_8G 

±8g - sensitivity 1024 LSB/g

QMA6100P_RANGE_16G 

±16g - sensitivity 512 LSB/g

QMA6100P_RANGE_32G 

±32g - sensitivity 256 LSB/g

Definition at line 62 of file qma6100p.h.

Function Documentation

◆ qma6100p_init()

int qma6100p_init ( qma6100p_t * dev,
const qma6100p_params_t * params )

Initialize the QMA6100P accelerometer driver.

Runs the init sequence, sets ODR, range and master clock from params.

The device is left in active mode; call qma6100p_set_low_power afterwards to enter Ultra-Low Power State (ULPS) if needed.

Parameters
[out]devdevice descriptor of accelerometer to initialize
[in]paramsconfiguration parameters
Return values
QMA6100P_OKon success
QMA6100P_NOI2Cif initialization of I2C bus failed
QMA6100P_NODEVif accelerometer test failed

◆ qma6100p_read()

int qma6100p_read ( const qma6100p_t * dev,
qma6100p_data_t * data )

Read accelerometer data converted to ug.

Converts raw counts using the configured range sensitivity.

Parameters
[in]devdevice descriptor of accelerometer
[out]dataacceleration in ug per axis
Return values
QMA6100P_NO_NEW_DATANo new measurement data is available, the data structure remains unchanged.

◆ qma6100p_read_raw()

int qma6100p_read_raw ( const qma6100p_t * dev,
qma6100p_raw_data_t * data )

Read raw accelerometer data (ADC counts)

Parameters
[in]devdevice descriptor of accelerometer
[out]dataraw ADC counts per axis
Return values
QMA6100P_NO_NEW_DATANo new measurement data is available, the data structure remains unchanged.

◆ qma6100p_set_active_mode()

int qma6100p_set_active_mode ( qma6100p_t * dev)

Enter active mode.

Exits Ultra-Low Power State (ULPS) and restores the configured parameters.

Parameters
[in,out]devdevice descriptor of accelerometer
Return values
QMA6100P_OKon success
QMA6100P_NOI2Cif I2C transaction failed
QMA6100P_NODEVif device not found on bus

◆ qma6100p_set_data_ready_int()

int qma6100p_set_data_ready_int ( qma6100p_t * dev,
qma6100p_int_pin_num_t line,
qma6100p_int_cb_t cb,
void * arg )

Configure data-ready interrupt.

Writes INTPIN_CONF, INTx_MAP1, and INT_EN1 registers to route the data-ready event to the line INT pin, then arms the matching MCU GPIO ISR (qma6100p_params_t::int1_pin / qma6100p_params_t::int2_pin).

Parameters
[in,out]devdevice descriptor of accelerometer
[in]lineINT line to route the data-ready event to (QMA6100P_INT1 or QMA6100P_INT2)
[in]cbcallback invoked when the data-ready event fires
[in]argargument passed to cb
Return values
QMA6100P_OKon success
QMA6100P_GPIO_ERRORif the line's GPIO is unwired or initialization failed
QMA6100P_INVALID_ARGif line is invalid
QMA6100P_NOI2Cif I2C transaction failed
QMA6100P_NODEVif device not found on bus
Warning
The callback is invoked from interrupt context, keep it short

◆ qma6100p_set_low_power()

int qma6100p_set_low_power ( qma6100p_t * dev)

Enter Ultra-Low Power State (ULPS)

Parameters
[in,out]devdevice descriptor of accelerometer
Return values
QMA6100P_OKon success
QMA6100P_NOI2Cif I2C transaction failed
QMA6100P_NODEVif device not found on bus