Open lgehreke opened 3 days ago
Hello @lgehreke, thank you for the PR, I'll check and test the changes and let you know asap. It's weird that the two complement calculation is wrong, because the formula is used by multiple other projects, but I haven't dug deeper into it yet.
I did some research on it. What the xor does is mapping the negative values coming from the chip from [−8388608, 8388607] to [0, 16777215]. For this use case it is perfectly usable. Maybe the "correct" conversion can be added as Kconfig option.
Some fixups and additions:
Power management
PM_DEVICE_ACTION_TURN_OFF
is only used by power domains. To correctly power down the sensor it needs to react toPM_DEVICE_ACTION_SUSPEND
.Twos complement conversion
The sensor outputs the adc value as twos complement. Even though it is given in the datasheets example code, performing a xor with 0x800000 is not the correct way to convert the value. See https://en.wikipedia.org/wiki/Two%27s_complement for details.
Addition