mirror of
https://github.com/andreili/klipper.git
synced 2025-09-14 17:31:12 +02:00
sx1509: migrate i2c write to connect phase
Signed-off-by: Timofey Titovets <nefelim4ag@gmail.com>
This commit is contained in:
parent
b817848567
commit
9a1ac45d19
@ -29,7 +29,6 @@ class SX1509(object):
|
||||
self._ppins = self._printer.lookup_object("pins")
|
||||
self._ppins.register_chip("sx1509_" + self._name, self)
|
||||
self._mcu = self._i2c.get_mcu()
|
||||
self._mcu.register_config_callback(self._build_config)
|
||||
self._oid = self._i2c.get_oid()
|
||||
self._last_clock = 0
|
||||
# Set up registers default values
|
||||
@ -37,22 +36,22 @@ class SX1509(object):
|
||||
REG_PULLUP : 0, REG_PULLDOWN : 0,
|
||||
REG_INPUT_DISABLE : 0, REG_ANALOG_DRIVER_ENABLE : 0}
|
||||
self.reg_i_on_dict = {reg : 0 for reg in REG_I_ON}
|
||||
def _build_config(self):
|
||||
config.get_printer().register_event_handler("klippy:connect",
|
||||
self.handle_connect)
|
||||
def handle_connect(self):
|
||||
# Reset the chip, Default RegClock/RegMisc 0x0
|
||||
self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % (
|
||||
self._oid, REG_RESET, 0x12))
|
||||
self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % (
|
||||
self._oid, REG_RESET, 0x34))
|
||||
self._i2c.i2c_write([REG_RESET, 0x12])
|
||||
self._i2c.i2c_write([REG_RESET, 0x34])
|
||||
# Enable Oscillator
|
||||
self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % (
|
||||
self._oid, REG_CLOCK, (1 << 6)))
|
||||
self._i2c.i2c_write([REG_CLOCK, (1 << 6)])
|
||||
# Setup Clock Divider
|
||||
self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % (
|
||||
self._oid, REG_MISC, (1 << 4)))
|
||||
self._i2c.i2c_write([REG_MISC, (1 << 4)])
|
||||
# Transfer all regs with their initial cached state
|
||||
for _reg, _data in self.reg_dict.items():
|
||||
self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%04x" % (
|
||||
self._oid, _reg, _data), is_init=True)
|
||||
reactor = self._mcu.get_printer().get_reactor()
|
||||
for _reg in self.reg_dict:
|
||||
curtime = reactor.monotonic()
|
||||
printtime = self._mcu.estimated_print_time(curtime)
|
||||
self.send_register(_reg, printtime)
|
||||
def setup_pin(self, pin_type, pin_params):
|
||||
if pin_type == 'digital_out' and pin_params['pin'][0:4] == "PIN_":
|
||||
return SX1509_digital_out(self, pin_params)
|
||||
|
Loading…
x
Reference in New Issue
Block a user