Add /dev/i2c driver

This commit is contained in:
Patrick Moessler 2022-01-09 19:38:19 +01:00
parent accbed7d3b
commit d55e9e63f5

View file

@ -27,6 +27,36 @@ class I2CInterface:
pass
class DevI2CInterface(I2CInterface):
def __init__(self, bus) -> None:
super().__init__()
from smbus import SMBus, i2c_msg
self.bus = SMBus(bus)
self.msg = i2c_msg
def read(self, addr: int, length: int) -> bytes:
m = self.msg.read(addr, length)
self.bus.i2c_rdwr(m)
return bytes(m.buf[0:length])
def write(self, addr: int, data: bytes) -> None:
m = self.msg.write(addr, data)
self.bus.i2c_rdwr(m)
def write_read(self, addr: int, data: bytes, length: int) -> bytes:
mw = self.msg.write(addr, data)
mr = self.msg.read(addr, length)
self.bus.i2c_rdwr(mw, mr)
return bytes(mr.buf[0:length])
def open(self) -> None:
pass
def close(self) -> None:
pass
class JLinkSwdI2CInterface(I2CInterface):
GPIO_BASE = {
'PA': 0x40010800,