mirror of https://github.com/Desuuuu/klipper.git
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:
parent
9136a29196
commit
0c425cf014
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue