Da Vinci Firmware 1
Firmware for the DaVinci-M rocket avionics board.
Loading...
Searching...
No Matches
"LIS2MDL Magnetometer Driver"

This file provides a set of functions needed to drive the lis2mdl enhanced inertial module. More...

Collaboration diagram for "LIS2MDL Magnetometer Driver":

Modules

 "Interfaces Functions"
 This section provide a set of functions used to read and write a generic register of the device. MANDATORY: return 0 -> no Error.
 
 "Sensitivity"
 These functions convert raw-data into engineering units.
 
 "Data Generation"
 This section group all the functions concerning data generation.
 
 "Common"
 This section group common useful functions.
 
 "Interrupts"
 This section group all the functions that manage interrupts.
 
 "Serial Interface"
 This section group all the functions concerning serial interface management.
 
 definitions
 
 sensors common types
 
 LSM9DS1_Infos
 
 LIS2MDL_Register_Union
 This union group all the registers having a bit-field description. This union is useful but it's not needed by the driver.
 

Data Structures

struct  lis2mdl_cfg_reg_a_t
 
struct  lis2mdl_cfg_reg_b_t
 
struct  lis2mdl_cfg_reg_c_t
 
struct  lis2mdl_int_crtl_reg_t
 
struct  lis2mdl_int_source_reg_t
 
struct  lis2mdl_status_reg_t
 

Macros

#define LIS2MDL_OFFSET_X_REG_L   0x45U
 
#define LIS2MDL_OFFSET_X_REG_H   0x46U
 
#define LIS2MDL_OFFSET_Y_REG_L   0x47U
 
#define LIS2MDL_OFFSET_Y_REG_H   0x48U
 
#define LIS2MDL_OFFSET_Z_REG_L   0x49U
 
#define LIS2MDL_OFFSET_Z_REG_H   0x4AU
 
#define LIS2MDL_WHO_AM_I   0x4FU
 
#define LIS2MDL_CFG_REG_A   0x60U
 
#define LIS2MDL_CFG_REG_B   0x61U
 
#define LIS2MDL_CFG_REG_C   0x62U
 
#define LIS2MDL_INT_CRTL_REG   0x63U
 
#define LIS2MDL_INT_SOURCE_REG   0x64U
 
#define LIS2MDL_INT_THS_L_REG   0x65U
 
#define LIS2MDL_INT_THS_H_REG   0x66U
 
#define LIS2MDL_STATUS_REG   0x67U
 
#define LIS2MDL_OUTX_L_REG   0x68U
 
#define LIS2MDL_OUTX_H_REG   0x69U
 
#define LIS2MDL_OUTY_L_REG   0x6AU
 
#define LIS2MDL_OUTY_H_REG   0x6BU
 
#define LIS2MDL_OUTZ_L_REG   0x6CU
 
#define LIS2MDL_OUTZ_H_REG   0x6DU
 
#define LIS2MDL_TEMP_OUT_L_REG   0x6EU
 
#define LIS2MDL_TEMP_OUT_H_REG   0x6FU
 
#define __weak   __attribute__((weak))
 

Enumerations

enum  lis2mdl_md_t { LIS2MDL_CONTINUOUS_MODE = 0 , LIS2MDL_SINGLE_TRIGGER = 1 , LIS2MDL_POWER_DOWN = 2 }
 
enum  lis2mdl_odr_t { LIS2MDL_ODR_10Hz = 0 , LIS2MDL_ODR_20Hz = 1 , LIS2MDL_ODR_50Hz = 2 , LIS2MDL_ODR_100Hz = 3 }
 
enum  lis2mdl_lp_t { LIS2MDL_HIGH_RESOLUTION = 0 , LIS2MDL_LOW_POWER = 1 }
 
enum  lis2mdl_lpf_t { LIS2MDL_ODR_DIV_2 = 0 , LIS2MDL_ODR_DIV_4 = 1 }
 
enum  lis2mdl_set_rst_t { LIS2MDL_SET_SENS_ODR_DIV_63 = 0 , LIS2MDL_SENS_OFF_CANC_EVERY_ODR = 1 , LIS2MDL_SET_SENS_ONLY_AT_POWER_ON = 2 }
 
enum  lis2mdl_ble_t { LIS2MDL_LSB_AT_LOW_ADD = 0 , LIS2MDL_MSB_AT_LOW_ADD = 1 }
 
enum  lis2mdl_int_on_dataoff_t { LIS2MDL_CHECK_BEFORE = 0 , LIS2MDL_CHECK_AFTER = 1 }
 
enum  lis2mdl_sim_t { LIS2MDL_SPI_4_WIRE = 1 , LIS2MDL_SPI_3_WIRE = 0 }
 
enum  lis2mdl_i2c_dis_t { LIS2MDL_I2C_ENABLE = 0 , LIS2MDL_I2C_DISABLE = 1 }
 

Functions

int32_t lis2mdl_read_reg (const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
 Read generic device register.
 
int32_t lis2mdl_write_reg (const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
 Write generic device register.
 
float_t lis2mdl_from_lsb_to_mgauss (int16_t lsb)
 
float_t lis2mdl_from_lsb_to_celsius (int16_t lsb)
 
float_t lis2mdl_from_lsb_to_nanotesla (int16_t lsb)
 Converts raw magnetic data to nanotesla (nT). Sensitivity: 1 LSB = 1.5 mG = 150 nT.
 
int32_t lis2mdl_mag_user_offset_set (const stmdev_ctx_t *ctx, int16_t *val)
 These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compensate environmental effects. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG. These values act on the magnetic output data value in order to delete the environmental offset.[set].
 
int32_t lis2mdl_mag_user_offset_get (const stmdev_ctx_t *ctx, int16_t *val)
 These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compensate environmental effects. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG. These values act on the magnetic output data value in order to delete the environmental offset.[get].
 
int32_t lis2mdl_operating_mode_set (const stmdev_ctx_t *ctx, lis2mdl_md_t val)
 Operating mode selection.[set].
 
int32_t lis2mdl_operating_mode_get (const stmdev_ctx_t *ctx, lis2mdl_md_t *val)
 Operating mode selection.[get].
 
int32_t lis2mdl_data_rate_set (const stmdev_ctx_t *ctx, lis2mdl_odr_t val)
 Output data rate selection.[set].
 
int32_t lis2mdl_data_rate_get (const stmdev_ctx_t *ctx, lis2mdl_odr_t *val)
 Output data rate selection.[get].
 
int32_t lis2mdl_power_mode_set (const stmdev_ctx_t *ctx, lis2mdl_lp_t val)
 Enables high-resolution/low-power mode.[set].
 
int32_t lis2mdl_power_mode_get (const stmdev_ctx_t *ctx, lis2mdl_lp_t *val)
 Enables high-resolution/low-power mode.[get].
 
int32_t lis2mdl_offset_temp_comp_set (const stmdev_ctx_t *ctx, uint8_t val)
 Enables the magnetometer temperature compensation.[set].
 
int32_t lis2mdl_offset_temp_comp_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Enables the magnetometer temperature compensation.[get].
 
int32_t lis2mdl_low_pass_bandwidth_set (const stmdev_ctx_t *ctx, lis2mdl_lpf_t val)
 Low-pass bandwidth selection.[set].
 
int32_t lis2mdl_low_pass_bandwidth_get (const stmdev_ctx_t *ctx, lis2mdl_lpf_t *val)
 Low-pass bandwidth selection.[get].
 
int32_t lis2mdl_set_rst_mode_set (const stmdev_ctx_t *ctx, lis2mdl_set_rst_t val)
 Reset mode.[set].
 
int32_t lis2mdl_set_rst_mode_get (const stmdev_ctx_t *ctx, lis2mdl_set_rst_t *val)
 Reset mode.[get].
 
int32_t lis2mdl_set_rst_sensor_single_set (const stmdev_ctx_t *ctx, uint8_t val)
 Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabling offset cancellation in single measurement mode this means a call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR) is need.[set].
 
int32_t lis2mdl_set_rst_sensor_single_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabling offset cancellation in single measurement mode this means a call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR) is need.[get].
 
int32_t lis2mdl_block_data_update_set (const stmdev_ctx_t *ctx, uint8_t val)
 Blockdataupdate.[set].
 
int32_t lis2mdl_block_data_update_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Blockdataupdate.[get].
 
int32_t lis2mdl_mag_data_ready_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Magnetic set of data available.[get].
 
int32_t lis2mdl_mag_data_ovr_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Magnetic set of data overrun.[get].
 
int32_t lis2mdl_magnetic_raw_get (const stmdev_ctx_t *ctx, int16_t *val)
 Magnetic output value.[get].
 
int32_t lis2mdl_temperature_raw_get (const stmdev_ctx_t *ctx, int16_t *val)
 Temperature output value.[get].
 
int32_t lis2mdl_device_id_get (const stmdev_ctx_t *ctx, uint8_t *buff)
 DeviceWhoamI.[get].
 
int32_t lis2mdl_reset_set (const stmdev_ctx_t *ctx, uint8_t val)
 Software reset. Restore the default values in user registers.[set].
 
int32_t lis2mdl_reset_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Software reset. Restore the default values in user registers.[get].
 
int32_t lis2mdl_boot_set (const stmdev_ctx_t *ctx, uint8_t val)
 Reboot memory content. Reload the calibration parameters.[set].
 
int32_t lis2mdl_boot_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Reboot memory content. Reload the calibration parameters.[get].
 
int32_t lis2mdl_self_test_set (const stmdev_ctx_t *ctx, uint8_t val)
 Selftest.[set].
 
int32_t lis2mdl_self_test_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Selftest.[get].
 
int32_t lis2mdl_data_format_set (const stmdev_ctx_t *ctx, lis2mdl_ble_t val)
 Big/Little Endian data selection.[set].
 
int32_t lis2mdl_data_format_get (const stmdev_ctx_t *ctx, lis2mdl_ble_t *val)
 Big/Little Endian data selection.[get].
 
int32_t lis2mdl_status_get (const stmdev_ctx_t *ctx, lis2mdl_status_reg_t *val)
 Info about device status.[get].
 
int32_t lis2mdl_offset_int_conf_set (const stmdev_ctx_t *ctx, lis2mdl_int_on_dataoff_t val)
 The interrupt block recognition checks data after/before the hard-iron correction to discover the interrupt.[set].
 
int32_t lis2mdl_offset_int_conf_get (const stmdev_ctx_t *ctx, lis2mdl_int_on_dataoff_t *val)
 The interrupt block recognition checks data after/before the hard-iron correction to discover the interrupt.[get].
 
int32_t lis2mdl_drdy_on_pin_set (const stmdev_ctx_t *ctx, uint8_t val)
 Data-ready signal on INT_DRDY pin.[set].
 
int32_t lis2mdl_drdy_on_pin_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Data-ready signal on INT_DRDY pin.[get].
 
int32_t lis2mdl_int_on_pin_set (const stmdev_ctx_t *ctx, uint8_t val)
 Interrupt signal on INT_DRDY pin.[set].
 
int32_t lis2mdl_int_on_pin_get (const stmdev_ctx_t *ctx, uint8_t *val)
 Interrupt signal on INT_DRDY pin.[get].
 
int32_t lis2mdl_int_gen_conf_set (const stmdev_ctx_t *ctx, lis2mdl_int_crtl_reg_t *val)
 Interrupt generator configuration register.[set].
 
int32_t lis2mdl_int_gen_conf_get (const stmdev_ctx_t *ctx, lis2mdl_int_crtl_reg_t *val)
 Interrupt generator configuration register.[get].
 
int32_t lis2mdl_int_gen_source_get (const stmdev_ctx_t *ctx, lis2mdl_int_source_reg_t *val)
 Interrupt generator source register.[get].
 
int32_t lis2mdl_int_gen_threshold_set (const stmdev_ctx_t *ctx, uint16_t val)
 User-defined threshold value for xl interrupt event on generator. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG.[set].
 
int32_t lis2mdl_int_gen_threshold_get (const stmdev_ctx_t *ctx, uint16_t *val)
 User-defined threshold value for xl interrupt event on generator. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG.[get].
 
int32_t lis2mdl_spi_mode_set (const stmdev_ctx_t *ctx, lis2mdl_sim_t val)
 SPI Serial Interface Mode selection.[set].
 
int32_t lis2mdl_spi_mode_get (const stmdev_ctx_t *ctx, lis2mdl_sim_t *val)
 SPI Serial Interface Mode selection.[get].
 
int32_t lis2mdl_i2c_interface_set (const stmdev_ctx_t *ctx, lis2mdl_i2c_dis_t val)
 Enable/Disable I2C interface.[set].
 
int32_t lis2mdl_i2c_interface_get (const stmdev_ctx_t *ctx, lis2mdl_i2c_dis_t *val)
 Enable/Disable I2C interface.[get].
 
int32_t lis2mdl_init (stmdev_ctx_t *ctx)
 Initialize the LIS2MDL sensor.
 
int32_t lis2mdl_init_2 (stmdev_ctx_t *ctx)
 

Detailed Description

This file provides a set of functions needed to drive the lis2mdl enhanced inertial module.

Macro Definition Documentation

◆ __weak

#define __weak   __attribute__((weak))

Definition at line 362 of file lis2mdl_reg.h.

◆ LIS2MDL_CFG_REG_A

#define LIS2MDL_CFG_REG_A   0x60U

Definition at line 189 of file lis2mdl_reg.h.

◆ LIS2MDL_CFG_REG_B

#define LIS2MDL_CFG_REG_B   0x61U

Definition at line 209 of file lis2mdl_reg.h.

◆ LIS2MDL_CFG_REG_C

#define LIS2MDL_CFG_REG_C   0x62U

Definition at line 227 of file lis2mdl_reg.h.

◆ LIS2MDL_INT_CRTL_REG

#define LIS2MDL_INT_CRTL_REG   0x63U

Definition at line 251 of file lis2mdl_reg.h.

◆ LIS2MDL_INT_SOURCE_REG

#define LIS2MDL_INT_SOURCE_REG   0x64U

Definition at line 273 of file lis2mdl_reg.h.

◆ LIS2MDL_INT_THS_H_REG

#define LIS2MDL_INT_THS_H_REG   0x66U

Definition at line 298 of file lis2mdl_reg.h.

◆ LIS2MDL_INT_THS_L_REG

#define LIS2MDL_INT_THS_L_REG   0x65U

Definition at line 297 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_X_REG_H

#define LIS2MDL_OFFSET_X_REG_H   0x46U

Definition at line 183 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_X_REG_L

#define LIS2MDL_OFFSET_X_REG_L   0x45U

Definition at line 182 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_Y_REG_H

#define LIS2MDL_OFFSET_Y_REG_H   0x48U

Definition at line 185 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_Y_REG_L

#define LIS2MDL_OFFSET_Y_REG_L   0x47U

Definition at line 184 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_Z_REG_H

#define LIS2MDL_OFFSET_Z_REG_H   0x4AU

Definition at line 187 of file lis2mdl_reg.h.

◆ LIS2MDL_OFFSET_Z_REG_L

#define LIS2MDL_OFFSET_Z_REG_L   0x49U

Definition at line 186 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTX_H_REG

#define LIS2MDL_OUTX_H_REG   0x69U

Definition at line 324 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTX_L_REG

#define LIS2MDL_OUTX_L_REG   0x68U

Definition at line 323 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTY_H_REG

#define LIS2MDL_OUTY_H_REG   0x6BU

Definition at line 326 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTY_L_REG

#define LIS2MDL_OUTY_L_REG   0x6AU

Definition at line 325 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTZ_H_REG

#define LIS2MDL_OUTZ_H_REG   0x6DU

Definition at line 328 of file lis2mdl_reg.h.

◆ LIS2MDL_OUTZ_L_REG

#define LIS2MDL_OUTZ_L_REG   0x6CU

Definition at line 327 of file lis2mdl_reg.h.

◆ LIS2MDL_STATUS_REG

#define LIS2MDL_STATUS_REG   0x67U

Definition at line 299 of file lis2mdl_reg.h.

◆ LIS2MDL_TEMP_OUT_H_REG

#define LIS2MDL_TEMP_OUT_H_REG   0x6FU

Definition at line 330 of file lis2mdl_reg.h.

◆ LIS2MDL_TEMP_OUT_L_REG

#define LIS2MDL_TEMP_OUT_L_REG   0x6EU

Definition at line 329 of file lis2mdl_reg.h.

◆ LIS2MDL_WHO_AM_I

#define LIS2MDL_WHO_AM_I   0x4FU

Definition at line 188 of file lis2mdl_reg.h.

Enumeration Type Documentation

◆ lis2mdl_ble_t

Enumerator
LIS2MDL_LSB_AT_LOW_ADD 
LIS2MDL_MSB_AT_LOW_ADD 

Definition at line 471 of file lis2mdl_reg.h.

472{
lis2mdl_ble_t
@ LIS2MDL_LSB_AT_LOW_ADD
@ LIS2MDL_MSB_AT_LOW_ADD

◆ lis2mdl_i2c_dis_t

Enumerator
LIS2MDL_I2C_ENABLE 
LIS2MDL_I2C_DISABLE 

Definition at line 519 of file lis2mdl_reg.h.

520{
lis2mdl_i2c_dis_t
@ LIS2MDL_I2C_ENABLE
@ LIS2MDL_I2C_DISABLE

◆ lis2mdl_int_on_dataoff_t

Enumerator
LIS2MDL_CHECK_BEFORE 
LIS2MDL_CHECK_AFTER 

Definition at line 483 of file lis2mdl_reg.h.

484{
lis2mdl_int_on_dataoff_t
@ LIS2MDL_CHECK_AFTER
@ LIS2MDL_CHECK_BEFORE

◆ lis2mdl_lp_t

Enumerator
LIS2MDL_HIGH_RESOLUTION 
LIS2MDL_LOW_POWER 

Definition at line 411 of file lis2mdl_reg.h.

412{
lis2mdl_lp_t
@ LIS2MDL_LOW_POWER
@ LIS2MDL_HIGH_RESOLUTION

◆ lis2mdl_lpf_t

Enumerator
LIS2MDL_ODR_DIV_2 
LIS2MDL_ODR_DIV_4 

Definition at line 422 of file lis2mdl_reg.h.

423{
lis2mdl_lpf_t
@ LIS2MDL_ODR_DIV_4
@ LIS2MDL_ODR_DIV_2

◆ lis2mdl_md_t

Enumerator
LIS2MDL_CONTINUOUS_MODE 
LIS2MDL_SINGLE_TRIGGER 
LIS2MDL_POWER_DOWN 

Definition at line 390 of file lis2mdl_reg.h.

391{
lis2mdl_md_t
@ LIS2MDL_POWER_DOWN
@ LIS2MDL_CONTINUOUS_MODE
@ LIS2MDL_SINGLE_TRIGGER

◆ lis2mdl_odr_t

Enumerator
LIS2MDL_ODR_10Hz 
LIS2MDL_ODR_20Hz 
LIS2MDL_ODR_50Hz 
LIS2MDL_ODR_100Hz 

Definition at line 401 of file lis2mdl_reg.h.

402{
lis2mdl_odr_t
@ LIS2MDL_ODR_100Hz
@ LIS2MDL_ODR_50Hz
@ LIS2MDL_ODR_10Hz
@ LIS2MDL_ODR_20Hz

◆ lis2mdl_set_rst_t

Enumerator
LIS2MDL_SET_SENS_ODR_DIV_63 
LIS2MDL_SENS_OFF_CANC_EVERY_ODR 
LIS2MDL_SET_SENS_ONLY_AT_POWER_ON 

Definition at line 432 of file lis2mdl_reg.h.

433{
lis2mdl_set_rst_t
@ LIS2MDL_SET_SENS_ODR_DIV_63
@ LIS2MDL_SET_SENS_ONLY_AT_POWER_ON
@ LIS2MDL_SENS_OFF_CANC_EVERY_ODR

◆ lis2mdl_sim_t

Enumerator
LIS2MDL_SPI_4_WIRE 
LIS2MDL_SPI_3_WIRE 

Definition at line 511 of file lis2mdl_reg.h.

512{
lis2mdl_sim_t
@ LIS2MDL_SPI_3_WIRE
@ LIS2MDL_SPI_4_WIRE

Function Documentation

◆ lis2mdl_block_data_update_get()

int32_t lis2mdl_block_data_update_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Blockdataupdate.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of bdu in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 646 of file lis2mdl_reg.c.

647{
649 int32_t ret;
650
651 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
652 *val = reg.bdu;
653
654 return ret;
655}
int32_t __weak lis2mdl_read_reg(const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
Read generic device register.
Definition lis2mdl_reg.c:66
#define LIS2MDL_CFG_REG_C

References lis2mdl_cfg_reg_c_t::bdu, LIS2MDL_CFG_REG_C, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_block_data_update_set()

int32_t lis2mdl_block_data_update_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Blockdataupdate.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of bdu in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 622 of file lis2mdl_reg.c.

623{
625 int32_t ret;
626
627 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
628
629 if (ret == 0)
630 {
631 reg.bdu = val;
632 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
633 }
634
635 return ret;
636}
int32_t __weak lis2mdl_write_reg(const stmdev_ctx_t *ctx, uint8_t reg, uint8_t *data, uint16_t len)
Write generic device register.
Definition lis2mdl_reg.c:92

References lis2mdl_cfg_reg_c_t::bdu, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_boot_get()

int32_t lis2mdl_boot_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Reboot memory content. Reload the calibration parameters.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of reboot in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 843 of file lis2mdl_reg.c.

844{
846 int32_t ret;
847
848 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
849 *val = reg.reboot;
850
851 return ret;
852}
#define LIS2MDL_CFG_REG_A

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), and lis2mdl_cfg_reg_a_t::reboot.

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_boot_set()

int32_t lis2mdl_boot_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Reboot memory content. Reload the calibration parameters.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of reboot in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 819 of file lis2mdl_reg.c.

820{
822 int32_t ret;
823
824 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
825
826 if (ret == 0)
827 {
828 reg.reboot = val;
829 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
830 }
831
832 return ret;
833}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_a_t::reboot.

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_data_format_get()

int32_t lis2mdl_data_format_get ( const stmdev_ctx_t ctx,
lis2mdl_ble_t val 
)

Big/Little Endian data selection.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of ble in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 929 of file lis2mdl_reg.c.

930{
932 int32_t ret;
933
934 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
935
936 switch (reg.ble)
937 {
940 break;
941
944 break;
945
946 default:
948 break;
949 }
950
951 return ret;
952}

References lis2mdl_cfg_reg_c_t::ble, LIS2MDL_CFG_REG_C, LIS2MDL_LSB_AT_LOW_ADD, LIS2MDL_MSB_AT_LOW_ADD, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_data_format_set()

int32_t lis2mdl_data_format_set ( const stmdev_ctx_t ctx,
lis2mdl_ble_t  val 
)

Big/Little Endian data selection.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of ble in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 905 of file lis2mdl_reg.c.

906{
908 int32_t ret;
909
910 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
911
912 if (ret == 0)
913 {
914 reg.ble = (uint8_t)val;
915 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
916 }
917
918 return ret;
919}

References lis2mdl_cfg_reg_c_t::ble, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_data_rate_get()

int32_t lis2mdl_data_rate_get ( const stmdev_ctx_t ctx,
lis2mdl_odr_t val 
)

Output data rate selection.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of odr in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 306 of file lis2mdl_reg.c.

307{
309 int32_t ret;
310
311 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
312
313 switch (reg.odr)
314 {
315 case LIS2MDL_ODR_10Hz:
316 *val = LIS2MDL_ODR_10Hz;
317 break;
318
319 case LIS2MDL_ODR_20Hz:
320 *val = LIS2MDL_ODR_20Hz;
321 break;
322
323 case LIS2MDL_ODR_50Hz:
324 *val = LIS2MDL_ODR_50Hz;
325 break;
326
328 *val = LIS2MDL_ODR_100Hz;
329 break;
330
331 default:
332 *val = LIS2MDL_ODR_10Hz;
333 break;
334 }
335
336 return ret;
337}

References LIS2MDL_CFG_REG_A, LIS2MDL_ODR_100Hz, LIS2MDL_ODR_10Hz, LIS2MDL_ODR_20Hz, LIS2MDL_ODR_50Hz, lis2mdl_read_reg(), and lis2mdl_cfg_reg_a_t::odr.

Here is the call graph for this function:

◆ lis2mdl_data_rate_set()

int32_t lis2mdl_data_rate_set ( const stmdev_ctx_t ctx,
lis2mdl_odr_t  val 
)

Output data rate selection.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of odr in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 282 of file lis2mdl_reg.c.

283{
285 int32_t ret;
286
287 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
288
289 if (ret == 0)
290 {
291 reg.odr = (uint8_t)val;
292 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
293 }
294
295 return ret;
296}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_a_t::odr.

Here is the call graph for this function:

◆ lis2mdl_device_id_get()

int32_t lis2mdl_device_id_get ( const stmdev_ctx_t ctx,
uint8_t *  buff 
)

DeviceWhoamI.[get].

Parameters
ctxread / write interface definitions.(ptr)
buffthat stores data read
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 759 of file lis2mdl_reg.c.

760{
761 int32_t ret;
762
763 ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
764
765 return ret;
766}
#define LIS2MDL_WHO_AM_I

References lis2mdl_read_reg(), and LIS2MDL_WHO_AM_I.

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_drdy_on_pin_get()

int32_t lis2mdl_drdy_on_pin_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Data-ready signal on INT_DRDY pin.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of drdy_on_pin in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1077 of file lis2mdl_reg.c.

1078{
1080 int32_t ret;
1081
1082 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1083 *val = reg.drdy_on_pin;
1084
1085 return ret;
1086}

References lis2mdl_cfg_reg_c_t::drdy_on_pin, LIS2MDL_CFG_REG_C, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_drdy_on_pin_set()

int32_t lis2mdl_drdy_on_pin_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Data-ready signal on INT_DRDY pin.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of drdy_on_pin in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1053 of file lis2mdl_reg.c.

1054{
1056 int32_t ret;
1057
1058 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1059
1060 if (ret == 0)
1061 {
1062 reg.drdy_on_pin = val;
1063 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1064 }
1065
1066 return ret;
1067}

References lis2mdl_cfg_reg_c_t::drdy_on_pin, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_from_lsb_to_celsius()

float_t lis2mdl_from_lsb_to_celsius ( int16_t  lsb)

Definition at line 124 of file lis2mdl_reg.c.

125{
126 return (((float_t)lsb / 8.0f) + 25.0f);
127}

◆ lis2mdl_from_lsb_to_mgauss()

float_t lis2mdl_from_lsb_to_mgauss ( int16_t  lsb)

Definition at line 119 of file lis2mdl_reg.c.

120{
121 return ((float_t)lsb * 1.5f);
122}

◆ lis2mdl_from_lsb_to_nanotesla()

float_t lis2mdl_from_lsb_to_nanotesla ( int16_t  lsb)

Converts raw magnetic data to nanotesla (nT). Sensitivity: 1 LSB = 1.5 mG = 150 nT.

Parameters
lsbraw data from sensor output register (16-bit)
Return values
magneticfield in nanotesla

Definition at line 137 of file lis2mdl_reg.c.

138{
139 return ((float_t)lsb * 150.0f);
140}

◆ lis2mdl_i2c_interface_get()

int32_t lis2mdl_i2c_interface_get ( const stmdev_ctx_t ctx,
lis2mdl_i2c_dis_t val 
)

Enable/Disable I2C interface.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of i2c_dis in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1332 of file lis2mdl_reg.c.

1334{
1336 int32_t ret;
1337
1338 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1339
1340 switch (reg.i2c_dis)
1341 {
1342 case LIS2MDL_I2C_ENABLE:
1343 *val = LIS2MDL_I2C_ENABLE;
1344 break;
1345
1347 *val = LIS2MDL_I2C_DISABLE;
1348 break;
1349
1350 default:
1351 *val = LIS2MDL_I2C_ENABLE;
1352 break;
1353 }
1354
1355 return ret;
1356}

References lis2mdl_cfg_reg_c_t::i2c_dis, LIS2MDL_CFG_REG_C, LIS2MDL_I2C_DISABLE, LIS2MDL_I2C_ENABLE, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_i2c_interface_set()

int32_t lis2mdl_i2c_interface_set ( const stmdev_ctx_t ctx,
lis2mdl_i2c_dis_t  val 
)

Enable/Disable I2C interface.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of i2c_dis in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1307 of file lis2mdl_reg.c.

1309{
1311 int32_t ret;
1312
1313 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1314
1315 if (ret == 0)
1316 {
1317 reg.i2c_dis = (uint8_t)val;
1318 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1319 }
1320
1321 return ret;
1322}

References lis2mdl_cfg_reg_c_t::i2c_dis, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_init()

int32_t lis2mdl_init ( stmdev_ctx_t ctx)

Initialize the LIS2MDL sensor.

Parameters
ctxSensor context with SPI handle and platform functions
Return values
0if OK, -1 if error or WHO_AM_I mismatch

Definition at line 1461 of file lis2mdl_reg.c.

1462{
1463 uint8_t who_am_i = 0;
1464 uint8_t val = 0; // Temporary variable for get functions
1465 lis2mdl_cfg_reg_a_t cfg_a;
1466 lis2mdl_cfg_reg_c_t cfg_c;
1467
1468
1469 if (ctx == NULL) return -1;
1470
1471
1474 ctx->handle = &hspi2; // Your SPI_HandleTypeDef
1475
1476 // Check WHO_AM_I register
1477 if (lis2mdl_device_id_get(ctx, &who_am_i) != 0) return -1; // Error reading WHO_AM_I
1478 if (who_am_i != LIS2MDL_ID){
1479 return -1;
1480 } // WHO_AM_I mismatch (LIS2MDL_ID should be 0x40 as per datasheet)
1481
1482 // Perform a software reset
1483 if (lis2mdl_reset_set(ctx, 1) != 0) return -1;
1484 platform_delay(5); // Wait for reset to complete (datasheet doesn't specify, 5ms is a guess)
1485 do {
1486 if (lis2mdl_reset_get(ctx, &val) != 0) return -1;
1487 } while (val); // Poll SOFT_RST bit until it is cleared
1488
1489
1490 // Reboot memory content to reload calibration parameters
1491 if (lis2mdl_boot_set(ctx, 1) != 0) return -1;
1492 platform_delay(5); // Wait for boot to complete
1493 do {
1494 if (lis2mdl_boot_get(ctx, &val) != 0) return -1;
1495 } while (val); // Poll REBOOT bit until it is cleared
1496
1497 // Configure for 4-wire SPI mode
1498 // Note: The LIS2MDL CS pin (pin 3) must be tied LOW to enable SPI mode.
1499 // This function configures the 4WSPI bit in CFG_REG_C for the SDO line.
1500 if (lis2mdl_spi_mode_set(ctx, LIS2MDL_SPI_4_WIRE) != 0) return -1;
1501
1502
1503 // Configure CFG_REG_A for:
1504 // - Temperature compensation enabled
1505 // - Continuous mode
1506 // - ODR 10 Hz
1507 // - High-resolution mode
1508 // This matches the datasheet startup example (CFG_REG_A = 0x80)
1509
1510 // Method 1: Using individual set functions (less efficient due to multiple R-M-W)
1511 // if (lis2mdl_offset_temp_comp_set(ctx, 1) != 0) return -1;
1512 // if (lis2mdl_operating_mode_set(ctx, LIS2MDL_CONTINUOUS_MODE) != 0) return -1;
1513 // if (lis2mdl_data_rate_set(ctx, LIS2MDL_ODR_10HZ) != 0) return -1; // Assuming LIS2MDL_ODR_10HZ is defined
1514 // if (lis2mdl_power_mode_set(ctx, LIS2MDL_HIGH_RESOLUTION) != 0) return -1;
1515
1516 // Method 2: Direct write to CFG_REG_A (more efficient)
1517 cfg_a.comp_temp_en = 1;
1518 cfg_a.reboot = 0;
1519 cfg_a.soft_rst = 0;
1520 cfg_a.lp = (uint8_t)LIS2MDL_HIGH_RESOLUTION; // Assuming LIS2MDL_HIGH_RESOLUTION = 0
1521 cfg_a.odr = (uint8_t)LIS2MDL_ODR_10Hz; // Assuming LIS2MDL_ODR_10Hz = 0
1522 cfg_a.md = (uint8_t)LIS2MDL_CONTINUOUS_MODE; // Assuming LIS2MDL_CONTINUOUS_MODE = 0
1523 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&cfg_a, 1) != 0) return -1;
1524
1525
1526 // Configure CFG_REG_C for:
1527 // - Block Data Update (BDU) enabled
1528 // - Data Ready signal on INT/DRDY pin enabled (optional, as per datasheet startup example)
1529 // - 4-wire SPI is already set by lis2mdl_spi_mode_set above.
1530
1531 // Method 1: Using individual set functions
1532 // if (lis2mdl_block_data_update_set(ctx, 1) != 0) return -1;
1533 // if (lis2mdl_drdy_on_pin_set(ctx, 1) != 0) return -1; // Optional: enable DRDY on pin
1534
1535 // Method 2: Direct write to CFG_REG_C (more efficient, considers 4WSPI already set)
1536 if (lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1537 cfg_c.bdu = 1;
1538 cfg_c.drdy_on_pin = 1; // Enable DRDY on pin as per datasheet example
1539 // cfg_c._4wspi is already set by lis2mdl_spi_mode_set, no need to change it here
1540 // unless lis2mdl_spi_mode_set is not called before this.
1541 // For safety, ensure it's set if not using the dedicated function earlier:
1542 // cfg_c._4wspi = 1; // If LIS2MDL_SPI_4_WIRE is desired
1543 cfg_c.i2c_dis = 1; // Disable I2C if exclusively using SPI
1544 cfg_c.int_on_pin = 0; // Disable interrupt on pin unless specifically needed
1545 cfg_c.self_test = 0; // Disable self-test
1546 cfg_c.ble = (uint8_t)LIS2MDL_LSB_AT_LOW_ADD; // Default data format
1547
1548 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1549
1550
1551 // Sensor is now initialized with basic settings.
1552 // Further configuration (e.g., interrupts, thresholds) can be done as needed.
1553 return 0; // Success
1554}
#define NULL
Definition bmp3_defs.h:88
SPI_HandleTypeDef hspi2
HAL SPI handle for Sensor Bus 1 (e.g., IMU, Baro).
Definition main.c:62
static int32_t platform_spi_write(void *handle, uint8_t reg, const uint8_t *bufp, uint16_t len)
Write data to LIS2MDL sensor via SPI.
static int32_t platform_spi_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
Read data from LIS2MDL sensor via SPI.
int32_t lis2mdl_boot_get(const stmdev_ctx_t *ctx, uint8_t *val)
Reboot memory content. Reload the calibration parameters.[get].
int32_t lis2mdl_reset_get(const stmdev_ctx_t *ctx, uint8_t *val)
Software reset. Restore the default values in user registers.[get].
int32_t lis2mdl_reset_set(const stmdev_ctx_t *ctx, uint8_t val)
Software reset. Restore the default values in user registers.[set].
int32_t lis2mdl_device_id_get(const stmdev_ctx_t *ctx, uint8_t *buff)
DeviceWhoamI.[get].
int32_t lis2mdl_boot_set(const stmdev_ctx_t *ctx, uint8_t val)
Reboot memory content. Reload the calibration parameters.[set].
int32_t lis2mdl_spi_mode_set(const stmdev_ctx_t *ctx, lis2mdl_sim_t val)
SPI Serial Interface Mode selection.[set].
#define LIS2MDL_ID
#define platform_delay(ms)
Definition lis2mdl_reg.c:32
stmdev_read_ptr read_reg
stmdev_write_ptr write_reg

References lis2mdl_cfg_reg_c_t::bdu, lis2mdl_cfg_reg_c_t::ble, lis2mdl_cfg_reg_a_t::comp_temp_en, lis2mdl_cfg_reg_c_t::drdy_on_pin, stmdev_ctx_t::handle, hspi2, lis2mdl_cfg_reg_c_t::i2c_dis, lis2mdl_cfg_reg_c_t::int_on_pin, lis2mdl_boot_get(), lis2mdl_boot_set(), LIS2MDL_CFG_REG_A, LIS2MDL_CFG_REG_C, LIS2MDL_CONTINUOUS_MODE, lis2mdl_device_id_get(), LIS2MDL_HIGH_RESOLUTION, LIS2MDL_ID, LIS2MDL_LSB_AT_LOW_ADD, LIS2MDL_ODR_10Hz, lis2mdl_read_reg(), lis2mdl_reset_get(), lis2mdl_reset_set(), LIS2MDL_SPI_4_WIRE, lis2mdl_spi_mode_set(), lis2mdl_write_reg(), lis2mdl_cfg_reg_a_t::lp, lis2mdl_cfg_reg_a_t::md, NULL, lis2mdl_cfg_reg_a_t::odr, platform_delay, platform_spi_read(), platform_spi_write(), stmdev_ctx_t::read_reg, lis2mdl_cfg_reg_a_t::reboot, lis2mdl_cfg_reg_c_t::self_test, lis2mdl_cfg_reg_a_t::soft_rst, and stmdev_ctx_t::write_reg.

Here is the call graph for this function:

◆ lis2mdl_init_2()

int32_t lis2mdl_init_2 ( stmdev_ctx_t ctx)

Definition at line 1556 of file lis2mdl_reg.c.

1557{
1558 uint8_t who_am_i = 0;
1559 uint8_t val = 0; // Temporary variable for get functions
1560 lis2mdl_cfg_reg_a_t cfg_a;
1561 lis2mdl_cfg_reg_c_t cfg_c;
1562
1563
1564 if (ctx == NULL) return -1;
1565
1566
1569 ctx->handle = &hspi3; // Your SPI_HandleTypeDef
1570
1571 // Check WHO_AM_I register
1572 if (lis2mdl_device_id_get(ctx, &who_am_i) != 0) return -1; // Error reading WHO_AM_I
1573 if (who_am_i != LIS2MDL_ID) return -1; // WHO_AM_I mismatch (LIS2MDL_ID should be 0x40 as per datasheet)
1574
1575 // Perform a software reset
1576 if (lis2mdl_reset_set(ctx, 1) != 0) return -1;
1577 platform_delay(5); // Wait for reset to complete (datasheet doesn't specify, 5ms is a guess)
1578 do {
1579 if (lis2mdl_reset_get(ctx, &val) != 0) return -1;
1580 } while (val); // Poll SOFT_RST bit until it is cleared
1581
1582
1583 // Reboot memory content to reload calibration parameters
1584 if (lis2mdl_boot_set(ctx, 1) != 0) return -1;
1585 platform_delay(5); // Wait for boot to complete
1586 do {
1587 if (lis2mdl_boot_get(ctx, &val) != 0) return -1;
1588 } while (val); // Poll REBOOT bit until it is cleared
1589
1590 // Configure for 4-wire SPI mode
1591 // Note: The LIS2MDL CS pin (pin 3) must be tied LOW to enable SPI mode.
1592 // This function configures the 4WSPI bit in CFG_REG_C for the SDO line.
1593 if (lis2mdl_spi_mode_set(ctx, LIS2MDL_SPI_4_WIRE) != 0) return -1;
1594
1595
1596 // Configure CFG_REG_A for:
1597 // - Temperature compensation enabled
1598 // - Continuous mode
1599 // - ODR 10 Hz
1600 // - High-resolution mode
1601 // This matches the datasheet startup example (CFG_REG_A = 0x80)
1602
1603 // Method 1: Using individual set functions (less efficient due to multiple R-M-W)
1604 // if (lis2mdl_offset_temp_comp_set(ctx, 1) != 0) return -1;
1605 // if (lis2mdl_operating_mode_set(ctx, LIS2MDL_CONTINUOUS_MODE) != 0) return -1;
1606 // if (lis2mdl_data_rate_set(ctx, LIS2MDL_ODR_10HZ) != 0) return -1; // Assuming LIS2MDL_ODR_10HZ is defined
1607 // if (lis2mdl_power_mode_set(ctx, LIS2MDL_HIGH_RESOLUTION) != 0) return -1;
1608
1609 // Method 2: Direct write to CFG_REG_A (more efficient)
1610 cfg_a.comp_temp_en = 1;
1611 cfg_a.reboot = 0;
1612 cfg_a.soft_rst = 0;
1613 cfg_a.lp = (uint8_t)LIS2MDL_HIGH_RESOLUTION; // Assuming LIS2MDL_HIGH_RESOLUTION = 0
1614 cfg_a.odr = (uint8_t)LIS2MDL_ODR_10Hz; // Assuming LIS2MDL_ODR_10Hz = 0
1615 cfg_a.md = (uint8_t)LIS2MDL_CONTINUOUS_MODE; // Assuming LIS2MDL_CONTINUOUS_MODE = 0
1616 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&cfg_a, 1) != 0) return -1;
1617
1618
1619 // Configure CFG_REG_C for:
1620 // - Block Data Update (BDU) enabled
1621 // - Data Ready signal on INT/DRDY pin enabled (optional, as per datasheet startup example)
1622 // - 4-wire SPI is already set by lis2mdl_spi_mode_set above.
1623
1624 // Method 1: Using individual set functions
1625 // if (lis2mdl_block_data_update_set(ctx, 1) != 0) return -1;
1626 // if (lis2mdl_drdy_on_pin_set(ctx, 1) != 0) return -1; // Optional: enable DRDY on pin
1627
1628 // Method 2: Direct write to CFG_REG_C (more efficient, considers 4WSPI already set)
1629 if (lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1630 cfg_c.bdu = 1;
1631 cfg_c.drdy_on_pin = 1; // Enable DRDY on pin as per datasheet example
1632 // cfg_c._4wspi is already set by lis2mdl_spi_mode_set, no need to change it here
1633 // unless lis2mdl_spi_mode_set is not called before this.
1634 // For safety, ensure it's set if not using the dedicated function earlier:
1635 // cfg_c._4wspi = 1; // If LIS2MDL_SPI_4_WIRE is desired
1636 cfg_c.i2c_dis = 1; // Disable I2C if exclusively using SPI
1637 cfg_c.int_on_pin = 0; // Disable interrupt on pin unless specifically needed
1638 cfg_c.self_test = 0; // Disable self-test
1639 cfg_c.ble = (uint8_t)LIS2MDL_LSB_AT_LOW_ADD; // Default data format
1640
1641 if (lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&cfg_c, 1) != 0) return -1;
1642
1643
1644 // Sensor is now initialized with basic settings.
1645 // Further configuration (e.g., interrupts, thresholds) can be done as needed.
1646 return 0; // Success
1647}
SPI_HandleTypeDef hspi3
HAL SPI handle for Sensor Bus 2 (e.g., secondary sensors).
Definition main.c:63

References lis2mdl_cfg_reg_c_t::bdu, lis2mdl_cfg_reg_c_t::ble, lis2mdl_cfg_reg_a_t::comp_temp_en, lis2mdl_cfg_reg_c_t::drdy_on_pin, stmdev_ctx_t::handle, hspi3, lis2mdl_cfg_reg_c_t::i2c_dis, lis2mdl_cfg_reg_c_t::int_on_pin, lis2mdl_boot_get(), lis2mdl_boot_set(), LIS2MDL_CFG_REG_A, LIS2MDL_CFG_REG_C, LIS2MDL_CONTINUOUS_MODE, lis2mdl_device_id_get(), LIS2MDL_HIGH_RESOLUTION, LIS2MDL_ID, LIS2MDL_LSB_AT_LOW_ADD, LIS2MDL_ODR_10Hz, lis2mdl_read_reg(), lis2mdl_reset_get(), lis2mdl_reset_set(), LIS2MDL_SPI_4_WIRE, lis2mdl_spi_mode_set(), lis2mdl_write_reg(), lis2mdl_cfg_reg_a_t::lp, lis2mdl_cfg_reg_a_t::md, NULL, lis2mdl_cfg_reg_a_t::odr, platform_delay, platform_spi_read(), platform_spi_write(), stmdev_ctx_t::read_reg, lis2mdl_cfg_reg_a_t::reboot, lis2mdl_cfg_reg_c_t::self_test, lis2mdl_cfg_reg_a_t::soft_rst, and stmdev_ctx_t::write_reg.

Here is the call graph for this function:

◆ lis2mdl_int_gen_conf_get()

int32_t lis2mdl_int_gen_conf_get ( const stmdev_ctx_t ctx,
lis2mdl_int_crtl_reg_t val 
)

Interrupt generator configuration register.[get].

Parameters
ctxread / write interface definitions.(ptr)
valregisters INT_CRTL_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1157 of file lis2mdl_reg.c.

1159{
1160 int32_t ret;
1161
1162 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
1163
1164 return ret;
1165}
#define LIS2MDL_INT_CRTL_REG

References LIS2MDL_INT_CRTL_REG, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_int_gen_conf_set()

int32_t lis2mdl_int_gen_conf_set ( const stmdev_ctx_t ctx,
lis2mdl_int_crtl_reg_t val 
)

Interrupt generator configuration register.[set].

Parameters
ctxread / write interface definitions.(ptr)
valregisters INT_CRTL_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1139 of file lis2mdl_reg.c.

1141{
1142 int32_t ret;
1143
1144 ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
1145
1146 return ret;
1147}

References LIS2MDL_INT_CRTL_REG, and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_int_gen_source_get()

int32_t lis2mdl_int_gen_source_get ( const stmdev_ctx_t ctx,
lis2mdl_int_source_reg_t val 
)

Interrupt generator source register.[get].

Parameters
ctxread / write interface definitions.(ptr)
valregisters INT_SOURCE_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1175 of file lis2mdl_reg.c.

1177{
1178 int32_t ret;
1179
1180 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t *) val, 1);
1181
1182 return ret;
1183}
#define LIS2MDL_INT_SOURCE_REG

References LIS2MDL_INT_SOURCE_REG, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_int_gen_threshold_get()

int32_t lis2mdl_int_gen_threshold_get ( const stmdev_ctx_t ctx,
uint16_t *  val 
)

User-defined threshold value for xl interrupt event on generator. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG.[get].

Parameters
ctxread / write interface definitions.(ptr)
buffthat stores data read
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1217 of file lis2mdl_reg.c.

1218{
1219 uint8_t buff[2];
1220 int32_t ret;
1221
1222 ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
1223 *val = buff[1];
1224 *val = (*val * 256U) + buff[0];
1225
1226 return ret;
1227}
#define LIS2MDL_INT_THS_L_REG

References LIS2MDL_INT_THS_L_REG, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_int_gen_threshold_set()

int32_t lis2mdl_int_gen_threshold_set ( const stmdev_ctx_t ctx,
uint16_t  val 
)

User-defined threshold value for xl interrupt event on generator. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG.[set].

Parameters
ctxread / write interface definitions.(ptr)
buffthat contains data to write
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1195 of file lis2mdl_reg.c.

1196{
1197 uint8_t buff[2];
1198 int32_t ret;
1199
1200 buff[1] = (uint8_t)(val / 256U);
1201 buff[0] = (uint8_t)(val - (buff[1] * 256U));
1202 ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
1203
1204 return ret;
1205}

References LIS2MDL_INT_THS_L_REG, and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_int_on_pin_get()

int32_t lis2mdl_int_on_pin_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Interrupt signal on INT_DRDY pin.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of int_on_pin in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1120 of file lis2mdl_reg.c.

1121{
1123 int32_t ret;
1124
1125 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1126 *val = reg.int_on_pin;
1127
1128 return ret;
1129}

References lis2mdl_cfg_reg_c_t::int_on_pin, LIS2MDL_CFG_REG_C, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_int_on_pin_set()

int32_t lis2mdl_int_on_pin_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Interrupt signal on INT_DRDY pin.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of int_on_pin in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1096 of file lis2mdl_reg.c.

1097{
1099 int32_t ret;
1100
1101 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1102
1103 if (ret == 0)
1104 {
1105 reg.int_on_pin = val;
1106 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1107 }
1108
1109 return ret;
1110}

References lis2mdl_cfg_reg_c_t::int_on_pin, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_low_pass_bandwidth_get()

int32_t lis2mdl_low_pass_bandwidth_get ( const stmdev_ctx_t ctx,
lis2mdl_lpf_t val 
)

Low-pass bandwidth selection.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of lpf in reg CFG_REG_B.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 472 of file lis2mdl_reg.c.

474{
476 int32_t ret;
477
478 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
479
480 switch (reg.lpf)
481 {
483 *val = LIS2MDL_ODR_DIV_2;
484 break;
485
487 *val = LIS2MDL_ODR_DIV_4;
488 break;
489
490 default:
491 *val = LIS2MDL_ODR_DIV_2;
492 break;
493 }
494
495 return ret;
496}
#define LIS2MDL_CFG_REG_B

References LIS2MDL_CFG_REG_B, LIS2MDL_ODR_DIV_2, LIS2MDL_ODR_DIV_4, lis2mdl_read_reg(), and lis2mdl_cfg_reg_b_t::lpf.

Here is the call graph for this function:

◆ lis2mdl_low_pass_bandwidth_set()

int32_t lis2mdl_low_pass_bandwidth_set ( const stmdev_ctx_t ctx,
lis2mdl_lpf_t  val 
)

Low-pass bandwidth selection.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of lpf in reg CFG_REG_B
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 447 of file lis2mdl_reg.c.

449{
451 int32_t ret;
452
453 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
454
455 if (ret == 0)
456 {
457 reg.lpf = (uint8_t)val;
458 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
459 }
460
461 return ret;
462}

References LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_b_t::lpf.

Here is the call graph for this function:

◆ lis2mdl_mag_data_ovr_get()

int32_t lis2mdl_mag_data_ovr_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Magnetic set of data overrun.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of zyxor in reg STATUS_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 684 of file lis2mdl_reg.c.

685{
687 int32_t ret;
688
689 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
690 *val = reg.zyxor;
691
692 return ret;
693}
#define LIS2MDL_STATUS_REG

References lis2mdl_read_reg(), LIS2MDL_STATUS_REG, and lis2mdl_status_reg_t::zyxor.

Here is the call graph for this function:

◆ lis2mdl_mag_data_ready_get()

int32_t lis2mdl_mag_data_ready_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Magnetic set of data available.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of zyxda in reg STATUS_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 665 of file lis2mdl_reg.c.

666{
668 int32_t ret;
669
670 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
671 *val = reg.zyxda;
672
673 return ret;
674}

References lis2mdl_read_reg(), LIS2MDL_STATUS_REG, and lis2mdl_status_reg_t::zyxda.

Here is the call graph for this function:

◆ lis2mdl_mag_user_offset_get()

int32_t lis2mdl_mag_user_offset_get ( const stmdev_ctx_t ctx,
int16_t *  val 
)

These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compensate environmental effects. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG. These values act on the magnetic output data value in order to delete the environmental offset.[get].

Parameters
ctxread / write interface definitions.(ptr)
buffthat stores data read
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 195 of file lis2mdl_reg.c.

196{
197 uint8_t buff[6];
198 int32_t ret;
199
200 ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
201 val[0] = (int16_t)buff[1];
202 val[0] = (val[0] * 256) + (int16_t)buff[0];
203 val[1] = (int16_t)buff[3];
204 val[1] = (val[1] * 256) + (int16_t)buff[2];
205 val[2] = (int16_t)buff[5];
206 val[2] = (val[2] * 256) + (int16_t)buff[4];
207
208 return ret;
209}
#define LIS2MDL_OFFSET_X_REG_L

References LIS2MDL_OFFSET_X_REG_L, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_mag_user_offset_set()

int32_t lis2mdl_mag_user_offset_set ( const stmdev_ctx_t ctx,
int16_t *  val 
)

These registers comprise a 3 group of 16-bit number and represent hard-iron offset in order to compensate environmental effects. Data format is the same of output data raw: two’s complement with 1LSb = 1.5mG. These values act on the magnetic output data value in order to delete the environmental offset.[set].

Parameters
ctxread / write interface definitions.(ptr)
buffbuffer that contains data to write
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 167 of file lis2mdl_reg.c.

168{
169 uint8_t buff[6];
170 int32_t ret;
171
172 buff[1] = (uint8_t)((uint16_t)val[0] / 256U);
173 buff[0] = (uint8_t)((uint16_t)val[0] - (buff[1] * 256U));
174 buff[3] = (uint8_t)((uint16_t)val[1] / 256U);
175 buff[2] = (uint8_t)((uint16_t)val[1] - (buff[3] * 256U));
176 buff[5] = (uint8_t)((uint16_t)val[2] / 256U);
177 buff[4] = (uint8_t)((uint16_t)val[2] - (buff[5] * 256U));
178 ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
179
180 return ret;
181}

References LIS2MDL_OFFSET_X_REG_L, and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_magnetic_raw_get()

int32_t lis2mdl_magnetic_raw_get ( const stmdev_ctx_t ctx,
int16_t *  val 
)

Magnetic output value.[get].

Parameters
ctxread / write interface definitions.(ptr)
buffthat stores data read
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 703 of file lis2mdl_reg.c.

704{
705 uint8_t buff[6];
706 int32_t ret;
707
708 ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
709 val[0] = (int16_t)buff[1];
710 val[0] = (val[0] * 256) + (int16_t)buff[0];
711 val[1] = (int16_t)buff[3];
712 val[1] = (val[1] * 256) + (int16_t)buff[2];
713 val[2] = (int16_t)buff[5];
714 val[2] = (val[2] * 256) + (int16_t)buff[4];
715
716 return ret;
717}
#define LIS2MDL_OUTX_L_REG

References LIS2MDL_OUTX_L_REG, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_offset_int_conf_get()

int32_t lis2mdl_offset_int_conf_get ( const stmdev_ctx_t ctx,
lis2mdl_int_on_dataoff_t val 
)

The interrupt block recognition checks data after/before the hard-iron correction to discover the interrupt.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of int_on_dataoff in reg CFG_REG_B.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 1019 of file lis2mdl_reg.c.

1021{
1023 int32_t ret;
1024
1025 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1026
1027 switch (reg.int_on_dataoff)
1028 {
1030 *val = LIS2MDL_CHECK_BEFORE;
1031 break;
1032
1034 *val = LIS2MDL_CHECK_AFTER;
1035 break;
1036
1037 default:
1038 *val = LIS2MDL_CHECK_BEFORE;
1039 break;
1040 }
1041
1042 return ret;
1043}

References lis2mdl_cfg_reg_b_t::int_on_dataoff, LIS2MDL_CFG_REG_B, LIS2MDL_CHECK_AFTER, LIS2MDL_CHECK_BEFORE, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_offset_int_conf_set()

int32_t lis2mdl_offset_int_conf_set ( const stmdev_ctx_t ctx,
lis2mdl_int_on_dataoff_t  val 
)

The interrupt block recognition checks data after/before the hard-iron correction to discover the interrupt.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of int_on_dataoff in reg CFG_REG_B
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 993 of file lis2mdl_reg.c.

995{
997 int32_t ret;
998
999 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1000
1001 if (ret == 0)
1002 {
1003 reg.int_on_dataoff = (uint8_t)val;
1004 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
1005 }
1006
1007 return ret;
1008}

References lis2mdl_cfg_reg_b_t::int_on_dataoff, LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_offset_temp_comp_get()

int32_t lis2mdl_offset_temp_comp_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Enables the magnetometer temperature compensation.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of comp_temp_en in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 428 of file lis2mdl_reg.c.

429{
431 int32_t ret;
432
433 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
434 *val = reg.comp_temp_en;
435
436 return ret;
437}

References lis2mdl_cfg_reg_a_t::comp_temp_en, LIS2MDL_CFG_REG_A, and lis2mdl_read_reg().

Here is the call graph for this function:

◆ lis2mdl_offset_temp_comp_set()

int32_t lis2mdl_offset_temp_comp_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Enables the magnetometer temperature compensation.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of comp_temp_en in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 404 of file lis2mdl_reg.c.

405{
407 int32_t ret;
408
409 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
410
411 if (ret == 0)
412 {
413 reg.comp_temp_en = val;
414 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
415 }
416
417 return ret;
418}

References lis2mdl_cfg_reg_a_t::comp_temp_en, LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), and lis2mdl_write_reg().

Here is the call graph for this function:

◆ lis2mdl_operating_mode_get()

int32_t lis2mdl_operating_mode_get ( const stmdev_ctx_t ctx,
lis2mdl_md_t val 
)

Operating mode selection.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of md in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 244 of file lis2mdl_reg.c.

246{
248 int32_t ret;
249
250 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
251
252 switch (reg.md)
253 {
255 *val = LIS2MDL_POWER_DOWN;
256 break;
257
260 break;
261
264 break;
265
266 default:
267 *val = LIS2MDL_POWER_DOWN;
268 break;
269 }
270
271 return ret;
272}

References LIS2MDL_CFG_REG_A, LIS2MDL_CONTINUOUS_MODE, LIS2MDL_POWER_DOWN, lis2mdl_read_reg(), LIS2MDL_SINGLE_TRIGGER, and lis2mdl_cfg_reg_a_t::md.

Here is the call graph for this function:

◆ lis2mdl_operating_mode_set()

int32_t lis2mdl_operating_mode_set ( const stmdev_ctx_t ctx,
lis2mdl_md_t  val 
)

Operating mode selection.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of md in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 219 of file lis2mdl_reg.c.

221{
223 int32_t ret;
224
225 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
226
227 if (ret == 0)
228 {
229 reg.md = (uint8_t)val;
230 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
231 }
232
233 return ret;
234}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_a_t::md.

Here is the call graph for this function:

◆ lis2mdl_power_mode_get()

int32_t lis2mdl_power_mode_get ( const stmdev_ctx_t ctx,
lis2mdl_lp_t val 
)

Enables high-resolution/low-power mode.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of lp in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 371 of file lis2mdl_reg.c.

372{
374 int32_t ret;
375
376 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
377
378 switch (reg.lp)
379 {
382 break;
383
385 *val = LIS2MDL_LOW_POWER;
386 break;
387
388 default:
390 break;
391 }
392
393 return ret;
394}

References LIS2MDL_CFG_REG_A, LIS2MDL_HIGH_RESOLUTION, LIS2MDL_LOW_POWER, lis2mdl_read_reg(), and lis2mdl_cfg_reg_a_t::lp.

Here is the call graph for this function:

◆ lis2mdl_power_mode_set()

int32_t lis2mdl_power_mode_set ( const stmdev_ctx_t ctx,
lis2mdl_lp_t  val 
)

Enables high-resolution/low-power mode.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of lp in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 347 of file lis2mdl_reg.c.

348{
350 int32_t ret;
351
352 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
353
354 if (ret == 0)
355 {
356 reg.lp = (uint8_t)val;
357 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
358 }
359
360 return ret;
361}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_a_t::lp.

Here is the call graph for this function:

◆ lis2mdl_read_reg()

int32_t lis2mdl_read_reg ( const stmdev_ctx_t ctx,
uint8_t  reg,
uint8_t *  data,
uint16_t  len 
)

Read generic device register.

Parameters
ctxread / write interface definitions(ptr)
regregister to read
datapointer to buffer that store the data read(ptr)
lennumber of consecutive register to read
Return values
interfacestatus (MANDATORY: return 0 -> no Error)

Definition at line 66 of file lis2mdl_reg.c.

69{
70 int32_t ret;
71
72 if (ctx == NULL)
73 {
74 return -1;
75 }
76
77 ret = ctx->read_reg(ctx->handle, reg, data, len);
78
79 return ret;
80}

References stmdev_ctx_t::handle, NULL, and stmdev_ctx_t::read_reg.

Referenced by lis2mdl_block_data_update_get(), lis2mdl_block_data_update_set(), lis2mdl_boot_get(), lis2mdl_boot_set(), lis2mdl_data_format_get(), lis2mdl_data_format_set(), lis2mdl_data_rate_get(), lis2mdl_data_rate_set(), lis2mdl_device_id_get(), lis2mdl_drdy_on_pin_get(), lis2mdl_drdy_on_pin_set(), lis2mdl_i2c_interface_get(), lis2mdl_i2c_interface_set(), lis2mdl_init(), lis2mdl_init_2(), lis2mdl_int_gen_conf_get(), lis2mdl_int_gen_source_get(), lis2mdl_int_gen_threshold_get(), lis2mdl_int_on_pin_get(), lis2mdl_int_on_pin_set(), lis2mdl_low_pass_bandwidth_get(), lis2mdl_low_pass_bandwidth_set(), lis2mdl_mag_data_ovr_get(), lis2mdl_mag_data_ready_get(), lis2mdl_mag_user_offset_get(), lis2mdl_magnetic_raw_get(), lis2mdl_offset_int_conf_get(), lis2mdl_offset_int_conf_set(), lis2mdl_offset_temp_comp_get(), lis2mdl_offset_temp_comp_set(), lis2mdl_operating_mode_get(), lis2mdl_operating_mode_set(), lis2mdl_power_mode_get(), lis2mdl_power_mode_set(), lis2mdl_reset_get(), lis2mdl_reset_set(), lis2mdl_self_test_get(), lis2mdl_self_test_set(), lis2mdl_set_rst_mode_get(), lis2mdl_set_rst_mode_set(), lis2mdl_set_rst_sensor_single_get(), lis2mdl_set_rst_sensor_single_set(), lis2mdl_spi_mode_get(), lis2mdl_spi_mode_set(), lis2mdl_status_get(), and lis2mdl_temperature_raw_get().

Here is the caller graph for this function:

◆ lis2mdl_reset_get()

int32_t lis2mdl_reset_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Software reset. Restore the default values in user registers.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of soft_rst in reg CFG_REG_A.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 800 of file lis2mdl_reg.c.

801{
803 int32_t ret;
804
805 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
806 *val = reg.soft_rst;
807
808 return ret;
809}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), and lis2mdl_cfg_reg_a_t::soft_rst.

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_reset_set()

int32_t lis2mdl_reset_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Software reset. Restore the default values in user registers.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of soft_rst in reg CFG_REG_A
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 776 of file lis2mdl_reg.c.

777{
779 int32_t ret;
780
781 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
782
783 if (ret == 0)
784 {
785 reg.soft_rst = val;
786 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
787 }
788
789 return ret;
790}

References LIS2MDL_CFG_REG_A, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_a_t::soft_rst.

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_self_test_get()

int32_t lis2mdl_self_test_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Selftest.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of self_test in reg CFG_REG_C.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 886 of file lis2mdl_reg.c.

887{
889 int32_t ret;
890
891 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
892 *val = reg.self_test;
893
894 return ret;
895}

References LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_cfg_reg_c_t::self_test.

Here is the call graph for this function:

◆ lis2mdl_self_test_set()

int32_t lis2mdl_self_test_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Selftest.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of self_test in reg CFG_REG_C
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 862 of file lis2mdl_reg.c.

863{
865 int32_t ret;
866
867 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
868
869 if (ret == 0)
870 {
871 reg.self_test = val;
872 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
873 }
874
875 return ret;
876}

References LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_c_t::self_test.

Here is the call graph for this function:

◆ lis2mdl_set_rst_mode_get()

int32_t lis2mdl_set_rst_mode_get ( const stmdev_ctx_t ctx,
lis2mdl_set_rst_t val 
)

Reset mode.[get].

Parameters
ctxread / write interface definitions.(ptr)
valGet the values of set_rst in reg CFG_REG_B.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 531 of file lis2mdl_reg.c.

533{
535 int32_t ret;
536
537 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
538
539 switch (reg.set_rst)
540 {
543 break;
544
547 break;
548
551 break;
552
553 default:
555 break;
556 }
557
558 return ret;
559}

References LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), LIS2MDL_SENS_OFF_CANC_EVERY_ODR, LIS2MDL_SET_SENS_ODR_DIV_63, LIS2MDL_SET_SENS_ONLY_AT_POWER_ON, and lis2mdl_cfg_reg_b_t::set_rst.

Here is the call graph for this function:

◆ lis2mdl_set_rst_mode_set()

int32_t lis2mdl_set_rst_mode_set ( const stmdev_ctx_t ctx,
lis2mdl_set_rst_t  val 
)

Reset mode.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of set_rst in reg CFG_REG_B
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 506 of file lis2mdl_reg.c.

508{
510 int32_t ret;
511
512 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
513
514 if (ret == 0)
515 {
516 reg.set_rst = (uint8_t)val;
517 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
518 }
519
520 return ret;
521}

References LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_b_t::set_rst.

Here is the call graph for this function:

◆ lis2mdl_set_rst_sensor_single_get()

int32_t lis2mdl_set_rst_sensor_single_get ( const stmdev_ctx_t ctx,
uint8_t *  val 
)

Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabling offset cancellation in single measurement mode this means a call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR) is need.[get].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of off_canc_one_shot in reg CFG_REG_B.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 602 of file lis2mdl_reg.c.

