ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_lsm6dso.h File Reference

ST LSM6DSO 6-DoF IMU driver (accel + gyro + temperature). More...

#include <stdint.h>
#include "ra8_err.h"
Include dependency graph for ra8_lsm6dso.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ra8_lsm6dso_xyz_t
 3-axis raw sample (X, Y, Z as 16-bit two's-complement counts). More...
struct  ra8_lsm6dso_bus_t
 Transport interface bound at ra8_lsm6dso_init time. More...
struct  ra8_lsm6dso_t
 Per-instance driver state. More...

Typedefs

typedef ra8_err_t(* ra8_lsm6dso_read_fn_t) (void *ctx, uint8_t reg, uint8_t *buf, uint32_t len)
 Read len bytes from reg on the target.
typedef ra8_err_t(* ra8_lsm6dso_write_fn_t) (void *ctx, uint8_t reg, const uint8_t *buf, uint32_t len)
 Write len bytes starting at reg on the target.

Enumerations

enum  ra8_lsm6dso_const_t : uint8_t {
  k_lsm6dso_who_am_i_value = 0x6CU ,
  k_lsm6dso_fifo_words_max = 0x80U ,
  k_lsm6dso_fifo_bytes_word = 0x07U
}
 Part-level identification + sizing constants. More...
enum  ra8_lsm6dso_i2c_addr_t : uint8_t {
  k_lsm6dso_i2c_addr_sa0_low = 0x6AU ,
  k_lsm6dso_i2c_addr_sa0_high = 0x6BU
}
 Default 7-bit I2C target addresses. More...
enum  ra8_lsm6dso_reg_t : uint8_t {
  k_lsm6dso_reg_fifo_ctrl1 = 0x07U ,
  k_lsm6dso_reg_fifo_ctrl2 = 0x08U ,
  k_lsm6dso_reg_fifo_ctrl3 = 0x09U ,
  k_lsm6dso_reg_fifo_ctrl4 = 0x0AU ,
  k_lsm6dso_reg_who_am_i = 0x0FU ,
  k_lsm6dso_reg_ctrl1_xl = 0x10U ,
  k_lsm6dso_reg_ctrl2_g = 0x11U ,
  k_lsm6dso_reg_ctrl3_c = 0x12U ,
  k_lsm6dso_reg_ctrl6_c = 0x15U ,
  k_lsm6dso_reg_ctrl7_g = 0x16U ,
  k_lsm6dso_reg_out_temp_l = 0x20U ,
  k_lsm6dso_reg_outx_l_g = 0x22U ,
  k_lsm6dso_reg_outx_l_a = 0x28U ,
  k_lsm6dso_reg_fifo_status1 = 0x3AU ,
  k_lsm6dso_reg_fifo_data_out = 0x78U
}
 Register-map addresses used by this driver. More...
enum  ra8_lsm6dso_xl_fs_t : uint8_t {
  k_lsm6dso_xl_fs_2g = 0x00U ,
  k_lsm6dso_xl_fs_16g = 0x01U ,
  k_lsm6dso_xl_fs_4g = 0x02U ,
  k_lsm6dso_xl_fs_8g = 0x03U
}
 Accelerometer full-scale (FS_XL) range codes. More...
enum  ra8_lsm6dso_g_fs_t : uint8_t {
  k_lsm6dso_g_fs_125dps = 0x00U ,
  k_lsm6dso_g_fs_250dps = 0x01U ,
  k_lsm6dso_g_fs_500dps = 0x02U ,
  k_lsm6dso_g_fs_1000dps = 0x03U ,
  k_lsm6dso_g_fs_2000dps = 0x04U
}
 Gyroscope full-scale (FS_G) range codes. More...
enum  ra8_lsm6dso_odr_t : uint8_t {
  k_lsm6dso_odr_off = 0x00U ,
  k_lsm6dso_odr_12_5hz = 0x01U ,
  k_lsm6dso_odr_26hz = 0x02U ,
  k_lsm6dso_odr_52hz = 0x03U ,
  k_lsm6dso_odr_104hz = 0x04U ,
  k_lsm6dso_odr_208hz = 0x05U ,
  k_lsm6dso_odr_416hz = 0x06U ,
  k_lsm6dso_odr_833hz = 0x07U ,
  k_lsm6dso_odr_1660hz = 0x08U ,
  k_lsm6dso_odr_3330hz = 0x09U ,
  k_lsm6dso_odr_6660hz = 0x0AU
}
 Output Data Rate codes (shared between XL and G). More...

Functions

ra8_err_t ra8_lsm6dso_init (ra8_lsm6dso_t *out_dev, const ra8_lsm6dso_bus_t *bus)
 Bind a transport to a driver instance.
ra8_err_t ra8_lsm6dso_who_am_i (ra8_lsm6dso_t *dev, uint8_t *out_id)
 Read the WHO_AM_I register.
ra8_err_t ra8_lsm6dso_set_accel_range (ra8_lsm6dso_t *dev, ra8_lsm6dso_xl_fs_t fs)
 Program the accelerometer full-scale range.
ra8_err_t ra8_lsm6dso_set_gyro_range (ra8_lsm6dso_t *dev, ra8_lsm6dso_g_fs_t fs)
 Program the gyroscope full-scale range.
ra8_err_t ra8_lsm6dso_set_odr (ra8_lsm6dso_t *dev, ra8_lsm6dso_odr_t odr)
 Program the Output Data Rate for both the accelerometer and the gyroscope.
ra8_err_t ra8_lsm6dso_read_accel (ra8_lsm6dso_t *dev, ra8_lsm6dso_xyz_t *out)
 Read one accelerometer sample (raw 16-bit two's-complement).
ra8_err_t ra8_lsm6dso_read_gyro (ra8_lsm6dso_t *dev, ra8_lsm6dso_xyz_t *out)
 Read one gyroscope sample (raw 16-bit two's-complement).
ra8_err_t ra8_lsm6dso_read_temp (ra8_lsm6dso_t *dev, int32_t *out_centi_c)
 Read the on-die temperature in centi-degrees Celsius.
ra8_err_t ra8_lsm6dso_read_xl_gyro_fifo (ra8_lsm6dso_t *dev, uint8_t *out_buf, uint32_t max_words, uint32_t *out_words)
 Drain up to max_samples paired XL+G samples from the embedded FIFO.

Detailed Description

ST LSM6DSO 6-DoF IMU driver (accel + gyro + temperature).

Tag
[Ring 4 / Service] {World: NS}

Public API for a polling, transport-agnostic driver for the STMicroelectronics LSM6DSO 3-axis accelerometer + 3-axis gyroscope. The part is carried by the MikroE 6DOF IMU 12 Click (Digikey 1471-MIKROE-4073-ND); the same silicon ships on several other MEMS-sensor break-out boards as well. All register-level citations point at "LSM6DSO datasheet (ST DS12140 Rev 4)".

Transport abstraction (Dependency Inversion, see CLAUDE.md "SOLID Principles for C"):

  • The driver does not call ra8_iic_b_* or ra8_spi_* directly.
  • Instead the caller hands a ra8_lsm6dso_bus_t interface whose read_regs / write_regs callbacks address the part. The production firmware wires these to ra8_iic_b_transfer / ra8_iic_b_write (I2C) or ra8_spi_xfer8 (SPI); unit tests wire them to a software-mock transport in tests/misc/src/test_ra8_lsm6dso.c.

Surface (mirrors the deliverables list in the task brief):

The driver carries no global state outside the caller's ra8_lsm6dso_t – multiple LSM6DSO parts on different buses can coexist with one descriptor each.

Since
0.1.0

Definition in file ra8_lsm6dso.h.

Typedef Documentation

◆ ra8_lsm6dso_read_fn_t

typedef ra8_err_t(* ra8_lsm6dso_read_fn_t) (void *ctx, uint8_t reg, uint8_t *buf, uint32_t len)

Read len bytes from reg on the target.

Implementations must honor the LSM6DSO auto-increment behaviour (DS12140 sec 6.1.2 "I2C Operation") so that a multi-byte read starting at register N returns bytes from N, N+1, ... – the production I2C and SPI HAL paths do this naturally.

Parameters
[in]ctxTransport context (e.g. ra8_lsm6dso_i2c_ctx_t or ra8_lsm6dso_spi_ctx_t cast to void*).
[in]regFirst register address.
[out]bufDestination buffer (non-NULL when len > 0).
[in]lenByte count.
Returns
ra8_err_t Error code propagated from the transport.
Return values
k_ra8_okTransfer succeeded.
k_ra8_err_nackTarget NACKed (I2C) or returned a hard error (SPI).
k_ra8_err_null_ptrbuf is NULL with non-zero len.

Definition at line 238 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_write_fn_t

typedef ra8_err_t(* ra8_lsm6dso_write_fn_t) (void *ctx, uint8_t reg, const uint8_t *buf, uint32_t len)

Write len bytes starting at reg on the target.

Parameters
[in]ctxTransport context.
[in]regFirst register address.
[in]bufSource buffer (non-NULL when len > 0).
[in]lenByte count.
Returns
ra8_err_t Error code propagated from the transport.

Definition at line 251 of file ra8_lsm6dso.h.

Enumeration Type Documentation

◆ ra8_lsm6dso_const_t

enum ra8_lsm6dso_const_t : uint8_t

Part-level identification + sizing constants.

Per LSM6DSO DS12140 Rev 4 sec 9.11 "WHO_AM_I (0Fh)": the read-only device-identification register returns 0x6C (binary 0b01101100) on a healthy part. Any other value indicates a wrong part, a wired-up wrong address, or a dead bus.

Enumerator
k_lsm6dso_who_am_i_value 

WHO_AM_I expected value (DS12140 sec 9.11).

k_lsm6dso_fifo_words_max 

Default FIFO-batch cap exposed to callers.

k_lsm6dso_fifo_bytes_word 

Bytes per FIFO word (TAG + 6 data, sec 9.7).

Definition at line 78 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_g_fs_t

enum ra8_lsm6dso_g_fs_t : uint8_t

Gyroscope full-scale (FS_G) range codes.

Per DS12140 sec 9.13 "CTRL2_G (11h)" Table 47 "Gyroscope full-scale selection": FS_G[1:0] occupies CTRL2_G bits [3:2], with the FS_125 bit at bit [1] selecting the +-125 dps narrow scale. The driver folds both fields into a single enum.

Sensitivity (mdps/LSB) per FS_G = 4.375 / 8.75 / 17.5 / 35 / 70 for +-125, +-250, +-500, +-1000, +-2000 dps respectively (DS12140 Table 3).

Enumerator
k_lsm6dso_g_fs_125dps 

+-125 dps narrow scale (FS_125 = 1).

k_lsm6dso_g_fs_250dps 

+-250 dps (default).

k_lsm6dso_g_fs_500dps 

+-500 dps.

k_lsm6dso_g_fs_1000dps 

+-1000 dps.

k_lsm6dso_g_fs_2000dps 

+-2000 dps.

Definition at line 162 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_i2c_addr_t

enum ra8_lsm6dso_i2c_addr_t : uint8_t

Default 7-bit I2C target addresses.

Per DS12140 sec 6.1.1 "I2C operation": the LSM6DSO 7-bit peripheral address is 1101 010x where x is the inverted SDO/SA0 pin level. SDO/SA0 = 0 selects 0x6A; SDO/SA0 = 1 selects 0x6B. The MikroE 6DOF IMU 12 Click ties SA0 high by default (per MikroE schematic rev v100), so the default board address is 0x6B.

Enumerator
k_lsm6dso_i2c_addr_sa0_low 

SDO/SA0 tied low.

k_lsm6dso_i2c_addr_sa0_high 

SDO/SA0 tied high.

Definition at line 96 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_odr_t

enum ra8_lsm6dso_odr_t : uint8_t

Output Data Rate codes (shared between XL and G).

Per DS12140 sec 9.12 "CTRL1_XL (10h)" Table 45 (ODR_XL) and sec 9.13 "CTRL2_G (11h)" Table 48 (ODR_G): the four-bit ODR field occupies bits [7:4] of CTRL1_XL and CTRL2_G respectively. The codes are identical for both peripherals; ra8_lsm6dso_set_odr writes the chosen code into the high nibble of both CTRL1_XL and CTRL2_G.

Enumerator
k_lsm6dso_odr_off 

Power-down (default).

k_lsm6dso_odr_12_5hz 

12.5 Hz (low-power).

k_lsm6dso_odr_26hz 

26 Hz.

k_lsm6dso_odr_52hz 

52 Hz.

k_lsm6dso_odr_104hz 

104 Hz (normal mode).

k_lsm6dso_odr_208hz 

208 Hz.

k_lsm6dso_odr_416hz 

416 Hz.

k_lsm6dso_odr_833hz 

833 Hz.

k_lsm6dso_odr_1660hz 

1.66 kHz.

k_lsm6dso_odr_3330hz 

3.33 kHz.

k_lsm6dso_odr_6660hz 

6.66 kHz.

Definition at line 181 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_reg_t

enum ra8_lsm6dso_reg_t : uint8_t

Register-map addresses used by this driver.

Subset of the full LSM6DSO register map (DS12140 sec 9 "Register description"). Only registers actually accessed by the driver appear here – adding embedded-functions or pedometer registers is a future extension.

Enumerator
k_lsm6dso_reg_fifo_ctrl1 

FIFO_CTRL1 (DS12140 sec 9.6).

k_lsm6dso_reg_fifo_ctrl2 

FIFO_CTRL2 (DS12140 sec 9.7).

k_lsm6dso_reg_fifo_ctrl3 

FIFO_CTRL3 (DS12140 sec 9.8).

k_lsm6dso_reg_fifo_ctrl4 

FIFO_CTRL4 (DS12140 sec 9.9).

k_lsm6dso_reg_who_am_i 

WHO_AM_I (DS12140 sec 9.11).

k_lsm6dso_reg_ctrl1_xl 

CTRL1_XL (DS12140 sec 9.12).

k_lsm6dso_reg_ctrl2_g 

CTRL2_G (DS12140 sec 9.13).

k_lsm6dso_reg_ctrl3_c 

CTRL3_C (DS12140 sec 9.14).

k_lsm6dso_reg_ctrl6_c 

CTRL6_C (DS12140 sec 9.17).

k_lsm6dso_reg_ctrl7_g 

CTRL7_G (DS12140 sec 9.18).

k_lsm6dso_reg_out_temp_l 

OUT_TEMP_L (DS12140 sec 9.27).

k_lsm6dso_reg_outx_l_g 

OUTX_L_G (DS12140 sec 9.29).

k_lsm6dso_reg_outx_l_a 

OUTX_L_A (DS12140 sec 9.35).

k_lsm6dso_reg_fifo_status1 

FIFO_STATUS1 (DS12140 sec 9.44).

k_lsm6dso_reg_fifo_data_out 

FIFO_DATA_OUT_TAG (DS12140 sec 9.60).

Definition at line 111 of file ra8_lsm6dso.h.

◆ ra8_lsm6dso_xl_fs_t

enum ra8_lsm6dso_xl_fs_t : uint8_t

Accelerometer full-scale (FS_XL) range codes.

Per DS12140 sec 9.12 "CTRL1_XL (10h)" Table 44 "Accelerometer full-scale selection": FS_XL[1:0] occupies CTRL1_XL bits [3:2]. The numeric values below are the raw bit-field codes for FS_XL.

Sensitivity (LSB/g) per FS_XL = 0.061 / 0.122 / 0.244 / 0.488 mg/LSB for +-2, +-4, +-8, +-16 g respectively (DS12140 Table 3).

Enumerator
k_lsm6dso_xl_fs_2g 

+-2 g, sens 0.061 mg/LSB (default).

k_lsm6dso_xl_fs_16g 

+-16 g, sens 0.488 mg/LSB.

k_lsm6dso_xl_fs_4g 

+-4 g, sens 0.122 mg/LSB.

k_lsm6dso_xl_fs_8g 

+-8 g, sens 0.244 mg/LSB.

Definition at line 141 of file ra8_lsm6dso.h.

Function Documentation

◆ ra8_lsm6dso_init()

ra8_err_t ra8_lsm6dso_init ( ra8_lsm6dso_t * out_dev,
const ra8_lsm6dso_bus_t * bus )
nodiscard

Bind a transport to a driver instance.

Copies the supplied bus interface into out_dev and marks the instance initialised. Does not touch the wire – the caller is expected to follow this with ra8_lsm6dso_who_am_i (sanity check) and then ra8_lsm6dso_set_* calls to configure the part.

Parameters
[out]out_devDriver state, populated on success.
[in]busTransport interface (must have non-NULL read_regs and write_regs).
Returns
ra8_err_t Error code.
Return values
k_ra8_okDriver state initialized.
k_ra8_err_null_ptrout_dev or bus is NULL, or one of the callbacks in bus is NULL.
Precondition
out_dev points at writable storage.
bus->read_regs and bus->write_regs are non-NULL.
Postcondition
On success out_dev->initialized == true.
On success the transport is captured by value; the caller may release *bus after this returns.
Note
Not thread-safe. Call once per driver instance from init context.
Since
0.1.0

Definition at line 256 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::accel_fs_code, ra8_lsm6dso_t::bus, ra8_lsm6dso_t::gyro_fs_code, ra8_lsm6dso_t::initialized, k_lsm6dso_g_fs_250dps, k_lsm6dso_odr_off, k_lsm6dso_xl_fs_2g, k_ra8_ok, ra8_lsm6dso_t::odr_code, RA8_CHECK_NULL_PTR, ra8_lsm6dso_bus_t::read_regs, s_lsm6dso_tag, and ra8_lsm6dso_bus_t::write_regs.

Referenced by main().

◆ ra8_lsm6dso_read_accel()

ra8_err_t ra8_lsm6dso_read_accel ( ra8_lsm6dso_t * dev,
ra8_lsm6dso_xyz_t * out )
nodiscard

Read one accelerometer sample (raw 16-bit two's-complement).

Burst-reads 6 bytes starting at OUTX_L_A (0x28) into a 3x16 sample (DS12140 sec 9.35 .. 9.40). The LSM6DSO is little-endian so the bytes are combined as (high << 8) | low.

Parameters
[in]devDriver instance.
[out]out3-axis raw sample.
Returns
ra8_err_t Error code.
Return values
k_ra8_okSample read.
k_ra8_err_null_ptrdev or out is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
Caller has previously enabled the XL with ra8_lsm6dso_set_odr.
Postcondition
On success *out carries the latest XL sample.
On failure *out is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 422 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::initialized, internal_lsm6dso_read_xyz(), k_lsm6dso_reg_outx_l_a, RA8_CHECK_NULL_PTR, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_sample_and_emit().

◆ ra8_lsm6dso_read_gyro()

ra8_err_t ra8_lsm6dso_read_gyro ( ra8_lsm6dso_t * dev,
ra8_lsm6dso_xyz_t * out )
nodiscard

Read one gyroscope sample (raw 16-bit two's-complement).

Burst-reads 6 bytes starting at OUTX_L_G (0x22) into a 3x16 sample (DS12140 sec 9.29 .. 9.34). The LSM6DSO is little-endian so the bytes are combined as (high << 8) | low.

Parameters
[in]devDriver instance.
[out]out3-axis raw sample.
Returns
ra8_err_t Error code.
Return values
k_ra8_okSample read.
k_ra8_err_null_ptrdev or out is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
Caller has previously enabled the G with ra8_lsm6dso_set_odr.
Postcondition
On success *out carries the latest G sample.
On failure *out is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 431 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::initialized, internal_lsm6dso_read_xyz(), k_lsm6dso_reg_outx_l_g, RA8_CHECK_NULL_PTR, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_sample_and_emit().

◆ ra8_lsm6dso_read_temp()

ra8_err_t ra8_lsm6dso_read_temp ( ra8_lsm6dso_t * dev,
int32_t * out_centi_c )
nodiscard

Read the on-die temperature in centi-degrees Celsius.

Reads the 16-bit two's-complement OUT_TEMP register pair (0x20..0x21, DS12140 sec 9.27 / 9.28) and converts to centi-degrees Celsius using the datasheet formula T[C] = (raw / 256) + 25. Multiplied by 100 to stay in integer arithmetic the formula becomes out_centi_c = (raw * 100) / 256 + 2500, which is what the driver implements.

Parameters
[in]devDriver instance.
[out]out_centi_cReceives the temperature in centi-deg C.
Returns
ra8_err_t Error code.
Return values
k_ra8_okTemperature read.
k_ra8_err_null_ptrdev or out_centi_c is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
out_centi_c points at writable storage.
Postcondition
On success *out_centi_c carries centi-degC.
On failure *out_centi_c is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 440 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::bus, ra8_lsm6dso_bus_t::ctx, ra8_lsm6dso_t::initialized, k_lsm6dso_idx_high, k_lsm6dso_idx_low, k_lsm6dso_reg_out_temp_l, k_lsm6dso_temp_burst_bytes, k_lsm6dso_temp_offset_centi_c, k_lsm6dso_temp_scale_den, k_lsm6dso_temp_scale_num, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_VALIDATE_INIT, ra8_lsm6dso_bus_t::read_regs, and s_lsm6dso_tag.

Referenced by imu_demo_sample_and_emit().

◆ ra8_lsm6dso_read_xl_gyro_fifo()

ra8_err_t ra8_lsm6dso_read_xl_gyro_fifo ( ra8_lsm6dso_t * dev,
uint8_t * out_buf,
uint32_t max_words,
uint32_t * out_words )
nodiscard

Drain up to max_samples paired XL+G samples from the embedded FIFO.

Polls FIFO_STATUS1/2 (DS12140 sec 9.44 / 9.45) for the live sample count, then issues a burst read of FIFO_DATA_OUT_TAG (0x78, DS12140 sec 9.60 .. 9.66) for each available 7-byte FIFO word. The tag byte identifies the source (XL vs G) per Table 167 "Tag codes"; this helper returns whatever the FIFO happens to hold and lets the caller demux.

Parameters
[in]devDriver instance.
[out]out_bufDestination buffer; receives raw FIFO words laid out as [tag][b0 b1 b2 b3 b4 b5] repeated.
[in]max_wordsMaximum FIFO words the caller can store (capacity of out_buf in bytes is max_words * k_lsm6dso_fifo_bytes_word).
[out]out_wordsNumber of FIFO words actually read into out_buf.
Returns
ra8_err_t Error code.
Return values
k_ra8_okFIFO drained (possibly to zero words).
k_ra8_err_null_ptrAny of the pointers is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_invalid_argmax_words == 0.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
The FIFO has been enabled by the caller (FIFO_CTRL1..4).
Postcondition
On success *out_words <= max_words.
On failure *out_words is set to 0.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 590 of file ra8_lsm6dso.c.

References internal_lsm6dso_burst_fifo(), internal_lsm6dso_fifo_check_args(), internal_lsm6dso_read_fifo_depth(), and k_ra8_ok.

◆ ra8_lsm6dso_set_accel_range()

ra8_err_t ra8_lsm6dso_set_accel_range ( ra8_lsm6dso_t * dev,
ra8_lsm6dso_xl_fs_t fs )
nodiscard

Program the accelerometer full-scale range.

Read-modify-writes the FS_XL field in CTRL1_XL (DS12140 sec 9.12). The ODR_XL nibble is preserved by reading the current value first.

Parameters
[in,out]devDriver instance.
[in]fsRange code (one of k_lsm6dso_xl_fs_*).
Returns
ra8_err_t Error code.
Return values
k_ra8_okRange programmed.
k_ra8_err_null_ptrdev is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_invalid_argfs out of range.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
fs is one of the accel full-scale enum values.
Postcondition
On success dev->accel_fs_code == fs.
On failure dev->accel_fs_code is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 291 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::accel_fs_code, ra8_lsm6dso_t::initialized, internal_lsm6dso_read_byte(), internal_lsm6dso_write_byte(), k_lsm6dso_mask_fs_xl, k_lsm6dso_reg_ctrl1_xl, k_lsm6dso_shift_fs_xl, k_lsm6dso_xl_fs_cap, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_CHECK_RANGE_TAG, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_configure().

◆ ra8_lsm6dso_set_gyro_range()

ra8_err_t ra8_lsm6dso_set_gyro_range ( ra8_lsm6dso_t * dev,
ra8_lsm6dso_g_fs_t fs )
nodiscard

Program the gyroscope full-scale range.

Read-modify-writes the FS_G[1:0] and FS_125 fields in CTRL2_G (DS12140 sec 9.13). The ODR_G nibble is preserved by reading the current value first.

Parameters
[in,out]devDriver instance.
[in]fsRange code (one of k_lsm6dso_g_fs_*).
Returns
ra8_err_t Error code.
Return values
k_ra8_okRange programmed.
k_ra8_err_null_ptrdev is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_invalid_argfs out of range.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
fs is one of the gyro full-scale enum values.
Postcondition
On success dev->gyro_fs_code == fs.
On failure dev->gyro_fs_code is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 318 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::gyro_fs_code, ra8_lsm6dso_t::initialized, internal_lsm6dso_g_fs_bits(), internal_lsm6dso_read_byte(), internal_lsm6dso_write_byte(), k_lsm6dso_g_fs_cap, k_lsm6dso_mask_fs_g_full, k_lsm6dso_reg_ctrl2_g, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_CHECK_RANGE_TAG, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_configure().

◆ ra8_lsm6dso_set_odr()

ra8_err_t ra8_lsm6dso_set_odr ( ra8_lsm6dso_t * dev,
ra8_lsm6dso_odr_t odr )
nodiscard

Program the Output Data Rate for both the accelerometer and the gyroscope.

Writes odr into the ODR_XL field of CTRL1_XL and the ODR_G field of CTRL2_G. The full-scale nibble of each register is preserved by reading the current value first. The two blocks share an ODR scale (DS12140 sec 5.3 "Output data rate and bandwidth selection") so one parameter covers both.

Parameters
[in,out]devDriver instance.
[in]odrODR code (one of k_lsm6dso_odr_*).
Returns
ra8_err_t Error code.
Return values
k_ra8_okODR programmed for XL and G.
k_ra8_err_null_ptrdev is NULL.
k_ra8_err_invalid_statedev not initialized.
k_ra8_err_invalid_argodr out of range.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
odr is one of the ODR enum values.
Postcondition
On success dev->odr_code == odr.
On failure dev->odr_code is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 344 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::initialized, internal_lsm6dso_rmw_odr(), k_lsm6dso_mask_nibble, k_lsm6dso_odr_cap, k_lsm6dso_reg_ctrl1_xl, k_lsm6dso_reg_ctrl2_g, k_lsm6dso_shift_odr, k_ra8_err_invalid_arg, k_ra8_ok, ra8_lsm6dso_t::odr_code, RA8_CHECK_NULL_PTR, RA8_CHECK_RANGE_TAG, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_configure().

◆ ra8_lsm6dso_who_am_i()

ra8_err_t ra8_lsm6dso_who_am_i ( ra8_lsm6dso_t * dev,
uint8_t * out_id )
nodiscard

Read the WHO_AM_I register.

Reads register 0x0F and returns the raw byte. On a healthy LSM6DSO this is 0x6C (k_lsm6dso_who_am_i_value); any other value means the wrong part is wired or the bus is mis-addressed.

Parameters
[in]devDriver instance.
[out]out_idReceives the WHO_AM_I byte.
Returns
ra8_err_t Error code.
Return values
k_ra8_ok*out_id populated.
k_ra8_err_null_ptrdev or out_id is NULL.
k_ra8_err_invalid_statedev has not been initialized.
k_ra8_err_nackTransport reported a NACK.
Precondition
ra8_lsm6dso_init returned k_ra8_ok for dev.
out_id points at writable storage.
Postcondition
On success *out_id carries the device-ID byte.
On failure *out_id is unmodified.
Note
Not thread-safe per-instance.
Since
0.1.0

Definition at line 276 of file ra8_lsm6dso.c.

References ra8_lsm6dso_t::initialized, internal_lsm6dso_read_byte(), k_lsm6dso_reg_who_am_i, RA8_CHECK_NULL_PTR, RA8_VALIDATE_INIT, and s_lsm6dso_tag.

Referenced by imu_demo_check_who_am_i().