From f63adb5c578bb6a7a5908f86f9a04de2d4327443 Mon Sep 17 00:00:00 2001 From: Andy Farthing Date: Thu, 1 Aug 2019 17:07:06 +0100 Subject: [PATCH 1/4] Add PCA10056 variant --- variants/PCA10056/pins_arduino.h | 17 ++++ variants/PCA10056/variant.cpp | 109 ++++++++++++++++++++++++ variants/PCA10056/variant.h | 142 +++++++++++++++++++++++++++++++ 3 files changed, 268 insertions(+) create mode 100644 variants/PCA10056/pins_arduino.h create mode 100644 variants/PCA10056/variant.cpp create mode 100644 variants/PCA10056/variant.h diff --git a/variants/PCA10056/pins_arduino.h b/variants/PCA10056/pins_arduino.h new file mode 100644 index 00000000..3ef4d4a9 --- /dev/null +++ b/variants/PCA10056/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/PCA10056/variant.cpp b/variants/PCA10056/variant.cpp new file mode 100644 index 00000000..8c63db06 --- /dev/null +++ b/variants/PCA10056/variant.cpp @@ -0,0 +1,109 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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 PinDescription g_ADigitalPinMap[] = { + {0,0}, // D0 + {0,1}, // D1 + {0,2}, + {0,3}, + {0,4}, + {0,5}, + {0,6}, + {0,7}, + {0,8}, + {0,9}, + {0,10}, + {0,11}, + {0,12}, + {0,13}, + {0,14}, + {0,15}, + {0,16}, + {0,17}, + {0,18}, + {0,19}, + {0,20}, + {0,21}, + {0,22}, + {0,23}, + {0,24}, + {0,25}, + {0,26}, + {0,27}, + {0,28}, + {0,29}, + {0,30}, + {0,31}, + {1,0}, // D32 + {1,1}, // D1 + {1,2}, + {1,3}, + {1,4}, + {1,5}, + {1,6}, // D38 + {1,7}, + {1,8}, + {1,9}, // D41 + {1,10}, // D42 + {1,11}, + {1,12}, + {1,13}, // D45 + {1,14}, + {1,15}, // D47 +}; + +/** + * Function for configuring UICR_REGOUT0 register + * to set GPIO output voltage to 3.0V. + */ +static void gpio_output_voltage_setup(void) +{ + // Configure UICR_REGOUT0 register only if it is set to default value. + if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) == + (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos)) + { + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + + NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) | + (UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos); + + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + + // System reset is needed to update UICR registers. + NVIC_SystemReset(); + } +} + +void initVariant() +{ + // If nRF52 USB Dongle is powered from USB (high voltage mode), + // GPIO output voltage is set to 1.8 V by default, which is not + // enough to turn on green and blue LEDs. Therefore, GPIO voltage + // needs to be increased to 3.0 V by configuring the UICR register. + + if (NRF_POWER->MAINREGSTATUS & + (POWER_MAINREGSTATUS_MAINREGSTATUS_High << POWER_MAINREGSTATUS_MAINREGSTATUS_Pos)) + { + gpio_output_voltage_setup(); + } +} \ No newline at end of file diff --git a/variants/PCA10056/variant.h b/variants/PCA10056/variant.h new file mode 100644 index 00000000..2f3bdfdb --- /dev/null +++ b/variants/PCA10056/variant.h @@ -0,0 +1,142 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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_PCA10056_ +#define _VARIANT_PCA10056_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +#define NRF_GPIO_PIN_MAP(port, pin) ((port << 5) | (pin & 0x1F)) + + +/* GPIO */ +#define GPIO_PRESENT +#define GPIO_COUNT 2 + +#define P0_PIN_NUM 32 +#define P1_PIN_NUM 16 + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (13) // P1.13 +#define PIN_LED2 (14) // P1.14 +#define PIN_LED3 (15) // P1.15 +#define PIN_LED4 (16) // P1.16 + +#define LED_BUILTIN PIN_LED1 + +// Buttons +#define PIN_BUTTON1 (11) // P1.11 +#define PIN_BUTTON1 (12) // P1.12 +#define PIN_BUTTON1 (24) // P0.24 +#define PIN_BUTTON1 (25) // P0.25 + +/* + * Analog pins + */ +#define PIN_A0 (3) // P0.03 +#define PIN_A1 (4) // P0.04 +#define PIN_A2 (28) // P0.28 +#define PIN_A3 (29) // P0.29 +#define PIN_A4 (30) // P0.30 +#define PIN_A5 (31) // P0.31 + +static const uint8_t A0 = PIN_A0 ; +static const uint8_t A1 = PIN_A1 ; +static const uint8_t A2 = PIN_A2 ; +static const uint8_t A3 = PIN_A3 ; +static const uint8_t A4 = PIN_A4 ; +static const uint8_t A5 = PIN_A5 ; +#define ADC_RESOLUTION 14 + +// Other pins +#define PIN_NFC1 (9) // P0.09 +#define PIN_NFC2 (10) // P1.10 + +/* + * Serial interfaces + */ +// Serial +#define PIN_SERIAL_RX (8) // P0.08 +#define PIN_SERIAL_TX (6) // P0.06 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (46) // P1.14 +#define PIN_SPI_MOSI (45) // P1.13 +#define PIN_SPI_SCK (47) // P1.15 + +static const uint8_t SS = 44 ; // P1.12 +static const uint8_t MOSI = PIN_SPI_MOSI ; +static const uint8_t MISO = PIN_SPI_MISO ; +static const uint8_t SCK = PIN_SPI_SCK ; + +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (26) // P0.26 +#define PIN_WIRE_SCL (27) // P0.27 + +static const uint8_t SDA = PIN_WIRE_SDA; +static const uint8_t SCL = PIN_WIRE_SCL; + +/* + * QSPI interface for external flash + */ +#define PIN_QSPI_SCK (19) +#define PIN_QSPI_CS (17) +#define PIN_QSPI_DATA0 (20) +#define PIN_QSPI_DATA1 (21) +#define PIN_QSPI_DATA2 (22) +#define PIN_QSPI_DATA3 (23) + +// On-board QSPI Flash +// If EXTERNAL_FLASH_DEVICES is not defined, all supported devices will be used +#define EXTERNAL_FLASH_DEVICES MX25R6435F + +/* + * Reset Button at P0.18 + */ +#define RESET_PIN 18 + +#ifdef __cplusplus +} +#endif + +#endif From 6510778137580b3b1075c15759a5ad6df4ef630a Mon Sep 17 00:00:00 2001 From: Andy Farthing Date: Sat, 3 Aug 2019 14:33:39 +0100 Subject: [PATCH 2/4] Fix duped button defines --- variants/PCA10056/variant.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variants/PCA10056/variant.h b/variants/PCA10056/variant.h index 2f3bdfdb..0a2f4055 100644 --- a/variants/PCA10056/variant.h +++ b/variants/PCA10056/variant.h @@ -58,9 +58,9 @@ extern "C" // Buttons #define PIN_BUTTON1 (11) // P1.11 -#define PIN_BUTTON1 (12) // P1.12 -#define PIN_BUTTON1 (24) // P0.24 -#define PIN_BUTTON1 (25) // P0.25 +#define PIN_BUTTON2 (12) // P1.12 +#define PIN_BUTTON3 (24) // P0.24 +#define PIN_BUTTON4 (25) // P0.25 /* * Analog pins From 15a342f051fef3d798e582db3bab75cf630e3cb4 Mon Sep 17 00:00:00 2001 From: Andy Farthing Date: Sat, 3 Aug 2019 14:34:41 +0100 Subject: [PATCH 3/4] Add MyBOARDNRF52840 variant --- variants/MyBoardNRF52840/pins_arduino.h | 17 ++++ variants/MyBoardNRF52840/variant.cpp | 111 ++++++++++++++++++++++++ variants/MyBoardNRF52840/variant.h | 77 ++++++++++++++++ 3 files changed, 205 insertions(+) create mode 100644 variants/MyBoardNRF52840/pins_arduino.h create mode 100644 variants/MyBoardNRF52840/variant.cpp create mode 100644 variants/MyBoardNRF52840/variant.h diff --git a/variants/MyBoardNRF52840/pins_arduino.h b/variants/MyBoardNRF52840/pins_arduino.h new file mode 100644 index 00000000..3ef4d4a9 --- /dev/null +++ b/variants/MyBoardNRF52840/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/MyBoardNRF52840/variant.cpp b/variants/MyBoardNRF52840/variant.cpp new file mode 100644 index 00000000..f1359fa4 --- /dev/null +++ b/variants/MyBoardNRF52840/variant.cpp @@ -0,0 +1,111 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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" +// MyBoardNRF52840 library must be included in PIO libs dir +#include + +const PinDescription g_ADigitalPinMap[] = { + {0,0}, // D0 + {0,1}, // D1 + {0,2}, + {0,3}, + {0,4}, + {0,5}, + {0,6}, + {0,7}, + {0,8}, + {0,9}, + {0,10}, + {0,11}, + {0,12}, + {0,13}, + {0,14}, + {0,15}, + {0,16}, + {0,17}, + {0,18}, + {0,19}, + {0,20}, + {0,21}, + {0,22}, + {0,23}, + {0,24}, + {0,25}, + {0,26}, + {0,27}, + {0,28}, + {0,29}, + {0,30}, + {0,31}, + {1,0}, // D32 + {1,1}, // D1 + {1,2}, + {1,3}, + {1,4}, + {1,5}, + {1,6}, // D38 + {1,7}, + {1,8}, + {1,9}, // D41 + {1,10}, // D42 + {1,11}, + {1,12}, + {1,13}, // D45 + {1,14}, + {1,15}, // D47 +}; + +/** + * Function for configuring UICR_REGOUT0 register + * to set GPIO output voltage to 3.0V. + */ +static void gpio_output_voltage_setup(void) +{ + // Configure UICR_REGOUT0 register only if it is set to default value. + if ((NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) == + (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos)) + { + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + + NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) | + (UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos); + + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy){} + + // System reset is needed to update UICR registers. + NVIC_SystemReset(); + } +} + +void initVariant() +{ + // If nRF52 USB Dongle is powered from USB (high voltage mode), + // GPIO output voltage is set to 1.8 V by default, which is not + // enough to turn on green and blue LEDs. Therefore, GPIO voltage + // needs to be increased to 3.0 V by configuring the UICR register. + + if (NRF_POWER->MAINREGSTATUS & + (POWER_MAINREGSTATUS_MAINREGSTATUS_High << POWER_MAINREGSTATUS_MAINREGSTATUS_Pos)) + { + gpio_output_voltage_setup(); + } +} \ No newline at end of file diff --git a/variants/MyBoardNRF52840/variant.h b/variants/MyBoardNRF52840/variant.h new file mode 100644 index 00000000..f446e924 --- /dev/null +++ b/variants/MyBoardNRF52840/variant.h @@ -0,0 +1,77 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry 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_MYBOARDNRF52840_ +#define _VARIANT_MYBOARDNRF52840_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" +{ +#endif // __cplusplus + +#define NRF_GPIO_PIN_MAP(port, pin) ((port << 5) | (pin & 0x1F)) + + +/* GPIO */ +#define GPIO_PRESENT +#define GPIO_COUNT 2 + +#define P0_PIN_NUM 32 +#define P1_PIN_NUM 16 + +/* + * Analog pins + */ +#define PIN_A0 (3) // P0.03 +#define PIN_A1 (4) // P0.04 +#define PIN_A2 (28) // P0.28 +#define PIN_A3 (29) // P0.29 +#define PIN_A4 (30) // P0.30 +#define PIN_A5 (31) // P0.31 + +#define ADC_RESOLUTION 14 + +// Other pins +#define PIN_NFC1 (9) // P0.09 +#define PIN_NFC2 (10) // P1.10 + +// On-board QSPI Flash +// If EXTERNAL_FLASH_DEVICES is not defined, all supported devices will be used +#define EXTERNAL_FLASH_DEVICES MX25R6435F + +/* + * Reset Button at P0.18 + */ +#define RESET_PIN 18 + +#ifdef __cplusplus +} +#endif + +// MyBoardNRF52840 library must be included in PIO libs dir +#include + +#endif From ca209c738792281118baa4dd495a5385f54790b1 Mon Sep 17 00:00:00 2001 From: Andy Farthing Date: Sun, 4 Aug 2019 11:00:04 +0100 Subject: [PATCH 4/4] Fix incorrect SS pin mapping --- variants/PCA10056/variant.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/variants/PCA10056/variant.h b/variants/PCA10056/variant.h index 0a2f4055..e1fb5eef 100644 --- a/variants/PCA10056/variant.h +++ b/variants/PCA10056/variant.h @@ -99,8 +99,9 @@ static const uint8_t A5 = PIN_A5 ; #define PIN_SPI_MISO (46) // P1.14 #define PIN_SPI_MOSI (45) // P1.13 #define PIN_SPI_SCK (47) // P1.15 +#define PIN_SPI_SS (44) // P1.12 -static const uint8_t SS = 44 ; // P1.12 +static const uint8_t SS = PIN_SPI_SS ; static const uint8_t MOSI = PIN_SPI_MOSI ; static const uint8_t MISO = PIN_SPI_MISO ; static const uint8_t SCK = PIN_SPI_SCK ;