604{
606 int32_t ret;
607
608 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
609 *val = reg.off_canc_one_shot;
610
611 return ret;
612}

References LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), and lis2mdl_cfg_reg_b_t::off_canc_one_shot.

Here is the call graph for this function:

◆ lis2mdl_set_rst_sensor_single_set()

int32_t lis2mdl_set_rst_sensor_single_set ( const stmdev_ctx_t ctx,
uint8_t  val 
)

Enables offset cancellation in single measurement mode. The OFF_CANC bit must be set to 1 when enabling offset cancellation in single measurement mode this means a call function: set_rst_mode(SENS_OFF_CANC_EVERY_ODR) is need.[set].

Parameters
ctxread / write interface definitions.(ptr)
valchange the values of off_canc_one_shot in reg CFG_REG_B
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 573 of file lis2mdl_reg.c.

575{
577 int32_t ret;
578
579 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
580
581 if (ret == 0)
582 {
583 reg.off_canc_one_shot = val;
584 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
585 }
586
587 return ret;
588}

References LIS2MDL_CFG_REG_B, lis2mdl_read_reg(), lis2mdl_write_reg(), and lis2mdl_cfg_reg_b_t::off_canc_one_shot.

Here is the call graph for this function:

◆ lis2mdl_spi_mode_get()

