qmi8656c

package
v0.0.0-...-0087ba1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package qmi8658c provides a driver for the QMI8658C accelerometer and gyroscope made by QST Solutions.

Datasheet: https://www.qstcorp.com/upload/pdf/202202/%EF%BC%88%E5%B7%B2%E4%BC%A0%EF%BC%89QMI8658C%20datasheet%20rev%200.9.pdf

Index

Constants

View Source
const (
	// Who am I
	WHO_AM_I   = 0x00
	IDENTIFIER = 0x05

	// Configuration registers
	CTRL1 = 0x02 // SPI Modes
	CTRL2 = 0x03 // Accelerometer config
	CTRL3 = 0x04 // Gyro config
	CTRL4 = 0x05 // Magnetometer config (ignored)
	CTRL5 = 0x06 // Sensor DSP config
	CTRL6 = 0x07 // Motion on Demand (ignored)
	CTRL7 = 0x08 // Sensors config

	// Interface config (CTRL1)
	SPI_4_WIRE        = 0x00
	SPI_3_WIRE        = 0x80
	SPI_NOT_AUTO_INC  = 0x00
	SPI_AUTO_INC      = 0x40
	SPI_LITTLE_ENDIAN = 0x00
	SPI_BIG_ENDIAN    = 0x20

	// Accelerometer scale config (CTRL2-H)
	ACC_SELF_TEST = 0x80

	// Accelerometer scale config (CTRL2-H)
	ACC_2G  = 0x00
	ACC_4G  = 0x10
	ACC_8G  = 0x20
	ACC_16G = 0x30

	// Accelerometer output data rate (ODR) config (CTRL2-L)
	ACC_NORMAL_8000HZ   = 0x00
	ACC_NORMAL_4000HZ   = 0x01
	ACC_NORMAL_2000HZ   = 0x02
	ACC_NORMAL_1000HZ   = 0x03
	ACC_NORMAL_500HZ    = 0x04
	ACC_NORMAL_250HZ    = 0x05
	ACC_NORMAL_125HZ    = 0x06
	ACC_NORMAL_62HZ     = 0x07
	ACC_NORMAL_31HZ     = 0x08
	ACC_LOW_POWER_128HZ = 0x0C
	ACC_LOW_POWER_21HZ  = 0x0D
	ACC_LOW_POWER_11HZ  = 0x0E
	ACC_LOW_POWER_3HZ   = 0x0F

	// Gyro scale config (CTRL3-H)
	GYRO_SELF_TEST = 0x80

	// Gyro scale config (CTRL3-H)
	GYRO_16DPS   = 0x00
	GYRO_32DPS   = 0x10
	GYRO_64DPS   = 0x20
	GYRO_128DPS  = 0x30
	GYRO_256DPS  = 0x40
	GYRO_512DPS  = 0x50
	GYRO_1024DPS = 0x60
	GYRO_2048DPS = 0x70

	// Gyro output data rate (ODR) config (CTRL3-L)
	GYRO_8000HZ = 0x00
	GYRO_4000HZ = 0x01
	GYRO_2000HZ = 0x02
	GYRO_1000HZ = 0x03
	GYRO_500HZ  = 0x04
	GYRO_250HZ  = 0x05
	GYRO_125HZ  = 0x06
	GYRO_62HZ   = 0x07
	GYRO_31HZ   = 0x08

	// Gyro DSP config (CTRL4-H)
	GYRO_LOW_PASS_OFF  = 0x00 // Disabled
	GYRO_LOW_PASS_2_62 = 0x10 // 2.62% of output data rate (ODR)
	GYRO_LOW_PASS_3_59 = 0x30 // 3.59% of output data rate (ODR)
	GYRO_LOW_PASS_5_32 = 0x50 // 5.32% of output data rate (ODR)
	GYRO_LOW_PASS_14   = 0x70 // 14% of output data rate (ODR)

	// Accelerometer DSP config (CTRL4-L)
	ACC_LOW_PASS_OFF  = 0x00 // Disabled
	ACC_LOW_PASS_2_62 = 0x01 // 2.62% of output data rate (ODR)
	ACC_LOW_PASS_3_59 = 0x03 // 3.59% of output data rate (ODR)
	ACC_LOW_PASS_5_32 = 0x05 // 5.32% of output data rate (ODR)
	ACC_LOW_PASS_14   = 0x07 // 14% of output data rate (ODR)

	// Motion on demand (MOD) (CTRL6)
	MOD_DISABLE = 0x00
	MOD_ENABLE  = 0x80

	// Enable sensors (CTRL7)
	GYRO_DISABLE       = 0x00
	GYRO_FULL_ENABLE   = 0x02
	GYRO_SNOOZE_ENABLE = 0x12
	ACC_DISABLE        = 0x00
	ACC_ENABLE         = 0x01

	// Timestamp Outputs Register Adresses
	TIMESTAMP_OUT_L = 0x30
	TIMESTAMP_OUT_M = 0x31
	TIMESTAMP_OUT_H = 0x32

	// Temperature Outputs Register Adresses
	TEMP_OUT_L = 0x33
	TEMP_OUT_H = 0x34

	// Acceleration Outputs Register Adresses
	ACC_XOUT_L = 0x35
	ACC_XOUT_H = 0x36
	ACC_YOUT_L = 0x37
	ACC_YOUT_H = 0x38
	ACC_ZOUT_L = 0x39
	ACC_ZOUT_H = 0x3A

	// Angular Rate Outputs Register Adresses
	GYRO_XOUT_L = 0x3B
	GYRO_XOUT_H = 0x3C
	GYRO_YOUT_L = 0x3D
	GYRO_YOUT_H = 0x3E
	GYRO_ZOUT_L = 0x3F
	GYRO_ZOUT_H = 0x40

	// Quaternion Outputs Register Adresses
	DELTA_QUAT_WOUT_L = 0x49
	DELTA_QUAT_WOUT_H = 0x4A
	DELTA_QUAT_XOUT_L = 0x4B
	DELTA_QUAT_XOUT_H = 0x4C
	DELTA_QUAT_YOUT_L = 0x4D
	DELTA_QUAT_YOUT_H = 0x4E
	DELTA_QUAT_ZOUT_L = 0x4F
	DELTA_QUAT_ZOUT_H = 0x50

	// Delta Velocity Outputs Register Adresses
	DELTA_VEL_XOUT_L = 0x51
	DELTA_VEL_XOUT_H = 0x52
	DELTA_VEL_YOUT_L = 0x53
	DELTA_VEL_YOUT_H = 0x54
	DELTA_VEL_ZOUT_L = 0x55
	DELTA_VEL_ZOUT_H = 0x56
)
View Source
const Address = 0x6B

