nobodyguy / HX711_zephyr_driver

Out of tree HX711 weight sensor driver for Zephyr RTOS
Apache License 2.0
23 stars 15 forks source link

Driver logic fixups and additions #13

Open lgehreke opened 3 days ago

lgehreke commented 3 days ago

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 to PM_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

nobodyguy commented 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.

lgehreke commented 2 days ago

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.