From 3794b76d46314be1ccc92e308784cecfb15d6ebb Mon Sep 17 00:00:00 2001
From: Matthew Blue <matthew.blue.neuro@gmail.com>
Date: Fri, 23 Mar 2018 22:23:29 -0400
Subject: [PATCH] boards/mega-xplained: Initial Mega1284P Xplained support

---
 boards/mega-xplained/Makefile                 |   3 +
 boards/mega-xplained/Makefile.dep             |   4 +
 boards/mega-xplained/Makefile.features        |  14 ++
 boards/mega-xplained/Makefile.include         |  24 +++
 boards/mega-xplained/board.c                  |  99 +++++++++++++
 boards/mega-xplained/dist/debug.sh            |   8 +
 boards/mega-xplained/dist/debug_srv.sh        |   7 +
 boards/mega-xplained/dist/gdb.conf            |   1 +
 boards/mega-xplained/doc.txt                  |  37 +++++
 boards/mega-xplained/include/adc_params.h     |  58 ++++++++
 boards/mega-xplained/include/board.h          | 138 ++++++++++++++++++
 boards/mega-xplained/include/gpio_params.h    |  68 +++++++++
 .../include/mega-xplained_pinmap.h            |  78 ++++++++++
 boards/mega-xplained/include/periph_conf.h    | 125 ++++++++++++++++
 14 files changed, 664 insertions(+)
 create mode 100644 boards/mega-xplained/Makefile
 create mode 100644 boards/mega-xplained/Makefile.dep
 create mode 100644 boards/mega-xplained/Makefile.features
 create mode 100644 boards/mega-xplained/Makefile.include
 create mode 100644 boards/mega-xplained/board.c
 create mode 100755 boards/mega-xplained/dist/debug.sh
 create mode 100755 boards/mega-xplained/dist/debug_srv.sh
 create mode 100644 boards/mega-xplained/dist/gdb.conf
 create mode 100644 boards/mega-xplained/doc.txt
 create mode 100644 boards/mega-xplained/include/adc_params.h
 create mode 100644 boards/mega-xplained/include/board.h
 create mode 100644 boards/mega-xplained/include/gpio_params.h
 create mode 100644 boards/mega-xplained/include/mega-xplained_pinmap.h
 create mode 100644 boards/mega-xplained/include/periph_conf.h