The I2C address that the sensor listens to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// SPI Config
	SPIMode    byte // One of SPI_X_WIRE
	SPIEndian  byte // One of SPI_XXX_ENDIAN
	SPIAutoInc byte // One of SPI_NOT_AUTO_INC or SPI_AUTO_INC
	// Accelerometer
	AccEnable  byte // One of ACC_ENABLE or ACC_DISABLE
	AccScale   byte // One of ACC_XG
	AccRate    byte // One of ACC_XX_YYHZ
	AccLowPass byte // One of ACC_LOW_PASS_X
	// Gyro
	GyroEnable  byte // One of GYRO_X_ENABLE or GYRO_DISABLE
	GyroScale   byte // One of GYRO_XDPS
	GyroRate    byte // One of GYRO_X_YHZ
	GyroLowPass byte // One of GYRO_LOW_PASS_X
}

func DefaultConfig

func DefaultConfig() (cfg Config)

Create a basic default configuration that works with the "WaveShare RP2040 Round LCD 1.28in".

type Device

type Device struct {
	Address    uint16
	AccLsbDiv  uint16
	GyroLsbDiv uint16
	// contains filtered or unexported fields
}

Device wraps the I2C connection to the QMIC8658 sensor

func New

func New(bus drivers.I2C) Device

Create a new device with the I2C passed, correct address and nil values for AccLsbDiv and GyroLsbDiv, which will be corrected based on the config.

func (*Device) Configure

func (d *Device) Configure(cfg Config)

Check if the user has defined a desired configuration, if not uses the DefaultConfig, then defines the AccLsbDiv and GyroLsbDiv based on the configurations and, finally, send the commands and configure the IMU.

func (*Device) Connected

func (d *Device) Connected() bool

Check if the device is connected by calling WHO_AM_I and checking the default identifier.

func (*Device) ReadAcceleration

func (d *Device) ReadAcceleration() (x int32, y int32, z int32)

Read the acceleration from the sensor, the values returned are in mg (milli gravity), which means that 1000 = 1g.

func (*Device) ReadRegister

func (d *Device) ReadRegister(reg uint8, buf []byte) error

Convenience method to read the register and avoid repetition.

func (*Device) ReadRotation

func (d *Device) ReadRotation() (x int32, y int32, z int32)

Read the rotation from the sensor, the values returned are in mdeg/sec (milli degress/second), which means that a full rotation is 360000.

func (*Device) ReadTemperature

func (d *Device) ReadTemperature() (int32, error)

Read the temperature from the sensor, the values returned are in millidegrees Celsius.

func (*Device) WriteRegister

func (d *Device) WriteRegister(reg uint8, v uint16) error

Convenience method to write the register and avoid repetition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL