adafruit / Adafruit_CircuitPython_Register

Python data descriptor classes to represent hardware registers on I2C devices.
MIT License
47 stars 21 forks source link

RWBits: Add support for signed registers #39

Closed jepler closed 4 years ago

jepler commented 4 years ago

An example of a signed register is the calibration value of the PCF8523 real-time clock, which stores values from -64 to +63 in 7 bits. This could now be specified as

calibration = i2c_bits.RWBits(7, 0xe, 0, signed=True)

Note that assigning a negative value to an RWBits already worked, regardless of whether the register was signed, so it was already possible to write -2 to the register; this just allows it to be read back as -2 instead of 126.

jepler commented 3 years ago

Thank you!