mcu: Rename add_config_object() to register_config_callback()
Change the name of the config registration method and pass an explicit reference to the callback to the new method. This makes the relationship between mcu registration and build_config() more clear in the calling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a8d4a7ef46
commit
30013a1fb8
|
@ -46,7 +46,7 @@ class MCU_buttons:
|
||||||
def __init__(self, printer, mcu):
|
def __init__(self, printer, mcu):
|
||||||
self.reactor = printer.get_reactor()
|
self.reactor = printer.get_reactor()
|
||||||
self.mcu = mcu
|
self.mcu = mcu
|
||||||
mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
self.pin_list = []
|
self.pin_list = []
|
||||||
self.callbacks = []
|
self.callbacks = []
|
||||||
self.invert = self.last_button = 0
|
self.invert = self.last_button = 0
|
||||||
|
|
|
@ -33,7 +33,7 @@ class HD44780:
|
||||||
self.pins = [pin_params['pin'] for pin_params in pins]
|
self.pins = [pin_params['pin'] for pin_params in pins]
|
||||||
self.mcu = mcu
|
self.mcu = mcu
|
||||||
self.oid = self.mcu.create_oid()
|
self.oid = self.mcu.create_oid()
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
self.send_data_cmd = self.send_cmds_cmd = None
|
self.send_data_cmd = self.send_cmds_cmd = None
|
||||||
# framebuffers
|
# framebuffers
|
||||||
self.text_framebuffer = (bytearray(' '*80), bytearray('~'*80), 0x80)
|
self.text_framebuffer = (bytearray(' '*80), bytearray('~'*80), 0x80)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ST7920:
|
||||||
self.pins = [pin_params['pin'] for pin_params in pins]
|
self.pins = [pin_params['pin'] for pin_params in pins]
|
||||||
self.mcu = mcu
|
self.mcu = mcu
|
||||||
self.oid = self.mcu.create_oid()
|
self.oid = self.mcu.create_oid()
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
self.send_data_cmd = self.send_cmds_cmd = None
|
self.send_data_cmd = self.send_cmds_cmd = None
|
||||||
self.is_extended = False
|
self.is_extended = False
|
||||||
# framebuffers
|
# framebuffers
|
||||||
|
|
|
@ -28,7 +28,7 @@ class UC1701:
|
||||||
self.mcu = mcu
|
self.mcu = mcu
|
||||||
self.spi_oid = self.mcu.create_oid()
|
self.spi_oid = self.mcu.create_oid()
|
||||||
self.a0_oid = self.mcu.create_oid()
|
self.a0_oid = self.mcu.create_oid()
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
self.glyph_buffer = []
|
self.glyph_buffer = []
|
||||||
self.spi_xfer_cmd = self.set_pin_cmd = None
|
self.spi_xfer_cmd = self.set_pin_cmd = None
|
||||||
self.vram = ([bytearray(128) for i in range(8)],
|
self.vram = ([bytearray(128) for i in range(8)],
|
||||||
|
|
|
@ -31,7 +31,7 @@ class PrinterProbe:
|
||||||
pin = config.get('pin')
|
pin = config.get('pin')
|
||||||
pin_params = ppins.lookup_pin(pin, can_invert=True, can_pullup=True)
|
pin_params = ppins.lookup_pin(pin, can_invert=True, can_pullup=True)
|
||||||
mcu = pin_params['chip']
|
mcu = pin_params['chip']
|
||||||
mcu.add_config_object(self)
|
mcu.register_config_callback(self.build_config)
|
||||||
self.mcu_probe = mcu.setup_pin('endstop', pin_params)
|
self.mcu_probe = mcu.setup_pin('endstop', pin_params)
|
||||||
if (config.get('activate_gcode', None) is not None or
|
if (config.get('activate_gcode', None) is not None or
|
||||||
config.get('deactivate_gcode', None) is not None):
|
config.get('deactivate_gcode', None) is not None):
|
||||||
|
|
|
@ -20,7 +20,7 @@ class pca9685_pwm:
|
||||||
if pin_type not in ['digital_out', 'pwm']:
|
if pin_type not in ['digital_out', 'pwm']:
|
||||||
raise pins.error("Pin type not supported on replicape")
|
raise pins.error("Pin type not supported on replicape")
|
||||||
self._mcu = replicape.host_mcu
|
self._mcu = replicape.host_mcu
|
||||||
self._mcu.add_config_object(self)
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._bus = REPLICAPE_PCA9685_BUS
|
self._bus = REPLICAPE_PCA9685_BUS
|
||||||
self._address = REPLICAPE_PCA9685_ADDRESS
|
self._address = REPLICAPE_PCA9685_ADDRESS
|
||||||
self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
|
self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
|
||||||
|
@ -53,7 +53,7 @@ class pca9685_pwm:
|
||||||
self._is_static = is_static
|
self._is_static = is_static
|
||||||
self._replicape.note_pwm_start_value(
|
self._replicape.note_pwm_start_value(
|
||||||
self._channel, self._start_value, self._shutdown_value)
|
self._channel, self._start_value, self._shutdown_value)
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
|
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
|
||||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||||
if self._is_static:
|
if self._is_static:
|
||||||
|
@ -175,7 +175,7 @@ class Replicape:
|
||||||
and self.stepper_dacs):
|
and self.stepper_dacs):
|
||||||
shift_registers[4] &= ~1
|
shift_registers[4] &= ~1
|
||||||
self.sr_enabled = tuple(reversed(shift_registers))
|
self.sr_enabled = tuple(reversed(shift_registers))
|
||||||
self.host_mcu.add_config_object(self)
|
self.host_mcu.register_config_callback(self._build_config)
|
||||||
self.sr_oid = self.host_mcu.create_oid()
|
self.sr_oid = self.host_mcu.create_oid()
|
||||||
str_sr_disabled = "".join(["%02x" % (x,) for x in self.sr_disabled])
|
str_sr_disabled = "".join(["%02x" % (x,) for x in self.sr_disabled])
|
||||||
self.host_mcu.add_config_cmd(
|
self.host_mcu.add_config_cmd(
|
||||||
|
@ -184,7 +184,7 @@ class Replicape:
|
||||||
self.sr_oid, REPLICAPE_SHIFT_REGISTER_BUS, str_sr_disabled))
|
self.sr_oid, REPLICAPE_SHIFT_REGISTER_BUS, str_sr_disabled))
|
||||||
self.host_mcu.add_config_cmd("spi_send oid=%d data=%s" % (
|
self.host_mcu.add_config_cmd("spi_send oid=%d data=%s" % (
|
||||||
self.sr_oid, str_sr_disabled), is_init=True)
|
self.sr_oid, str_sr_disabled), is_init=True)
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
cmd_queue = self.host_mcu.alloc_command_queue()
|
cmd_queue = self.host_mcu.alloc_command_queue()
|
||||||
self.spi_send_cmd = self.host_mcu.lookup_command(
|
self.spi_send_cmd = self.host_mcu.lookup_command(
|
||||||
"spi_send oid=%c data=%*s", cq=cmd_queue)
|
"spi_send oid=%c data=%*s", cq=cmd_queue)
|
||||||
|
|
|
@ -46,7 +46,7 @@ class SensorBase:
|
||||||
oid, spi_oid, chip_type))
|
oid, spi_oid, chip_type))
|
||||||
mcu.register_msg(self._handle_spi_response,
|
mcu.register_msg(self._handle_spi_response,
|
||||||
"thermocouple_result", oid)
|
"thermocouple_result", oid)
|
||||||
mcu.add_config_object(self)
|
mcu.register_config_callback(self._build_config)
|
||||||
def setup_minmax(self, min_temp, max_temp):
|
def setup_minmax(self, min_temp, max_temp):
|
||||||
adc_range = [self.calc_adc(min_temp), self.calc_adc(max_temp)]
|
adc_range = [self.calc_adc(min_temp), self.calc_adc(max_temp)]
|
||||||
self.min_sample_value = min(adc_range)
|
self.min_sample_value = min(adc_range)
|
||||||
|
@ -55,7 +55,7 @@ class SensorBase:
|
||||||
self._callback = cb
|
self._callback = cb
|
||||||
def get_report_time_delta(self):
|
def get_report_time_delta(self):
|
||||||
return REPORT_TIME
|
return REPORT_TIME
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
clock = self.mcu.get_query_slot(self.oid)
|
clock = self.mcu.get_query_slot(self.oid)
|
||||||
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)
|
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)
|
||||||
self.mcu.add_config_cmd(
|
self.mcu.add_config_cmd(
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TMC2130:
|
||||||
"config_spi oid=%d bus=%d pin=%s mode=%d rate=%d shutdown_msg=" % (
|
"config_spi oid=%d bus=%d pin=%s mode=%d rate=%d shutdown_msg=" % (
|
||||||
self.oid, 0, cs_pin_params['pin'], 3, 4000000))
|
self.oid, 0, cs_pin_params['pin'], 3, 4000000))
|
||||||
self.spi_send_cmd = self.spi_transfer_cmd = None
|
self.spi_send_cmd = self.spi_transfer_cmd = None
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
# Allow virtual endstop to be created
|
# Allow virtual endstop to be created
|
||||||
self.diag1_pin = config.get('diag1_pin', None)
|
self.diag1_pin = config.get('diag1_pin', None)
|
||||||
ppins.register_chip("tmc2130_" + self.name, self)
|
ppins.register_chip("tmc2130_" + self.name, self)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class TMC2208:
|
||||||
self.tx_pin = tx_pin_params['pin']
|
self.tx_pin = tx_pin_params['pin']
|
||||||
self.oid = self.mcu.create_oid()
|
self.oid = self.mcu.create_oid()
|
||||||
self.tmcuart_send_cmd = None
|
self.tmcuart_send_cmd = None
|
||||||
self.mcu.add_config_object(self)
|
self.mcu.register_config_callback(self.build_config)
|
||||||
# Add DUMP_TMC command
|
# Add DUMP_TMC command
|
||||||
gcode = self.printer.lookup_object("gcode")
|
gcode = self.printer.lookup_object("gcode")
|
||||||
gcode.register_mux_command(
|
gcode.register_mux_command(
|
||||||
|
|
|
@ -15,6 +15,7 @@ class MCU_stepper:
|
||||||
def __init__(self, mcu, pin_params):
|
def __init__(self, mcu, pin_params):
|
||||||
self._mcu = mcu
|
self._mcu = mcu
|
||||||
self._oid = oid = self._mcu.create_oid()
|
self._oid = oid = self._mcu.create_oid()
|
||||||
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._step_pin = pin_params['pin']
|
self._step_pin = pin_params['pin']
|
||||||
self._invert_step = pin_params['invert']
|
self._invert_step = pin_params['invert']
|
||||||
self._dir_pin = self._invert_dir = None
|
self._dir_pin = self._invert_dir = None
|
||||||
|
@ -43,7 +44,7 @@ class MCU_stepper:
|
||||||
ffi_main, ffi_lib = chelper.get_ffi()
|
ffi_main, ffi_lib = chelper.get_ffi()
|
||||||
sk = ffi_main.gc(getattr(ffi_lib, alloc_func)(*params), ffi_lib.free)
|
sk = ffi_main.gc(getattr(ffi_lib, alloc_func)(*params), ffi_lib.free)
|
||||||
self.set_stepper_kinematics(sk)
|
self.set_stepper_kinematics(sk)
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
max_error = self._mcu.get_max_stepper_error()
|
max_error = self._mcu.get_max_stepper_error()
|
||||||
min_stop_interval = max(0., self._min_stop_interval - max_error)
|
min_stop_interval = max(0., self._min_stop_interval - max_error)
|
||||||
self._mcu.add_config_cmd(
|
self._mcu.add_config_cmd(
|
||||||
|
@ -142,6 +143,7 @@ class MCU_endstop:
|
||||||
self._pullup = pin_params['pullup']
|
self._pullup = pin_params['pullup']
|
||||||
self._invert = pin_params['invert']
|
self._invert = pin_params['invert']
|
||||||
self._oid = self._home_cmd = self._query_cmd = None
|
self._oid = self._home_cmd = self._query_cmd = None
|
||||||
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._homing = False
|
self._homing = False
|
||||||
self._min_query_time = self._next_query_time = 0.
|
self._min_query_time = self._next_query_time = 0.
|
||||||
self._last_state = {}
|
self._last_state = {}
|
||||||
|
@ -155,7 +157,7 @@ class MCU_endstop:
|
||||||
self._steppers.append(stepper)
|
self._steppers.append(stepper)
|
||||||
def get_steppers(self):
|
def get_steppers(self):
|
||||||
return list(self._steppers)
|
return list(self._steppers)
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
self._oid = self._mcu.create_oid()
|
self._oid = self._mcu.create_oid()
|
||||||
self._mcu.add_config_cmd(
|
self._mcu.add_config_cmd(
|
||||||
"config_end_stop oid=%d pin=%s pull_up=%d stepper_count=%d" % (
|
"config_end_stop oid=%d pin=%s pull_up=%d stepper_count=%d" % (
|
||||||
|
@ -236,6 +238,7 @@ class MCU_digital_out:
|
||||||
def __init__(self, mcu, pin_params):
|
def __init__(self, mcu, pin_params):
|
||||||
self._mcu = mcu
|
self._mcu = mcu
|
||||||
self._oid = None
|
self._oid = None
|
||||||
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._pin = pin_params['pin']
|
self._pin = pin_params['pin']
|
||||||
self._invert = pin_params['invert']
|
self._invert = pin_params['invert']
|
||||||
self._start_value = self._shutdown_value = self._invert
|
self._start_value = self._shutdown_value = self._invert
|
||||||
|
@ -253,7 +256,7 @@ class MCU_digital_out:
|
||||||
self._start_value = (not not start_value) ^ self._invert
|
self._start_value = (not not start_value) ^ self._invert
|
||||||
self._shutdown_value = (not not shutdown_value) ^ self._invert
|
self._shutdown_value = (not not shutdown_value) ^ self._invert
|
||||||
self._is_static = is_static
|
self._is_static = is_static
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
if self._is_static:
|
if self._is_static:
|
||||||
self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % (
|
self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % (
|
||||||
self._pin, self._start_value))
|
self._pin, self._start_value))
|
||||||
|
@ -282,6 +285,7 @@ class MCU_pwm:
|
||||||
self._cycle_time = 0.100
|
self._cycle_time = 0.100
|
||||||
self._max_duration = 2.
|
self._max_duration = 2.
|
||||||
self._oid = None
|
self._oid = None
|
||||||
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._pin = pin_params['pin']
|
self._pin = pin_params['pin']
|
||||||
self._invert = pin_params['invert']
|
self._invert = pin_params['invert']
|
||||||
self._start_value = self._shutdown_value = float(self._invert)
|
self._start_value = self._shutdown_value = float(self._invert)
|
||||||
|
@ -305,7 +309,7 @@ class MCU_pwm:
|
||||||
self._start_value = max(0., min(1., start_value))
|
self._start_value = max(0., min(1., start_value))
|
||||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||||
self._is_static = is_static
|
self._is_static = is_static
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
cmd_queue = self._mcu.alloc_command_queue()
|
cmd_queue = self._mcu.alloc_command_queue()
|
||||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||||
if self._hardware_pwm:
|
if self._hardware_pwm:
|
||||||
|
@ -363,6 +367,7 @@ class MCU_adc:
|
||||||
self._sample_count = self._range_check_count = 0
|
self._sample_count = self._range_check_count = 0
|
||||||
self._report_clock = 0
|
self._report_clock = 0
|
||||||
self._oid = self._callback = None
|
self._oid = self._callback = None
|
||||||
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._inv_max_adc = 0.
|
self._inv_max_adc = 0.
|
||||||
def get_mcu(self):
|
def get_mcu(self):
|
||||||
return self._mcu
|
return self._mcu
|
||||||
|
@ -376,7 +381,7 @@ class MCU_adc:
|
||||||
def setup_adc_callback(self, report_time, callback):
|
def setup_adc_callback(self, report_time, callback):
|
||||||
self._report_time = report_time
|
self._report_time = report_time
|
||||||
self._callback = callback
|
self._callback = callback
|
||||||
def build_config(self):
|
def _build_config(self):
|
||||||
if not self._sample_count:
|
if not self._sample_count:
|
||||||
return
|
return
|
||||||
self._oid = self._mcu.create_oid()
|
self._oid = self._mcu.create_oid()
|
||||||
|
@ -437,7 +442,7 @@ class MCU:
|
||||||
# Config building
|
# Config building
|
||||||
self._printer.lookup_object('pins').register_chip(self._name, self)
|
self._printer.lookup_object('pins').register_chip(self._name, self)
|
||||||
self._oid_count = 0
|
self._oid_count = 0
|
||||||
self._config_objects = []
|
self._config_callbacks = []
|
||||||
self._init_cmds = []
|
self._init_cmds = []
|
||||||
self._config_cmds = []
|
self._config_cmds = []
|
||||||
self._pin_map = config.get('pin_map', None)
|
self._pin_map = config.get('pin_map', None)
|
||||||
|
@ -516,8 +521,8 @@ class MCU:
|
||||||
self.add_config_cmd(line)
|
self.add_config_cmd(line)
|
||||||
def _send_config(self, prev_crc):
|
def _send_config(self, prev_crc):
|
||||||
# Build config commands
|
# Build config commands
|
||||||
for co in self._config_objects:
|
for cb in self._config_callbacks:
|
||||||
co.build_config()
|
cb()
|
||||||
self._add_custom()
|
self._add_custom()
|
||||||
self._config_cmds.insert(0, "allocate_oids count=%d" % (
|
self._config_cmds.insert(0, "allocate_oids count=%d" % (
|
||||||
self._oid_count,))
|
self._oid_count,))
|
||||||
|
@ -622,14 +627,12 @@ class MCU:
|
||||||
'digital_out': MCU_digital_out, 'pwm': MCU_pwm, 'adc': MCU_adc}
|
'digital_out': MCU_digital_out, 'pwm': MCU_pwm, 'adc': MCU_adc}
|
||||||
if pin_type not in pcs:
|
if pin_type not in pcs:
|
||||||
raise pins.error("pin type %s not supported on mcu" % (pin_type,))
|
raise pins.error("pin type %s not supported on mcu" % (pin_type,))
|
||||||
co = pcs[pin_type](self, pin_params)
|
return pcs[pin_type](self, pin_params)
|
||||||
self.add_config_object(co)
|
|
||||||
return co
|
|
||||||
def create_oid(self):
|
def create_oid(self):
|
||||||
self._oid_count += 1
|
self._oid_count += 1
|
||||||
return self._oid_count - 1
|
return self._oid_count - 1
|
||||||
def add_config_object(self, co):
|
def register_config_callback(self, cb):
|
||||||
self._config_objects.append(co)
|
self._config_callbacks.append(cb)
|
||||||
def add_config_cmd(self, cmd, is_init=False):
|
def add_config_cmd(self, cmd, is_init=False):
|
||||||
if is_init:
|
if is_init:
|
||||||
self._init_cmds.append(cmd)
|
self._init_cmds.append(cmd)
|
||||||
|
|
Loading…
Reference in New Issue