int32_t lis2mdl_spi_mode_get ( const stmdev_ctx_t ctx,
lis2mdl_sim_t val 
)

SPI Serial Interface Mode selection.[get].

Parameters
ctxread / write interface definitions
valGet the values of 4wspi in reg CFG_REG_C
Return values
interfacestatus (MANDATORY: return 0 -> no Error)

Definition at line 1274 of file lis2mdl_reg.c.

1275{
1277 int32_t ret;
1278
1279 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1280
1281 switch (reg._4wspi)
1282 {
1283 case LIS2MDL_SPI_4_WIRE:
1284 *val = LIS2MDL_SPI_4_WIRE;
1285 break;
1286
1287 case LIS2MDL_SPI_3_WIRE:
1288 *val = LIS2MDL_SPI_3_WIRE;
1289 break;
1290
1291 default:
1292 *val = LIS2MDL_SPI_3_WIRE;
1293 break;
1294 }
1295
1296 return ret;
1297}

References lis2mdl_cfg_reg_c_t::_4wspi, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), LIS2MDL_SPI_3_WIRE, and LIS2MDL_SPI_4_WIRE.

Here is the call graph for this function:

◆ lis2mdl_spi_mode_set()

int32_t lis2mdl_spi_mode_set ( const stmdev_ctx_t ctx,
lis2mdl_sim_t  val 
)

