From 0f4bd654d2255cdb3a0ec192ddf051e55010eee3 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 18 Jun 2026 16:23:36 -0700 Subject: [PATCH] Introduce lsm6dsv16x_from_f32_to_f16() Introduce lsm6dsv16x_from_f32_to_f16() which is inverse of lsm6dsv16x_from_f16_to_f32() already exported by the library. This is useful for setting various FP16 parameters in the IMU, e.g. things related to sensor fusion algorithm. --- lsm6dsv16x_reg.c | 4 ++++ lsm6dsv16x_reg.h | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lsm6dsv16x_reg.c b/lsm6dsv16x_reg.c index 1899a52..0089881 100644 --- a/lsm6dsv16x_reg.c +++ b/lsm6dsv16x_reg.c @@ -7910,6 +7910,10 @@ static uint16_t npy_float_to_half(float_t f) return npy_floatbits_to_halfbits(fbits); } +uint16_t lsm6dsv16x_from_f32_to_f16(float_t val) +{ + return npy_float_to_half(val); +} int32_t lsm6dsv16x_sflp_game_gbias_set(const stmdev_ctx_t *ctx, const lsm6dsv16x_sflp_gbias_t *val) diff --git a/lsm6dsv16x_reg.h b/lsm6dsv16x_reg.h index 8f836bb..39c625b 100644 --- a/lsm6dsv16x_reg.h +++ b/lsm6dsv16x_reg.h @@ -4077,6 +4077,15 @@ float_t lsm6dsv16x_from_lsb_to_mv(int16_t lsb); */ uint32_t lsm6dsv16x_from_f16_to_f32(uint16_t val); +/** + * @brief Convert from FP32 to FP16 numbers (e.g. quaternions) + * + * @param val single-precision (32-bit) float number + * @retval half-precision (16-bit) float number + * + */ +uint16_t lsm6dsv16x_from_f32_to_f16(float_t val); + /** * @} *