From 8f541d090ed6c21e2487047df97a46f98a93a941 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 12 Mar 2019 12:08:05 -0400 Subject: [PATCH] avr: Use enumerations for pin mappings Signed-off-by: Kevin O'Connor --- klippy/pins.py | 21 +++++++++++---------- src/avr/gpio.c | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/klippy/pins.py b/klippy/pins.py index 62e33764..8263f455 100644 --- a/klippy/pins.py +++ b/klippy/pins.py @@ -38,12 +38,6 @@ def beaglebone_pins(): return gpios MCU_PINS = { - "atmega168": port_pins(5), - "atmega328": port_pins(5), "atmega328p": port_pins(5), - "atmega644p": port_pins(4), "atmega1284p": port_pins(4), - "at90usb1286": port_pins(6), "at90usb646": port_pins(6), - "atmega32u4": port_pins(6), - "atmega1280": port_pins(12), "atmega2560": port_pins(12), "sam3x8e": port_pins(4, 32), "sam3x8c": port_pins(2, 32), "sam4s8c": port_pins(3, 32), "sam4e8e" : port_pins(5, 32), "samd21g18a": port_pins(2, 32), "samd21e18a": port_pins(2, 32), @@ -122,10 +116,14 @@ def update_map_arduino(pins, mcu): if mcu not in Arduino_from_mcu: raise error("Arduino aliases not supported on mcu '%s'" % (mcu,)) dpins, apins = Arduino_from_mcu[mcu] + aliases = {} for i in range(len(dpins)): - pins['ar' + str(i)] = pins[dpins[i]] + aliases['ar' + str(i)] = dpins[i] for i in range(len(apins)): - pins['analog%d' % (i,)] = pins[apins[i]] + aliases['analog%d' % (i,)] = apins[i] + if pins: + aliases = {a: pins[v] for a, v in aliases.items()} + pins.update(aliases) ###################################################################### @@ -191,9 +189,12 @@ class PinResolver: def update_command(self, cmd): def pin_fixup(m): name = m.group('name') - if name not in self.pins: + if name in self.pins: + pin_id = self.pins[name] + elif not self.pins: + pin_id = name + else: raise error("Unable to translate pin name: %s" % (cmd,)) - pin_id = self.pins[name] if (name != self.active_pins.setdefault(pin_id, name) and self.validate_aliases): raise error("pin %s is an alias for %s" % ( diff --git a/src/avr/gpio.c b/src/avr/gpio.c index 6ff21c26..03d6aff5 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -12,6 +12,24 @@ #include "pgm.h" // PROGMEM #include "sched.h" // sched_shutdown +#ifdef PINA +DECL_ENUMERATION_RANGE("pin", "PA0", GPIO('A', 0), 8); +#endif +DECL_ENUMERATION_RANGE("pin", "PB0", GPIO('B', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PC0", GPIO('C', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PD0", GPIO('D', 0), 8); +#ifdef PINE +DECL_ENUMERATION_RANGE("pin", "PE0", GPIO('E', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PF0", GPIO('F', 0), 8); +#endif +#ifdef PING +DECL_ENUMERATION_RANGE("pin", "PG0", GPIO('G', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PH0", GPIO('H', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PJ0", GPIO('J', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PK0", GPIO('K', 0), 8); +DECL_ENUMERATION_RANGE("pin", "PL0", GPIO('L', 0), 8); +#endif + volatile uint8_t * const digital_regs[] PROGMEM = { #ifdef PINA &PINA,