iio: hid-sensor: Fix scale for magnetic north heading
Subsystems (2)
PATCH 1/1 iio: hid-sensor: Fix scale for magnetic north heading
hid_sensor_format_scale() applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].
Rotation-from-north support uses HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.
Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.
--- drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2 -0
@@ -38,6 +38,8 @@ static const struct { {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000}, {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0}, + {HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0}, + {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
Signature · 1 line
2.56.0
Jonathan Cameron
maintainerQuoted 9 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:
hid_sensor_format_scale()applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].Rotation-from-north support uses
HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.
Quoted 7 lines
Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for rotation from north")Signed-off-by Maximilian Czirr <[email protected]>
+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.
Quoted 17 lines
--- drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2
-0@@ -38,6 +38,8 @@ static const struct { {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000}, {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0}, + {HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0}, + {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
Jonathan Cameron
maintainerQuoted 16 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 13 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:
hid_sensor_format_scale()applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].Rotation-from-north support uses
HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in the conversion table. As a result, the unit exponent is ignored and the heading can be exposed with a scale of 1 instead of the scale specified by the HID descriptor.Add a unitless conversion entry so the HID unit exponent is applied to the magnetic north heading. A sensor reporting an exponent of -5 then correctly exposes a scale of 0.00001 instead of 1.
Quoted 7 lines
Quoted 3 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support for rotation from north")Signed-off-by Maximilian Czirr <[email protected]>+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.
Srinivas, another one for you to check when you have a moment!
No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.
thanks
Jonathan
Quoted 19 lines
Quoted 17 lines
--- drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++ 1 file changed, 2 insertions(+)drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2
-0@@ -38,6 +38,8 @@ static const struct { {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000}, {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0}, + {HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0}, + {HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D, HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
srinivas pandruvada
Acked-byQuoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:
hid_sensor_format_scale()applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].Rotation-from-north support uses
HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in
the conversion table. As a result, the unit exponent is ignored and the
heading can be exposed with a scale of 1 instead of the scale specified
by the HID descriptor.Add a unitless conversion entry so the HID unit exponent is applied to
the magnetic north heading. A sensor reporting an exponent of -5 then
correctly exposes a scale of 0.00001 instead of 1.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support forrotation from north")
Signed-off-by Maximilian Czirr <[email protected]>
Quoted 33 lines
Quoted 3 lines
+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.
Srinivas, another one for you to check when you have a moment!
No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.
thanks
Jonathan
Quoted 22 lines
Quoted 20 lines
---
drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++1 file changed, 2 insertions(+)(quoted diff) +0
-0
attributes.cb/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index9e7c26e37880..26f8554d18a5100644drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0
-0@@ -38,6 +38,8 @@ static const struct { {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000}, {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2
-0+ {HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0}, +{
HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D,HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},
Quoted 25 lines · On Mon, 02 Nov 2026 09:15:07 -0800 srinivas pandruvada…
Quoted 24 lines · Jonathan Cameron
Quoted 21 lines · On Sun, 18 Oct 2026 20:36:59 +0100 Jonathan Cameron <[email protected]> wrote:
Quoted 18 lines · On Wed, 7 Oct 2026 02:01:07 +0200 Maximilian Czirr <[email protected]> wrote:
hid_sensor_format_scale()applies the HID unit exponent only when the usage and unit match an entry in unit_conversion[].Rotation-from-north support uses
HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, but that usage has no entry in
the conversion table. As a result, the unit exponent is ignored and the
heading can be exposed with a scale of 1 instead of the scale specified
by the HID descriptor.Add a unitless conversion entry so the HID unit exponent is applied to
the magnetic north heading. A sensor reporting an exponent of -5 then
correctly exposes a scale of 0.00001 instead of 1.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Fixes abea9c62c32f ("iio: hid-sensor-magn-3d: Add support forrotation from north")
Signed-off-by Maximilian Czirr <[email protected]>
Thanks.
Applied to the fixes-togreg branch of iio.git
Jonathan
Quoted 34 lines
Quoted 34 lines
Quoted 4 lines
+CC the hid-sensors maintainers + Lixu who has been helping a lot with this driver recently.
Srinivas, another one for you to check when you have a moment!
No huge rush - I'm just having a scan through what is outstanding in patchwork to make sure I didn't miss anything.
thanks
Jonathan
Quoted 22 lines
Quoted 20 lines
---
drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 2 ++1 file changed, 2 insertions(+)(quoted diff) +0
-0
attributes.cb/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index9e7c26e37880..26f8554d18a5100644drivers/iio/common/hid-sensors/hid-sensor-attributes.c +0
-0@@ -38,6 +38,8 @@ static const struct { {HID_USAGE_SENSOR_COMPASS_3D, 0, 0, 1000000}, {HID_USAGE_SENSOR_COMPASS_3D, HID_USAGE_SENSOR_UNITS_GAUSS, 1, 0},drivers/iio/common/hid-sensors/hid-sensor-attributes.c +2
-0+ {HID_USAGE_SENSOR_ORIENT_COMP_MAGN_NORTH, 0, 1, 0}, +{
HID_USAGE_SENSOR_INCLINOMETER_3D, 0, 0, 17453293}, {HID_USAGE_SENSOR_INCLINOMETER_3D,HID_USAGE_SENSOR_UNITS_DEGREES, 0, 17453293},