Add /dev/i2c driver
This commit is contained in:
parent
accbed7d3b
commit
d55e9e63f5
1 changed files with 30 additions and 0 deletions
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue