From 965c2bda8d1e5d92d49c224bf57e401ff3e45db7 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 13 Oct 2020 13:59:06 +0800 Subject: [PATCH 01/16] corvus2 board builds --- boards/eink.json | 2 +- boards/lora-relay-v2.json | 46 ++++++++ platformio.ini | 27 ++++- src/gps/Air530GPS.cpp | 8 +- src/gps/GPS.cpp | 16 +++ src/gps/GPS.h | 4 +- variants/lora_relay_v2/variant.cpp | 105 +++++++++++++++++ variants/lora_relay_v2/variant.h | 176 +++++++++++++++++++++++++++++ 8 files changed, 373 insertions(+), 11 deletions(-) create mode 100644 boards/lora-relay-v2.json create mode 100644 variants/lora_relay_v2/variant.cpp create mode 100644 variants/lora_relay_v2/variant.h diff --git a/boards/eink.json b/boards/eink.json index d9f40e804..e2414b23f 100644 --- a/boards/eink.json +++ b/boards/eink.json @@ -5,7 +5,7 @@ }, "core": "nRF5", "cpu": "cortex-m4", - "extra_flags": "-DARDUINO_NRF52840_LORA_RELAY_V1 -DNRF52840_XXAA", + "extra_flags": "-DARDUINO_NRF52840_TTGO_EINK -DNRF52840_XXAA", "f_cpu": "64000000L", "hwids": [ [ diff --git a/boards/lora-relay-v2.json b/boards/lora-relay-v2.json new file mode 100644 index 000000000..2cca8ae9a --- /dev/null +++ b/boards/lora-relay-v2.json @@ -0,0 +1,46 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_LORA_RELAY_V2 -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [["0x239A", "0x4406"]], + "usb_product": "LORA_RELAY", + "mcu": "nrf52840", + "variant": "lora_relay_v2", + "variants_dir": "variants", + "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", + "onboard_tools": ["jlink"], + "svd_path": "nrf52840.svd" + }, + "frameworks": ["arduino"], + "name": "Meshtastic Lora Relay V1 (Adafruit BSP)", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "require_upload_port": true, + "speed": 115200, + "protocol": "jlink", + "protocols": ["jlink", "nrfjprog", "stlink"] + }, + "url": "https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay", + "vendor": "BigCorvus" +} diff --git a/platformio.ini b/platformio.ini index 8109bf0e7..5397f693c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = tbeam # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = lora-relay-v2 # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = heltec # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] @@ -269,7 +269,30 @@ lib_deps = ${arduino_base.lib_deps} SparkFun BQ27441 LiPo Fuel Gauge Arduino Library TFT_eSPI - # Adafruit ST7735 and ST7789 Library + +; The https://github.com/BigCorvus/LoRa-BLE-Relay-v2 board by @BigCorvus +[env:lora-relay-v2] +extends = nrf52_base +board = lora-relay-v2 +# add our variants files to the include and src paths +# define build flags for the TFT_eSPI library +build_flags = ${nrf52_base.build_flags} -Ivariants/lora_relay_v2 + -DUSER_SETUP_LOADED + -DTFT_WIDTH=80 + -DTFT_HEIGHT=160 + -DST7735_GREENTAB160x80 + -DST7735_DRIVER + -DTFT_CS=ST7735_CS + -DTFT_DC=ST7735_RS + -DTFT_RST=ST7735_RESET + -DSPI_FREQUENCY=27000000 + -DTFT_WR=ST7735_SDA + -DTFT_SCLK=ST7735_SCK +src_filter = ${nrf52_base.src_filter} +<../variants/lora_relay_v2> +lib_deps = + ${arduino_base.lib_deps} + SparkFun BQ27441 LiPo Fuel Gauge Arduino Library + TFT_eSPI ; The Portduino based sim environment on top of linux [env:linux] diff --git a/src/gps/Air530GPS.cpp b/src/gps/Air530GPS.cpp index db0ddd445..857118963 100644 --- a/src/gps/Air530GPS.cpp +++ b/src/gps/Air530GPS.cpp @@ -65,9 +65,8 @@ void Air530GPS::sendCommand(const char *cmd) { } void Air530GPS::sleep() { + NMEAGPS::sleep(); #ifdef PIN_GPS_WAKE - digitalWrite(PIN_GPS_WAKE, 0); - pinMode(PIN_GPS_WAKE, OUTPUT); sendCommand("$PGKC105,4"); #endif } @@ -76,10 +75,7 @@ void Air530GPS::sleep() { void Air530GPS::wake() { #if 1 -#ifdef PIN_GPS_WAKE - digitalWrite(PIN_GPS_WAKE, 1); - pinMode(PIN_GPS_WAKE, OUTPUT); -#endif + NMEAGPS::wake(); #else // For power testing - keep GPS sleeping forever sleep(); diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index f5bd9f3f0..fccce06d4 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -36,6 +36,22 @@ bool GPS::setup() return ok; } +void GPS::wake() +{ +#ifdef PIN_GPS_WAKE + digitalWrite(PIN_GPS_WAKE, 1); + pinMode(PIN_GPS_WAKE, OUTPUT); +#endif +} + + +void GPS::sleep() { +#ifdef PIN_GPS_WAKE + digitalWrite(PIN_GPS_WAKE, 0); + pinMode(PIN_GPS_WAKE, OUTPUT); +#endif +} + /// Record that we have a GPS void GPS::setConnected() { diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 7e752f509..36859c9dc 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -75,10 +75,10 @@ class GPS : private concurrency::OSThread virtual bool setupGPS() = 0; /// If possible force the GPS into sleep/low power mode - virtual void sleep() {} + virtual void sleep(); /// wake the GPS into normal operation mode - virtual void wake() {} + virtual void wake(); /** Subclasses should look for serial rx characters here and feed it to their GPS parser * diff --git a/variants/lora_relay_v2/variant.cpp b/variants/lora_relay_v2/variant.cpp new file mode 100644 index 000000000..147f535c9 --- /dev/null +++ b/variants/lora_relay_v2/variant.cpp @@ -0,0 +1,105 @@ +/* + 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 "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +const uint32_t g_ADigitalPinMap[] = { + // D0 .. D13 + 25, // D0 is P0.25 (UART TX) + 24, // D1 is P0.24 (UART RX + 10, // D2 is P0.10 (NFC2) + 47, // D3 is P1.15 (LED1) + (32 + 10), // D4 is P1.10 (LED2) + 40, // D5 is P1.08 + 7, // D6 is P0.07 + 34, // D7 is P1.02 (Switch) + 16, // D8 is P0.16 (NeoPixel) + 26, // D9 is P0.26 D_RS (IPS data/command control) + 27, // D10 is P0.27 + 6, // D11 is P0.06 D_RES (IPS display reset) + 8, // D12 is P0.08 D_CS (IPS display chip select) + 41, // D13 is P0.23 BLT (IPS display backlight) + 4, // D14 is P0.04 SX1262 RXEN + 5, // D15 is P0.05 BOOST_EN (5V buck converter enable for the the radio power) + + // D14 .. D21 (aka A0 .. A7) + 30, // D16 is P0.30 (A0) + 28, // D17 is P0.28 (A1) + 2, // D18 is P0.02 (A2) + 3, // D19 is P0.03 (A3) + 29, // D20 is P0.29 (A4, Battery) + 31, // D21 is P0.31 (A5, ARef) + + // D22 .. D23 (aka I2C pins) + 12, // D22 is P0.12 (SDA) + 11, // D23 is P0.11 (SCL) + + // D24 .. D26 (aka SPI pins) + 15, // D24 is P0.15 (SPI MISO) + 13, // D25 is P0.13 (SPI MOSI) + 14, // D26 is P0.14 (SPI SCK ) + + // QSPI pins (not exposed via any header / test point) + // 19, // P0.19 (QSPI CLK) + // 20, // P0.20 (QSPI CS) + // 17, // P0.17 (QSPI Data 0) + // 22, // P0.22 (QSPI Data 1) + // 23, // P0.23 (QSPI Data 2) + // 21, // P0.21 (QSPI Data 3) + + // The remaining NFC pin + 9, // D27 P0.09 (NFC1, exposed only via test point on bottom of board) + + // The following pins were never listed as they were considered unusable + // 0, // P0.00 is XL1 (attached to 32.768kHz crystal) Never expose as GPIOs + // 1, // P0.01 is XL2 (attached to 32.768kHz crystal) + 18, // D28 P0.18 is RESET (attached to switch) + // 32, // P1.00 is SWO (attached to debug header) + + // D29-D43 + 32 + 12, // D29 P0.27 E22-SX1262 DIO1 + 28, // D30 P0.28 E22-SX1262 DIO2 + 30, // D31 P0.30 E22-SX1262 TXEN + 35, // D32 P1.03 E22-SX1262 NSS + 32 + 8, // D33 P1.08 E22-SX1262 BUSY + 27, // D34 P0.27 E22-SX1262 RESET + 32 + 1, // D35 P1.01 BTN_UP + 32, // D36 P1.0 GPS power + 21, // D37 P0.21 disp_clk + 36, // P1.04 BTN_OK + 37, // D39 P0.19 disp_SDA + 38, // D40 P1.06 BUZZER + 39, // P1.07 is not connected per schematic + 43, // P1.11 is not connected per schematic + 45, // P1.13 is not connected per schematic +}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); +} diff --git a/variants/lora_relay_v2/variant.h b/variants/lora_relay_v2/variant.h new file mode 100644 index 000000000..54e9586d9 --- /dev/null +++ b/variants/lora_relay_v2/variant.h @@ -0,0 +1,176 @@ +/* + 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_LORA_RELAY_V1_ +#define _VARIANT_LORA_RELAY_V1_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// define USE_LFRC // Board uses RC for LF + +/* +kevinh todo + +ok leds +ok buttons +ok gps power +ok gps signal +ok? lcd +ok buzzer +serial flash +ok lora (inc boost en) + +mention dat1 and dat2 on sd card + +*/ + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (43) +#define NUM_DIGITAL_PINS (43) +#define NUM_ANALOG_INPUTS (6) // A6 is used for battery, A7 is analog reference +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (3) +#define PIN_LED2 (4) +#define PIN_NEOPIXEL (8) +#define PIN_BUZZER (40) + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_RED PIN_LED1 +#define LED_BLUE PIN_LED2 + +#define LED_STATE_ON 1 // State when LED is litted + +/* + * Buttons + */ +#define PIN_BUTTON1 (7) +#define PIN_BUTTON2 (35) +#define PIN_BUTTON3 (37) + +/* + * Analog pins + */ +#define PIN_A0 (16) +#define PIN_A1 (17) +#define PIN_A2 (18) +#define PIN_A3 (19) +#define PIN_A4 (20) +#define PIN_A5 (21) + +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_AREF PIN_A5 +#define PIN_VBAT PIN_A4 +#define PIN_NFC1 (33) +#define PIN_NFC2 (2) +#define PIN_PIEZO (37) +static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX (1) +#define PIN_SERIAL1_TX (0) + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (24) +#define PIN_SPI_MOSI (25) +#define PIN_SPI_SCK (26) + +static const uint8_t SS = (5); +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 (22) +#define PIN_WIRE_SCL (23) + +// I2C device addresses +#define I2C_ADDR_BQ27441 0x55 // Battery gauge + +// CUSTOM GPIOs the SX1262 +#define SX1262_CS (32) + +// If you would prefer to get console debug output over the JTAG ICE connection rather than the CDC-ACM USB serial device, just +// define this. #define USE_SEGGER + +#define SX1262_DIO1 (29) +#define SX1262_DIO2 (30) +#define SX1262_BUSY (33) // Supposed to be P0.18 but because of reworks, now on P0.31 (18) +#define SX1262_RESET (34) +// #define SX1262_ANT_SW (32 + 10) +#define SX1262_RXEN (14) +#define SX1262_TXEN (31) +#define SX1262_POWER_EN \ + (15) // FIXME, see warning hre https://github.com/BigCorvus/SX1262-LoRa-BLE-Relay/blob/master/LORA_RELAY_NRF52840.ino +#define SX1262_E22 // Indicates this SX1262 is inside of an ebyte E22 module and special config should be done for that + +// ST7565 SPI +#define ST7735_RESET (11) // Output +#define ST7735_CS (12) +#define ST7735_BACKLIGHT_EN (13) +#define ST7735_RS (9) +#define ST7735_SDA (39) // actually spi MOSI +#define ST7735_SCK (37) // actually spi clk + +#define PIN_GPS_WAKE 36 // Just kill GPS power when we want it to sleep? FIXME + +// #define LORA_DISABLE_SENDING // The board can brownout during lora TX if you don't have a battery connected. Disable sending +// to allow USB power only based debugging + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif From ca77d48b20ef4a415c62d740c235c3b178eb4a96 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 13 Oct 2020 14:43:28 +0800 Subject: [PATCH 02/16] corvus2 gps still doesn't work WIP --- bin/upload-to-bootloader.sh | 2 +- src/gps/GPS.cpp | 9 +++++++-- src/gps/NMEAGPS.cpp | 2 +- src/main.cpp | 32 ++++++++++++++++---------------- variants/lora_relay_v2/variant.h | 2 ++ 5 files changed, 27 insertions(+), 20 deletions(-) diff --git a/bin/upload-to-bootloader.sh b/bin/upload-to-bootloader.sh index 55a039a67..ba4b7b48c 100755 --- a/bin/upload-to-bootloader.sh +++ b/bin/upload-to-bootloader.sh @@ -1,4 +1,4 @@ echo "Converting to uf2 for NRF52 Adafruit bootloader" -bin/uf2conv.py .pio/build/lora-relay-v1/firmware.hex -f 0xADA52840 +bin/uf2conv.py .pio/build/lora-relay-v2/firmware.hex -f 0xADA52840 # cp flash.uf2 /media/kevinh/FTH*BOOT/ diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index fccce06d4..4469fd97e 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -36,10 +36,15 @@ bool GPS::setup() return ok; } +// Allow defining the polarity of the WAKE output. default is active high +#ifndef GPS_WAKE_ACTIVE +#define GPS_WAKE_ACTIVE 1 +#endif + void GPS::wake() { #ifdef PIN_GPS_WAKE - digitalWrite(PIN_GPS_WAKE, 1); + digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE); pinMode(PIN_GPS_WAKE, OUTPUT); #endif } @@ -47,7 +52,7 @@ void GPS::wake() void GPS::sleep() { #ifdef PIN_GPS_WAKE - digitalWrite(PIN_GPS_WAKE, 0); + digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE ? 0 : 1); pinMode(PIN_GPS_WAKE, OUTPUT); #endif } diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index d4d9639df..517f5580b 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -102,7 +102,7 @@ bool NMEAGPS::whileIdle() // First consume any chars that have piled up at the receiver while (_serial_gps->available() > 0) { int c = _serial_gps->read(); - // DEBUG_MSG("%c", c); + DEBUG_MSG("%c", c); isValid |= reader.encode(c); } diff --git a/src/main.cpp b/src/main.cpp index f082c8f7a..d8c666ad8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -301,39 +301,39 @@ void setup() readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) -// If we know we have a L80 GPS, don't try UBLOX -#ifndef L80_RESET +// If we don't have bidirectional comms, we can't even try talking to UBLOX + UBloxGPS *ublox = NULL; +#ifdef GPS_TX_PIN // Init GPS - first try ublox - auto ublox = new UBloxGPS(); + ublox = new UBloxGPS(); gps = ublox; if (!gps->setup()) { DEBUG_MSG("ERROR: No UBLOX GPS found\n"); delete ublox; gps = ublox = NULL; + } +#endif - if (GPS::_serial_gps) { - // Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just - // assume NMEA at 9600 baud. - // dumb NMEA access only work for serial GPSes) - DEBUG_MSG("Hoping that NMEA might work\n"); + if (!gps && GPS::_serial_gps) { + // Some boards might have only the TX line from the GPS connected, in that case, we can't configure it at all. Just + // assume NMEA at 9600 baud. + // dumb NMEA access only work for serial GPSes) + DEBUG_MSG("Hoping that NMEA might work\n"); #ifdef HAS_AIR530_GPS - gps = new Air530GPS(); + gps = new Air530GPS(); #else - gps = new NMEAGPS(); + gps = new NMEAGPS(); #endif - gps->setup(); - } + gps->setup(); } -#else - gps = new NMEAGPS(); - gps->setup(); -#endif + if (gps) gpsStatus->observe(&gps->newStatus); else DEBUG_MSG("Warning: No GPS found - running without GPS\n"); + nodeStatus->observe(&nodeDB.newStatus); service.init(); diff --git a/variants/lora_relay_v2/variant.h b/variants/lora_relay_v2/variant.h index 54e9586d9..6814fdb3c 100644 --- a/variants/lora_relay_v2/variant.h +++ b/variants/lora_relay_v2/variant.h @@ -38,6 +38,7 @@ serial flash ok lora (inc boost en) mention dat1 and dat2 on sd card +use hardware spi controller for lcd - not bitbang */ @@ -161,6 +162,7 @@ static const uint8_t SCK = PIN_SPI_SCK; #define ST7735_SCK (37) // actually spi clk #define PIN_GPS_WAKE 36 // Just kill GPS power when we want it to sleep? FIXME +#define GPS_WAKE_ACTIVE 0 // GPS Power output is active low // #define LORA_DISABLE_SENDING // The board can brownout during lora TX if you don't have a battery connected. Disable sending // to allow USB power only based debugging From 5b1511c930b83d5e01f01626c3e2f072f268f2ec Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 14 Oct 2020 10:21:55 +0800 Subject: [PATCH 03/16] ppr1 make jlink scripts --- bin/nrf52832-gdbserver.sh | 2 +- bin/nrf52833-gdbserver.sh | 3 +++ bin/nrf52840-gdbserver.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100755 bin/nrf52833-gdbserver.sh diff --git a/bin/nrf52832-gdbserver.sh b/bin/nrf52832-gdbserver.sh index 15fb8fbff..122a43301 100755 --- a/bin/nrf52832-gdbserver.sh +++ b/bin/nrf52832-gdbserver.sh @@ -1,3 +1,3 @@ -JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52840_XXAA +JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52832_XXAA diff --git a/bin/nrf52833-gdbserver.sh b/bin/nrf52833-gdbserver.sh new file mode 100755 index 000000000..03636e755 --- /dev/null +++ b/bin/nrf52833-gdbserver.sh @@ -0,0 +1,3 @@ + + +JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52833_XXAA diff --git a/bin/nrf52840-gdbserver.sh b/bin/nrf52840-gdbserver.sh index 122a43301..15fb8fbff 100755 --- a/bin/nrf52840-gdbserver.sh +++ b/bin/nrf52840-gdbserver.sh @@ -1,3 +1,3 @@ -JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52832_XXAA +JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52840_XXAA From 5f2f3c94b9c522b5eb9321d57a953f2bfe16bd17 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 15 Oct 2020 13:47:10 +0800 Subject: [PATCH 04/16] PPR1 and allow boards to set lower or higher sx1262 power limits --- bin/install-bootloader.sh | 18 +++- bin/view-map.sh | 2 + boards/ppr1.json | 46 ++++++++++ platformio.ini | 12 ++- src/gps/GPS.cpp | 8 +- src/mesh/SX1262Interface.cpp | 11 ++- variants/ppr1/variant.cpp | 43 +++++++++ variants/ppr1/variant.h | 163 +++++++++++++++++++++++++++++++++++ 8 files changed, 295 insertions(+), 8 deletions(-) create mode 100755 bin/view-map.sh create mode 100644 boards/ppr1.json create mode 100644 variants/ppr1/variant.cpp create mode 100644 variants/ppr1/variant.h diff --git a/bin/install-bootloader.sh b/bin/install-bootloader.sh index 5dde70505..cd03281fb 100755 --- a/bin/install-bootloader.sh +++ b/bin/install-bootloader.sh @@ -2,7 +2,19 @@ set -e +# dependencies +# apt install srecord + BOOTDIR=/home/kevinh/development/meshtastic/Adafruit_nRF52_Bootloader +BOARD=othernet_ppr1 +BOOTVER=0.3.2 +BOOTNUM=125 +BOOTSHA=g4582f73 +SDVER=6.1.1 +PROJ=ppr1 + +# FIXME for nRF52840 use 0xff000 +BOOTSET=0x7f000 nrfjprog --eraseall -f nrf52 @@ -11,12 +23,12 @@ nrfjprog --eraseall -f nrf52 # first 4 bytes should be 0x01 to indicate valid app image # second 4 bytes should be 0x00 to indicate no CRC required for image echo "01 00 00 00 00 00 00 00" | xxd -r -p - >/tmp/bootconf.bin -srec_cat /tmp/bootconf.bin -binary -offset 0xff000 -output /tmp/bootconf.hex -intel +srec_cat /tmp/bootconf.bin -binary -offset $BOOTSET -output /tmp/bootconf.hex -intel echo Generating merged hex file -mergehex -m $BOOTDIR/_build/build-ttgo_eink/ttgo_eink_bootloader-0.3.2-124-g69bd8eb-dirty_s140_6.1.1.hex .pio/build/eink/firmware.hex /tmp/bootconf.hex -o ttgo_eink_full.hex +mergehex -o ${BOARD}_full.hex -m $BOOTDIR/_build/build-$BOARD/${BOARD}_bootloader-$BOOTVER-$BOOTNUM-$BOOTSHA-dirty_s140_$SDVER.hex .pio/build/$PROJ/firmware.hex /tmp/bootconf.hex echo Telling bootloader app region is valid and telling CPU to run -nrfjprog --program ttgo_eink_full.hex -f nrf52 --reset +nrfjprog --program ${BOARD}_full.hex -f nrf52 --reset # nrfjprog --readuicr /tmp/uicr.hex; objdump -s /tmp/uicr.hex | less diff --git a/bin/view-map.sh b/bin/view-map.sh new file mode 100755 index 000000000..badeb0843 --- /dev/null +++ b/bin/view-map.sh @@ -0,0 +1,2 @@ +echo using amap tool to display memory map +amap .pio/build/output.map diff --git a/boards/ppr1.json b/boards/ppr1.json new file mode 100644 index 000000000..6c395b0b4 --- /dev/null +++ b/boards/ppr1.json @@ -0,0 +1,46 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52833_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52833_PPR -DNRF52833_XXAA", + "f_cpu": "64000000L", + "hwids": [["0x239A", "0x4406"]], + "usb_product": "PPR", + "mcu": "nrf52833", + "variant": "ppr", + "variants_dir": "variants", + "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": "nRF52833_xxAA", + "onboard_tools": ["jlink"], + "svd_path": "nrf52833.svd" + }, + "frameworks": ["arduino"], + "name": "Meshtastic PPR1 (Adafruit BSP)", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "require_upload_port": true, + "speed": 115200, + "protocol": "jlink", + "protocols": ["jlink", "nrfjprog", "stlink"] + }, + "url": "https://meshtastic.org/", + "vendor": "Othernet" +} diff --git a/platformio.ini b/platformio.ini index 5397f693c..5e2c701bc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = lora-relay-v2 # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = ppr1 # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = heltec # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] @@ -234,6 +234,16 @@ lib_deps = ${arduino_base.lib_deps} UC1701 +; The PPR board +[env:ppr1] +extends = nrf52_base +board = ppr1 +build_flags = ${nrf52_base.build_flags} -Ivariants/ppr1 +src_filter = ${nrf52_base.src_filter} +<../variants/ppr1> +lib_deps = + ${arduino_base.lib_deps} + UC1701 + ; Prototype eink/nrf52840/sx1262 device [env:eink] extends = nrf52_base diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 4469fd97e..5d5cb59e8 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -10,7 +10,7 @@ #ifdef GPS_RX_PIN HardwareSerial _serial_gps_real(GPS_SERIAL_NUM); HardwareSerial *GPS::_serial_gps = &_serial_gps_real; -#elif defined(NRF52840_XXAA) +#elif defined(NRF52840_XXAA) || defined(NRF52833_XXAA) // Assume NRF52840 HardwareSerial *GPS::_serial_gps = &Serial1; #else @@ -47,6 +47,12 @@ void GPS::wake() digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE); pinMode(PIN_GPS_WAKE, OUTPUT); #endif + +#ifdef PIN_GPS_RESET + digitalWrite(PIN_GPS_RESET, 0); + pinMode(PIN_GPS_RESET, OUTPUT); +#endif + } diff --git a/src/mesh/SX1262Interface.cpp b/src/mesh/SX1262Interface.cpp index a177441a4..86a096137 100644 --- a/src/mesh/SX1262Interface.cpp +++ b/src/mesh/SX1262Interface.cpp @@ -1,6 +1,11 @@ #include "SX1262Interface.h" #include +// Particular boards might define a different max power based on what their hardware can do +#ifndef SX1262_MAX_POWER +#define SX1262_MAX_POWER 22 +#endif + SX1262Interface::SX1262Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi) : RadioLibInterface(cs, irq, rst, busy, spi, &lora), lora(&module) @@ -39,10 +44,10 @@ bool SX1262Interface::init() applyModemConfig(); if (power == 0) - power = 22; + power = SX1262_MAX_POWER; - if (power > 22) // This chip has lower power limits than some - power = 22; + if (power > SX1262_MAX_POWER) // This chip has lower power limits than some + power = SX1262_MAX_POWER; limitPower(); diff --git a/variants/ppr1/variant.cpp b/variants/ppr1/variant.cpp new file mode 100644 index 000000000..7c763037d --- /dev/null +++ b/variants/ppr1/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 "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.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}; + +void initVariant() +{ + // LED1 & LED2 + pinMode(PIN_LED1, OUTPUT); + ledOff(PIN_LED1); + + pinMode(PIN_LED2, OUTPUT); + ledOff(PIN_LED2); +} diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h new file mode 100644 index 000000000..0e703f4eb --- /dev/null +++ b/variants/ppr1/variant.h @@ -0,0 +1,163 @@ +/* + 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 +*/ + +#pragma once + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +// This board does have a 32khz crystal +#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 (46) +#define NUM_DIGITAL_PINS (46) +#define NUM_ANALOG_INPUTS (0) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (25) +#define PIN_LED2 (11) + +#define LED_BUILTIN PIN_LED1 +#define LED_CONN PIN_LED2 + +#define LED_RED PIN_LED1 +#define LED_GREEN PIN_LED2 + +// FIXME, bluefruit automatically blinks this led while connected. call AdafruitBluefruit::autoConnLed to change this. +#define LED_BLUE LED_GREEN + +#define LED_STATE_ON 1 // State when LED is litted + +/* + * Buttons + */ +#define PIN_BUTTON1 4 // up +#define PIN_BUTTON2 2 // left +#define PIN_BUTTON3 3 // center +#define PIN_BUTTON4 5 // right +#define PIN_BUTTON5 6 // down + +/* + * Analog pins + */ +#define PIN_A0 (0xff) +#define PIN_A1 (0xff) +#define PIN_A2 (0xff) +#define PIN_A3 (0xff) +#define PIN_A4 (0xff) +#define PIN_A5 (0xff) +#define PIN_A6 (0xff) +#define PIN_A7 (0xff) + +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; +static const uint8_t A6 = PIN_A6; +static const uint8_t A7 = PIN_A7; +#define ADC_RESOLUTION 14 + +// Other pins +#define PIN_AREF (0xff) +//#define PIN_NFC1 (9) +//#define PIN_NFC2 (10) + +static const uint8_t AREF = PIN_AREF; + +/* + * Serial interfaces + */ + +// GPS is on Serial1 +#define PIN_SERIAL1_RX (8) +#define PIN_SERIAL1_TX (9) + +// We intentionally leave this undefined so we don't even try to make a Ublox driver +// #define GPS_TX_PIN PIN_SERIAL1_TX +// #define GPS_RX_PIN PIN_SERIAL1_RX + +#define PIN_GPS_RESET 29 // active high? +#define PIN_GPS_PPS 28 +#define PIN_GPS_WAKE 7 // GPS_EN active high? + +#define PIN_VUSB_EN 21 + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO (15) +#define PIN_SPI_MOSI (13) +#define PIN_SPI_SCK (12) + +// static const uint8_t SS = 44; +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 (32 + 2) +#define PIN_WIRE_SCL (32) + +// CUSTOM GPIOs the SX1262 +#define SX1262_CS (0 + 10) // FIXME - we really should define LORA_CS instead +#define SX1262_DIO1 (0 + 20) +#define SX1262_DIO2 (0 + 26) +#define SX1262_BUSY (0 + 19) +#define SX1262_RESET (0 + 17) +#define SX1262_TXEN (0 + 24) +#define SX1262_RXEN (0 + 22) +#define SX1262_E22 // Not really an E22 but this board clones using DIO3 for tcxo control + +// FIXME, to prevent burning out parts I've set the power level super low, because I don't have +// an antenna wired up +#define SX1262_MAX_POWER 1 + +#define LORA_DISABLE_SENDING // Define this to disable transmission for testing (power testing etc...) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +#define USE_SEGGER + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ From e1f0e11cb89131efd6b47311d08e40621f4c4d63 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 17 Oct 2020 13:15:12 +0800 Subject: [PATCH 05/16] ppr1 WIP DO NOT MERGE - will break other clients --- src/gps/GPS.cpp | 6 ++++++ src/main.cpp | 10 +++++++--- src/mesh/NodeDB.cpp | 2 +- src/nrf52/main-nrf52.cpp | 2 +- variants/ppr1/variant.h | 7 ++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 5d5cb59e8..a6fc69d5f 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -27,6 +27,12 @@ GPS *gps; bool GPS::setup() { + // Master power for the GPS +#ifdef PIN_GPS_EN + digitalWrite(PIN_GPS_EN, PIN_GPS_EN); + pinMode(PIN_GPS_EN, OUTPUT); +#endif + setAwake(true); // Wake GPS power before doing any init bool ok = setupGPS(); diff --git a/src/main.cpp b/src/main.cpp index 6da0d3ca0..ac20eee7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -245,11 +245,15 @@ void setup() #else Wire.begin(); #endif - // i2c still busted on new board -#ifndef ARDUINO_NRF52840_PPR - scanI2Cdevice(); + +#ifdef PIN_LCD_RESET + // FIXME - move this someplace better + pinMode(PIN_LCD_RESET, OUTPUT); + digitalWrite(PIN_LCD_RESET, 0); #endif + scanI2Cdevice(); + // Buttons & LED buttonThread = new ButtonThread(); #ifdef LED_PIN diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cf47cfd15..6d7a81e1b 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -138,7 +138,7 @@ bool NodeDB::resetRadioConfig() crypto->setKey(channelSettings.psk.size, channelSettings.psk.bytes); // temp hack for quicker testing - // devicestate.no_save = true; + devicestate.no_save = true; if (devicestate.no_save) { DEBUG_MSG("***** DEVELOPMENT MODE - DO NOT RELEASE *****\n"); diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 867cdeefc..8abed8889 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -49,7 +49,7 @@ void getMacAddr(uint8_t *dmac) NRF52Bluetooth *nrf52Bluetooth; static bool bleOn = false; -static const bool enableBle = true; // Set to false for easier debugging +static const bool enableBle = false; // Set to false for easier debugging void setBluetoothEnable(bool on) { diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index 0e703f4eb..57b4e9c38 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -109,10 +109,15 @@ static const uint8_t AREF = PIN_AREF; #define PIN_GPS_RESET 29 // active high? #define PIN_GPS_PPS 28 -#define PIN_GPS_WAKE 7 // GPS_EN active high? +// #define PIN_GPS_WAKE 20 // CELL_CTRL in schematic? based on their example code +#define PIN_GPS_EN 7 // GPS_EN active high? #define PIN_VUSB_EN 21 +// LCD + +// #define PIN_LCD_RESET 23 // active high? + /* * SPI Interfaces */ From a102e49fdb9f186309d19fadeaa4bc98ad8b551a Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 23 Oct 2020 17:10:48 +0800 Subject: [PATCH 06/16] PPR1 WIP - hacky code to make LCD talk on I2C. Works! --- platformio.ini | 1 - src/main.cpp | 3 +++ variants/ppr1/variant.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/platformio.ini b/platformio.ini index 1ff93a3d5..12d41772f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -245,7 +245,6 @@ build_flags = ${nrf52_base.build_flags} -Ivariants/ppr1 src_filter = ${nrf52_base.src_filter} +<../variants/ppr1> lib_deps = ${arduino_base.lib_deps} - UC1701 ; Prototype eink/nrf52840/sx1262 device [env:eink] diff --git a/src/main.cpp b/src/main.cpp index 9e80a1343..922e1dd3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -250,6 +250,9 @@ void setup() // FIXME - move this someplace better pinMode(PIN_LCD_RESET, OUTPUT); digitalWrite(PIN_LCD_RESET, 0); + delay(20); + digitalWrite(PIN_LCD_RESET, 1); + delay(20); #endif scanI2Cdevice(); diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index 57b4e9c38..e0ca6ec19 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -116,7 +116,7 @@ static const uint8_t AREF = PIN_AREF; // LCD -// #define PIN_LCD_RESET 23 // active high? +#define PIN_LCD_RESET 23 // active low, pulse low for 20ms at boot /* * SPI Interfaces From b081a6da562c88cbe7c1c2efb40fb62ae9dc2407 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 23 Oct 2020 18:00:43 +0800 Subject: [PATCH 07/16] ppr1 st7567 lcd kinda works now --- docs/software/nrf52-TODO.md | 8 +++++++- src/configuration.h | 1 + src/graphics/Screen.h | 4 ++++ src/main.cpp | 25 +++++++++++++++---------- src/main.h | 1 - variants/ppr1/variant.h | 1 + 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 257862c3b..4fc5d3b70 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -5,7 +5,13 @@ ## RAK815 -TODO: +### PPR1 TODO + +* Test GPS +* make ST7567Wire driver less ugly +* leave LCD screen on most of the time (because it needs little power) + +### general nrf52 TODO: - enter SDS state at correct time (to protect battery or loss of phone contact) - show screen on eink when we enter SDS state (with app info and say sleeping) diff --git a/src/configuration.h b/src/configuration.h index 504a7aad8..a810aff1b 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -139,6 +139,7 @@ along with this program. If not, see . // ----------------------------------------------------------------------------- #define SSD1306_ADDRESS 0x3C +#define ST7567_ADDRESS 0x3F // The SH1106 controller is almost, but not quite, the same as SSD1306 // Define this if you know you have that controller or your "SSD1306" misbehaves. diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index b2f90e840..056798544 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -6,6 +6,8 @@ #ifdef USE_SH1106 #include +#elif defined(USE_ST7567) +#include #else #include #endif @@ -250,6 +252,8 @@ class Screen : public concurrency::OSThread EInkDisplay dispdev; #elif defined(USE_SH1106) SH1106Wire dispdev; +#elif defined(USE_ST7567) + ST7567Wire dispdev; #else SSD1306Wire dispdev; #endif diff --git a/src/main.cpp b/src/main.cpp index 922e1dd3e..960d42828 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,9 @@ meshtastic::GPSStatus *gpsStatus = new meshtastic::GPSStatus(); // Global Node status meshtastic::NodeStatus *nodeStatus = new meshtastic::NodeStatus(); -bool ssd1306_found; +/// The I2C address of our display (if found) +uint8_t screen_found; + bool axp192_found; Router *router = NULL; // Users of router don't care what sort of subclass implements that API @@ -72,9 +74,13 @@ void scanI2Cdevice(void) nDevices++; if (addr == SSD1306_ADDRESS) { - ssd1306_found = true; + screen_found = addr; DEBUG_MSG("ssd1306 display found\n"); } + if (addr == ST7567_ADDRESS) { + screen_found = addr; + DEBUG_MSG("st7567 display found\n"); + } #ifdef AXP192_SLAVE_ADDRESS if (addr == AXP192_SLAVE_ADDRESS) { axp192_found = true; @@ -247,7 +253,7 @@ void setup() #endif #ifdef PIN_LCD_RESET - // FIXME - move this someplace better + // FIXME - move this someplace better, LCD is at address 0x3F pinMode(PIN_LCD_RESET, OUTPUT); digitalWrite(PIN_LCD_RESET, 0); delay(20); @@ -270,7 +276,7 @@ void setup() #ifndef NO_ESP32 // Don't init display if we don't have one or we are waking headless due to a timer event if (wakeCause == ESP_SLEEP_WAKEUP_TIMER) - ssd1306_found = false; // forget we even have the hardware + screen_found = 0; // forget we even have the hardware esp32Setup(); #endif @@ -296,11 +302,11 @@ void setup() #endif // Initialize the screen first so we can show the logo while we start up everything else. - screen = new graphics::Screen(SSD1306_ADDRESS); + screen = new graphics::Screen(screen_found); readFromRTC(); // read the main CPU RTC at first (in case we can't get GPS time) -// If we don't have bidirectional comms, we can't even try talking to UBLOX + // If we don't have bidirectional comms, we can't even try talking to UBLOX UBloxGPS *ublox = NULL; #ifdef GPS_TX_PIN // Init GPS - first try ublox @@ -332,7 +338,7 @@ void setup() gpsStatus->observe(&gps->newStatus); else DEBUG_MSG("Warning: No GPS found - running without GPS\n"); - + nodeStatus->observe(&nodeDB.newStatus); service.init(); @@ -342,11 +348,11 @@ void setup() #if defined(ST7735_CS) || defined(HAS_EINK) screen->setup(); #else - if (ssd1306_found) + if (screen_found) screen->setup(); #endif - screen->print("Started...\n"); + screen->print("Started...\n"); // We have now loaded our saved preferences from flash @@ -401,7 +407,6 @@ void setup() // Initialize Wifi initWifi(); - if (!rIf) recordCriticalError(ErrNoRadio); diff --git a/src/main.h b/src/main.h index bb2635188..edb50d0d7 100644 --- a/src/main.h +++ b/src/main.h @@ -6,7 +6,6 @@ #include "graphics/Screen.h" extern bool axp192_found; -extern bool ssd1306_found; extern bool isCharging; extern bool isUSBPowered; diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index e0ca6ec19..b3a3e1b8e 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -117,6 +117,7 @@ static const uint8_t AREF = PIN_AREF; // LCD #define PIN_LCD_RESET 23 // active low, pulse low for 20ms at boot +#define USE_ST7567 /* * SPI Interfaces From 18bbf3523e88229223a10c2470419c38309381af Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 23 Oct 2020 22:18:22 +0800 Subject: [PATCH 08/16] remove unused display code --- src/nrf52/UC1701Spi.cpp | 53 ----------------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 src/nrf52/UC1701Spi.cpp diff --git a/src/nrf52/UC1701Spi.cpp b/src/nrf52/UC1701Spi.cpp deleted file mode 100644 index dcb6435c3..000000000 --- a/src/nrf52/UC1701Spi.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include - -class UC1701Spi : public OLEDDisplay -{ - private: - uint8_t _rst; - uint8_t _dc; - uint8_t _cs; - - public: - UC1701Spi() { setGeometry(GEOMETRY_128_64); } - - bool connect() - { - /* - pinMode(_dc, OUTPUT); - pinMode(_cs, OUTPUT); - pinMode(_rst, OUTPUT); - - SPI.begin(); - SPI.setClockDivider(SPI_CLOCK_DIV2); - - // Pulse Reset low for 10ms - digitalWrite(_rst, HIGH); - delay(1); - digitalWrite(_rst, LOW); - delay(10); - digitalWrite(_rst, HIGH); - */ - return true; - } - - void display(void) {} - - private: -}; - -#include "variant.h" - -#ifdef ERC12864_CS -#include -static UC1701 lcd(PIN_SPI_SCK, PIN_SPI_MOSI, ERC12864_CS, ERC12864_CD); - -void testLCD() -{ - // PCD8544-compatible displays may have a different resolution... - lcd.begin(); - - // Write a piece of text on the first line... - lcd.setCursor(0, 0); - lcd.print("Hello, World!"); -} -#endif \ No newline at end of file From 0767c8be03ba46cb9e8d6c4d62dc096ee02b8038 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 24 Oct 2020 08:16:15 +0800 Subject: [PATCH 09/16] PPR1 fix screen mirroring on LCD --- docs/software/nrf52-TODO.md | 8 +++++++- src/configuration.h | 5 ++++- src/graphics/Screen.cpp | 14 +++++++++++--- src/graphics/Screen.h | 7 ++++++- src/main.cpp | 4 ++-- src/mesh/NodeDB.cpp | 2 +- variants/ppr1/variant.h | 3 +++ 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 4fc5d3b70..2d268e028 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -7,12 +7,18 @@ ### PPR1 TODO +* fix usb +* fix bluetooth * Test GPS -* make ST7567Wire driver less ugly +* make ST7567Wire driver less ugly, move OLED stuff into a common class treee +* add power save mode for lcd per page 31 of datasheet +* add power off sequence per datasheet to lcd driver * leave LCD screen on most of the time (because it needs little power) ### general nrf52 TODO: +- turn off transitions on eink screens +- change update interval on eink from 1/sec frames to one frame every 5 mins - enter SDS state at correct time (to protect battery or loss of phone contact) - show screen on eink when we enter SDS state (with app info and say sleeping) - require button press to pair diff --git a/src/configuration.h b/src/configuration.h index a810aff1b..179c49466 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -147,7 +147,10 @@ along with this program. If not, see . // Flip the screen upside down by default as it makes more sense on T-BEAM // devices. Comment this out to not rotate screen 180 degrees. -#define FLIP_SCREEN_VERTICALLY +#define SCREEN_FLIP_VERTICALLY + +// Define if screen should be mirrored left to right +// #define SCREEN_MIRROR // ----------------------------------------------------------------------------- // GPS diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 7773cdc32..adfe15e90 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -627,7 +627,8 @@ void Screen::setup() // is never found when probing i2c and therefore we don't call setup and never want to do (invalid) accesses to this device. useDisplay = true; - dispdev.resetOrientation(); + // I think this is not needed - redundant with ui.init + // dispdev.resetOrientation(); // Initialising the UI will init the display too. ui.init(); @@ -635,7 +636,12 @@ void Screen::setup() displayWidth = dispdev.width(); displayHeight = dispdev.height(); - ui.setTimePerTransition(300); // msecs + uint16_t transitionTime = 300; // msecs +#ifdef HAS_EINK + transitionTime = 0; +#endif + ui.setTimePerTransition(transitionTime); + ui.setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. ui.setIndicatorDirection(LEFT_RIGHT); @@ -661,7 +667,9 @@ void Screen::setup() // Set up a log buffer with 3 lines, 32 chars each. dispdev.setLogBuffer(3, 32); -#ifdef FLIP_SCREEN_VERTICALLY +#ifdef SCREEN_MIRROR + dispdev.mirrorScreen(); +#elif defined(SCREEN_FLIP_VERTICALLY) dispdev.flipScreenVertically(); #endif diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 056798544..5539dcc76 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -21,6 +21,11 @@ #include "power.h" #include +// 0 to 255, though particular variants might define different defaults +#ifndef BRIGHTNESS_DEFAULT +#define BRIGHTNESS_DEFAULT 150 +#endif + namespace graphics { @@ -99,7 +104,7 @@ class Screen : public concurrency::OSThread // Implementation to Adjust Brightness void adjustBrightness(); - uint8_t brightness = 150; + uint8_t brightness = BRIGHTNESS_DEFAULT; /// Starts showing the Bluetooth PIN screen. // diff --git a/src/main.cpp b/src/main.cpp index 960d42828..9830c8232 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -256,9 +256,9 @@ void setup() // FIXME - move this someplace better, LCD is at address 0x3F pinMode(PIN_LCD_RESET, OUTPUT); digitalWrite(PIN_LCD_RESET, 0); - delay(20); + delay(1); digitalWrite(PIN_LCD_RESET, 1); - delay(20); + delay(1); #endif scanI2Cdevice(); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 135a7cb61..1febc0ae1 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -138,7 +138,7 @@ bool NodeDB::resetRadioConfig() crypto->setKey(channelSettings.psk.size, channelSettings.psk.bytes); // temp hack for quicker testing - devicestate.no_save = true; + // devicestate.no_save = true; if (devicestate.no_save) { DEBUG_MSG("***** DEVELOPMENT MODE - DO NOT RELEASE *****\n"); diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index b3a3e1b8e..2733d6529 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -119,6 +119,9 @@ static const uint8_t AREF = PIN_AREF; #define PIN_LCD_RESET 23 // active low, pulse low for 20ms at boot #define USE_ST7567 +// Define if screen should be mirrored left to right +#define SCREEN_MIRROR + /* * SPI Interfaces */ From d4e95e95a647a6010789387bc08aabf064ec09a1 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 24 Oct 2020 08:44:54 +0800 Subject: [PATCH 10/16] fix long-press handling on alternate button --- src/main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9830c8232..f5d279b62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,7 +179,7 @@ class ButtonThread : public OSThread #ifdef BUTTON_PIN_ALT userButtonAlt = OneButton(BUTTON_PIN_ALT, true, true); userButtonAlt.attachClick(userButtonPressed); - userButton.attachDuringLongPress(userButtonPressedLong); + userButtonAlt.attachDuringLongPress(userButtonPressedLong); wakeOnIrq(BUTTON_PIN_ALT, FALLING); #endif } @@ -196,9 +196,10 @@ class ButtonThread : public OSThread #endif #ifdef BUTTON_PIN_ALT userButtonAlt.tick(); - canSleep &= userButton.isIdle(); + canSleep &= userButtonAlt.isIdle(); #endif - // if(!canSleep) DEBUG_MSG("Supressing sleep!\n"); + // if (!canSleep) DEBUG_MSG("Supressing sleep!\n"); + //else DEBUG_MSG("sleep ok\n"); return 5; } @@ -209,7 +210,11 @@ class ButtonThread : public OSThread // DEBUG_MSG("press!\n"); powerFSM.trigger(EVENT_PRESS); } - static void userButtonPressedLong() { screen->adjustBrightness(); } + static void userButtonPressedLong() + { + DEBUG_MSG("Long press!\n"); + screen->adjustBrightness(); + } }; static Periodic *ledPeriodic; From f0eeaf01d46052bf979786501721ea119d991d30 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 24 Oct 2020 09:49:14 +0800 Subject: [PATCH 11/16] ppr1 lcd is 'good enough' for now --- docs/software/nrf52-TODO.md | 4 ++-- src/graphics/Screen.cpp | 20 ++++++++++---------- src/graphics/configs.h | 1 - variants/eink/variant.h | 3 +++ variants/ppr1/variant.h | 4 ++++ 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 2d268e028..891e5615d 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -11,8 +11,8 @@ * fix bluetooth * Test GPS * make ST7567Wire driver less ugly, move OLED stuff into a common class treee -* add power save mode for lcd per page 31 of datasheet -* add power off sequence per datasheet to lcd driver +* add LCD power save mode for lcd per page 31 of datasheet +* add LCD power off sequence per datasheet to lcd driver * leave LCD screen on most of the time (because it needs little power) ### general nrf52 TODO: diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index adfe15e90..3e53d130e 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -58,10 +58,6 @@ static char ourId[5]; static bool heartbeat = false; #endif -// We used to use constants for this - now we pull from the device at startup -//#define SCREEN_WIDTH 128 -//#define SCREEN_HEIGHT 64 - static uint16_t displayWidth, displayHeight; #define SCREEN_WIDTH displayWidth @@ -85,6 +81,10 @@ static uint16_t displayWidth, displayHeight; #define getStringCenteredX(s) ((SCREEN_WIDTH - display->getStringWidth(s)) / 2) +#ifndef SCREEN_TRANSITION_MSECS +#define SCREEN_TRANSITION_MSECS 300 +#endif + static void drawBootScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { // draw an xbm image. @@ -636,11 +636,7 @@ void Screen::setup() displayWidth = dispdev.width(); displayHeight = dispdev.height(); - uint16_t transitionTime = 300; // msecs -#ifdef HAS_EINK - transitionTime = 0; -#endif - ui.setTimePerTransition(transitionTime); + ui.setTimePerTransition(SCREEN_TRANSITION_MSECS); ui.setIndicatorPosition(BOTTOM); // Defines where the first frame is located in the bar. @@ -882,12 +878,16 @@ void Screen::handleOnPress() } } +#ifndef SCREEN_TRANSITION_FRAMERATE +#define SCREEN_TRANSITION_FRAMERATE 30 // fps +#endif + void Screen::setFastFramerate() { DEBUG_MSG("Setting fast framerate\n"); // We are about to start a transition so speed up fps - targetFramerate = TRANSITION_FRAMERATE; + targetFramerate = SCREEN_TRANSITION_FRAMERATE; ui.setTargetFPS(targetFramerate); setInterval(0); // redraw ASAP } diff --git a/src/graphics/configs.h b/src/graphics/configs.h index 65128294c..65077b9d4 100644 --- a/src/graphics/configs.h +++ b/src/graphics/configs.h @@ -3,7 +3,6 @@ #include "fonts.h" // This means the *visible* area (sh1106 can address 132, but shows 128 for example) -#define TRANSITION_FRAMERATE 30 // fps #define IDLE_FRAMERATE 1 // in fps #define COMPASS_DIAM 44 diff --git a/variants/eink/variant.h b/variants/eink/variant.h index 2dc5ccc1c..a37c50aba 100644 --- a/variants/eink/variant.h +++ b/variants/eink/variant.h @@ -209,6 +209,9 @@ External serial flash WP25R1635FZUIL0 #define HAS_EINK +// No screen wipes on eink +#define SCREEN_TRANSITION_MSECS 0 + #define PIN_SPI1_MISO \ (32 + 7) // FIXME not really needed, but for now the SPI code requires something to be defined, pick an used GPIO #define PIN_SPI1_MOSI PIN_EINK_MOSI diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index 2733d6529..2a287ea95 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -122,6 +122,10 @@ static const uint8_t AREF = PIN_AREF; // Define if screen should be mirrored left to right #define SCREEN_MIRROR +// LCD screens are slow, so slowdown the wipe so it looks better +#define SCREEN_TRANSITION_MSECS 1000 +#define SCREEN_TRANSITION_FRAMERATE 10 // fps + /* * SPI Interfaces */ From 1a8891c33df385dc3bc78a5d925afcead6561755 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 24 Oct 2020 18:40:47 +0800 Subject: [PATCH 12/16] ppr1: add crude version of charge controller driver --- docs/software/nrf52-TODO.md | 7 ++- src/gps/GPS.cpp | 13 ++--- src/nrf52/BQ25713.cpp | 100 ++++++++++++++++++++++++++++++++++++ src/nrf52/BQ25713.h | 22 ++++++++ src/nrf52/main-nrf52.cpp | 9 +++- variants/ppr1/variant.h | 7 ++- 6 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 src/nrf52/BQ25713.cpp create mode 100644 src/nrf52/BQ25713.h diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 891e5615d..42c535757 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -7,9 +7,12 @@ ### PPR1 TODO -* fix usb +* fix usb - check latest tinyusb +* Test GPS - try pulsing reset +* properly test charge controller config and read battery/charge status * fix bluetooth -* Test GPS +* fix LCD max contrast (currently too high, needs to be about 40?) +* save brightness settings in flash * make ST7567Wire driver less ugly, move OLED stuff into a common class treee * add LCD power save mode for lcd per page 31 of datasheet * add LCD power off sequence per datasheet to lcd driver diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index a6fc69d5f..6076749f3 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -33,6 +33,13 @@ bool GPS::setup() pinMode(PIN_GPS_EN, OUTPUT); #endif +#ifdef PIN_GPS_RESET + digitalWrite(PIN_GPS_RESET, 1); // assert for 10ms + pinMode(PIN_GPS_RESET, OUTPUT); + delay(10); + digitalWrite(PIN_GPS_RESET, 0); +#endif + setAwake(true); // Wake GPS power before doing any init bool ok = setupGPS(); @@ -53,12 +60,6 @@ void GPS::wake() digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE); pinMode(PIN_GPS_WAKE, OUTPUT); #endif - -#ifdef PIN_GPS_RESET - digitalWrite(PIN_GPS_RESET, 0); - pinMode(PIN_GPS_RESET, OUTPUT); -#endif - } diff --git a/src/nrf52/BQ25713.cpp b/src/nrf52/BQ25713.cpp new file mode 100644 index 000000000..52f4381fa --- /dev/null +++ b/src/nrf52/BQ25713.cpp @@ -0,0 +1,100 @@ +#include "BQ25713.h" +#include "configuration.h" + +#include + +#ifdef BQ25703A_ADDR + +const uint8_t BQ25713::devAddr = BQ25703A_ADDR; + +bool BQ25713::setup() +{ + DEBUG_MSG("Init BQ25713\n"); + + // if(!writeReg(0x34,0x9034)) return false; + // + // if(!writeReg(0x34,0x8034)) return false; + + if (!writeReg(0x00, 0x0F0A)) + return false; // Config Charge Option 0 + + if (!writeReg(0x02, 0x0224)) + return false; // Config Charge Current + + if (!writeReg(0x04, 0x1070)) + return false; // Config Charge Voltage + + if (!writeReg(0x06, 0x099C)) + return false; // Config OTG Voltage + + if (!writeReg(0x08, 0x5000)) + return false; // Config OTG Current + + // if(!writeReg(0x0A,0x0100)) return false;//Config Input Voltage + + if (!writeReg(0x0C, 0x1800)) + return false; // Config Minimum System Voltage + + if (!writeReg(0x0E, 0x4900)) + return false; // Config Input Current + + if (!writeReg(0x30, 0xE210)) + return false; // Config Charge Option 1 + + if (!writeReg(0x32, 0x32BF)) + return false; // Config Charge Option 2 + + if (!writeReg(0x34, 0x0834)) + return false; // Config Charge Option 3 + + if (!writeReg(0x36, 0x4A65)) + return false; // Config Prochot Option 0 + + if (!writeReg(0x38, 0x81FF)) + return false; // Config Prochot Option 1 + + if (!writeReg(0x3A, 0xA0FF)) + return false; // Config ADC Option + + return true; +} + +uint16_t BQ25713::readReg(uint8_t reg) +{ + Wire.beginTransmission(devAddr); + Wire.write(reg); + byte err = Wire.endTransmission(); + if (!err) { + int readLen = 2; + Wire.requestFrom(devAddr, (int)(readLen + 1)); + if (Wire.available() >= readLen) { + uint8_t lsb = Wire.read(), msb = Wire.read(); + + return (((uint16_t)msb) << 8) + lsb; + } else + return 0; + } else { + return 0; + } +} + +bool BQ25713::writeReg(uint8_t reg, uint16_t v) +{ + Wire.beginTransmission(devAddr); + Wire.write(reg); + Wire.write(v & 0xff); + Wire.write((v >> 8) & 0xff); + byte err = Wire.endTransmission(); // 0 for success + + if (!err) { + // Do a test readback for early debugging + uint16_t found = readReg(reg); + if (found != v) { + DEBUG_MSG("Readback reg=0x%0x test failed, expected 0x%0x, found 0x%0x!\n", reg, v, found); + return true; // claim success - FIXME + } + } + return !err; +} + +#endif \ No newline at end of file diff --git a/src/nrf52/BQ25713.h b/src/nrf52/BQ25713.h new file mode 100644 index 000000000..7dd62bac1 --- /dev/null +++ b/src/nrf52/BQ25713.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +/** + * Driver class to control/monitor BQ25713 charge controller + */ +class BQ25713 { + static const uint8_t devAddr; + +public: + + /// Return true for success + bool setup(); + +private: + uint16_t readReg(uint8_t reg); + + /// Return true for success + bool writeReg(uint8_t reg, uint16_t v); +}; + diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 8abed8889..3048588f2 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -82,6 +82,8 @@ int printf(const char *fmt, ...) return res; } +#include "BQ25713.h" + void nrf52Setup() { @@ -93,8 +95,11 @@ void nrf52Setup() // This is the recommended setting for Monitor Mode Debugging NVIC_SetPriority(DebugMonitor_IRQn, 6UL); - // Not yet on board - // pmu.init(); +#ifdef BQ25703A_ADDR + auto *bq = new BQ25713(); + if(!bq->setup()) + DEBUG_MSG("ERROR! Charge controller init failed\n"); +#endif // Init random seed // FIXME - use this to get random numbers diff --git a/variants/ppr1/variant.h b/variants/ppr1/variant.h index 2a287ea95..cfefa091b 100644 --- a/variants/ppr1/variant.h +++ b/variants/ppr1/variant.h @@ -107,10 +107,10 @@ static const uint8_t AREF = PIN_AREF; // #define GPS_TX_PIN PIN_SERIAL1_TX // #define GPS_RX_PIN PIN_SERIAL1_RX -#define PIN_GPS_RESET 29 // active high? +#define PIN_GPS_RESET 29 // active high #define PIN_GPS_PPS 28 // #define PIN_GPS_WAKE 20 // CELL_CTRL in schematic? based on their example code -#define PIN_GPS_EN 7 // GPS_EN active high? +#define PIN_GPS_EN 7 // GPS_EN active high #define PIN_VUSB_EN 21 @@ -119,6 +119,9 @@ static const uint8_t AREF = PIN_AREF; #define PIN_LCD_RESET 23 // active low, pulse low for 20ms at boot #define USE_ST7567 +/// Charge controller I2C address +#define BQ25703A_ADDR 0x6b + // Define if screen should be mirrored left to right #define SCREEN_MIRROR From 7597d5b3fd05f646e21a218f1e69131b0a3563ca Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sun, 25 Oct 2020 17:07:54 +0800 Subject: [PATCH 13/16] PPR1 - GPS serial now works --- docs/software/nrf52-TODO.md | 9 +++++++-- src/gps/GPS.cpp | 16 ++++++++++++++++ src/gps/GPS.h | 2 +- src/gps/NMEAGPS.cpp | 2 ++ src/gps/UBloxGPS.cpp | 11 +---------- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 42c535757..294a09de0 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -7,8 +7,13 @@ ### PPR1 TODO -* fix usb - check latest tinyusb -* Test GPS - try pulsing reset +* fix usb - I think the problem is VBUS in HW + +* Test GPS - try pulsing reset - no joy. R19 is the resistor on the TX path from GPS to CPU +R17 is the resistor for V_BK GPS power (measured 3V - ok!), R20 is the resistor for the RX path from CPU to GPS. R18 for RESET (it is low and GPS reset is high - ok!) +* V_BK for the GPS should probably be supplied from something always on + +* use S113 soft device 7.2.0 * properly test charge controller config and read battery/charge status * fix bluetooth * fix LCD max contrast (currently too high, needs to be about 40?) diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 6076749f3..d72ff70f5 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -25,6 +25,22 @@ uint8_t GPS::i2cAddress = 0; GPS *gps; +bool GPS::setupGPS() +{ + if (_serial_gps) { +#ifdef GPS_RX_PIN + _serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); +#else + _serial_gps->begin(GPS_BAUDRATE); +#endif +#ifndef NO_ESP32 + _serial_gps->setRxBufferSize(2048); // the default is 256 +#endif + } + + return true; +} + bool GPS::setup() { // Master power for the GPS diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 36859c9dc..98ad185f2 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -72,7 +72,7 @@ class GPS : private concurrency::OSThread protected: /// Do gps chipset specific init, return true for success - virtual bool setupGPS() = 0; + virtual bool setupGPS(); /// If possible force the GPS into sleep/low power mode virtual void sleep(); diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 9062c20ad..78a8e4eb4 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -13,6 +13,8 @@ static int32_t toDegInt(RawDegrees d) bool NMEAGPS::setupGPS() { + GPS::setupGPS(); + #ifdef PIN_GPS_PPS // pulse per second // FIXME - move into shared GPS code diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index 1ff622897..2db5d775f 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -29,16 +29,7 @@ bool UBloxGPS::tryConnect() bool UBloxGPS::setupGPS() { - if (_serial_gps) { -#ifdef GPS_RX_PIN - _serial_gps->begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); -#else - _serial_gps->begin(GPS_BAUDRATE); -#endif -#ifndef NO_ESP32 - _serial_gps->setRxBufferSize(2048); // the default is 256 -#endif - } + GPS::setupGPS(); // uncomment to see debug info // ublox.enableDebugging(Serial); From 5e0d53a1e31bab98130ec7bc83d23fd89a9ff100 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Oct 2020 09:48:28 +0800 Subject: [PATCH 14/16] ppr1 todo updates --- docs/software/nrf52-TODO.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 294a09de0..4a03b4230 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -7,10 +7,6 @@ ### PPR1 TODO -* fix usb - I think the problem is VBUS in HW - -* Test GPS - try pulsing reset - no joy. R19 is the resistor on the TX path from GPS to CPU -R17 is the resistor for V_BK GPS power (measured 3V - ok!), R20 is the resistor for the RX path from CPU to GPS. R18 for RESET (it is low and GPS reset is high - ok!) * V_BK for the GPS should probably be supplied from something always on * use S113 soft device 7.2.0 From 6b838002d432af725ba20da85cb9810ef1511e4e Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Oct 2020 09:51:30 +0800 Subject: [PATCH 15/16] switch back to tbeam for merge to master --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 12d41772f..eee8e627f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = ppr1 # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here +default_envs = tbeam # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here ;default_envs = heltec # lora-relay-v1 # nrf52840dk-geeksville # linux # or if you'd like to change the default to something like lora-relay-v1 put that here [common] From 4ad562b9f41a73337f0480e3ce2693e5d921cab5 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Oct 2020 13:01:50 +0800 Subject: [PATCH 16/16] The new 7.2.0 soft device works on nrf52833 --- bin/install-bootloader.sh | 13 +++++++------ boards/ppr1.json | 8 ++++---- src/gps/NMEAGPS.cpp | 2 +- src/nrf52/main-nrf52.cpp | 2 +- variants/pca10056-rc-clock/variant.h | 3 +++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/bin/install-bootloader.sh b/bin/install-bootloader.sh index cd03281fb..eeb2071b9 100755 --- a/bin/install-bootloader.sh +++ b/bin/install-bootloader.sh @@ -8,12 +8,13 @@ set -e BOOTDIR=/home/kevinh/development/meshtastic/Adafruit_nRF52_Bootloader BOARD=othernet_ppr1 BOOTVER=0.3.2 -BOOTNUM=125 -BOOTSHA=g4582f73 -SDVER=6.1.1 +BOOTNUM=128 +BOOTSHA=gc01b9ea +SDCODE=s113 +SDVER=7.2.0 PROJ=ppr1 -# FIXME for nRF52840 use 0xff000 +# FIXME for nRF52840 use 0xff000, for nRF52833 use 0x7f000 BOOTSET=0x7f000 nrfjprog --eraseall -f nrf52 @@ -25,8 +26,8 @@ nrfjprog --eraseall -f nrf52 echo "01 00 00 00 00 00 00 00" | xxd -r -p - >/tmp/bootconf.bin srec_cat /tmp/bootconf.bin -binary -offset $BOOTSET -output /tmp/bootconf.hex -intel -echo Generating merged hex file -mergehex -o ${BOARD}_full.hex -m $BOOTDIR/_build/build-$BOARD/${BOARD}_bootloader-$BOOTVER-$BOOTNUM-$BOOTSHA-dirty_s140_$SDVER.hex .pio/build/$PROJ/firmware.hex /tmp/bootconf.hex +echo Generating merged hex file from .pio/build/$PROJ/firmware.hex +mergehex -o ${BOARD}_full.hex -m $BOOTDIR/_build/build-$BOARD/${BOARD}_bootloader-$BOOTVER-$BOOTNUM-$BOOTSHA-dirty_${SDCODE}_$SDVER.hex .pio/build/$PROJ/firmware.hex /tmp/bootconf.hex echo Telling bootloader app region is valid and telling CPU to run nrfjprog --program ${BOARD}_full.hex -f nrf52 --reset diff --git a/boards/ppr1.json b/boards/ppr1.json index 6c395b0b4..4c0528245 100644 --- a/boards/ppr1.json +++ b/boards/ppr1.json @@ -1,7 +1,7 @@ { "build": { "arduino": { - "ldscript": "nrf52833_s140_v6.ld" + "ldscript": "nrf52833_s113_v7.ld" }, "core": "nRF5", "cpu": "cortex-m4", @@ -16,9 +16,9 @@ "name": "adafruit" }, "softdevice": { - "sd_flags": "-DS140", - "sd_name": "s140", - "sd_version": "6.1.1", + "sd_flags": "-DS113", + "sd_name": "s113", + "sd_version": "7.2.0", "sd_fwid": "0x00b6" }, "bootloader": { diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 78a8e4eb4..6a707bd8f 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -104,7 +104,7 @@ bool NMEAGPS::whileIdle() // First consume any chars that have piled up at the receiver while (_serial_gps->available() > 0) { int c = _serial_gps->read(); - DEBUG_MSG("%c", c); + // DEBUG_MSG("%c", c); isValid |= reader.encode(c); } diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index 3048588f2..6b4b1adc1 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -49,7 +49,7 @@ void getMacAddr(uint8_t *dmac) NRF52Bluetooth *nrf52Bluetooth; static bool bleOn = false; -static const bool enableBle = false; // Set to false for easier debugging +static const bool enableBle = true; // Set to false for easier debugging void setBluetoothEnable(bool on) { diff --git a/variants/pca10056-rc-clock/variant.h b/variants/pca10056-rc-clock/variant.h index b7201812a..48dc72df2 100644 --- a/variants/pca10056-rc-clock/variant.h +++ b/variants/pca10056-rc-clock/variant.h @@ -146,6 +146,9 @@ static const uint8_t SCK = PIN_SPI_SCK; #define SX1262_RESET (0 + 3) // P0.03 #define SX1262_ANT_SW (32 + 10) // P1.10 +// To debug via the segger JLINK console rather than the CDC-ACM serial device +#define USE_SEGGER + #ifdef __cplusplus } #endif