From b7aa1397c76e3e3304b74eeef8d6c46ea7c2800b Mon Sep 17 00:00:00 2001 From: Mark Trevor Birss Date: Tue, 5 Apr 2022 18:46:07 +0200 Subject: [PATCH] Add DIY nRF82540 PCA10059 4.2inch NiceRF 868 (#1354) * Update build-all.sh * Update configuration.h * Update EInkDisplay2.cpp * Create platformio.ini * Create variant.cpp * Create variant.h * Update platformio.ini * Update check-all.sh * Create nordic_pca10059.json * Update variant.h * Update EInkDisplay2.cpp * Update configuration.h * Update platformio.ini * Update EInkDisplay2.cpp * Update variant.h * Update EInkDisplay2.cpp * Update configuration.h * Update EInkDisplay2.cpp * Update variant.h * Update nordic_pca10059.json * Update platformio.ini * Update platformio.ini * Update platformio.ini * Update platformio.ini * Update variant.h * Update variant.h * Update variant.h * Update variant.h * Update variant.h * Update variant.h * Update variant.h * Update configuration.h * Update EInkDisplay2.cpp * Update variant.h * Update variant.h * Update platformio.ini * Update configuration.h * Update configuration.h * Update platformio.ini * Update platformio.ini * Update configuration.h * Update platformio.ini * Update configuration.h * Update platformio.ini * Update configuration.h * Update configuration.h * Update platformio.ini * Update configuration.h Co-authored-by: Ben Meadors --- bin/build-all.sh | 2 +- bin/check-all.sh | 2 +- boards/nordic_pca10059.json | 72 +++++++ platformio.ini | 1 + src/configuration.h | 4 + src/graphics/EInkDisplay2.cpp | 30 ++- .../platformio.ini | 9 + .../Dongle_nRF52840-pca10059-v1/variant.cpp | 43 +++++ .../Dongle_nRF52840-pca10059-v1/variant.h | 180 ++++++++++++++++++ 9 files changed, 334 insertions(+), 9 deletions(-) create mode 100644 boards/nordic_pca10059.json create mode 100644 variants/Dongle_nRF52840-pca10059-v1/platformio.ini create mode 100644 variants/Dongle_nRF52840-pca10059-v1/variant.cpp create mode 100644 variants/Dongle_nRF52840-pca10059-v1/variant.h diff --git a/bin/build-all.sh b/bin/build-all.sh index 0645f05dd..a92a04745 100755 --- a/bin/build-all.sh +++ b/bin/build-all.sh @@ -9,7 +9,7 @@ BOARDS_ESP32="rak11200 tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec- #BOARDS_ESP32=tbeam # FIXME note nrf52840dk build is for some reason only generating a BIN file but not a HEX file nrf52840dk-geeksville is fine -BOARDS_NRF52="rak4631_5005 rak4631_5005_eink rak4631_19003 t-echo" +BOARDS_NRF52="rak4631_5005 rak4631_5005_eink rak4631_19003 t-echo pca10059_diy_eink" #BOARDS_NRF52="" OUTDIR=release/latest diff --git a/bin/check-all.sh b/bin/check-all.sh index dde1dd3b1..f18f87f15 100755 --- a/bin/check-all.sh +++ b/bin/check-all.sh @@ -13,7 +13,7 @@ if [[ $# -gt 0 ]]; then # can override which environment by passing arg BOARDS="$@" else - BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631_5005 rak4631_19003 rak11200 t-echo" + BOARDS="tlora-v2 tlora-v1 tlora_v1_3 tlora-v2-1-1.6 tbeam heltec-v1 heltec-v2.0 heltec-v2.1 tbeam0.7 meshtastic-diy-v1 rak4631_5005 rak4631_19003 rak11200 t-echo pca10059_diy_eink" fi echo "BOARDS:${BOARDS}" diff --git a/boards/nordic_pca10059.json b/boards/nordic_pca10059.json new file mode 100644 index 000000000..b3d2cc7bd --- /dev/null +++ b/boards/nordic_pca10059.json @@ -0,0 +1,72 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + [ + "0x239A", + "0x8029" + ], + [ + "0x239A", + "0x0029" + ], + [ + "0x239A", + "0x002A" + ], + [ + "0x239A", + "0x802A" + ] + ], + "usb_product": "PCA10059", + "mcu": "nrf52840", + "variant": "nRF52840 Dongle", + "bsp": { + "name": "adafruit" + }, + "softdevice": { + "sd_flags": "-DS140", + "sd_name": "s140", + "sd_version": "6.1.1", + "sd_fwid": "0x00B6" + }, + "bootloader": { + "settings_addr": "0xFF000" + } + }, + "connectivity": [ + "bluetooth" + ], + "debug": { + "jlink_device": "nRF52840_xxAA", + "svd_path": "nrf52840.svd" + }, + "frameworks": [ + "arduino" + ], + "name": "nRF52840 Dongle", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "speed": 115200, + "protocol": "nrfutil", + "protocols": [ + "jlink", + "nrfjprog", + "nrfutil", + "stlink" + ], + "use_1200bps_touch": true, + "require_upload_port": true, + "wait_for_upload_port": true + }, + "url": "https://www.nordicsemi.com/Products/Development-hardware/nrf52840-dongle", + "vendor": "Nordic Semiconductor" +} diff --git a/platformio.ini b/platformio.ini index c91b95247..7b0964820 100644 --- a/platformio.ini +++ b/platformio.ini @@ -20,6 +20,7 @@ default_envs = tbeam ;default_envs = rak4631_5005_eink ;default_envs = rak4631_19003 ;default_envs = nano-g1 +;default_envs = pca10059_diy_eink ;default_envs = meshtastic-diy-v1 ;default_envs = meshtastic-diy-v1.1 diff --git a/src/configuration.h b/src/configuration.h index d1b335ecb..742d9e75e 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -244,6 +244,10 @@ along with this program. If not, see . #define HW_VENDOR HardwareModel_NANO_G1 +#elif defined(NORDIC_PCA10059) + +#define HW_VENDOR HardwareModel_NRF52840_PCA10059 + #elif NRF52_SERIES #define HW_VENDOR HardwareModel_NRF52_UNKNOWN diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index adb284a74..47ced53c6 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -25,6 +25,11 @@ //1.54 inch 200x200 - GxEPD2_154_M09 //#define TECHO_DISPLAY_MODEL GxEPD2_154_M09 +#elif defined(PCA10059) + +//4.2 inch 300x400 - GxEPD2_420_M01 +#define TECHO_DISPLAY_MODEL GxEPD2_420_M01 + #endif GxEPD2_BW *adafruitDisplay; @@ -47,6 +52,11 @@ EInkDisplay::EInkDisplay(uint8_t address, int sda, int scl) //GxEPD2_154_M09 //setGeometry(GEOMETRY_RAWMODE, 200, 200); + #elif defined(PCA10059) + + //GxEPD2_420_M01 + setGeometry(GEOMETRY_RAWMODE, 300, 400); + #endif // setGeometry(GEOMETRY_RAWMODE, 128, 64); // old resolution // setGeometry(GEOMETRY_128_64); // We originally used this because I wasn't sure if rawmode worked - it does @@ -71,8 +81,8 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit) // FIXME - only draw bits have changed (use backbuf similar to the other displays) // tft.drawBitmap(0, 0, buffer, 128, 64, TFT_YELLOW, TFT_BLACK); - for (uint64_t y = 0; y < displayHeight; y++) { - for (uint64_t x = 0; x < displayWidth; x++) { + for (uint32_t y = 0; y < displayHeight; y++) { + for (uint32_t x = 0; x < displayWidth; x++) { // get src pixel in the page based ordering the OLED lib uses FIXME, super inefficent auto b = buffer[x + (y / 8) * displayWidth]; @@ -81,11 +91,7 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit) } } - #if defined(TTGO_T_ECHO) - DEBUG_MSG("Updating T-ECHO E-Paper... "); - #elif defined(RAK4630) - DEBUG_MSG("Updating RAK4361_5005 E-Paper... "); - #endif + DEBUG_MSG("Updating E-Paper... "); #if defined(TTGO_T_ECHO) // ePaper.Reset(); // wake the screen from sleep @@ -101,6 +107,8 @@ bool EInkDisplay::forceDisplay(uint32_t msecLimit) // 4.2 inch 300x400 - GxEPD2_420_M01 //adafruitDisplay->nextPage(); + #elif defined(PCA10059) + adafruitDisplay->nextPage(); #endif // Put screen to sleep to save power (possibly not necessary because we already did poweroff inside of display) @@ -176,6 +184,14 @@ bool EInkDisplay::connect() adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); } +#elif defined(PCA10059) +{ + auto lowLevel = new TECHO_DISPLAY_MODEL(PIN_EINK_CS, PIN_EINK_DC, PIN_EINK_RES, PIN_EINK_BUSY); + adafruitDisplay = new GxEPD2_BW(*lowLevel); + adafruitDisplay->init(115200, true, 10, false, SPI1, SPISettings(4000000, MSBFIRST, SPI_MODE0)); + adafruitDisplay->setRotation(3); + adafruitDisplay->setPartialWindow(0, 0, displayWidth, displayHeight); +} #endif diff --git a/variants/Dongle_nRF52840-pca10059-v1/platformio.ini b/variants/Dongle_nRF52840-pca10059-v1/platformio.ini new file mode 100644 index 000000000..e527dd988 --- /dev/null +++ b/variants/Dongle_nRF52840-pca10059-v1/platformio.ini @@ -0,0 +1,9 @@ +[env:pca10059_diy_eink] +extends = nrf52840_base +board = nordic_pca10059 +build_flags = ${nrf52840_base.build_flags} -Ivariants/Dongle_nRF52840-pca10059-v1 -D NORDIC_PCA10059 +src_filter = ${nrf52_base.src_filter} +<../variants/Dongle_nRF52840-pca10059-v1> +lib_deps = + ${nrf52840_base.lib_deps} + https://github.com/ZinggJM/GxEPD2.git +debug_tool = jlink diff --git a/variants/Dongle_nRF52840-pca10059-v1/variant.cpp b/variants/Dongle_nRF52840-pca10059-v1/variant.cpp new file mode 100644 index 000000000..5b9288319 --- /dev/null +++ b/variants/Dongle_nRF52840-pca10059-v1/variant.cpp @@ -0,0 +1,43 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + 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" +#include "wiring_constants.h" +#include "wiring_digital.h" +#include "nrf.h" + +const uint32_t g_ADigitalPinMap[] = + { + // P0 + 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, + + // P1 + 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); +} diff --git a/variants/Dongle_nRF52840-pca10059-v1/variant.h b/variants/Dongle_nRF52840-pca10059-v1/variant.h new file mode 100644 index 000000000..9e69a3e9e --- /dev/null +++ b/variants/Dongle_nRF52840-pca10059-v1/variant.h @@ -0,0 +1,180 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + 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_NORDIC_PCA10059_ +#define _VARIANT_NORDIC_PCA10059_ + +#define PCA10059 + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// 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 (0 + 12) // Blue LED P1.12 +#define PIN_LED2 (0 + 6) // Built in Green P0.06 + +//Green Built in LED1 +//#define PIN_LED1 (0 + 6) // LED1 P1.15 + +//RGB NeoPixel LED2 +//#define PIN_LED1 (0 + 8) Red +//#define PIN_LED1 (32 + 9) Green +//#define PIN_LED1 (0 + 12) Blue + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_GREEN PIN_LED1 +#define LED_BLUE PIN_LED2 + +#define LED_STATE_ON 0 // State when LED is litted + +/* + * Buttons + */ + +#define PIN_BUTTON1 (32 + 6) // BTN_DN P1.06 Built in button + +/* + * Analog pins + */ +#define PIN_A0 (-1) + +static const uint8_t A0 = PIN_A0; +#define ADC_RESOLUTION 14 + +// Other pins +#define PIN_AREF (-1) // AREF Not yet used + + +static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX (-1) +#define PIN_SERIAL1_TX (-1) + +// Connected to Jlink CDC +#define PIN_SERIAL2_RX (-1) +#define PIN_SERIAL2_TX (-1) + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +#define PIN_SPI_MISO (0 + 17) // MISO P0.17 +#define PIN_SPI_MOSI (0 + 15) // MOSI P0.15 +#define PIN_SPI_SCK (0 + 13) // SCK P0.13 + +#define PIN_SPI1_MISO (-1) // +#define PIN_SPI1_MOSI (10) // EPD_MOSI P0.10 +#define PIN_SPI1_SCK (9) // EPD_SCLK P0.09 + +static const uint8_t SS = (0 + 31); // LORA_CS P0.31 +static const uint8_t MOSI = PIN_SPI_MOSI; +static const uint8_t MISO = PIN_SPI_MISO; +static const uint8_t SCK = PIN_SPI_SCK; + + /* + * eink display pins + */ + +//#define PIN_EINK_EN (-1) +#define PIN_EINK_EN (0 + 6) // Turn on the Green built in LED +#define PIN_EINK_CS (32) // EPD_CS +#define PIN_EINK_BUSY (20) // EPD_BUSY +#define PIN_EINK_DC (24) // EPD_D/C +#define PIN_EINK_RES (-1) // Not Connected P0.22 available +#define PIN_EINK_SCLK (9) // EPD_SCLK +#define PIN_EINK_MOSI (10) // EPD_MOSI + +#define HAS_EINK + +/* + * Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (32 + 4) // SDA +#define PIN_WIRE_SCL (32 + 7) // SCL + +// NiceRF 868 LoRa module +#define USE_SX1262 +#define SX126X_CS (0 + 31) // LORA_CS P0.31 +#define SX126X_DIO1 (0 + 29) // DIO1 P0.29 +#define SX126X_BUSY (0 + 2) // LORA_BUSY P0.02 +#define SX126X_RESET (32 + 15) // LORA_RESET P1.15 +#define SX126X_TXEN (-1) // TXEN P1.13 NiceRF 868 dont use +#define SX126X_RXEN (-1) // RXEN P1.10 NiceRF 868 dont use +#define SX126X_E22 + +#define PIN_GPS_EN (-1) +#define PIN_GPS_PPS (-1) // Pulse per second input from the GPS + +#define GPS_RX_PIN PIN_SERIAL1_RX +#define GPS_TX_PIN PIN_SERIAL1_TX + +// Battery +// The battery sense is hooked to pin A0 (5) +#define BATTERY_PIN PIN_A0 +// and has 12 bit resolution +#define BATTERY_SENSE_RESOLUTION_BITS 12 +#define BATTERY_SENSE_RESOLUTION 4096.0 +// Definition of milliVolt per LSB => 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096 +#define VBAT_MV_PER_LSB (0.73242188F) +// Voltage divider value => 1.5M + 1M voltage divider on VBAT = (1.5M / (1M + 1.5M)) +#define VBAT_DIVIDER (0.4F) +// Compensation factor for the VBAT divider +#define VBAT_DIVIDER_COMP (1.73) +// Fixed calculation of milliVolt from compensation value +#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) +#undef AREF_VOLTAGE +#define AREF_VOLTAGE 3.0 +#define VBAT_AR_INTERNAL AR_INTERNAL_3_0 +#define ADC_MULTIPLIER VBAT_DIVIDER_COMP //REAL_VBAT_MV_PER_LSB +#define VBAT_RAW_TO_SCALED(x) (REAL_VBAT_MV_PER_LSB * x) + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif