Ejemplo n.º 1
0
 def setup_pin(self, pin_type, pin_params):
     if pin_type != 'endstop' or pin_params['pin'] != 'z_virtual_endstop':
         raise pins.error(
             "Probe virtual endstop only useful as endstop pin")
     if pin_params['invert'] or pin_params['pullup']:
         raise pins.error("Can not pullup/invert probe virtual endstop")
     return self.mcu_probe
Ejemplo n.º 2
0
 def __init__(self, replicape, channel, pin_type, pin_params):
     if pin_type != 'digital_out':
         raise pins.error("Replicape virtual enable pin must be digital_out")
     if pin_params['invert']:
         raise pins.error("Replicape virtual enable pin can not be inverted")
     self.mcu = replicape.host_mcu
     self.value = replicape.stepper_dacs[channel]
     self.pwm = pca9685_pwm(replicape, channel, pin_type, pin_params)
Ejemplo n.º 3
0
 def setup_pin(self, pin_type, pin_params):
     if pin_type != 'endstop' or pin_params['pin'] != 'z_virtual_endstop':
         raise pins.error("Probe virtual endstop only useful as endstop pin")
     if pin_params['invert'] or pin_params['pullup']:
         raise pins.error("Can not pullup/invert probe virtual endstop")
     self.z_virtual_endstop = ProbeVirtualEndstop(
         self.printer, self.mcu_probe)
     return self.z_virtual_endstop
Ejemplo n.º 4
0
 def __init__(self, replicape, channel, pin_params):
     if pin_params['type'] != 'digital_out':
         raise pins.error("Replicape virtual enable pin must be digital_out")
     if pin_params['invert']:
         raise pins.error("Replicape virtual enable pin can not be inverted")
     self.mcu = replicape.host_mcu
     self.value = replicape.stepper_dacs[channel]
     self.pwm = pca9685_pwm(replicape, channel, pin_params)
Ejemplo n.º 5
0
 def setup_pin(self, pin_params):
     if (pin_params['pin'] != 'z_virtual_endstop'
         or pin_params['type'] != 'endstop'):
         raise pins.error("Probe virtual endstop only useful as endstop pin")
     if pin_params['invert'] or pin_params['pullup']:
         raise pins.error("Can not pullup/invert probe virtual endstop")
     self.z_virtual_endstop = ProbeVirtualEndstop(
         self.printer, self.mcu_probe)
     return self.z_virtual_endstop
Ejemplo n.º 6
0
 def _build_config(self):
     if not self._hardware_pwm:
         raise pins.error("SX1509_pwm must have hardware_pwm enabled")
     if self._max_duration:
         raise pins.error("SX1509 pins are not suitable for heaters")
     # Send initial value
     self._sx1509.set_register(self._i_on_reg,
                               ~int(255 * self._start_value) & 0xFF)
     self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" %
                              (self._sx1509.get_oid(), self._i_on_reg,
                               self._sx1509.reg_i_on_dict[self._i_on_reg]),
                              is_init=True)
Ejemplo n.º 7
0
 def _build_config(self):
     if not self._hardware_pwm:
         raise pins.error("SX1509_pwm must have hardware_pwm enabled")
     if self._max_duration:
         raise pins.error("SX1509 pins are not suitable for heaters")
     # Send initial value
     self._sx1509.set_register(self._i_on_reg,
                               ~int(255 * self._start_value) & 0xFF)
     self._mcu.add_config_cmd("i2c_write oid=%d data=%02x%02x" % (
         self._sx1509.get_oid(),
         self._i_on_reg,
         self._sx1509.reg_i_on_dict[self._i_on_reg]
         ),
                              is_init=True)
Ejemplo n.º 8
0
 def __init__(self, replicape, pin_params):
     config_name = pin_params['pin']
     pwmchip = 'pwmchip0'
     if not replicape.host_mcu.is_fileoutput():
         try:
             # Determine the pwmchip number for the servo channels
             # /sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm
             # should be stable on the beagle bone black.
             # It contains only a "pwmchipX" directory. The entry in
             # /sys/class/pwm/ used by the Linux MCU should be a symlink
             # to this directory.
             pwmdev = os.listdir(
                 '/sys/devices/platform/ocp/48302000.epwmss/48302200.pwm/pwm/'
             )
             pwmchip = [pc for pc in pwmdev if pc.startswith('pwmchip')][0]
         except:
             raise pins.error("Replicape unable to determine pwmchip")
     pwm_pin, resv1, resv2 = SERVO_PINS[config_name]
     pin_params = dict(pin_params)
     pin_params['pin'] = pwmchip + pwm_pin
     # Setup actual pwm pin using linux hardware pwm on host
     self.mcu_pwm = replicape.host_mcu.setup_pin("pwm", pin_params)
     self.get_mcu = self.mcu_pwm.get_mcu
     self.setup_max_duration = self.mcu_pwm.setup_max_duration
     self.setup_start_value = self.mcu_pwm.setup_start_value
     self.set_pwm = self.mcu_pwm.set_pwm
     # Reserve pins to warn user of conflicts
     pru_mcu = replicape.mcu_pwm_enable.get_mcu()
     printer = pru_mcu.get_printer()
     ppins = printer.lookup_object('pins')
     pin_resolver = ppins.get_pin_resolver(pru_mcu.get_name())
     pin_resolver.reserve_pin(resv1, config_name)
     pin_resolver.reserve_pin(resv2, config_name)
Ejemplo n.º 9
0
 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)
     elif pin_type == 'pwm' and pin_params['pin'][0:4] == "PIN_":
         return SX1509_pwm(self, pin_params)
     raise pins.error("Wrong pin or incompatible type: %s with type %s! " %
                      (pin_params['pin'][0:4], pin_type))
Ejemplo n.º 10
0
 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)
     elif pin_type == 'pwm' and pin_params['pin'][0:4] == "PIN_":
         return SX1509_pwm(self, pin_params)
     raise pins.error("Wrong pin or incompatible type: %s with type %s! " % (
         pin_params['pin'][0:4], pin_type))
Ejemplo n.º 11
0
 def setup_pin(self, pin_type, pin_params):
     pcs = {'stepper': MCU_stepper, 'endstop': MCU_endstop,
            'digital_out': MCU_digital_out, 'pwm': MCU_pwm, 'adc': MCU_adc}
     if pin_type not in pcs:
         raise pins.error("pin type %s not supported on mcu" % (pin_type,))
     co = pcs[pin_type](self, pin_params)
     self.add_config_object(co)
     return co
Ejemplo n.º 12
0
 def setup_pin(self, pin_type, pin_params):
     pcs = {'stepper': MCU_stepper, 'endstop': MCU_endstop,
            'digital_out': MCU_digital_out, 'pwm': MCU_pwm, 'adc': MCU_adc}
     if pin_type not in pcs:
         raise pins.error("pin type %s not supported on mcu" % (pin_type,))
     co = pcs[pin_type](self, pin_params)
     self.add_config_object(co)
     return co
Ejemplo n.º 13
0
 def __init__(self, tmc2130):
     self.tmc2130 = tmc2130
     if tmc2130.diag1_pin is None:
         raise pins.error("tmc2130 virtual endstop requires diag1_pin")
     ppins = tmc2130.printer.lookup_object('pins')
     self.mcu_endstop = ppins.setup_pin('endstop', tmc2130.diag1_pin)
     if self.mcu_endstop.get_mcu() is not tmc2130.spi.get_mcu():
         raise pins.error("tmc2130 virtual endstop must be on same mcu")
     # Wrappers
     self.get_mcu = self.mcu_endstop.get_mcu
     self.add_stepper = self.mcu_endstop.add_stepper
     self.get_steppers = self.mcu_endstop.get_steppers
     self.home_start = self.mcu_endstop.home_start
     self.home_wait = self.mcu_endstop.home_wait
     self.query_endstop = self.mcu_endstop.query_endstop
     self.query_endstop_wait = self.mcu_endstop.query_endstop_wait
     self.TimeoutError = self.mcu_endstop.TimeoutError
Ejemplo n.º 14
0
 def setup_pin(self, pin_params):
     pin_name = pin_params['pin']
     pin = self.printer.objects.get('multi_pin ' + pin_name)
     if pin is not self:
         if pin is None:
             raise pins.error("multi_pin %s not configured" % (pin_name,))
         return pin.setup_pin(pin_params)
     if self.pin_type is not None:
         raise pins.error("Can't setup multi_pin %s twice" % (pin_name,))
     self.pin_type = pin_params['type']
     invert = ""
     if pin_params['invert']:
         invert = "!"
     self.mcu_pins = [
         pins.setup_pin(self.printer, self.pin_type, invert + pin_desc)
         for pin_desc in self.pin_list]
     return self
Ejemplo n.º 15
0
 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")
     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
Ejemplo n.º 16
0
 def _build_config(self):
     cmd_queue = self._mcu.alloc_command_queue()
     curtime = self._mcu.get_printer().get_reactor().monotonic()
     printtime = self._mcu.estimated_print_time(curtime)
     self._last_clock = self._mcu.print_time_to_clock(printtime + 0.200)
     cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
     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(
             "config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" %
             (self._oid, self._pin, cycle_ticks, self._start_value *
              self._pwm_max, self._shutdown_value * self._pwm_max,
              self._mcu.seconds_to_clock(self._max_duration)))
         svalue = int(self._start_value * self._pwm_max + 0.5)
         self._mcu.add_config_cmd("queue_pwm_out oid=%d clock=%d value=%d" %
                                  (self._oid, self._last_clock, svalue),
                                  on_restart=True)
         self._set_cmd = self._mcu.lookup_command(
             "queue_pwm_out oid=%c clock=%u value=%hu", cq=cmd_queue)
         return
     # 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
     self._mcu.request_move_queue_slot()
     self._oid = self._mcu.create_oid()
     self._mcu.add_config_cmd(
         "config_digital_out oid=%d pin=%s value=%d"
         " default_value=%d max_duration=%d" %
         (self._oid, self._pin, self._start_value >= 1.0,
          self._shutdown_value >= 0.5,
          self._mcu.seconds_to_clock(self._max_duration)))
     self._mcu.add_config_cmd(
         "set_digital_out_pwm_cycle oid=%d cycle_ticks=%d" %
         (self._oid, cycle_ticks))
     self._last_cycle_ticks = cycle_ticks
     svalue = int(self._start_value * cycle_ticks + 0.5)
     self._mcu.add_config_cmd(
         "queue_digital_out oid=%d clock=%d on_ticks=%d" %
         (self._oid, self._last_clock, svalue),
         is_init=True)
     self._set_cmd = self._mcu.lookup_command(
         "queue_digital_out oid=%c clock=%u on_ticks=%u", cq=cmd_queue)
     self._set_cycle_ticks = self._mcu.lookup_command(
         "set_digital_out_pwm_cycle oid=%c cycle_ticks=%u", cq=cmd_queue)
Ejemplo n.º 17
0
Archivo: mcu.py Proyecto: N7QWT/klipper
 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")
     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
Ejemplo n.º 18
0
 def lookup_pin(self, pin_type, pin_desc, share_type=None):
     if pin_type not in [
             'gpio_in', 'gpio_out', 'gpio_event', 'spi', 'i2c', 'pwm'
     ]:
         raise pins.error("Invalid pin type %s" % pin_type)
     can_invert = pin_type in ['gpio_in', 'gpio_out']
     can_pullup = pin_type == 'gpio_in'
     desc = pin_desc
     pullup = invert = 0
     if can_pullup and '^' in desc:
         pullup = 1
     if can_invert and '!' in desc:
         invert = 1
     pin = re.sub('[\^!]', '', desc).strip()
     if [c for c in '^!: ' if c in pin]:
         format = ""
         if can_pullup:
             format += "[^] "
         if can_invert:
             format += "[!] "
         raise pins.error("Invalid pin description '%s'\n"
                          "Format is: %s pin_name" % (pin_desc, format))
     if pin in self.active_pins:
         pin_params = self.active_pins[pin]
         if (share_type is None and pin_params['class'] is not None) or \
                 share_type != pin_params['share_type']:
             raise pins.error("pin %s used multiple times in config" %
                              (pin, ))
         if invert != pin_params['invert'] or pullup != pin_params['pullup']:
             raise pins.error("Shared pin %s must have same polarity" %
                              (pin, ))
         return pin_params
     pin_params = {
         'chip': self,
         'chip_name': "hostcpu",
         'type': pin_type,
         'share_type': share_type,
         'pin': pin,
         'invert': invert,
         'pullup': pullup,
         'class': None
     }
     self.active_pins[pin] = pin_params
     return pin_params
Ejemplo n.º 19
0
 def setup_pin(self, pin_type, pin_params):
     pcs = {
         'endstop': mcu.MCU_endstop,
         'digital_out': mcu.MCU_digital_out,
         'pwm': mcu.MCU_pwm
     }
     if pin_type not in pcs:
         raise pins.error("pin type %s not supported on fpga" %
                          (pin_type, ))
     return pcs[pin_type](self, pin_params)
Ejemplo n.º 20
0
 def setup_pin(self, pin_type, pin_desc):
     pin_params = self.lookup_pin(pin_type, pin_desc)
     pcs = {'gpio_in': HostGpioIn, 'gpio_out': HostGpioOut,
            'spi': HostSpi, 'i2c': HostI2C, 'pwm': HostPwm,
            'event': HostGpioEvent}
     pin_type = pin_params['type']
     if pin_type not in pcs:
         raise pins.error("pin type %s not supported on mcu" % (pin_type,))
     co = pcs[pin_type](self, pin_params)
     return co
Ejemplo n.º 21
0
 def build_config(self):
     if self._hard_pwm:
         self._pwm_max = self._mcu.get_constant_float("PWM_MAX")
         if self._static_value is not None:
             value = int(self._static_value * self._pwm_max + 0.5)
             self._mcu.add_config_cmd(
                 "set_pwm_out pin=%s cycle_ticks=%d value=%d" % (
                     self._pin, self._cycle_time, value))
             return
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin, self._cycle_time,
                 self._start_value * self._pwm_max,
                 self._shutdown_value * self._pwm_max,
                 self._mcu.seconds_to_clock(self._max_duration)))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_pwm_out oid=%c clock=%u value=%hu")
     else:
         self._pwm_max = self._mcu.get_constant_float("SOFT_PWM_MAX")
         if self._static_value is not None:
             if self._static_value not in [0., 1.]:
                 raise pins.error(
                     "static value must be 0.0 or 1.0 on soft pwm")
             self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % (
                 self._pin, self._static_value >= 0.5))
             return
         if (self._start_value not in [0., 1.]
             or self._shutdown_value not in [0., 1.]):
             raise pins.error(
                 "start and shutdown values must be 0.0 or 1.0 on soft pwm")
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_soft_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin,
                 self._mcu.seconds_to_clock(self._cycle_time),
                 self._start_value >= 0.5, self._shutdown_value >= 0.5,
                 self._mcu.seconds_to_clock(self._max_duration)))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_soft_pwm_out oid=%c clock=%u value=%hu")
Ejemplo n.º 22
0
 def set_state(self, print_time, pin, value):
     if not pin in self.pins:
         raise pins.error("Toogle pin not configured")
     if value == self.pins[pin]['last_value']:
         return
     if value == 0:
         self.pins[pin]['mcu_pin'].set_digital(print_time, False)
     else:
         self.pins[pin]['mcu_pin'].set_digital(print_time, True)
     self.pins[pin]['last_value'] = value
     pass
Ejemplo n.º 23
0
 def setup_start_value(self, start_value, shutdown_value, is_static=False):
     if is_static or shutdown_value:
         raise pins.error(
             "SX1509 Pins should not be declared static or have a 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 = False
Ejemplo n.º 24
0
 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")
     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:
         self._sx1509.set_bits_in_register(REG_DATA, self._bitmask)
     else:
         self._sx1509.clear_bits_in_register(REG_DATA, self._bitmask)
Ejemplo n.º 25
0
 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")
     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:
         self._sx1509.set_bits_in_register(REG_DATA, self._bitmask)
     else:
         self._sx1509.clear_bits_in_register(REG_DATA, self._bitmask)
Ejemplo n.º 26
0
 def setup_pin(self, pin_type, pin_params):
     pin = pin_params['pin']
     if pin in self.pins:
         pclass, channel = self.pins[pin]
         return pclass(self, channel, pin_type, pin_params)
     elif pin in self.servo_pins:
         # enable servo pins via shift registers
         index = self.servo_pins[pin]
         self.sr_enabled[index] |= 1
         self.sr_disabled[index] |= 1
         self.sr_spi.spi_send(self.sr_disabled)
         return servo_pwm(self, pin_params)
     raise pins.error("Unknown replicape pin %s" % (pin,))
Ejemplo n.º 27
0
 def setup_pin(self, pin_type, pin_params):
     pin = pin_params['pin']
     if pin in self.pins:
         pclass, channel = self.pins[pin]
         return pclass(self, channel, pin_type, pin_params)
     elif pin in self.servo_pins:
         # enable servo pins via shift registers
         index = self.servo_pins[pin]
         self.sr_enabled[index] |= 1
         self.sr_disabled[index] |= 1
         self.sr_spi.spi_send(self.sr_disabled)
         return servo_pwm(self, pin_params)
     raise pins.error("Unknown replicape pin %s" % (pin, ))
Ejemplo n.º 28
0
 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")
     mdur_ticks = self._mcu.seconds_to_clock(self._max_duration)
     if mdur_ticks >= 1 << 31:
         raise pins.error("Digital pin max duration too large")
     self._mcu.request_move_queue_slot()
     self._oid = self._mcu.create_oid()
     self._mcu.add_config_cmd(
         "config_digital_out oid=%d pin=%s value=%d default_value=%d"
         " max_duration=%d" % (self._oid, self._pin, self._start_value,
                               self._shutdown_value, mdur_ticks))
     self._mcu.add_config_cmd("update_digital_out oid=%d value=%d" %
                              (self._oid, self._start_value),
                              on_restart=True)
     cmd_queue = self._mcu.alloc_command_queue()
     self._set_cmd = self._mcu.lookup_command(
         "queue_digital_out oid=%c clock=%u on_ticks=%u", cq=cmd_queue)
Ejemplo n.º 29
0
 def __init__(self, config):
     printer = config.get_printer()
     enable_pin_params = pins.get_printer_pins(printer).lookup_pin(
         'digital_out', config.get('enable_pin'))
     if enable_pin_params['invert']:
         raise pins.error("ad5206 can not invert pin")
     self.mcu = enable_pin_params['chip']
     self.pin = enable_pin_params['pin']
     self.mcu.add_config_object(self)
     scale = config.getfloat('scale', 1., above=0.)
     self.channels = [None] * 6
     for i in range(len(self.channels)):
         val = config.getfloat('channel_%d' % (i+1,), None,
                               minval=0., maxval=scale)
         if val is not None:
             self.channels[i] = int(val * 256. / scale + .5)
Ejemplo n.º 30
0
 def _build_config(self):
     cmd_queue = self._mcu.alloc_command_queue()
     cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
     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._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin, cycle_ticks,
                 self._start_value * self._pwm_max,
                 self._shutdown_value * self._pwm_max,
                 self._mcu.seconds_to_clock(self._max_duration)))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_pwm_out oid=%c clock=%u value=%hu", cq=cmd_queue)
     else:
         if self._shutdown_value not in [0., 1.]:
             raise pins.error(
                 "shutdown value must be 0.0 or 1.0 on soft pwm")
         self._pwm_max = float(cycle_ticks)
         if self._is_static:
             self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % (
                 self._pin, self._start_value >= 0.5))
             return
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_soft_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin, cycle_ticks,
                 self._start_value >= 1.0, self._shutdown_value >= 0.5,
                 self._mcu.seconds_to_clock(self._max_duration)))
         if self._start_value not in [0., 1.]:
             clock = self._mcu.get_query_slot(self._oid)
             svalue = int(self._start_value * self._pwm_max + 0.5)
             self._mcu.add_config_cmd(
                 "schedule_soft_pwm_out oid=%d clock=%d on_ticks=%d" % (
                     self._oid, clock, svalue))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_soft_pwm_out oid=%c clock=%u on_ticks=%u",
             cq=cmd_queue)
Ejemplo n.º 31
0
 def __init__(self, replicape, channel, pin_params):
     self._replicape = replicape
     self._channel = channel
     if pin_params['type'] not in ['digital_out', 'pwm']:
         raise pins.error("Pin type not supported on replicape")
     self._mcu = replicape.host_mcu
     self._mcu.add_config_object(self)
     self._bus = REPLICAPE_PCA9685_BUS
     self._address = REPLICAPE_PCA9685_ADDRESS
     self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
     self._max_duration = 2.
     self._oid = None
     self._invert = pin_params['invert']
     self._start_value = self._shutdown_value = float(self._invert)
     self._is_static = False
     self._last_clock = 0
     self._pwm_max = 0.
     self._set_cmd = None
Ejemplo n.º 32
0
 def __init__(self, replicape, channel, pin_type, pin_params):
     self._replicape = replicape
     self._channel = channel
     if pin_type not in ['digital_out', 'pwm']:
         raise pins.error("Pin type not supported on replicape")
     self._mcu = replicape.host_mcu
     self._mcu.add_config_object(self)
     self._bus = REPLICAPE_PCA9685_BUS
     self._address = REPLICAPE_PCA9685_ADDRESS
     self._cycle_time = REPLICAPE_PCA9685_CYCLE_TIME
     self._max_duration = 2.
     self._oid = None
     self._invert = pin_params['invert']
     self._start_value = self._shutdown_value = float(self._invert)
     self._is_static = False
     self._last_clock = 0
     self._pwm_max = 0.
     self._set_cmd = None
Ejemplo n.º 33
0
 def __init__(self, recore, channel, pin_type, pin_params):
   self._recore = recore
   self._channel = channel
   if pin_type not in ['digital_out', 'pwm']:
     raise pins.error("Pin type not supported on recore")
   self._mcu = recore.host_mcu
   self._mcu.register_config_callback(self._build_config)
   self._bus = recore_PCA9685_BUS
   self._address = recore_PCA9685_ADDRESS
   self._cycle_time = recore_PCA9685_CYCLE_TIME
   self._max_duration = 2.
   self._oid = None
   self._invert = pin_params['invert']
   self._start_value = self._shutdown_value = float(self._invert)
   self._is_static = False
   self._last_clock = 0
   self._pwm_max = 0.
   self._set_cmd = None
Ejemplo n.º 34
0
Archivo: mcu.py Proyecto: N7QWT/klipper
 def _build_config(self):
     cmd_queue = self._mcu.alloc_command_queue()
     cycle_ticks = self._mcu.seconds_to_clock(self._cycle_time)
     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._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin, cycle_ticks,
                 self._start_value * self._pwm_max,
                 self._shutdown_value * self._pwm_max,
                 self._mcu.seconds_to_clock(self._max_duration)))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_pwm_out oid=%c clock=%u value=%hu", cq=cmd_queue)
     else:
         if (self._start_value not in [0., 1.]
             or self._shutdown_value not in [0., 1.]):
             raise pins.error(
                 "start and shutdown values must be 0.0 or 1.0 on soft pwm")
         self._pwm_max = self._mcu.get_constant_float("SOFT_PWM_MAX")
         if self._is_static:
             self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % (
                 self._pin, self._start_value >= 0.5))
             return
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_soft_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d"
             " default_value=%d max_duration=%d" % (
                 self._oid, self._pin, cycle_ticks,
                 self._start_value >= 0.5, self._shutdown_value >= 0.5,
                 self._mcu.seconds_to_clock(self._max_duration)))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_soft_pwm_out oid=%c clock=%u value=%hu", cq=cmd_queue)
Ejemplo n.º 35
0
    def _build_config(self):
        # Build config commands
        for co in self._config_objects:
            co.build_config()
        self._add_custom()
        self._config_cmds.insert(0, "allocate_oids count=%d" % (
            self._oid_count,))

        # Resolve pin names
        mcu = self._serial.msgparser.get_constant('MCU')
        pnames = pins.get_pin_map(mcu, self._pin_map)
        updated_cmds = []
        for cmd in self._config_cmds:
            try:
                updated_cmds.append(pins.update_command(cmd, pnames))
            except:
                raise pins.error("Unable to translate pin name: %s" % (cmd,))
        self._config_cmds = updated_cmds

        # Calculate config CRC
        self._config_crc = zlib.crc32('\n'.join(self._config_cmds)) & 0xffffffff
        self.add_config_cmd("finalize_config crc=%d" % (self._config_crc,))
Ejemplo n.º 36
0
 def build_config(self):
     self._mcu_freq = self._mcu.get_mcu_freq()
     if self._hard_pwm:
         self._pwm_max = self._mcu.serial.msgparser.get_constant_float(
             "PWM_MAX")
         if self._static_value is not None:
             value = int(self._static_value * self._pwm_max + 0.5)
             self._mcu.add_config_cmd(
                 "set_pwm_out pin=%s cycle_ticks=%d value=%d" %
                 (self._pin, self._cycle_time, value))
             return
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_pwm_out oid=%d pin=%s cycle_ticks=%d default_value=%d"
             " max_duration=%d" %
             (self._oid, self._pin, self._cycle_time, self._invert,
              self._max_duration * self._mcu_freq))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_pwm_out oid=%c clock=%u value=%hu")
     else:
         self._pwm_max = self._mcu.serial.msgparser.get_constant_float(
             "SOFT_PWM_MAX")
         if self._static_value is not None:
             if self._static_value != 0. and self._static_value != 1.:
                 raise pins.error("static value on soft pwm not supported")
             self._mcu.add_config_cmd(
                 "set_digital_out pin=%s value=%d" %
                 (self._pin, self._static_value >= 0.5))
             return
         self._oid = self._mcu.create_oid()
         self._mcu.add_config_cmd(
             "config_soft_pwm_out oid=%d pin=%s cycle_ticks=%d"
             " default_value=%d max_duration=%d" %
             (self._oid, self._pin, self._cycle_time * self._mcu_freq,
              self._invert, self._max_duration * self._mcu_freq))
         self._set_cmd = self._mcu.lookup_command(
             "schedule_soft_pwm_out oid=%c clock=%u value=%hu")
Ejemplo n.º 37
0
 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")
     self._start_value = (not not start_value) ^ self._invert
     self._shutdown_value = (not not shutdown_value) ^ self._invert
     self._is_static = is_static
Ejemplo n.º 38
0
 def add_stepper(self, stepper):
     if stepper.get_mcu() is not self._mcu:
         raise pins.error("Endstop and stepper must be on the same mcu")
     self._steppers.append(stepper)
Ejemplo n.º 39
0
Archivo: mcu.py Proyecto: N7QWT/klipper
 def add_stepper(self, stepper):
     if stepper.get_mcu() is not self._mcu:
         raise pins.error("Endstop and stepper must be on the same mcu")
     if stepper in self._steppers:
         return
     self._steppers.append(stepper)
Ejemplo n.º 40
0
 def setup_cycle_time(self, cycle_time, hardware_pwm=False):
     if hardware_pwm:
         raise pins.error("pca9685 does not support hardware_pwm parameter")
     if cycle_time != self._cycle_time:
         logging.info("Ignoring pca9685 cycle time of %.6f (using %.6f)",
                      cycle_time, self._cycle_time)
Ejemplo n.º 41
0
Archivo: mcu.py Proyecto: N7QWT/klipper
 def setup_dir_pin(self, pin_params):
     if pin_params['chip'] is not self._mcu:
         raise pins.error("Stepper dir pin must be on same mcu as step pin")
     self._dir_pin = pin_params['pin']
     self._invert_dir = pin_params['invert']
Ejemplo n.º 42
0
 def setup_pin(self, pin_type, pin_params):
     pin = pin_params['pin']
     if pin not in self.pins:
         raise pins.error("Unknown replicape pin %s" % (pin,))
     pclass, channel = self.pins[pin]
     return pclass(self, channel, pin_type, pin_params)
Ejemplo n.º 43
0
 def setup_cycle_time(self, cycle_time, hardware_pwm=False):
     if hardware_pwm:
         raise pins.error("pca9685 does not support hardware_pwm parameter")
     if cycle_time != self._cycle_time:
         logging.info("Ignoring pca9685 cycle time of %.6f (using %.6f)",
                      cycle_time, self._cycle_time)
Ejemplo n.º 44
0
 def setup_dir_pin(self, pin_params):
     if pin_params['chip'] is not self._mcu:
         raise pins.error("Stepper dir pin must be on same mcu as step pin")
     self._dir_pin = pin_params['pin']
     self._invert_dir = pin_params['invert']
Ejemplo n.º 45
0
 def _build_config(self):
     if self._max_duration:
         raise pins.error("SX1509 pins are not suitable for heaters")
Ejemplo n.º 46
0
Archivo: mcu.py Proyecto: N7QWT/klipper
 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")
     self._start_value = (not not start_value) ^ self._invert
     self._shutdown_value = (not not shutdown_value) ^ self._invert
     self._is_static = is_static