mirror of https://github.com/Desuuuu/klipper.git
pins: Simplify pin map alias setup
Use map_pins() to obtain the pin mapping - don't export mcu_to_pins(). The functionality of mcu_to_pins() can be obtained by calling map_pins() with name=None. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0f2478b62f
commit
8e6d5efdac
|
@ -24,6 +24,8 @@ class KeyboardReader:
|
||||||
self.eval_globals = {}
|
self.eval_globals = {}
|
||||||
def connect(self, eventtime):
|
def connect(self, eventtime):
|
||||||
self.ser.connect()
|
self.ser.connect()
|
||||||
|
mcu = self.ser.msgparser.get_constant('MCU')
|
||||||
|
self.pins = pins.get_pin_map(mcu)
|
||||||
self.reactor.unregister_timer(self.connect_timer)
|
self.reactor.unregister_timer(self.connect_timer)
|
||||||
return self.reactor.NEVER
|
return self.reactor.NEVER
|
||||||
def update_evals(self, eventtime):
|
def update_evals(self, eventtime):
|
||||||
|
@ -32,8 +34,8 @@ class KeyboardReader:
|
||||||
self.eval_globals['freq'] = f
|
self.eval_globals['freq'] = f
|
||||||
self.eval_globals['clock'] = int(c)
|
self.eval_globals['clock'] = int(c)
|
||||||
def set_pin_map(self, parts):
|
def set_pin_map(self, parts):
|
||||||
mcu = self.ser.msgparser.config['MCU']
|
mcu = self.ser.msgparser.get_constant('MCU')
|
||||||
self.pins = pins.map_pins(parts[1], mcu)
|
self.pins = pins.get_pin_map(mcu, parts[1])
|
||||||
def set_var(self, parts):
|
def set_var(self, parts):
|
||||||
val = parts[2]
|
val = parts[2]
|
||||||
try:
|
try:
|
||||||
|
@ -44,10 +46,6 @@ class KeyboardReader:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
self.eval_globals[parts[1]] = val
|
self.eval_globals[parts[1]] = val
|
||||||
def lookup_pin(self, value):
|
|
||||||
if self.pins is None:
|
|
||||||
self.pins = pins.mcu_to_pins(self.ser.msgparser.config['MCU'])
|
|
||||||
return self.pins[value]
|
|
||||||
def translate(self, line, eventtime):
|
def translate(self, line, eventtime):
|
||||||
evalparts = re_eval.split(line)
|
evalparts = re_eval.split(line)
|
||||||
if len(evalparts) > 1:
|
if len(evalparts) > 1:
|
||||||
|
@ -60,8 +58,6 @@ class KeyboardReader:
|
||||||
return None
|
return None
|
||||||
line = ''.join(evalparts)
|
line = ''.join(evalparts)
|
||||||
print "Eval:", line
|
print "Eval:", line
|
||||||
if self.pins is None and self.ser.msgparser.config:
|
|
||||||
self.pins = pins.mcu_to_pins(self.ser.msgparser.config['MCU'])
|
|
||||||
if self.pins is not None:
|
if self.pins is not None:
|
||||||
try:
|
try:
|
||||||
line = pins.update_command(line, self.pins).strip()
|
line = pins.update_command(line, self.pins).strip()
|
||||||
|
|
|
@ -357,6 +357,7 @@ class MCU:
|
||||||
self._config_cmds = []
|
self._config_cmds = []
|
||||||
self._config_crc = None
|
self._config_crc = None
|
||||||
self._init_callbacks = []
|
self._init_callbacks = []
|
||||||
|
self._pin_map = config.get('pin_map', None)
|
||||||
# Move command queuing
|
# Move command queuing
|
||||||
ffi_main, self.ffi_lib = chelper.get_ffi()
|
ffi_main, self.ffi_lib = chelper.get_ffi()
|
||||||
self._steppers = []
|
self._steppers = []
|
||||||
|
@ -456,11 +457,7 @@ class MCU:
|
||||||
|
|
||||||
# Resolve pin names
|
# Resolve pin names
|
||||||
mcu = self.serial.msgparser.get_constant('MCU')
|
mcu = self.serial.msgparser.get_constant('MCU')
|
||||||
pin_map = self._config.get('pin_map', None)
|
pnames = pins.get_pin_map(mcu, self._pin_map)
|
||||||
if pin_map is None:
|
|
||||||
pnames = pins.mcu_to_pins(mcu)
|
|
||||||
else:
|
|
||||||
pnames = pins.map_pins(pin_map, mcu)
|
|
||||||
updated_cmds = []
|
updated_cmds = []
|
||||||
for cmd in self._config_cmds:
|
for cmd in self._config_cmds:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -16,25 +16,13 @@ def port_pins(port_count, bit_count=8):
|
||||||
pins['P%c%d' % (portchr, portbit)] = port * bit_count + portbit
|
pins['P%c%d' % (portchr, portbit)] = port * bit_count + portbit
|
||||||
return pins
|
return pins
|
||||||
|
|
||||||
PINS_atmega164 = port_pins(4)
|
|
||||||
PINS_atmega1280 = port_pins(12)
|
|
||||||
|
|
||||||
MCU_PINS = {
|
MCU_PINS = {
|
||||||
"atmega168": PINS_atmega164, "atmega644p": PINS_atmega164,
|
"atmega168": port_pins(4), "atmega644p": port_pins(4),
|
||||||
"at90usb1286": port_pins(5),
|
"at90usb1286": port_pins(5),
|
||||||
"atmega1280": PINS_atmega1280, "atmega2560": PINS_atmega1280,
|
"atmega1280": port_pins(12), "atmega2560": port_pins(12),
|
||||||
"sam3x8e": port_pins(4, 32)
|
"sam3x8e": port_pins(4, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
def mcu_to_pins(mcu):
|
|
||||||
return MCU_PINS.get(mcu, {})
|
|
||||||
|
|
||||||
re_pin = re.compile(r'(?P<prefix>[ _]pin=)(?P<name>[^ ]*)')
|
|
||||||
def update_command(cmd, pmap):
|
|
||||||
def fixup(m):
|
|
||||||
return m.group('prefix') + str(pmap[m.group('name')])
|
|
||||||
return re_pin.sub(fixup, cmd)
|
|
||||||
|
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
# Arduino mappings
|
# Arduino mappings
|
||||||
|
@ -96,12 +84,25 @@ Arduino_from_mcu = {
|
||||||
"sam3x8e": (Arduino_Due, Arduino_Due_analog),
|
"sam3x8e": (Arduino_Due, Arduino_Due_analog),
|
||||||
}
|
}
|
||||||
|
|
||||||
def map_pins(name, mcu):
|
|
||||||
|
######################################################################
|
||||||
|
# External commands
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
# Obtains the pin mappings
|
||||||
|
def get_pin_map(mcu, mapping_name=None):
|
||||||
pins = MCU_PINS.get(mcu, {})
|
pins = MCU_PINS.get(mcu, {})
|
||||||
if name == 'arduino':
|
if mapping_name == 'arduino':
|
||||||
dpins, apins = Arduino_from_mcu.get(mcu, [])
|
dpins, apins = Arduino_from_mcu.get(mcu, [])
|
||||||
for i in range(len(dpins)):
|
for i in range(len(dpins)):
|
||||||
pins['ar' + str(i)] = pins[dpins[i]]
|
pins['ar' + str(i)] = pins[dpins[i]]
|
||||||
for i in range(len(apins)):
|
for i in range(len(apins)):
|
||||||
pins['analog%d' % (i,)] = pins[apins[i]]
|
pins['analog%d' % (i,)] = pins[apins[i]]
|
||||||
return pins
|
return pins
|
||||||
|
|
||||||
|
# Translate pin names in a firmware command
|
||||||
|
re_pin = re.compile(r'(?P<prefix>[ _]pin=)(?P<name>[^ ]*)')
|
||||||
|
def update_command(cmd, pmap):
|
||||||
|
def fixup(m):
|
||||||
|
return m.group('prefix') + str(pmap[m.group('name')])
|
||||||
|
return re_pin.sub(fixup, cmd)
|
||||||
|
|
Loading…
Reference in New Issue