diff --git a/boards/mega-xplained/Makefile b/boards/mega-xplained/Makefile
new file mode 100644
index 0000000000..f8fcbb53a0
--- /dev/null
+++ b/boards/mega-xplained/Makefile
@@ -0,0 +1,3 @@
+MODULE = board
+
+include $(RIOTBASE)/Makefile.base
diff --git a/boards/mega-xplained/Makefile.dep b/boards/mega-xplained/Makefile.dep
new file mode 100644
index 0000000000..0688b61ce6
--- /dev/null
+++ b/boards/mega-xplained/Makefile.dep
@@ -0,0 +1,4 @@
+ifneq (,$(filter saul_default,$(USEMODULE)))
+  USEMODULE += saul_adc
+  USEMODULE += saul_gpio
+endif
diff --git a/boards/mega-xplained/Makefile.features b/boards/mega-xplained/Makefile.features
new file mode 100644
index 0000000000..02232a9488
--- /dev/null
+++ b/boards/mega-xplained/Makefile.features
@@ -0,0 +1,14 @@
+# Put defined MCU peripherals here (in alphabetical order)
+FEATURES_PROVIDED += periph_adc
+FEATURES_PROVIDED += periph_gpio
+FEATURES_PROVIDED += periph_i2c
+FEATURES_PROVIDED += periph_spi
+FEATURES_PROVIDED += periph_timer
+FEATURES_PROVIDED += periph_uart
+
+# Various other features (if any)
+
+# The board MPU family (used for grouping by the CI system)
+FEATURES_MCU_GROUP = avr8
+
+-include $(RIOTCPU)/atmega1284p/Makefile.features
diff --git a/boards/mega-xplained/Makefile.include b/boards/mega-xplained/Makefile.include
new file mode 100644
index 0000000000..83fb4efee0
--- /dev/null
+++ b/boards/mega-xplained/Makefile.include
@@ -0,0 +1,24 @@
+# define the cpu used by the Mega Xplained board
+export CPU = atmega1284p
+
+# configure the terminal program
+export PORT_LINUX  ?= /dev/ttyACM0
+export PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial*)))
+export BAUD        ?= 9600
+include $(RIOTMAKE)/tools/serial.inc.mk
+
+export FLASHER = avrdude
+export DIST_PATH = $(RIOTBOARD)/$(BOARD)/dist
+export DEBUGSERVER_PORT = 4242
+export DEBUGSERVER = $(DIST_PATH)/debug_srv.sh
+export DEBUGSERVER_FLAGS = "-g -j usb :$(DEBUGSERVER_PORT)"
+export DEBUGGER_FLAGS = "-x $(RIOTBOARD)/$(BOARD)/dist/gdb.conf $(ELFFILE)"
+export DEBUGGER = $(DIST_PATH)/debug.sh $(DEBUGSERVER_FLAGS) $(DIST_PATH) $(DEBUGSERVER_PORT)
+
+# PROGRAMMER defaults to the Bus Pirate ISP
+export PROGRAMMER ?= buspirate
+
+export PROGRAMMER_FLAGS = -P /dev/ttyUSB0
+
+export OFLAGS += -j .text -j .data -O ihex
+export FFLAGS += -p m1284p -c $(PROGRAMMER) $(PROGRAMMER_FLAGS) -F -U flash:w:bin/$(BOARD)/$(PROJECT)$(APPLICATION).hex
diff --git a/boards/mega-xplained/board.c b/boards/mega-xplained/board.c
new file mode 100644
index 0000000000..fe5d2a9ae9
--- /dev/null
+++ b/boards/mega-xplained/board.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
+ *               2015 Kaspar Schleiser <kaspar@schleiser.de>
+ *               2016 Laurent Navet <laurent.navet@gmail.com>
+ *               2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup     boards_mega-xplained
+ * @{
+ *
+ * @file
+ * @brief       Board specific implementation for the Mega Xplained
+ *
+ * @author      Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
+ * @author      Kaspar Schleiser <kaspar@schleiser.de>
+ * @author      Laurent Navet <laurent.navet@gmail.com>
+ * @author      Matthew Blue <matthew.blu.neuro@gmail.com>
+ *
+ * @}
+ */
+
+#include <stdio.h>
+#include <avr/io.h>
+
+#include "board.h"
+#include "cpu.h"
+#include "uart_stdio.h"
+#include "periph/gpio.h"
+
+void SystemInit(void);
+static int uart_putchar(char c, FILE *stream);
+static int uart_getchar(FILE *stream);
+static void led_init(void);
+
+static FILE uart_stdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE);
+static FILE uart_stdin = FDEV_SETUP_STREAM(NULL, uart_getchar, _FDEV_SETUP_READ);
+
+void board_init(void)
+{
+    /* initialize stdio via USART_1 */
+    SystemInit();
+
+    /* initialize the CPU */
+    cpu_init();
+
+    /* initialize the LEDs */
+    led_init();
+
+    irq_enable();
+}
+
+/**
+ * @brief Initialize the System, initialize IO via UART_1
+ */
+void SystemInit(void)
+{
+    /* initialize UART_1 for use as stdout */
+    uart_stdio_init();
+
+    stdout = &uart_stdout;
+    stdin = &uart_stdin;
+
+    /* Flush stdout */
+    puts("\f");
+}
+
+static int uart_putchar(char c, FILE *stream)
+{
+    (void) stream;
+    uart_stdio_write(&c, 1);
+    return 0;
+}
+
+int uart_getchar(FILE *stream)
+{
+    (void) stream;
+    char c;
+    uart_stdio_read(&c, 1);
+    return (int)c;
+}
+
+/**
+ * @brief Initialize the on-board LEDs
+ */
+void led_init(void)
+{
+    /* LED0,2 currently unsupported due to lack of GPIO_OD support */
+
+    LED1_ENABLE_PORT;
+    LED1_OFF;
+
+    LED3_ENABLE_PORT;
+    LED3_OFF;
+}
diff --git a/boards/mega-xplained/dist/debug.sh b/boards/mega-xplained/dist/debug.sh
new file mode 100755
index 0000000000..0b10852f20
--- /dev/null
+++ b/boards/mega-xplained/dist/debug.sh
@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+sleep 2
+setsid -w avarice $1 &
+#sleep 2 && $2/avr-gdb-wrapper -ex "target remote localhost:$3" $4
+sleep 3 && avr-gdb -ex "target remote localhost:$3" $4
+
+# avarice exits with 1 if the connection is released, therefore we always exit with 0
+exit 0
diff --git a/boards/mega-xplained/dist/debug_srv.sh b/boards/mega-xplained/dist/debug_srv.sh
new file mode 100755
index 0000000000..8e7de053ab
--- /dev/null
+++ b/boards/mega-xplained/dist/debug_srv.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+sleep 2
+avarice $1
+
+# avarice exits with 1 if the connection is released, therefore we always exit with 0
+exit 0
diff --git a/boards/mega-xplained/dist/gdb.conf b/boards/mega-xplained/dist/gdb.conf
new file mode 100644
index 0000000000..ca68eb344c
--- /dev/null
+++ b/boards/mega-xplained/dist/gdb.conf
@@ -0,0 +1 @@
+set $pc=0x00
diff --git a/boards/mega-xplained/doc.txt b/boards/mega-xplained/doc.txt
new file mode 100644
index 0000000000..e31867ecb1
--- /dev/null
+++ b/boards/mega-xplained/doc.txt
@@ -0,0 +1,37 @@
+/**
+ * @defgroup    boards_mega-xplained Mega1284P-Xplained
+ * @ingroup     boards
+ * @brief       Support for the Mega1284P-Xplained board.
+ *
+ * ### General information
+ *
+ * The [Mega1284P-Xplained](http://www.microchip.com/DevelopmentTools/ProductDetails.aspx?PartNO=atmega1284p-xpld)
+ * is an evaluation kit by Atmel (now Microchip) for their ATmega1284P microcontroller.
+ *
+ * ### Flash the board
+ *
+ * 1. The board may be flashed through JTAG or using a SPI ISP programmer. If
+ *    the Buspirate is being used, then `make flash` can be used to flash the
+ *    board:
+ * ```
+ *      make BOARD=mega-xplained -C examples/hello-world flash
+ * ```
+ *
+ * 2. The default fuse settings must also be changed.<br/>
+ *    If using the Buspirate:
+ * ```
+ *      avrdude -p m1284p -c buspirate -P /dev/ttyUSB0 -U efuse:w:0xFF:m
+ *      avrdude -p m1284p -c buspirate -P /dev/ttyUSB0 -U hfuse:w:0x99:m
+ *      avrdude -p m1284p -c buspirate -P /dev/ttyUSB0 -U lfuse:w:0xE2:m
+ * ```
+ * WARNING: setting the fuses incorrectly can brick your board!
+ *
+ * ### Accessing STDIO via UART
+ *
+ * STDIO can be accessed through the USB connector. The on-board UART-USB
+ * adapter is not affected by flashing. It shows up as /dev/ttyACM0 on Linux.
+ * It will be used automatically with `make term`:
+ * ```
+ *      make BOARD=mega-xplained -C examples/hello-world term
+ * ```
+ */
diff --git a/boards/mega-xplained/include/adc_params.h b/boards/mega-xplained/include/adc_params.h
new file mode 100644
index 0000000000..eede5f45ce
--- /dev/null
+++ b/boards/mega-xplained/include/adc_params.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2016 Eistec AB
+ *               2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup   boards_mega-xplained
+ * @{
+ *
+ * @file
+ * @brief     Board specific configuration of direct mapped ADC
+ *
+ * @author    Joakim Nohlgård <joakim.nohlgard@eistec.se>
+ * @author    Matthew Blue <matthew.blue.neuro@gmail.com>
+ */
+
+#ifndef ADC_PARAMS_H
+#define ADC_PARAMS_H
+
+#include "board.h"
+#include "saul/periph.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief    ADC configuration
+ */
+static const  saul_adc_params_t saul_adc_params[] =
+{
+    {
+        .name = "NTC thermistor",
+        .line = NTC_OUTPUT,
+        .res  = ADC_RES_10BIT,
+    },
+    {
+        .name = "Light sensor",
+        .line = LIGHT_SENSOR_OUTPUT,
+        .res  = ADC_RES_10BIT,
+    },
+    {
+        .name = "RC filter",
+        .line = FILTER_OUTPUT,
+        .res  = ADC_RES_10BIT,
+    }
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ADC_PARAMS_H */
+/** @} */
diff --git a/boards/mega-xplained/include/board.h b/boards/mega-xplained/include/board.h
new file mode 100644
index 0000000000..780405d826
--- /dev/null
+++ b/boards/mega-xplained/include/board.h
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
+ *               2016 Laurent Navet <laurent.navet@gmail.com>
+ *               2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/*
+ * @ingroup     boards_mega-xplained
+ * @brief       Support for the Mega Xplained board.
+ * @{
+ *
+ * @file
+ * @brief       Board specific definitions for the Mega Xplained board.
+ *
+ * @author      Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
+ * @author      Laurent Navet <laurent.navet@gmail.com>
+ * @author      Matthew Blue <matthew.blue.neuro@gmail.com>
+ */
+
+#ifndef BOARD_H
+#define BOARD_H
+
+#include "cpu.h"
+#include "periph_cpu.h"
+#include "mega-xplained_pinmap.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name    STDIO configuration
+ *
+ * As the CPU is too slow to handle 115200 baud, we set the default
+ * baudrate to 9600 for this board
+ * @{
+ */
+#ifndef UART_STDIO_BAUDRATE
+#define UART_STDIO_BAUDRATE (9600U)
+#endif
+/** @} */
+
+/**
+ * @brief   Use the UART 1 for STDIO on this board
+ */
+#define UART_STDIO_DEV       (UART_DEV(1))
+
+/**
+ * @brief   Context swap defines
+ *
+ * Setup to use PD7 which is pin change interrupt 31 (PCINT31)
+ * This emulates a software triggered interrupt
+ */
+#define AVR_CONTEXT_SWAP_INIT do { \
+            DDRD |= (1 << PD7); \
+            PCICR |= (1 << PCIE3); \
+            PCMSK3 |= (1 << PCINT31); \
+} while (0)
+#define AVR_CONTEXT_SWAP_INTERRUPT_VECT  PCINT3_vect
+#define AVR_CONTEXT_SWAP_TRIGGER   PORTD ^= (1 << PD7)
+
+/**
+ * @name    xtimer configuration values
+ *
+ * Xtimer runs at 8MHz / 64 = 125kHz
+ * @{
+ */
+#define XTIMER_DEV                  (0)
+#define XTIMER_CHAN                 (0)
+#define XTIMER_WIDTH                (16)
+#define XTIMER_HZ                   (125000UL)
+#define XTIMER_BACKOFF              (40)
+/** @} */
+
+/**
+ * @name    LED pin definitions
+ * @{
+ */
+/* LED0,2 currently unsupported due to lack of GPIO_OD support */
+#define LED1_PIN     GPIO_PIN(PORT_B, 3)
+#define LED1_MODE    GPIO_OUT
+
+#define LED3_PIN     GPIO_PIN(PORT_B, 2)
+#define LED3_MODE    GPIO_OUT
+/** @} */
+
+/**
+ * @name    Macros for controlling the on-board LEDs
+ * @{
+ */
+/* LED0,2 currently unsupported due to lack of GPIO_OD support */
+#define LED1_ENABLE_PORT    DDRB  |=  LED1_PIN
+#define LED1_ON             PORTB |=  LED1_PIN
+#define LED1_OFF            PORTB &= ~LED1_PIN
+#define LED1_TOGGLE         PORTB ^=  LED1_PIN
+
+#define LED3_ENABLE_PORT    DDRB  |=  LED3_PIN
+#define LED3_ON             PORTB |=  LED3_PIN
+#define LED3_OFF            PORTB &= ~LED3_PIN
+#define LED3_TOGGLE         PORTB ^=  LED3_PIN
+/** @} */
+
+/**
+ * @name    Button pin configuration
+ * @{
+ */
+#define BTN0_PIN     GPIO_PIN(PORT_B, 0)
+#define BTN0_MODE    GPIO_IN
+
+#define BTN1_PIN     GPIO_PIN(PORT_B, 1)
+#define BTN1_MODE    GPIO_IN
+
+/* BTN2 currently unsupported due to lack of GPIO_OD support */
+
+/**
+ * @name    ADC NTC, light sensor, and filter lines
+ * @{
+ */
+#define NTC_OUTPUT             GPIO_PIN(PORT_A, 5)
+#define LIGHT_SENSOR_OUTPUT    GPIO_PIN(PORT_A, 6)
+#define FILTER_OUTPUT          GPIO_PIN(PORT_A, 7)
+/** @} */
+
+/**
+ * @brief   Initialize board specific hardware, including clock, LEDs and std-IO
+ */
+void board_init(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BOARD_H */
+/** @} */
diff --git a/boards/mega-xplained/include/gpio_params.h b/boards/mega-xplained/include/gpio_params.h
new file mode 100644
index 0000000000..a0fc7fe3e7
--- /dev/null
+++ b/boards/mega-xplained/include/gpio_params.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2016 Freie Universität Berlin
+ *               2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup     boards_mega-xplained
+ * @{
+ *
+ * @file
+ * @brief       Configuration of SAUL mapped GPIO pins
+ *
+ * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
+ * @author      Matthew Blue <matthew.blue.neuro@gmail.com>
+ */
+
+#ifndef GPIO_PARAMS_H
+#define GPIO_PARAMS_H
+
+#include "board.h"
+#include "saul/periph.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief   GPIO configuration
+ */
+static const  saul_gpio_params_t saul_gpio_params[] =
+{
+    {
+        .name = "Button 0",
+        .pin  = BTN0_PIN,
+        .mode = BTN0_MODE,
+        .flags = SAUL_GPIO_INVERTED,
+    },
+    {
+        .name = "Button 1",
+        .pin  = BTN1_PIN,
+        .mode = BTN1_MODE,
+        .flags = SAUL_GPIO_INVERTED,
+    },
+    /* BTN2, LED0,2 currently unsupported due to lack of GPIO_OD support */
+    {
+        .name = "LED 1",
+        .pin = LED1_PIN,
+        .mode = LED1_MODE,
+        .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR),
+    },
+    {
+        .name = "LED 3",
+        .pin = LED3_PIN,
+        .mode = LED3_MODE,
+        .flags = (SAUL_GPIO_INVERTED | SAUL_GPIO_INIT_CLEAR),
+    }
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GPIO_PARAMS_H */
+/** @} */
diff --git a/boards/mega-xplained/include/mega-xplained_pinmap.h b/boards/mega-xplained/include/mega-xplained_pinmap.h
new file mode 100644
index 0000000000..0fdfd28400
--- /dev/null
+++ b/boards/mega-xplained/include/mega-xplained_pinmap.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup     boards_mega-xplained
+ * @{
+ *
+ * @file
+ * @brief       Mapping from MCU pins to Mega Xplained pins
+ *
+ * You can use the defines in this file for simplified interaction with the
+ * Mega Xplained specific pin numbers.
+ *
+ * @author      Matthew Blue <matthew.blue.neuro@gmail.com>
+ */
+
+#ifndef MEGA_XPLAINED_PINMAP_H
+#define MEGA_XPLAINED_PINMAP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name   Mapping of MCU pins to Mega Xplained pins
+ * @{
+ */
+/*
+ * DESCRIPTION Xplained API PIN          PORT   PIN
+ */
+#define J1_PIN1                 GPIO_PIN(PORT_C, 1)
+#define J1_PIN2                 GPIO_PIN(PORT_C, 0)
+#define J1_PIN3                 GPIO_PIN(PORT_D, 0)
+#define J1_PIN4                 GPIO_PIN(PORT_D, 1)
+#define J1_PIN5                 GPIO_PIN(PORT_B, 4)
+#define J1_PIN6                 GPIO_PIN(PORT_B, 5)
+#define J1_PIN7                 GPIO_PIN(PORT_B, 6)
+#define J1_PIN8                 GPIO_PIN(PORT_B, 7)
+
+#define J2_PIN1                 GPIO_PIN(PORT_A, 0)
+#define J2_PIN2                 GPIO_PIN(PORT_A, 1)
+#define J2_PIN3                 GPIO_PIN(PORT_A, 2)
+#define J2_PIN4                 GPIO_PIN(PORT_A, 3)
+#define J2_PIN5                 GPIO_PIN(PORT_A, 4)
+#define J2_PIN6                 GPIO_PIN(PORT_A, 5)
+#define J2_PIN7                 GPIO_PIN(PORT_A, 6)
+#define J2_PIN8                 GPIO_PIN(PORT_A, 7)
+
+#define J3_PIN1                 GPIO_PIN(PORT_B, 0)
+#define J3_PIN2                 GPIO_PIN(PORT_B, 1)
+#define J3_PIN3                 GPIO_PIN(PORT_B, 2)
+#define J3_PIN4                 GPIO_PIN(PORT_B, 3)
+#define J3_PIN5                 GPIO_PIN(PORT_D, 4)
+#define J3_PIN6                 GPIO_PIN(PORT_D, 5)
+#define J3_PIN7                 GPIO_PIN(PORT_C, 4)
+#define J3_PIN8                 GPIO_PIN(PORT_C, 5)
+
+#define J4_PIN1                 GPIO_PIN(PORT_C, 1)
+#define J4_PIN2                 GPIO_PIN(PORT_C, 0)
+#define J4_PIN3                 GPIO_PIN(PORT_D, 2)
+#define J4_PIN4                 GPIO_PIN(PORT_D, 3)
+#define J4_PIN5                 GPIO_PIN(PORT_D, 4)
+#define J4_PIN6                 GPIO_PIN(PORT_B, 5)
+#define J4_PIN7                 GPIO_PIN(PORT_B, 6)
+#define J4_PIN8                 GPIO_PIN(PORT_B, 7)
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MEGA_XPLAINED_PINMAP_H */
+/** @} */
diff --git a/boards/mega-xplained/include/periph_conf.h b/boards/mega-xplained/include/periph_conf.h
new file mode 100644
index 0000000000..f11a1803df
--- /dev/null
+++ b/boards/mega-xplained/include/periph_conf.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2014 Freie Universität Berlin, Hinnerk van Bruinehsen
+ *               2016 Laurent Navet <laurent.navet@gmail.com>
+ *               2017 HAW Hamburg, Dimitri Nahm
+ *               2018 Matthew Blue <matthew.blue.neuro@gmail.com>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License v2.1. See the file LICENSE in the top level
+ * directory for more details.
+ */
+
+/**
+ * @ingroup     boards_mega-xplained
+ * @{
+ *
+ * @file
+ * @brief       Common configuration of MCU periphery for Mega Xplained
+ *
+ * @author      Hinnerk van Bruinehsen <h.v.bruinehsen@fu-berlin.de>
+ * @author      Laurent Navet <laurent.navet@gmail.com>
+ * @author      Hauke Petersen <hauke.petersen@fu-berlin.de>
+ * @author      Dimitri Nahm <dimitri.nahm@haw-hamburg.de>
+ * @author      Matthew Blue <matthew.blue.neuro@gmail.com>
+ */
+
+#ifndef PERIPH_CONF_H
+#define PERIPH_CONF_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @name    Clock configuration
+ *
+ * Frequency of the internal 8MHz RC oscillator.
+ *
+ * @{
+ */
+#define CLOCK_CORECLOCK     (8000000UL)
+/** @} */
+
+/**
+ * @name    Timer configuration
+ *
+ * The ATmega1284P has 4 timers. Timer0 and Timer2 are 8 Bit Timers.
+ *
+ * The timer driver only supports the two 16-bit timers (Timer1 and
+ * Timer3), so those are the only ones we can use here.
+ *
+ * @{
+ */
+#define TIMER_NUMOF         (2U)
+
+#define TIMER_0             MEGA_TIMER1
+#define TIMER_0_MASK        &TIMSK1
+#define TIMER_0_FLAG        &TIFR1
+#define TIMER_0_ISRA        TIMER1_COMPA_vect
+#define TIMER_0_ISRB        TIMER1_COMPB_vect
+
+#define TIMER_1             MEGA_TIMER3
+#define TIMER_1_MASK        &TIMSK3
+#define TIMER_1_FLAG        &TIFR3
+#define TIMER_1_ISRA        TIMER3_COMPA_vect
+#define TIMER_1_ISRB        TIMER3_COMPB_vect
+/** @} */
+
+/**
+ * @name    UART configuration
+ *
+ * The UART devices have fixed pin mappings, so all we need to do, is to specify
+ * which devices we would like to use and their corresponding RX interrupts. See
+ * the reference manual for the fixed pin mapping.
+ *
+ * @{
+ */
+#define UART_NUMOF          (2U)
+
+#define UART_0              MEGA_UART0
+#define UART_0_ISR          USART0_RX_vect
+
+#define UART_1              MEGA_UART1
+#define UART_1_ISR          USART1_RX_vect
+/** @} */
+
+/**
+ * @name    SPI configuration
+ *
+ * The ATmega1284P has only one hardware SPI with fixed pin configuration, so
+ * all we can do here, is to enable or disable it...
+ *
+ * The fixed pins used are:
+ * MOSI - PB5 (pin  1)
+ * MISO - PB6 (pin  2)
+ * SCK  - PB7 (pin  3)
+ * SS   - PB4 (pin 44) -> this pin is configured as output, but not used
+ *
+ * The SS pin must be configured as output for the SPI device to work as
+ * master correctly, though we do not use it for now (as we handle the chip
+ * select externally for now)
+ *
+ * @{
+ */
+#define SPI_NUMOF           1           /* set to 0 to disable SPI */
+/** @} */
+
+/**
+ * @name    I2C configuration
+ * @{
+ */
+#define I2C_NUMOF           1
+/** @} */
+
+/**
+ * @name    ADC configuration
+ * @{
+ */
+#define ADC_NUMOF       (8U)
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PERIPH_CONF_H */
-- 
GitLab