aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-17 20:41:52 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-03-17 20:56:25 -0400
commit4a35f927fc1d7b8c3b34f32c1c889fb433752dcc (patch)
treee775cbf7f216996cd2056c6568c5fbc5eac1f3fb
parent0af89e4766e5a25abb9d5d9667e2f187c4cec7c1 (diff)
downloadkutter-4a35f927fc1d7b8c3b34f32c1c889fb433752dcc.tar.gz
kutter-4a35f927fc1d7b8c3b34f32c1c889fb433752dcc.tar.xz
kutter-4a35f927fc1d7b8c3b34f32c1c889fb433752dcc.zip
initial_pins: Add ability to configure output pins at mcu startup
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--scripts/buildcommands.py56
-rw-r--r--src/Kconfig9
-rw-r--r--src/Makefile2
-rw-r--r--src/initial_pins.c25
-rw-r--r--src/initial_pins.h15
5 files changed, 103 insertions, 4 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py
index 43e318e7..e796994e 100644
--- a/scripts/buildcommands.py
+++ b/scripts/buildcommands.py
@@ -16,6 +16,7 @@ FILEHEADER = """
#include "board/pgm.h"
#include "command.h"
#include "compiler.h"
+#include "initial_pins.h"
"""
def error(msg):
@@ -114,7 +115,8 @@ ctr_lookup_static_string(const char *str)
"""
return fmt % ("".join(code).strip(),)
-Handlers.append(HandleEnumerations())
+HandlerEnumerations = HandleEnumerations()
+Handlers.append(HandlerEnumerations)
######################################################################
@@ -146,7 +148,7 @@ class HandleConstants:
name, value = req.split()[1:]
self.set_value(name, decode_integer(value))
def decl_constant_str(self, req):
- name, value = req.split()[1:]
+ name, value = req.split(None, 2)[1:]
value = value.strip()
if value.startswith('"') and value.endswith('"'):
value = value[1:-1]
@@ -156,7 +158,55 @@ class HandleConstants:
def generate_code(self, options):
return ""
-Handlers.append(HandleConstants())
+HandlerConstants = HandleConstants()
+Handlers.append(HandlerConstants)
+
+
+######################################################################
+# Initial pins
+######################################################################
+
+class HandleInitialPins:
+ def __init__(self):
+ self.initial_pins = []
+ self.ctr_dispatch = { 'DECL_INITIAL_PINS': self.decl_initial_pins }
+ def decl_initial_pins(self, req):
+ pins = req.split(None, 1)[1].strip()
+ if pins.startswith('"') and pins.endswith('"'):
+ pins = pins[1:-1]
+ if pins:
+ self.initial_pins = [p.strip() for p in pins.split(',')]
+ HandlerConstants.decl_constant_str(
+ "_DECL_CONSTANT_STR INITIAL_PINS "
+ + ','.join(self.initial_pins))
+ def update_data_dictionary(self, data):
+ pass
+ def map_pins(self):
+ if not self.initial_pins:
+ return []
+ mp = msgproto.MessageParser()
+ mp._fill_enumerations(HandlerEnumerations.enumerations)
+ pinmap = mp.enumerations.get('pin', {})
+ out = []
+ for p in self.initial_pins:
+ flag = "IP_OUT_HIGH"
+ if p.startswith('!'):
+ flag = "0"
+ p = p[1:].strip()
+ if p not in pinmap:
+ error("Unknown initial pin '%s'" % (p,))
+ out.append("\n {%d, %s}, // %s" % (pinmap[p], flag, p))
+ return out
+ def generate_code(self, options):
+ out = self.map_pins()
+ fmt = """
+const struct initial_pin_s initial_pins[] PROGMEM = {%s
+};
+const int initial_pins_size PROGMEM = ARRAY_SIZE(initial_pins);
+"""
+ return fmt % (''.join(out),)
+
+Handlers.append(HandleInitialPins())
######################################################################
diff --git a/src/Kconfig b/src/Kconfig
index a80e1deb..7e6475b9 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -88,6 +88,15 @@ config STEP_DELAY
The default for AVR is -1, for all other micro-controllers it
is 2us.
+config INITIAL_PINS
+ string "GPIO pins to set at micro-controller startup"
+ depends on LOW_LEVEL_OPTIONS
+ help
+ One may specify a comma separated list of gpio pins to set
+ during the micro-controller startup sequence. By default the
+ pins will be set to output high - preface a pin with a '!'
+ character to set that pin to output low.
+
# The HAVE_GPIO_x options allow boards to disable support for some
# commands if the hardware does not support the feature.
config HAVE_GPIO
diff --git a/src/Makefile b/src/Makefile
index 546dc0a5..c838e911 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,6 +1,6 @@
# Main code build rules
-src-y += sched.c command.c basecmd.c debugcmds.c
+src-y += sched.c command.c basecmd.c debugcmds.c initial_pins.c
src-$(CONFIG_HAVE_GPIO) += gpiocmds.c stepper.c endstop.c
src-$(CONFIG_HAVE_GPIO_ADC) += adccmds.c
src-$(CONFIG_HAVE_GPIO_SPI) += spicmds.c thermocouple.c
diff --git a/src/initial_pins.c b/src/initial_pins.c
new file mode 100644
index 00000000..cd478508
--- /dev/null
+++ b/src/initial_pins.c
@@ -0,0 +1,25 @@
+// Support setting gpio pins at mcu start
+//
+// Copyright (C) 2019 Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#include "autoconf.h" // CONFIG_INITIAL_PINS
+#include "board/gpio.h" // gpio_out_setup
+#include "board/pgm.h" // READP
+#include "ctr.h" // DECL_CTR
+#include "initial_pins.h" // initial_pins
+#include "sched.h" // DECL_INIT
+
+DECL_CTR("DECL_INITIAL_PINS " __stringify(CONFIG_INITIAL_PINS));
+
+void
+initial_pins_setup(void)
+{
+ int i;
+ for (i=0; i<initial_pins_size; i++) {
+ const struct initial_pin_s *ip = &initial_pins[i];
+ gpio_out_setup(READP(ip->pin), READP(ip->flags) & IP_OUT_HIGH);
+ }
+}
+DECL_INIT(initial_pins_setup);
diff --git a/src/initial_pins.h b/src/initial_pins.h
new file mode 100644
index 00000000..95bb2921
--- /dev/null
+++ b/src/initial_pins.h
@@ -0,0 +1,15 @@
+#ifndef __INITIAl_PINS_H
+#define __INITIAl_PINS_H
+
+struct initial_pin_s {
+ int pin;
+ uint8_t flags;
+};
+
+enum { IP_OUT_HIGH = 1 };
+
+// out/compile_time_request.c (auto generated file)
+extern const struct initial_pin_s initial_pins[];
+extern const int initial_pins_size;
+
+#endif // initial_pins.h