aboutsummaryrefslogtreecommitdiffstats
path: root/src/avr
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-03-31 22:01:41 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-04-04 18:29:31 -0400
commit7765653d83364f266b7f1917b1cd6ab1508e7acf (patch)
tree6f0b0024ca431253e8b351fda0cb2e13af3def77 /src/avr
parent1ab02e522565ba991e13a0629041cadf60066926 (diff)
downloadkutter-7765653d83364f266b7f1917b1cd6ab1508e7acf.tar.gz
kutter-7765653d83364f266b7f1917b1cd6ab1508e7acf.tar.xz
kutter-7765653d83364f266b7f1917b1cd6ab1508e7acf.zip
avr: Use enumerations for buses and reserve pins
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/avr')
-rw-r--r--src/avr/Kconfig2
-rw-r--r--src/avr/i2c.c5
-rw-r--r--src/avr/serial.c16
-rw-r--r--src/avr/spi.c17
4 files changed, 33 insertions, 7 deletions
diff --git a/src/avr/Kconfig b/src/avr/Kconfig
index 6b9135b9..55269dc7 100644
--- a/src/avr/Kconfig
+++ b/src/avr/Kconfig
@@ -111,7 +111,7 @@ config SERIAL
default y
choice
depends on SERIAL
- prompt "Serial Port" if LOW_LEVEL_OPTIONS && (MACH_atmega2560 || MACH_atmega1280 || MACH_atmega1284p)
+ prompt "Serial Port" if LOW_LEVEL_OPTIONS && (MACH_atmega2560 || MACH_atmega1280 || MACH_atmega644p || MACH_atmega1284p)
help
Select the serial device to use on the AVR chip. This is
almost always UART0.
diff --git a/src/avr/i2c.c b/src/avr/i2c.c
index 9aada47d..4632497e 100644
--- a/src/avr/i2c.c
+++ b/src/avr/i2c.c
@@ -12,14 +12,19 @@
#include "internal.h" // GPIO
#include "sched.h" // sched_shutdown
+DECL_ENUMERATION("i2c_bus", "twi", 0);
+
#if CONFIG_MACH_atmega168 || CONFIG_MACH_atmega328 || CONFIG_MACH_atmega328p
static const uint8_t SCL = GPIO('C', 5), SDA = GPIO('C', 4);
+DECL_CONSTANT_STR("BUS_PINS_twi", "PC5,PC4");
#elif CONFIG_MACH_atmega644p || CONFIG_MACH_atmega1284p
static const uint8_t SCL = GPIO('C', 0), SDA = GPIO('C', 1);
+DECL_CONSTANT_STR("BUS_PINS_twi", "PC0,PC1");
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_at90usb646 \
|| CONFIG_MACH_atmega32u4 || CONFIG_MACH_atmega1280 \
|| CONFIG_MACH_atmega2560
static const uint8_t SCL = GPIO('D', 0), SDA = GPIO('D', 1);
+DECL_CONSTANT_STR("BUS_PINS_twi", "PD0,PD1");
#endif
static void
diff --git a/src/avr/serial.c b/src/avr/serial.c
index 4cc2ebc8..e0b35bef 100644
--- a/src/avr/serial.c
+++ b/src/avr/serial.c
@@ -7,8 +7,24 @@
#include <avr/interrupt.h> // USART_RX_vect
#include "autoconf.h" // CONFIG_SERIAL_BAUD
#include "board/serial_irq.h" // serial_rx_byte
+#include "command.h" // DECL_CONSTANT_STR
#include "sched.h" // DECL_INIT
+// Reserve serial pins
+#if CONFIG_SERIAL_PORT == 0
+ #if CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PE0,PE1");
+ #else
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PD0,PD1");
+ #endif
+#elif CONFIG_SERIAL_PORT == 1
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PD2,PD3");
+#elif CONFIG_SERIAL_PORT == 2
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PH0,PH1");
+#else
+DECL_CONSTANT_STR("RESERVE_PINS_serial", "PJ0,PJ1");
+#endif
+
// Helper macros for defining serial port aliases
#define AVR_SERIAL_REG1(prefix, id, suffix) prefix ## id ## suffix
#define AVR_SERIAL_REG(prefix, id, suffix) AVR_SERIAL_REG1(prefix, id, suffix)
diff --git a/src/avr/spi.c b/src/avr/spi.c
index 495e8330..319c51d6 100644
--- a/src/avr/spi.c
+++ b/src/avr/spi.c
@@ -11,17 +11,22 @@
#include "pgm.h" // READP
#include "sched.h" // sched_shutdown
+DECL_ENUMERATION("spi_bus", "spi", 0);
+
#if CONFIG_MACH_atmega168 || CONFIG_MACH_atmega328 || CONFIG_MACH_atmega328p
-static const uint8_t SS = GPIO('B', 2), SCK = GPIO('B', 5);
-static const uint8_t MOSI = GPIO('B', 3), MISO = GPIO('B', 4);
+static const uint8_t MISO = GPIO('B', 4), MOSI = GPIO('B', 3);
+static const uint8_t SCK = GPIO('B', 5), SS = GPIO('B', 2);
+DECL_CONSTANT_STR("BUS_PINS_spi", "PB4,PB3,PB5");
#elif CONFIG_MACH_atmega644p || CONFIG_MACH_atmega1284p
-static const uint8_t SS = GPIO('B', 4), SCK = GPIO('B', 7);
-static const uint8_t MOSI = GPIO('B', 5), MISO = GPIO('B', 6);
+static const uint8_t MISO = GPIO('B', 6), MOSI = GPIO('B', 5);
+static const uint8_t SCK = GPIO('B', 7), SS = GPIO('B', 4);
+DECL_CONSTANT_STR("BUS_PINS_spi", "PB6,PB5,PB7");
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_at90usb646 \
|| CONFIG_MACH_atmega32u4 || CONFIG_MACH_atmega1280 \
|| CONFIG_MACH_atmega2560
-static const uint8_t SS = GPIO('B', 0), SCK = GPIO('B', 1);
-static const uint8_t MOSI = GPIO('B', 2), MISO = GPIO('B', 3);
+static const uint8_t MISO = GPIO('B', 3), MOSI = GPIO('B', 2);
+static const uint8_t SCK = GPIO('B', 1), SS = GPIO('B', 0);
+DECL_CONSTANT_STR("BUS_PINS_spi", "PB3,PB2,PB1");
#endif
static void