duplicate_pin_override: Debugging tool to permit multiple use pins

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-06-13 22:52:57 -04:00
parent 4d559633e3
commit 7fd7853785
3 changed files with 41 additions and 3 deletions

View File

@ -1574,6 +1574,22 @@ main printer config file. Wildcards may also be used (eg,
[include my_other_config.cfg] [include my_other_config.cfg]
``` ```
## [duplicate_pin_override]
This tool allows a single micro-controller pin to be defined multiple
times in a config file without normal error checking. This is intended
for diagnostic and debugging purposes. This section is not needed
where Klipper supports using the same pin multiple times, and using
this override may cause confusing and unexpected results.
```
[duplicate_pin_override]
pins:
# A comma separated list of pins that may be used multiple times in
# a config file without normal error checks. This parameter must be
# provided.
```
# Bed probing hardware # Bed probing hardware
## [probe] ## [probe]

View File

@ -0,0 +1,15 @@
# Tool to disable config checks for duplicate pins
#
# Copyright (C) 2021 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
class PrinterDupPinOverride:
def __init__(self, config):
printer = config.get_printer()
ppins = printer.lookup_object('pins')
for pin_desc in config.get('pins').split(','):
ppins.allow_multi_use_pin(pin_desc)
def load_config(config):
return PrinterDupPinOverride(config)

View File

@ -205,6 +205,7 @@ class PrinterPins:
self.chips = {} self.chips = {}
self.active_pins = {} self.active_pins = {}
self.pin_resolvers = {} self.pin_resolvers = {}
self.allow_multi_use_pins = {}
def parse_pin(self, pin_desc, can_invert=False, can_pullup=False): def parse_pin(self, pin_desc, can_invert=False, can_pullup=False):
desc = pin_desc.strip() desc = pin_desc.strip()
pullup = invert = 0 pullup = invert = 0
@ -241,10 +242,12 @@ class PrinterPins:
share_name = "%s:%s" % (pin_params['chip_name'], pin) share_name = "%s:%s" % (pin_params['chip_name'], pin)
if share_name in self.active_pins: if share_name in self.active_pins:
share_params = self.active_pins[share_name] share_params = self.active_pins[share_name]
if share_type is None or share_type != share_params['share_type']: if share_name in self.allow_multi_use_pins:
pass
elif share_type is None or share_type != share_params['share_type']:
raise error("pin %s used multiple times in config" % (pin,)) raise error("pin %s used multiple times in config" % (pin,))
if (pin_params['invert'] != share_params['invert'] elif (pin_params['invert'] != share_params['invert']
or pin_params['pullup'] != share_params['pullup']): or pin_params['pullup'] != share_params['pullup']):
raise error("Shared pin %s must have same polarity" % (pin,)) raise error("Shared pin %s must have same polarity" % (pin,))
return share_params return share_params
pin_params['share_type'] = share_type pin_params['share_type'] = share_type
@ -268,6 +271,10 @@ class PrinterPins:
raise error("Duplicate chip name '%s'" % (chip_name,)) raise error("Duplicate chip name '%s'" % (chip_name,))
self.chips[chip_name] = chip self.chips[chip_name] = chip
self.pin_resolvers[chip_name] = PinResolver() self.pin_resolvers[chip_name] = PinResolver()
def allow_multi_use_pin(self, pin_desc):
pin_params = self.parse_pin(pin_desc)
share_name = "%s:%s" % (pin_params['chip_name'], pin_params['pin'])
self.allow_multi_use_pins[share_name] = True
def add_printer_objects(config): def add_printer_objects(config):
config.get_printer().add_object('pins', PrinterPins()) config.get_printer().add_object('pins', PrinterPins())