SPI Serial Interface Mode selection.[set].

Parameters
ctxread / write interface definitions
valchange the values of 4wspi in reg CFG_REG_C
Return values
interfacestatus (MANDATORY: return 0 -> no Error)

Definition at line 1250 of file lis2mdl_reg.c.

1251{
1253 int32_t ret;
1254
1255 ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1256
1257 if (ret == 0)
1258 {
1259 reg._4wspi = (uint8_t)val;
1260 ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
1261 }
1262
1263 return ret;
1264}

References lis2mdl_cfg_reg_c_t::_4wspi, LIS2MDL_CFG_REG_C, lis2mdl_read_reg(), and lis2mdl_write_reg().

Referenced by lis2mdl_init(), and lis2mdl_init_2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lis2mdl_status_get()

int32_t lis2mdl_status_get ( const stmdev_ctx_t ctx,
lis2mdl_status_reg_t val 
)

Info about device status.[get].

Parameters
ctxread / write interface definitions.(ptr)
valregisters STATUS_REG.(ptr)
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 962 of file lis2mdl_reg.c.

964{
965 int32_t ret;
966
967 ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *) val, 1);
968
969 return ret;
970}

References lis2mdl_read_reg(), and LIS2MDL_STATUS_REG.

Here is the call graph for this function:

◆ lis2mdl_temperature_raw_get()

