From 8caedb8ad372ab4d88657a1d9746b1adffb64c43 Mon Sep 17 00:00:00 2001
From: Moritz Krautwald <moritz.krautwald@mailbox.org>
Date: Thu, 13 Apr 2023 16:11:33 +0200
Subject: [PATCH 1/3] add AdafruitBleUartFriend board

---
 boards.txt                                    | 46 ++++++++++++++
 variants/AdafruitBleUartFriend/pins_arduino.h | 17 +++++
 variants/AdafruitBleUartFriend/variant.cpp    | 56 +++++++++++++++++
 variants/AdafruitBleUartFriend/variant.h      | 62 +++++++++++++++++++
 4 files changed, 181 insertions(+)
 create mode 100644 variants/AdafruitBleUartFriend/pins_arduino.h
 create mode 100644 variants/AdafruitBleUartFriend/variant.cpp
 create mode 100644 variants/AdafruitBleUartFriend/variant.h

diff --git a/boards.txt b/boards.txt
index a050d27e..30d65d9e 100644
--- a/boards.txt
+++ b/boards.txt
@@ -442,6 +442,52 @@ Generic_nRF51822.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC
 Generic_nRF51822.menu.lfclk.lfsynt=Synthesized
 Generic_nRF51822.menu.lfclk.lfsynt.build.lfclk_flags=-DUSE_LFSYNT
 
+
+AdafruitBleUartFriend.name=Adafruit BLE UART Friend
+
+AdafruitBleUartFriend.upload.tool=sandeepmistry:openocd
+AdafruitBleUartFriend.upload.target=nrf51
+AdafruitBleUartFriend.upload.maximum_size=262144
+
+AdafruitBleUartFriend.bootloader.tool=sandeepmistry:openocd
+
+AdafruitBleUartFriend.build.mcu=cortex-m0
+AdafruitBleUartFriend.build.f_cpu=16000000
+AdafruitBleUartFriend.build.board=ADAFRUIT_BLE_UART_FRIEND
+AdafruitBleUartFriend.build.core=nRF5
+AdafruitBleUartFriend.build.variant=AdafruitBleUartFriend
+AdafruitBleUartFriend.build.variant_system_lib=
+AdafruitBleUartFriend.build.extra_flags=-DNRF51
+AdafruitBleUartFriend.build.float_flags=
+AdafruitBleUartFriend.build.chip=xxac
+AdafruitBleUartFriend.build.ldscript=nrf51_{build.chip}.ld
+
+AdafruitBleUartFriend.menu.softdevice.none=None
+AdafruitBleUartFriend.menu.softdevice.none.softdevice=none
+AdafruitBleUartFriend.menu.softdevice.none.softdeviceversion=
+
+AdafruitBleUartFriend.menu.softdevice.s110=S110
+AdafruitBleUartFriend.menu.softdevice.s110.softdevice=s110
+AdafruitBleUartFriend.menu.softdevice.s110.softdeviceversion=8.0.0
+AdafruitBleUartFriend.menu.softdevice.s110.upload.maximum_size=151552
+AdafruitBleUartFriend.menu.softdevice.s110.build.extra_flags=-DNRF51 -DS110 -DNRF51_S110
+AdafruitBleUartFriend.menu.softdevice.s110.build.ldscript=armgcc_s110_nrf51822_{build.chip}.ld
+
+AdafruitBleUartFriend.menu.softdevice.s130=S130
+AdafruitBleUartFriend.menu.softdevice.s130.softdevice=s130
+AdafruitBleUartFriend.menu.softdevice.s130.softdeviceversion=2.0.1
+AdafruitBleUartFriend.menu.softdevice.s130.upload.maximum_size=151552
+AdafruitBleUartFriend.menu.softdevice.s130.build.extra_flags=-DNRF51 -DS130 -DNRF51_S130
+AdafruitBleUartFriend.menu.softdevice.s130.build.ldscript=armgcc_s130_nrf51822_{build.chip}.ld
+
+AdafruitBleUartFriend.menu.lfclk.lfxo=Crystal Oscillator
+AdafruitBleUartFriend.menu.lfclk.lfxo.build.lfclk_flags=-DUSE_LFXO
+AdafruitBleUartFriend.menu.lfclk.lfrc=RC Oscillator
+AdafruitBleUartFriend.menu.lfclk.lfrc.build.lfclk_flags=-DUSE_LFRC
+AdafruitBleUartFriend.menu.lfclk.lfsynt=Synthesized
+AdafruitBleUartFriend.menu.lfclk.lfsynt.build.lfclk_flags=-DUSE_LFSYNT
+
+
 BBCmicrobit.name=BBC micro:bit
 
 BBCmicrobit.vid.0=0x0d28
diff --git a/variants/AdafruitBleUartFriend/pins_arduino.h b/variants/AdafruitBleUartFriend/pins_arduino.h
new file mode 100644
index 00000000..3ef4d4a9
--- /dev/null
+++ b/variants/AdafruitBleUartFriend/pins_arduino.h
@@ -0,0 +1,17 @@
+/*
+  Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the GNU Lesser General Public License for more details.
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+// API compatibility
+#include "variant.h"
diff --git a/variants/AdafruitBleUartFriend/variant.cpp b/variants/AdafruitBleUartFriend/variant.cpp
new file mode 100644
index 00000000..49b54ba3
--- /dev/null
+++ b/variants/AdafruitBleUartFriend/variant.cpp
@@ -0,0 +1,56 @@
+/*
+  Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
+  Copyright (c) 2016 Sandeep Mistry All right reserved.
+  Copyright (c) 2016 Frank Holtz. All right reserved.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "variant.h"
+
+const uint32_t g_ADigitalPinMap[] = {
+  0,
+  1,
+  2,
+  3,
+  4,
+  5,
+  6,
+  7,
+  8,
+  9,
+  10,
+  11,
+  12,
+  13,
+  14,
+  15,
+  16,
+  17,
+  18,
+  19,
+  20,
+  21,
+  22,
+  23,
+  24,
+  25,
+  26,
+  27,
+  28,
+  29,
+  30,
+  31,
+};
diff --git a/variants/AdafruitBleUartFriend/variant.h b/variants/AdafruitBleUartFriend/variant.h
new file mode 100644
index 00000000..75050e59
--- /dev/null
+++ b/variants/AdafruitBleUartFriend/variant.h
@@ -0,0 +1,62 @@
+/*
+  Copyright (c) 2014-2015 Arduino LLC.  All right reserved.
+  Copyright (c) 2016 Sandeep Mistry All right reserved.
+  Copyright (c) 2016 Frank Holtz. All right reserved.
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License as published by the Free Software Foundation; either
+  version 2.1 of the License, or (at your option) any later version.
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+  See the GNU Lesser General Public License for more details.
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef _VARIANT_ADAFRUIT_BLE_UART_FRIEND_
+#define _VARIANT_ADAFRUIT_BLE_UART_FRIEND_
+
+/** Master clock frequency */
+#define VARIANT_MCK       (16000000ul)
+
+/*----------------------------------------------------------------------------
+ *        Headers
+ *----------------------------------------------------------------------------*/
+
+#include "WVariant.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif // __cplusplus
+
+#define PINS_COUNT           (8u)
+#define NUM_DIGITAL_PINS     (8u)
+#define NUM_ANALOG_INPUTS    (0u)
+#define NUM_ANALOG_OUTPUTS   (0u)
+
+// LEDs
+#define PIN_LED1                (19)
+#define PIN_LED2                (18)
+#define LED_BUILTIN             PIN_LED1
+
+// Other digital pins
+#define PIN_DFU             (7)
+#define PIN_MODE            (1)
+
+/*
+ * Serial interfaces
+ */
+#define PIN_SERIAL_RX       (11)
+#define PIN_SERIAL_CTS      (10)
+#define PIN_SERIAL_TX       (9)
+#define PIN_SERIAL_RTS      (8)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

From 7cb63cb37298e2fc15b465a37710dadd2e5f8855 Mon Sep 17 00:00:00 2001
From: Moritz Krautwald <moritz.krautwald@mailbox.org>
Date: Sat, 15 Apr 2023 18:51:34 +0200
Subject: [PATCH 2/3] fix leds

---
 variants/AdafruitBleUartFriend/variant.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/variants/AdafruitBleUartFriend/variant.h b/variants/AdafruitBleUartFriend/variant.h
index 75050e59..1283f92b 100644
--- a/variants/AdafruitBleUartFriend/variant.h
+++ b/variants/AdafruitBleUartFriend/variant.h
@@ -33,15 +33,15 @@ extern "C"
 {
 #endif // __cplusplus
 
-#define PINS_COUNT           (8u)
+#define PINS_COUNT           (32u)
 #define NUM_DIGITAL_PINS     (8u)
 #define NUM_ANALOG_INPUTS    (0u)
 #define NUM_ANALOG_OUTPUTS   (0u)
 
 // LEDs
-#define PIN_LED1                (19)
-#define PIN_LED2                (18)
-#define LED_BUILTIN             PIN_LED1
+#define PIN_LED_CONNECTED    (19)
+#define PIN_LED_MODE         (18)
+#define LED_BUILTIN          PIN_LED_MODE
 
 // Other digital pins
 #define PIN_DFU             (7)

From 386b9fe42845f4a23bf7bbe8e6d9a293a829dd1d Mon Sep 17 00:00:00 2001
From: Moritz Krautwald <moritz.krautwald@mailbox.org>
Date: Sat, 15 Apr 2023 18:57:08 +0200
Subject: [PATCH 3/3] add to README

---
 README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/README.md b/README.md
index 9ca86253..1a94facc 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s
 
 ### nRF51
  * [Plain nRF51 MCU](https://www.nordicsemi.com/eng/Products/Bluetooth-low-energy/nRF51822)
+ * [Adafruit BLE UART Friend](https://www.adafruit.com/product/2479)
  * [BBC micro:bit](https://microbit.org)
  * [Calliope mini](https://calliope.cc/en)
  * [Bluz DK](http://bluz.io)