Skip to content

Incorrect mapping from hwmon sensor type into iio sensor type #1401

@damijans

Description

@damijans

iio library defines two bunch of sensor type, one for hwmon and the other for iio sensors.

hwmon sensor type are defined with
enum hwmon_chan_type {
HWMON_VOLTAGE,
HWMON_FAN,
HWMON_PWM,
HWMON_TEMP,
HWMON_CURRENT,
HWMON_POWER,
HWMON_ENERGY,
HWMON_HUMIDITY,
HWMON_INTRUSION,
HWMON_CHAN_TYPE_UNKNOWN = IIO_CHAN_TYPE_UNKNOWN,
};
while iio sensor types are define with
enum iio_chan_type {
IIO_VOLTAGE,
IIO_CURRENT,
IIO_POWER,
IIO_ACCEL,
IIO_ANGL_VEL,
IIO_MAGN,
IIO_LIGHT,
IIO_INTENSITY,
IIO_PROXIMITY,
IIO_TEMP,
IIO_INCLI,
IIO_ROT,
IIO_ANGL,
IIO_TIMESTAMP,
IIO_CAPACITANCE,
IIO_ALTVOLTAGE,
IIO_CCT,
IIO_PRESSURE,
IIO_HUMIDITYRELATIVE,
IIO_ACTIVITY,
IIO_STEPS,
IIO_ENERGY,
IIO_DISTANCE,
IIO_VELOCITY,
IIO_CONCENTRATION,
IIO_RESISTANCE,
IIO_PH,
IIO_UVINDEX,
IIO_ELECTRICALCONDUCTIVITY,
IIO_COUNT,
IIO_INDEX,
IIO_GRAVITY,
IIO_POSITIONRELATIVE,
IIO_PHASE,
IIO_MASSCONCENTRATION,
IIO_DELTA_ANGL,
IIO_DELTA_VELOCITY,
IIO_COLORTEMP,
IIO_CHROMATICITY,
IIO_ATTENTION,
IIO_ALTCURRENT,
IIO_CHAN_TYPE_UNKNOWN = INT_MAX
};

when library enumerates hwmon sensors from the system fs, it converts type description into hwmon_chan_type in iio_channel_init_finalize() function based on hwmon_chan_type_name_spec table. Here "temp1" sensor description is correctly converted into HWMON_TEMP type. However, later on, this type is typecasted directly into iio_chan_type, i.e. HWMON_TEMP(value 3) is converted into IIO_ACCEL(value 3), what is wrong. Rather it should be converted into IIO_TEMP (value 7).

The same mistake happens also in the opposite direction, i.e. conversion from iio_chan_type into hwmon_chan_type (see hwmon_channel_get_type() function)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions