mcu: Remove support for "static" pins
Update static_digital_output.py to directly configure static digital pins. There are no other users of "static" pins, so remove that support from mcu.py, replicape.py, and sx1509.py. This simplifies the low-level pin handling code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
4115ea128a
commit
7abafb575b
|
@ -30,7 +30,6 @@ class pca9685_pwm:
|
|||
self._invert = pin_params['invert']
|
||||
self._start_value = self._shutdown_value = float(self._invert)
|
||||
self._is_enable = not not self._start_value
|
||||
self._is_static = False
|
||||
self._last_clock = 0
|
||||
self._pwm_max = 0.
|
||||
self._set_cmd = None
|
||||
|
@ -44,28 +43,18 @@ class pca9685_pwm:
|
|||
if cycle_time != self._cycle_time:
|
||||
logging.info("Ignoring pca9685 cycle time of %.6f (using %.6f)",
|
||||
cycle_time, self._cycle_time)
|
||||
def setup_start_value(self, start_value, shutdown_value, is_static=False):
|
||||
if is_static and start_value != shutdown_value:
|
||||
raise pins.error("Static pin can not have shutdown value")
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
if self._invert:
|
||||
start_value = 1. - start_value
|
||||
shutdown_value = 1. - shutdown_value
|
||||
self._start_value = max(0., min(1., start_value))
|
||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||
self._is_static = is_static
|
||||
self._replicape.note_pwm_start_value(
|
||||
self._channel, self._start_value, self._shutdown_value)
|
||||
self._is_enable = not not self._start_value
|
||||
def _build_config(self):
|
||||
self._pwm_max = self._mcu.get_constant_float("PCA9685_MAX")
|
||||
cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
|
||||
if self._is_static:
|
||||
self._mcu.add_config_cmd(
|
||||
"set_pca9685_out bus=%d addr=%d channel=%d"
|
||||
" cycle_ticks=%d value=%d" % (
|
||||
self._bus, self._address, self._channel,
|
||||
cycle_ticks, self._start_value * self._pwm_max))
|
||||
return
|
||||
self._mcu.request_move_queue_slot()
|
||||
self._oid = self._mcu.create_oid()
|
||||
self._mcu.add_config_cmd(
|
||||
|
|
|
@ -10,8 +10,10 @@ class PrinterStaticDigitalOut:
|
|||
ppins = printer.lookup_object('pins')
|
||||
pin_list = config.getlist('pins')
|
||||
for pin_desc in pin_list:
|
||||
mcu_pin = ppins.setup_pin('digital_out', pin_desc)
|
||||
mcu_pin.setup_start_value(1, 1, True)
|
||||
pin_params = ppins.lookup_pin(pin_desc, can_invert=True)
|
||||
mcu = pin_params['chip']
|
||||
mcu.add_config_cmd("set_digital_out pin=%s value=%d"
|
||||
% (pin_params['pin'], not pin_params['invert']))
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PrinterStaticDigitalOut(config)
|
||||
|
|
|
@ -104,7 +104,6 @@ class SX1509_digital_out(object):
|
|||
self._invert = pin_params['invert']
|
||||
self._mcu.register_config_callback(self._build_config)
|
||||
self._start_value = self._shutdown_value = self._invert
|
||||
self._is_static = False
|
||||
self._max_duration = 2.
|
||||
self._set_cmd = self._clear_cmd = None
|
||||
# Set direction to output
|
||||
|
@ -116,12 +115,9 @@ class SX1509_digital_out(object):
|
|||
return self._mcu
|
||||
def setup_max_duration(self, max_duration):
|
||||
self._max_duration = max_duration
|
||||
def setup_start_value(self, start_value, shutdown_value, is_static=False):
|
||||
if is_static and start_value != shutdown_value:
|
||||
raise pins.error("Static pin can not have shutdown value")
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
self._start_value = (not not start_value) ^ self._invert
|
||||
self._shutdown_value = self._invert
|
||||
self._is_static = is_static
|
||||
# We need to set the start value here so the register is
|
||||
# updated before the SX1509 class writes it.
|
||||
if self._start_value:
|
||||
|
@ -148,7 +144,6 @@ class SX1509_pwm(object):
|
|||
self._invert = pin_params['invert']
|
||||
self._mcu.register_config_callback(self._build_config)
|
||||
self._start_value = self._shutdown_value = float(self._invert)
|
||||
self._is_static = False
|
||||
self._max_duration = 2.
|
||||
self._hardware_pwm = False
|
||||
self._pwm_max = 0.
|
||||
|
@ -182,15 +177,12 @@ class SX1509_pwm(object):
|
|||
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
|
||||
self._cycle_time = cycle_time
|
||||
self._hardware_pwm = hardware_pwm
|
||||
def setup_start_value(self, start_value, shutdown_value, is_static=False):
|
||||
if is_static and start_value != shutdown_value:
|
||||
raise pins.error("Static pin can not have shutdown value")
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
if self._invert:
|
||||
start_value = 1. - start_value
|
||||
shutdown_value = 1. - shutdown_value
|
||||
self._start_value = max(0., min(1., start_value))
|
||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||
self._is_static = is_static
|
||||
def set_pwm(self, print_time, value, cycle_time=None):
|
||||
self._sx1509.set_register(self._i_on_reg, ~int(255 * value)
|
||||
if not self._invert
|
||||
|
|
|
@ -335,7 +335,6 @@ class MCU_digital_out:
|
|||
self._pin = pin_params['pin']
|
||||
self._invert = pin_params['invert']
|
||||
self._start_value = self._shutdown_value = self._invert
|
||||
self._is_static = False
|
||||
self._max_duration = 2.
|
||||
self._last_clock = 0
|
||||
self._set_cmd = None
|
||||
|
@ -343,17 +342,10 @@ class MCU_digital_out:
|
|||
return self._mcu
|
||||
def setup_max_duration(self, max_duration):
|
||||
self._max_duration = max_duration
|
||||
def setup_start_value(self, start_value, shutdown_value, is_static=False):
|
||||
if is_static and start_value != shutdown_value:
|
||||
raise pins.error("Static pin can not have shutdown value")
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
self._start_value = (not not start_value) ^ self._invert
|
||||
self._shutdown_value = (not not shutdown_value) ^ self._invert
|
||||
self._is_static = is_static
|
||||
def _build_config(self):
|
||||
if self._is_static:
|
||||
self._mcu.add_config_cmd("set_digital_out pin=%s value=%d"
|
||||
% (self._pin, self._start_value))
|
||||
return
|
||||
if self._max_duration and self._start_value != self._shutdown_value:
|
||||
raise pins.error("Pin with max duration must have start"
|
||||
" value equal to shutdown value")
|
||||
|
@ -389,7 +381,6 @@ class MCU_pwm:
|
|||
self._pin = pin_params['pin']
|
||||
self._invert = pin_params['invert']
|
||||
self._start_value = self._shutdown_value = float(self._invert)
|
||||
self._is_static = False
|
||||
self._last_clock = self._last_cycle_ticks = 0
|
||||
self._pwm_max = 0.
|
||||
self._set_cmd = self._set_cycle_ticks = None
|
||||
|
@ -400,15 +391,12 @@ class MCU_pwm:
|
|||
def setup_cycle_time(self, cycle_time, hardware_pwm=False):
|
||||
self._cycle_time = cycle_time
|
||||
self._hardware_pwm = hardware_pwm
|
||||
def setup_start_value(self, start_value, shutdown_value, is_static=False):
|
||||
if is_static and start_value != shutdown_value:
|
||||
raise pins.error("Static pin can not have shutdown value")
|
||||
def setup_start_value(self, start_value, shutdown_value):
|
||||
if self._invert:
|
||||
start_value = 1. - start_value
|
||||
shutdown_value = 1. - shutdown_value
|
||||
self._start_value = max(0., min(1., start_value))
|
||||
self._shutdown_value = max(0., min(1., shutdown_value))
|
||||
self._is_static = is_static
|
||||
def _build_config(self):
|
||||
if self._max_duration and self._start_value != self._shutdown_value:
|
||||
raise pins.error("Pin with max duration must have start"
|
||||
|
@ -423,12 +411,6 @@ class MCU_pwm:
|
|||
raise pins.error("PWM pin max duration too large")
|
||||
if self._hardware_pwm:
|
||||
self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
|
||||
if self._is_static:
|
||||
self._mcu.add_config_cmd(
|
||||
"set_pwm_out pin=%s cycle_ticks=%d value=%d"
|
||||
% (self._pin, cycle_ticks,
|
||||
self._start_value * self._pwm_max))
|
||||
return
|
||||
self._mcu.request_move_queue_slot()
|
||||
self._oid = self._mcu.create_oid()
|
||||
self._mcu.add_config_cmd(
|
||||
|
@ -447,10 +429,6 @@ class MCU_pwm:
|
|||
# Software PWM
|
||||
if self._shutdown_value not in [0., 1.]:
|
||||
raise pins.error("shutdown value must be 0.0 or 1.0 on soft pwm")
|
||||
if self._is_static:
|
||||
self._mcu.add_config_cmd("set_digital_out pin=%s value=%d"
|
||||
% (self._pin, self._start_value >= 0.5))
|
||||
return
|
||||
if cycle_ticks >= 1<<31:
|
||||
raise pins.error("PWM pin cycle time too large")
|
||||
self._mcu.request_move_queue_slot()
|
||||
|
|
Loading…
Reference in New Issue