3-axis MEMS ultra low power magnetometer

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   X_NUCLEO_IKS01A3

Revision:
1:8562ae1a0534
Parent:
0:671edf39d961
--- a/lis2mdl_reg.c	Tue Mar 05 18:06:37 2019 +0000
+++ b/lis2mdl_reg.c	Wed Jul 24 14:18:39 2019 +0000
@@ -62,12 +62,12 @@
   * @retval       interface status (MANDATORY: return 0 -> no Error)
   *
   */
-int32_t lis2mdl_read_reg(lis2mdl_ctx_t* ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_read_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
                          uint16_t len)
 {
-  int32_t ret;
-  ret = ctx->read_reg(ctx->handle, reg, data, len);
-  return ret;
+    int32_t ret;
+    ret = ctx->read_reg(ctx->handle, reg, data, len);
+    return ret;
 }
 
 /**
@@ -80,12 +80,12 @@
   * @retval       interface status (MANDATORY: return 0 -> no Error)
   *
   */
-int32_t lis2mdl_write_reg(lis2mdl_ctx_t* ctx, uint8_t reg, uint8_t* data,
+int32_t lis2mdl_write_reg(lis2mdl_ctx_t *ctx, uint8_t reg, uint8_t *data,
                           uint16_t len)
 {
-  int32_t ret;
-  ret = ctx->write_reg(ctx->handle, reg, data, len);
-  return ret;
+    int32_t ret;
+    ret = ctx->write_reg(ctx->handle, reg, data, len);
+    return ret;
 }
 
 /**
@@ -93,20 +93,20 @@
   *
   */
 
-  /**
-  * @defgroup    LIS2MDL_Sensitivity
-  * @brief       These functions convert raw-data into engineering units.
-  * @{
-  *
-  */
+/**
+* @defgroup    LIS2MDL_Sensitivity
+* @brief       These functions convert raw-data into engineering units.
+* @{
+*
+*/
 float_t lis2mdl_from_lsb_to_mgauss(int16_t lsb)
 {
-  return ((float_t)lsb * 1.5f);
+    return ((float_t)lsb * 1.5f);
 }
 
 float_t lis2mdl_from_lsb_to_celsius(int16_t lsb)
 {
-  return (((float_t)lsb / 8.0f) + 25.0f);
+    return (((float_t)lsb / 8.0f) + 25.0f);
 }
 
 /**
@@ -136,9 +136,9 @@
   */
 int32_t lis2mdl_mag_user_offset_set(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
+    return ret;
 }
 
 /**
@@ -155,9 +155,9 @@
   */
 int32_t lis2mdl_mag_user_offset_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
+    return ret;
 }
 
 /**
@@ -170,17 +170,17 @@
   */
 int32_t lis2mdl_operating_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_md_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.md = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.md = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -193,30 +193,30 @@
   */
 int32_t lis2mdl_operating_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_md_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  switch (reg.md){
-    case LIS2MDL_POWER_DOWN:
-      *val = LIS2MDL_POWER_DOWN;
-      break;
-    case LIS2MDL_CONTINUOUS_MODE:
-      *val = LIS2MDL_CONTINUOUS_MODE;
-      break;
-    case LIS2MDL_SINGLE_TRIGGER:
-      *val = LIS2MDL_SINGLE_TRIGGER;
-      break;
-    default:
-      *val = LIS2MDL_POWER_DOWN;
-      break;
-  }  
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    switch (reg.md) {
+        case LIS2MDL_POWER_DOWN:
+            *val = LIS2MDL_POWER_DOWN;
+            break;
+        case LIS2MDL_CONTINUOUS_MODE:
+            *val = LIS2MDL_CONTINUOUS_MODE;
+            break;
+        case LIS2MDL_SINGLE_TRIGGER:
+            *val = LIS2MDL_SINGLE_TRIGGER;
+            break;
+        default:
+            *val = LIS2MDL_POWER_DOWN;
+            break;
+    }
 
