20 lines
552 B
Python
20 lines
552 B
Python
|
|
|
|
class I2C_Device:
|
|
def __init__(self, i2c_dev, i2c_addr):
|
|
self._device = i2c_dev
|
|
self._addr = i2c_addr
|
|
|
|
def write8(self, register, data):
|
|
b = data.to_bytes(1, 'little')
|
|
self._device.writeto_mem(self._addr, register, b)
|
|
|
|
def readU8(self, register):
|
|
result = self._device.readfrom_mem(self._addr, register, 1)
|
|
return result[0]
|
|
|
|
def readU16LE(self, register):
|
|
result = self._device.readfrom_mem(self._addr, register, 2)
|
|
r = int.from_bytes(result, 'little')
|
|
return r
|