mcp4018: Support setting minclock and reqclock in SoftwareI2C class

This is in preparation for pca9632 changes.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-03-23 00:35:42 -04:00
parent 9136a29196
commit 0c425cf014
1 changed files with 14 additions and 11 deletions

View File

@ -31,18 +31,20 @@ class SoftwareI2C:
self.mcu.add_config_cmd("config_digital_out oid=%d pin=%s"
" value=%d default_value=%d max_duration=%d" % (
self.sda_oid, sda_params['pin'], 1, 1, 0))
def get_mcu(self):
return self.mcu
def build_config(self):
self.mcu.add_config_cmd("config_digital_out oid=%d pin=%s value=%d"
" default_value=%d max_duration=%d" % (
self.scl_oid, self.scl_pin, 1, 1, 0))
self.update_pin_cmd = self.mcu.lookup_command(
"update_digital_out oid=%c value=%c", cq=self.cmd_queue)
def i2c_write(self, msg):
def i2c_write(self, msg, minclock=0, reqclock=0):
msg = [self.addr] + msg
send = self.scl_main.update_pin_cmd.send
# Send ack
send([self.sda_oid, 0])
send([self.scl_oid, 0])
send([self.sda_oid, 0], minclock=minclock, reqclock=reqclock)
send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock)
# Send bytes
sda_last = 0
for data in msg:
@ -51,17 +53,18 @@ class SoftwareI2C:
sda_next = not not (data & (0x80 >> i))
if sda_last != sda_next:
sda_last = sda_next
send([self.sda_oid, sda_last])
send([self.scl_oid, 1])
send([self.scl_oid, 0])
send([self.sda_oid, sda_last],
minclock=minclock, reqclock=reqclock)
send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock)
send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock)
# Transmit clock for ack
send([self.scl_oid, 1])
send([self.scl_oid, 0])
send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock)
send([self.scl_oid, 0], minclock=minclock, reqclock=reqclock)
# Send stop
if sda_last:
send([self.sda_oid, 0])
send([self.scl_oid, 1])
send([self.sda_oid, 1])
send([self.sda_oid, 0], minclock=minclock, reqclock=reqclock)
send([self.scl_oid, 1], minclock=minclock, reqclock=reqclock)
send([self.sda_oid, 1], minclock=minclock, reqclock=reqclock)
class mcp4018:
def __init__(self, config):