pins: Explicitly pass can_invert and can_pullup to lookup_pin()

Don't pass pin_type to lookup_pin() - instead, if a pin can be
inverted or can have a pullup, then the caller must explicitly specify
that when calling lookup_pin().  This simplifies the code for the
cases where it is not valid to invert or pullup.

Explicitly pass the pin_type to setup_pin() and have ppins.setup_pin()
apply default pullup and invert flags.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-26 09:44:45 -04:00
parent 7a9553b38a
commit 273a98d39a
13 changed files with 39 additions and 50 deletions

View file

@ -17,15 +17,13 @@ class UC1701:
printer = config.get_printer()
# pin config
ppins = printer.lookup_object('pins')
pins = [ppins.lookup_pin('digital_out', config.get(name + '_pin'))
pins = [ppins.lookup_pin(config.get(name + '_pin'))
for name in ['cs','a0']]
mcu = None
for pin_params in pins:
if mcu is not None and pin_params['chip'] != mcu:
raise ppins.error("uc1701 all pins must be on same mcu")
mcu = pin_params['chip']
if pin_params['invert']:
raise ppins.error("uc1701 can not invert pin")
self.pins = [pin_params['pin'] for pin_params in pins]
self.mcu = mcu
self.spi_oid = self.mcu.create_oid()