int32_t lis2mdl_temperature_raw_get ( const stmdev_ctx_t ctx,
int16_t *  val 
)

Temperature output value.[get].

Parameters
ctxread / write interface definitions.(ptr)
buffthat stores data read
Return values
interfacestatus.(MANDATORY: return 0 -> no Error)

Definition at line 727 of file lis2mdl_reg.c.

728{
729 uint8_t buff[2];
730 int32_t ret;
731
732 ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
733 *val = (int16_t)buff[1];
734 *val = (*val * 256) + (int16_t)buff[0];
735
736 return ret;
737}
#define LIS2MDL_TEMP_OUT_L_REG

References lis2mdl_read_reg(), and LIS2MDL_TEMP_OUT_L_REG.

Here is the call graph for this function:

◆ lis2mdl_write_reg()

int32_t lis2mdl_write_reg ( const stmdev_ctx_t ctx,
uint8_t  reg,
uint8_t *  data,
uint16_t  len 
)

Write generic device register.

Parameters
ctxread / write interface definitions(ptr)
regregister to write
datapointer to data to write in register reg(ptr)
lennumber of consecutive register to write
Return values
interfacestatus (MANDATORY: return 0 -> no Error)

Definition at line 92 of file lis2mdl_reg.c.

95{
96 int32_t ret;
97
98 if (ctx == NULL)
99 {
100 return -1;
101 }
102
103 ret = ctx->write_reg(ctx->handle, reg, data, len);
104
105 return ret;
106}

References stmdev_ctx_t::handle, NULL, and stmdev_ctx_t::write_reg.

Referenced by lis2mdl_block_data_update_set(), lis2mdl_boot_set(), lis2mdl_data_format_set(), lis2mdl_data_rate_set(), lis2mdl_drdy_on_pin_set(), lis2mdl_i2c_interface_set(), lis2mdl_init(), lis2mdl_init_2(), lis2mdl_int_gen_conf_set(), lis2mdl_int_gen_threshold_set(), lis2mdl_int_on_pin_set(), lis2mdl_low_pass_bandwidth_set(), lis2mdl_mag_user_offset_set(), lis2mdl_offset_int_conf_set(), lis2mdl_offset_temp_comp_set(), lis2mdl_operating_mode_set(), lis2mdl_power_mode_set(), lis2mdl_reset_set(), lis2mdl_self_test_set(), lis2mdl_set_rst_mode_set(), lis2mdl_set_rst_sensor_single_set(), and lis2mdl_spi_mode_set().

Here is the caller graph for this function: