lis2mdl driver computes the wrong hard iron offsets
lis2mdl_reg.c has an error in the function int32_t lis2mdl_mag_user_offset_set(stmdev_ctx_t *ctx, int16_t *val).
The function incorrectly calculates the OFFSET_X_REG_H, OFFSET_Y_REG_H, and the OFFSET_Z_REG_H registers because it converts val[0] to an uint8_t before performing the calculation.
I believe the function should be modified as follows:
int32_t lis2mdl_mag_user_offset_set(stmdev_ctx_t *ctx, int16_t *val)
{
uint8_t buff[6];
int32_t ret;
buff[1] = (uint8_t) (val[0] / 256U);
buff[0] = (uint8_t) (val[0] - (buff[1] * 256U));
buff[3] = (uint8_t) (val[1] / 256U);
buff[2] = (uint8_t) (val[1] - (buff[1] * 256U));
buff[5] = (uint8_t) (val[2] / 256U);
buff[4] = (uint8_t) (val[2] - (buff[1] * 256U));
ret = lis2mdl_write_reg(ctx, LIS2MDL_OFFSET_X_REG_L, buff, 6);
return ret;
}