-  return ret;
+    return ret;
 }
 
 /**
-  * @brief  Output data rate selection.[set] 
+  * @brief  Output data rate selection.[set]
   *
   * @param  ctx   read / write interface definitions.(ptr)
   * @param  val   change the values of odr in reg CFG_REG_A
@@ -225,21 +225,21 @@
   */
 int32_t lis2mdl_data_rate_set(lis2mdl_ctx_t *ctx, lis2mdl_odr_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.odr = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.odr = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
-  * @brief  Output data rate selection.[get] 
+  * @brief  Output data rate selection.[get]
   *
   * @param  ctx   read / write interface definitions.(ptr)
   * @param  val   Get the values of odr in reg CFG_REG_A.(ptr)
@@ -248,28 +248,28 @@
   */
 int32_t lis2mdl_data_rate_get(lis2mdl_ctx_t *ctx, lis2mdl_odr_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  switch (reg.odr){
-    case LIS2MDL_ODR_10Hz:
-      *val = LIS2MDL_ODR_10Hz;
-      break;
-    case LIS2MDL_ODR_20Hz:
-      *val = LIS2MDL_ODR_20Hz;
-      break;
-    case LIS2MDL_ODR_50Hz:
-      *val = LIS2MDL_ODR_50Hz;
-      break;
-    case LIS2MDL_ODR_100Hz:
-      *val = LIS2MDL_ODR_100Hz;
-      break;
-    default:
-      *val = LIS2MDL_ODR_10Hz;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    switch (reg.odr) {
+        case LIS2MDL_ODR_10Hz:
+            *val = LIS2MDL_ODR_10Hz;
+            break;
+        case LIS2MDL_ODR_20Hz:
+            *val = LIS2MDL_ODR_20Hz;
+            break;
+        case LIS2MDL_ODR_50Hz:
+            *val = LIS2MDL_ODR_50Hz;
+            break;
+        case LIS2MDL_ODR_100Hz:
+            *val = LIS2MDL_ODR_100Hz;
+            break;
+        default:
+            *val = LIS2MDL_ODR_10Hz;
+            break;
+    }
+    return ret;
 }
 
 /**
@@ -282,17 +282,17 @@
   */
 int32_t lis2mdl_power_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_lp_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.lp = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.lp = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -305,26 +305,26 @@
   */
 int32_t lis2mdl_power_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_lp_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  switch (reg.lp){
-    case LIS2MDL_HIGH_RESOLUTION:
-      *val = LIS2MDL_HIGH_RESOLUTION;
-      break;
-    case LIS2MDL_LOW_POWER:
-      *val = LIS2MDL_LOW_POWER;
-      break;
-    default:
-      *val = LIS2MDL_HIGH_RESOLUTION;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    switch (reg.lp) {
+        case LIS2MDL_HIGH_RESOLUTION:
+            *val = LIS2MDL_HIGH_RESOLUTION;
+            break;
+        case LIS2MDL_LOW_POWER:
+            *val = LIS2MDL_LOW_POWER;
+            break;
+        default:
+            *val = LIS2MDL_HIGH_RESOLUTION;
+            break;
+    }
+    return ret;
 }
 
 /**
-  * @brief  Enables the magnetometer temperature compensation.[set] 
+  * @brief  Enables the magnetometer temperature compensation.[set]
   *
   * @param  ctx   read / write interface definitions.(ptr)
   * @param  val   change the values of comp_temp_en in reg CFG_REG_A
@@ -333,17 +333,17 @@
   */
 int32_t lis2mdl_offset_temp_comp_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.comp_temp_en = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.comp_temp_en = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -356,13 +356,13 @@
   */
 int32_t lis2mdl_offset_temp_comp_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  *val = reg.comp_temp_en;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    *val = reg.comp_temp_en;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -376,17 +376,17 @@
 int32_t lis2mdl_low_pass_bandwidth_set(lis2mdl_ctx_t *ctx,
                                        lis2mdl_lpf_t val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.lpf = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.lpf = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -400,22 +400,22 @@
 int32_t lis2mdl_low_pass_bandwidth_get(lis2mdl_ctx_t *ctx,
                                        lis2mdl_lpf_t *val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  switch (reg.lpf){
-    case LIS2MDL_ODR_DIV_2:
-      *val = LIS2MDL_ODR_DIV_2;
-      break;
-    case LIS2MDL_ODR_DIV_4:
-      *val = LIS2MDL_ODR_DIV_4;
-      break;
-    default:
-      *val = LIS2MDL_ODR_DIV_2;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    switch (reg.lpf) {
+        case LIS2MDL_ODR_DIV_2:
+            *val = LIS2MDL_ODR_DIV_2;
+            break;
+        case LIS2MDL_ODR_DIV_4:
+            *val = LIS2MDL_ODR_DIV_4;
+            break;
+        default:
+            *val = LIS2MDL_ODR_DIV_2;
+            break;
+    }
+    return ret;
 }
 
 /**
@@ -428,17 +428,17 @@
   */
 int32_t lis2mdl_set_rst_mode_set(lis2mdl_ctx_t *ctx, lis2mdl_set_rst_t val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.set_rst = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.set_rst = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -451,29 +451,29 @@
   */
 int32_t lis2mdl_set_rst_mode_get(lis2mdl_ctx_t *ctx, lis2mdl_set_rst_t *val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  switch (reg.set_rst){
-    case LIS2MDL_SET_SENS_ODR_DIV_63:
-      *val = LIS2MDL_SET_SENS_ODR_DIV_63;
-      break;
-    case LIS2MDL_SENS_OFF_CANC_EVERY_ODR:
-      *val = LIS2MDL_SENS_OFF_CANC_EVERY_ODR;
-      break;
-    case LIS2MDL_SET_SENS_ONLY_AT_POWER_ON:
-      *val = LIS2MDL_SET_SENS_ONLY_AT_POWER_ON;
-      break;
-    default:
-      *val = LIS2MDL_SET_SENS_ODR_DIV_63;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    switch (reg.set_rst) {
+        case LIS2MDL_SET_SENS_ODR_DIV_63:
+            *val = LIS2MDL_SET_SENS_ODR_DIV_63;
+            break;
+        case LIS2MDL_SENS_OFF_CANC_EVERY_ODR:
+            *val = LIS2MDL_SENS_OFF_CANC_EVERY_ODR;
+            break;
+        case LIS2MDL_SET_SENS_ONLY_AT_POWER_ON:
+            *val = LIS2MDL_SET_SENS_ONLY_AT_POWER_ON;
+            break;
+        default:
+            *val = LIS2MDL_SET_SENS_ODR_DIV_63;
+            break;
+    }
+    return ret;
 }
 
 /**
-  * @brief  Enables offset cancellation in single measurement mode. 
+  * @brief  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)
@@ -486,21 +486,21 @@
   */
 int32_t lis2mdl_set_rst_sensor_single_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.off_canc_one_shot = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.off_canc_one_shot = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
-  * @brief  Enables offset cancellation in single measurement mode. 
+  * @brief  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)
@@ -513,13 +513,13 @@
   */
 int32_t lis2mdl_set_rst_sensor_single_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  *val = reg.off_canc_one_shot;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    *val = reg.off_canc_one_shot;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -532,17 +532,17 @@
   */
 int32_t lis2mdl_block_data_update_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.bdu = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.bdu = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -555,13 +555,13 @@
   */
 int32_t lis2mdl_block_data_update_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  *val = reg.bdu;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    *val = reg.bdu;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -574,13 +574,13 @@
   */
 int32_t lis2mdl_mag_data_ready_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_status_reg_t reg;
-  int32_t ret;
+    lis2mdl_status_reg_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*)&reg, 1);
-  *val = reg.zyxda;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
+    *val = reg.zyxda;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -593,13 +593,13 @@
   */
 int32_t lis2mdl_mag_data_ovr_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_status_reg_t reg;
-  int32_t ret;
+    lis2mdl_status_reg_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*)&reg, 1);
-  *val = reg.zyxor;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *)&reg, 1);
+    *val = reg.zyxor;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -612,9 +612,9 @@
   */
 int32_t lis2mdl_magnetic_raw_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_OUTX_L_REG, buff, 6);
+    return ret;
 }
 
 /**
@@ -627,9 +627,9 @@
   */
 int32_t lis2mdl_temperature_raw_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_TEMP_OUT_L_REG, buff, 2);
+    return ret;
 }
 
 /**
@@ -654,9 +654,9 @@
   */
 int32_t lis2mdl_device_id_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_WHO_AM_I, buff, 1);
+    return ret;
 }
 
 /**
@@ -669,17 +669,17 @@
   */
 int32_t lis2mdl_reset_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.soft_rst = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.soft_rst = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -692,17 +692,17 @@
   */
 int32_t lis2mdl_reset_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  *val = reg.soft_rst;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    *val = reg.soft_rst;
 
-  return ret;
+    return ret;
 }
 
 /**
-  * @brief  Reboot memory content. Reload the calibration parameters.[set] 
+  * @brief  Reboot memory content. Reload the calibration parameters.[set]
   *
   * @param  ctx   read / write interface definitions.(ptr)
   * @param  val   change the values of reboot in reg CFG_REG_A
@@ -711,17 +711,17 @@
   */
 int32_t lis2mdl_boot_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.reboot = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.reboot = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -734,13 +734,13 @@
   */
 int32_t lis2mdl_boot_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_a_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_a_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t*)&reg, 1);
-  *val = reg.reboot;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_A, (uint8_t *)&reg, 1);
+    *val = reg.reboot;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -753,17 +753,17 @@
   */
 int32_t lis2mdl_self_test_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.self_test = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.self_test = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -776,13 +776,13 @@
   */
 int32_t lis2mdl_self_test_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  *val = reg.self_test;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    *val = reg.self_test;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -795,17 +795,17 @@
   */
 int32_t lis2mdl_data_format_set(lis2mdl_ctx_t *ctx, lis2mdl_ble_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.ble = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.ble = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -818,22 +818,22 @@
   */
 int32_t lis2mdl_data_format_get(lis2mdl_ctx_t *ctx, lis2mdl_ble_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  switch (reg.ble){
-    case LIS2MDL_LSB_AT_LOW_ADD:
-      *val = LIS2MDL_LSB_AT_LOW_ADD;
-      break;
-    case LIS2MDL_MSB_AT_LOW_ADD:
-      *val = LIS2MDL_MSB_AT_LOW_ADD;
-      break;
-    default:
-      *val = LIS2MDL_LSB_AT_LOW_ADD;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    switch (reg.ble) {
+        case LIS2MDL_LSB_AT_LOW_ADD:
+            *val = LIS2MDL_LSB_AT_LOW_ADD;
+            break;
+        case LIS2MDL_MSB_AT_LOW_ADD:
+            *val = LIS2MDL_MSB_AT_LOW_ADD;
+            break;
+        default:
+            *val = LIS2MDL_LSB_AT_LOW_ADD;
+            break;
+    }
+    return ret;
 }
 
 /**
@@ -846,9 +846,9 @@
   */
 int32_t lis2mdl_status_get(lis2mdl_ctx_t *ctx, lis2mdl_status_reg_t *val)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t*) val, 1);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_STATUS_REG, (uint8_t *) val, 1);
+    return ret;
 }
 
 /**
@@ -875,17 +875,17 @@
 int32_t lis2mdl_offset_int_conf_set(lis2mdl_ctx_t *ctx,
                                     lis2mdl_int_on_dataoff_t val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.int_on_dataoff = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.int_on_dataoff = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -900,22 +900,22 @@
 int32_t lis2mdl_offset_int_conf_get(lis2mdl_ctx_t *ctx,
                                     lis2mdl_int_on_dataoff_t *val)
 {
-  lis2mdl_cfg_reg_b_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_b_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t*)&reg, 1);
-  switch (reg.int_on_dataoff){
-    case LIS2MDL_CHECK_BEFORE:
-      *val = LIS2MDL_CHECK_BEFORE;
-      break;
-    case LIS2MDL_CHECK_AFTER:
-      *val = LIS2MDL_CHECK_AFTER;
-      break;
-    default:
-      *val = LIS2MDL_CHECK_BEFORE;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_B, (uint8_t *)&reg, 1);
+    switch (reg.int_on_dataoff) {
+        case LIS2MDL_CHECK_BEFORE:
+            *val = LIS2MDL_CHECK_BEFORE;
+            break;
+        case LIS2MDL_CHECK_AFTER:
+            *val = LIS2MDL_CHECK_AFTER;
+            break;
+        default:
+            *val = LIS2MDL_CHECK_BEFORE;
+            break;
+    }
+    return ret;
 }
 
 /**
@@ -928,17 +928,17 @@
   */
 int32_t lis2mdl_drdy_on_pin_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.drdy_on_pin = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.drdy_on_pin = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -951,13 +951,13 @@
   */
 int32_t lis2mdl_drdy_on_pin_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  *val = reg.drdy_on_pin;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    *val = reg.drdy_on_pin;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -970,17 +970,17 @@
   */
 int32_t lis2mdl_int_on_pin_set(lis2mdl_ctx_t *ctx, uint8_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.int_on_pin = val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.int_on_pin = val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -993,13 +993,13 @@
   */
 int32_t lis2mdl_int_on_pin_get(lis2mdl_ctx_t *ctx, uint8_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  *val = reg.int_on_pin;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    *val = reg.int_on_pin;
 
-  return ret;
+    return ret;
 }
 
 /**
@@ -1013,9 +1013,9 @@
 int32_t lis2mdl_int_gen_conf_set(lis2mdl_ctx_t *ctx,
                                  lis2mdl_int_crtl_reg_t *val)
 {
-  int32_t ret;
-  ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t*) val, 1);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
+    return ret;
 }
 
 /**
@@ -1029,9 +1029,9 @@
 int32_t lis2mdl_int_gen_conf_get(lis2mdl_ctx_t *ctx,
                                  lis2mdl_int_crtl_reg_t *val)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t*) val, 1);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_CRTL_REG, (uint8_t *) val, 1);
+    return ret;
 }
 
 /**
@@ -1045,9 +1045,9 @@
 int32_t lis2mdl_int_gen_source_get(lis2mdl_ctx_t *ctx,
                                    lis2mdl_int_source_reg_t *val)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t*) val, 1);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_SOURCE_REG, (uint8_t *) val, 1);
+    return ret;
 }
 
 /**
@@ -1062,9 +1062,9 @@
   */
 int32_t lis2mdl_int_gen_treshold_set(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_write_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
+    return ret;
 }
 
 /**
@@ -1079,9 +1079,9 @@
   */
 int32_t lis2mdl_int_gen_treshold_get(lis2mdl_ctx_t *ctx, uint8_t *buff)
 {
-  int32_t ret;
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
-  return ret;
+    int32_t ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_INT_THS_L_REG, buff, 2);
+    return ret;
 }
 
 /**
@@ -1107,17 +1107,17 @@
   */
 int32_t lis2mdl_i2c_interface_set(lis2mdl_ctx_t *ctx, lis2mdl_i2c_dis_t val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
+
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  
-  if(ret == 0){
-    reg.i2c_dis = (uint8_t)val;
-    ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  }
-  
-  return ret;
+    if (ret == 0) {
+        reg.i2c_dis = (uint8_t)val;
+        ret = lis2mdl_write_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    }
+
+    return ret;
 }
 
 /**
@@ -1130,22 +1130,22 @@
   */
 int32_t lis2mdl_i2c_interface_get(lis2mdl_ctx_t *ctx, lis2mdl_i2c_dis_t *val)
 {
-  lis2mdl_cfg_reg_c_t reg;
-  int32_t ret;
+    lis2mdl_cfg_reg_c_t reg;
+    int32_t ret;
 
-  ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t*)&reg, 1);
-  switch (reg.i2c_dis){
-    case LIS2MDL_I2C_ENABLE:
-      *val = LIS2MDL_I2C_ENABLE;
-      break;
-    case LIS2MDL_I2C_DISABLE:
-      *val = LIS2MDL_I2C_DISABLE;
-      break;
-    default:
-      *val = LIS2MDL_I2C_ENABLE;
-      break;
-  }
-  return ret;
+    ret = lis2mdl_read_reg(ctx, LIS2MDL_CFG_REG_C, (uint8_t *)&reg, 1);
+    switch (reg.i2c_dis) {
+        case LIS2MDL_I2C_ENABLE:
+            *val = LIS2MDL_I2C_ENABLE;
+            break;
+        case LIS2MDL_I2C_DISABLE:
+            *val = LIS2MDL_I2C_DISABLE;
+            break;
+        default:
+            *val = LIS2MDL_I2C_ENABLE;
+            break;
+    }
+    return ret;
 }
 
 /**