From 047df76373dfa2ea4d644d82cc3aed9de31e16c3 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 09:53:38 +0800 Subject: [PATCH 01/15] move rev 0.1 of the ttgo eink board to eink0.1 --- boards/{eink.json => eink0.1.json} | 2 +- platformio.ini | 12 ++++++------ src/graphics/EInkDisplay.cpp | 1 - variants/{eink => eink0.1}/variant.cpp | 0 variants/{eink => eink0.1}/variant.h | 0 5 files changed, 7 insertions(+), 8 deletions(-) rename boards/{eink.json => eink0.1.json} (97%) rename variants/{eink => eink0.1}/variant.cpp (100%) rename variants/{eink => eink0.1}/variant.h (100%) diff --git a/boards/eink.json b/boards/eink0.1.json similarity index 97% rename from boards/eink.json rename to boards/eink0.1.json index e2414b23..1c561489 100644 --- a/boards/eink.json +++ b/boards/eink0.1.json @@ -15,7 +15,7 @@ ], "usb_product": "TTGO_eink", "mcu": "nrf52840", - "variant": "eink", + "variant": "eink0.1", "variants_dir": "variants", "bsp": { "name": "adafruit" diff --git a/platformio.ini b/platformio.ini index 34667d2c..be9bd710 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = linux # 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 = eink0.1 # 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] @@ -247,15 +247,15 @@ src_filter = ${nrf52_base.src_filter} +<../variants/ppr1> lib_deps = ${arduino_base.lib_deps} -; Prototype eink/nrf52840/sx1262 device -[env:eink] +; First prototype eink/nrf52840/sx1262 device +[env:eink0.1] extends = nrf52_base -board = eink +board = eink0.1 # 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/eink +build_flags = ${nrf52_base.build_flags} -Ivariants/eink0.1 -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30 -src_filter = ${nrf52_base.src_filter} +<../variants/eink> +src_filter = ${nrf52_base.src_filter} +<../variants/eink0.1> lib_deps = ${arduino_base.lib_deps} https://github.com/geeksville/EPD_Libraries.git diff --git a/src/graphics/EInkDisplay.cpp b/src/graphics/EInkDisplay.cpp index 0d5e8307..2b530c0c 100644 --- a/src/graphics/EInkDisplay.cpp +++ b/src/graphics/EInkDisplay.cpp @@ -4,7 +4,6 @@ #include "EInkDisplay.h" #include "SPILock.h" #include "epd1in54.h" // Screen specific library -#include "graphics/configs.h" #include #include // Graphics library and Sprite class diff --git a/variants/eink/variant.cpp b/variants/eink0.1/variant.cpp similarity index 100% rename from variants/eink/variant.cpp rename to variants/eink0.1/variant.cpp diff --git a/variants/eink/variant.h b/variants/eink0.1/variant.h similarity index 100% rename from variants/eink/variant.h rename to variants/eink0.1/variant.h From 51d0d0d6c573050892af0d52230b6a64f22b59a1 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 09:57:55 +0800 Subject: [PATCH 02/15] begin new ttgo eink board --- boards/eink.json | 61 +++++++++ platformio.ini | 16 ++- variants/eink/variant.cpp | 44 +++++++ variants/eink/variant.h | 256 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 376 insertions(+), 1 deletion(-) create mode 100644 boards/eink.json create mode 100644 variants/eink/variant.cpp create mode 100644 variants/eink/variant.h diff --git a/boards/eink.json b/boards/eink.json new file mode 100644 index 00000000..e2414b23 --- /dev/null +++ b/boards/eink.json @@ -0,0 +1,61 @@ +{ + "build": { + "arduino": { + "ldscript": "nrf52840_s140_v6.ld" + }, + "core": "nRF5", + "cpu": "cortex-m4", + "extra_flags": "-DARDUINO_NRF52840_TTGO_EINK -DNRF52840_XXAA", + "f_cpu": "64000000L", + "hwids": [ + [ + "0x239A", + "0x4405" + ] + ], + "usb_product": "TTGO_eink", + "mcu": "nrf52840", + "variant": "eink", + "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": "TTGO eink (Adafruit BSP)", + "upload": { + "maximum_ram_size": 248832, + "maximum_size": 815104, + "require_upload_port": true, + "speed": 115200, + "protocol": "jlink", + "protocols": [ + "jlink", + "nrfjprog", + "stlink" + ] + }, + "url": "FIXME", + "vendor": "TTGO" +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index be9bd710..d43b1fd1 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = eink0.1 # 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 = eink # 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] @@ -247,6 +247,20 @@ src_filter = ${nrf52_base.src_filter} +<../variants/ppr1> lib_deps = ${arduino_base.lib_deps} +; First prototype eink/nrf52840/sx1262 device +[env:eink] +extends = nrf52_base +board = eink +# 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/eink + -DBUSY_PIN=3 -DRST_PIN=2 -DDC_PIN=28 -DCS_PIN=30 +src_filter = ${nrf52_base.src_filter} +<../variants/eink> +lib_deps = + ${arduino_base.lib_deps} + https://github.com/geeksville/EPD_Libraries.git + TFT_eSPI + ; First prototype eink/nrf52840/sx1262 device [env:eink0.1] extends = nrf52_base diff --git a/variants/eink/variant.cpp b/variants/eink/variant.cpp new file mode 100644 index 00000000..cae079b7 --- /dev/null +++ b/variants/eink/variant.cpp @@ -0,0 +1,44 @@ +/* + 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 - pins 0 and 1 are hardwired for xtal and should never be enabled + 0xff, 0xff, 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); + + pinMode(PIN_LED3, OUTPUT); + ledOff(PIN_LED3); +} diff --git a/variants/eink/variant.h b/variants/eink/variant.h new file mode 100644 index 00000000..6e3fedd6 --- /dev/null +++ b/variants/eink/variant.h @@ -0,0 +1,256 @@ +/* + 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_TTGO_EINK_V1_ +#define _VARIANT_TTGO_EINK_V1_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF + +/* +@geeksville eink TODO: + +soonish: +DONE hook cdc acm device to debug output +DONE fix bootloader to use two buttons - remove bootloader hacks +DONE get second button working in app load +DONE use tp_ser_io as a button, it goes high when pressed unify eink display classes +fix display width and height +clean up eink drawing to not have the nasty timeout hack +measure current draws +DONE put eink to sleep when we think the screen is off +enable gps sleep mode +turn off txco on lora? +make screen.adjustBrightness() a nop on eink screens + +later: +enable flash on qspi. +fix floating point SEGGER printf on nrf52 - see "new NMEA GPS pos" +add factory/power on self test + +feedback to give: + +* bootloader is finished + +* the capacitive touch sensor works, though I'm not sure what use you are intending for it + +* remove ipx connector for nfc, instead use two caps and loop traces on the back of the board as an antenna? + +* the i2c RTC seems to talk fine on the i2c bus. However, I'm not sure of the utility of that part. Instead I'd be in favor of +the following: + +* move BAT1 to power the GPS VBACKUP instead per page 6 of the Air530 datasheet. And remove the i2c RTC entirely. + +* remove the cp2014 chip. + +* I've made the serial flash chip work, but if you do a new spin of the board I recommend: +connect pin 3 and pin 7 of U4 to spare GPIOs on the processor (instead of their current connections), +This would allow using 4 bit wide interface mode to the serial flash - doubling the transfer speed! see example here: +https://infocenter.nordicsemi.com/topic/ug_nrf52840_dk/UG/nrf52840_DK/hw_external_memory.html?cp=4_0_4_7_4 +Once again - I'm glad you added that external flash chip. + +* Power measurements +When powered by 4V battery + +CPU on, lora radio RX mode, bluetooth enabled, GPS trying to lock. total draw 43mA +CPU on, lora radio RX mode, bluetooth enabled, GPS super low power sleep mode. Total draw 20mA +CPU on, lora radio TX mode, bluetooth enabled, GPS super low power sleep mode. Total draw 132mA + +Note: power consumption while connected via BLE to a phone almost identical. + +Note: eink display for all tests was in sleep mode most of the time. Current draw during the brief periods while the eink was being drawn was not +measured (but it was low). + +Note: Turning off EINK PWR_ON produces no noticeable power savings over just putting the eink display into sleep mode. + +*/ + +/*---------------------------------------------------------------------------- + * 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 (1) +#define NUM_ANALOG_OUTPUTS (0) + +// LEDs +#define PIN_LED1 (0 + 13) // green (but red on my prototype) +#define PIN_LED2 (0 + 15) // blue (but red on my prototype) +#define PIN_LED3 (0 + 14) // red (not functional on my prototype) + +#define LED_RED PIN_LED3 +#define LED_GREEN PIN_LED1 +#define LED_BLUE PIN_LED2 + +#define LED_BUILTIN LED_GREEN +#define LED_CONN PIN_BLUE + +#define LED_STATE_ON 0 // State when LED is lit +#define LED_INVERTED 1 + +/* + * Buttons + */ +#define PIN_BUTTON1 (32 + 10) +#define PIN_BUTTON2 (0 + 18) // 0.18 is labeled on the board as RESET but we configure it in the bootloader as a regular GPIO + +/* + * Analog pins + */ +#define PIN_A0 (4) // Battery ADC + +#define BATTERY_PIN PIN_A0 + +static const uint8_t A0 = PIN_A0; + +#define ADC_RESOLUTION 14 + +#define PIN_NFC1 (9) +#define PIN_NFC2 (10) + +/* + * Serial interfaces + */ + +/* +No longer populated on PCB +*/ +//#define PIN_SERIAL2_RX (0 + 6) +//#define PIN_SERIAL2_TX (0 + 8) +// #define PIN_SERIAL2_EN (0 + 17) + +/** + Wire Interfaces + */ +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA (26) // Not connected on board? +#define PIN_WIRE_SCL (27) + +/* touch sensor, active high */ + +#define TP_SER_IO (0 + 11) + +#define PIN_RTC_INT (0 + 16) // Interrupt from the PCF8563 RTC + +/* +External serial flash WP25R1635FZUIL0 +*/ + +// QSPI Pins +#define PIN_QSPI_SCK (32 + 14) +#define PIN_QSPI_CS (32 + 15) +#define PIN_QSPI_IO0 (32 + 12) // MOSI if using two bit interface +#define PIN_QSPI_IO1 (32 + 13) // MISO if using two bit interface +//#define PIN_QSPI_IO2 22 // WP if using two bit interface (i.e. not used) +//#define PIN_QSPI_IO3 23 // HOLD if using two bit interface (i.e. not used) + +// On-board QSPI Flash +#define EXTERNAL_FLASH_DEVICES MX25R1635F +#define EXTERNAL_FLASH_USE_QSPI + +/* + * Lora radio + */ + +#define SX1262_CS (0 + 24) // FIXME - we really should define LORA_CS instead +#define SX1262_DIO1 (0 + 20) +// Note DIO2 is attached internally to the module to an analog switch for TX/RX switching +#define SX1262_DIO3 \ + (0 + 21) // This is used as an *output* from the sx1262 and connected internally to power the tcxo, do not drive from the main + // CPU? +#define SX1262_BUSY (0 + 17) +#define SX1262_RESET (0 + 25) +#define SX1262_E22 // Not really an E22 but TTGO seems to be trying to clone that +// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface +// code) + +// #define LORA_DISABLE_SENDING // Define this to disable transmission for testing (power testing etc...) + +/* + * eink display pins + */ + +#define PIN_EINK_EN (32 + 11) +#define PIN_EINK_CS (0 + 30) +#define PIN_EINK_BUSY (0 + 3) +#define PIN_EINK_DC (0 + 28) +#define PIN_EINK_RES (0 + 2) +#define PIN_EINK_SCLK (0 + 31) +#define PIN_EINK_MOSI (0 + 29) // also called SDI + +// Controls power for the eink display - Board power is enabled either by VBUS from USB or the CPU asserting PWR_ON +// FIXME - I think this is actually just the board power enable - it enables power to the CPU also +#define PIN_EINK_PWR_ON (0 + 12) + +#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 +#define PIN_SPI1_SCK PIN_EINK_SCLK + +/* + * Air530 GPS pins + */ + +#define PIN_GPS_WAKE (32 + 2) // An output to wake GPS, low means allow sleep, high means force wake +#define PIN_GPS_PPS (32 + 4) // Pulse per second input from the GPS +#define PIN_GPS_TX (32 + 9) // This is for bits going TOWARDS the CPU +#define PIN_GPS_RX (32 + 8) // This is for bits going TOWARDS the GPS + +#define HAS_AIR530_GPS + +#define PIN_SERIAL1_RX PIN_GPS_TX +#define PIN_SERIAL1_TX PIN_GPS_RX + +/* + * SPI Interfaces + */ +#define SPI_INTERFACES_COUNT 2 + +// For LORA, spi 0 +#define PIN_SPI_MISO (0 + 23) +#define PIN_SPI_MOSI (0 + 22) +#define PIN_SPI_SCK (0 + 19) + +// To debug via the segger JLINK console rather than the CDC-ACM serial device +// #define USE_SEGGER + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif From 2684257e7ecd8dfd82cb13aad62e83cce029f0f1 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 09:59:43 +0800 Subject: [PATCH 03/15] update protobufs --- proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto b/proto index dfe7bc12..4c62d8e5 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit dfe7bc1217a00c23eecb9dfcf1d56fe95ebddc3b +Subproject commit 4c62d8e53696074d7c368518afd9d564df374fcf From f110225173a77326aac029321cdb6491bfa640f6 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 10:34:46 +0800 Subject: [PATCH 04/15] Update variant file and qspi flash programming settings for new ttgoeink Note: bin/qspi-flash-test.sh contains a script you can use for basic bench programming and testing of the serial spi flash over SWD --- bin/qspi-flash-test.sh | 2 +- nrf52/ttgo_eink_qpsi.ini | 21 ++++------- nrf52/ttgo_eink_qpsi0.1.ini | 69 +++++++++++++++++++++++++++++++++++++ variants/eink/variant.h | 9 ++--- 4 files changed, 82 insertions(+), 19 deletions(-) create mode 100644 nrf52/ttgo_eink_qpsi0.1.ini diff --git a/bin/qspi-flash-test.sh b/bin/qspi-flash-test.sh index 7fc186b5..6c03635d 100755 --- a/bin/qspi-flash-test.sh +++ b/bin/qspi-flash-test.sh @@ -1,6 +1,6 @@ # You probably don't need this - it is a basic test of the serial flash on the TTGO eink board -nrfjprog -qspiini nrf52/ttgo_eink_qpsi.ini --qspieraseall +nrfjprog --qspiini nrf52/ttgo_eink_qpsi.ini --qspieraseall nrfjprog --qspiini nrf52/ttgo_eink_qpsi.ini --memwr 0x12000000 --val 0xdeadbeef --verify nrfjprog --qspiini nrf52/ttgo_eink_qpsi.ini --readqspi spi.hex objdump -s spi.hex | less diff --git a/nrf52/ttgo_eink_qpsi.ini b/nrf52/ttgo_eink_qpsi.ini index d477db8e..053c8675 100644 --- a/nrf52/ttgo_eink_qpsi.ini +++ b/nrf52/ttgo_eink_qpsi.ini @@ -8,10 +8,10 @@ MemSize = 0x200000 ; Define the desired ReadMode. Valid options are FASTREAD, READ2O, READ2IO, READ4O and READ4IO -ReadMode = READ2IO +ReadMode = READ4IO ; Define the desired WriteMode. Valid options are PP, PP2O, PP4O and PP4IO -WriteMode = PP +WriteMode = PP4IO ; Define the desired AddressMode. Valid options are BIT24 and BIT32 AddressMode = BIT24 @@ -38,12 +38,10 @@ DIO0Pin = 12 DIO0Port = 1 DIO1Pin = 13 DIO1Port = 1 - -;These two pins are not connected, but we must name something -DIO2Pin = 3 -DIO2Port = 1 +DIO2Pin = 7 +DIO2Port = 0 DIO3Pin = 5 -DIO3Port = 1 +DIO3Port = 0 ; Define the Index of the Write In Progress (WIP) bit in the status register. Valid options are in the range of 0 to 7. WIPIndex = 0 @@ -57,13 +55,8 @@ PPSize = PAGE256 ; Numbers can be given in decimal, hex (starting with either 0x or 0X) and binary (starting with either 0b or 0B) formats. ; The custom instructions will be executed in the order found. -; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) enabling the Quad Operation and the High Performance -; mode for the MX25R6435F memory present in the nRF52840 DK. -;InitializationCustomInstruction = 0x06 -;InitializationCustomInstruction = 0x01, [0x40, 0, 0x2] - ; For MX25R1635F on TTGO board, only two data lines are connected -; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) disabling Quad Operation and the High Performance +; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) enabling Quad Operation and the High Performance ; mode. For normal operation you might want low power mode instead. InitializationCustomInstruction = 0x06 -InitializationCustomInstruction = 0x01, [0x00, 0, 0x2] +InitializationCustomInstruction = 0x01, [0x40, 0, 0x2] diff --git a/nrf52/ttgo_eink_qpsi0.1.ini b/nrf52/ttgo_eink_qpsi0.1.ini new file mode 100644 index 00000000..d477db8e --- /dev/null +++ b/nrf52/ttgo_eink_qpsi0.1.ini @@ -0,0 +1,69 @@ +; nrfjprog.exe configuration file. + +; Note: QSPI flash is mapped into memory at address 0x12000000 + +[DEFAULT_CONFIGURATION] +; Define the capacity of the flash memory device in bytes. Set to 0 if no external memory device is present in your board. +; MX25R1635F is 16Mbit/2Mbyte +MemSize = 0x200000 + +; Define the desired ReadMode. Valid options are FASTREAD, READ2O, READ2IO, READ4O and READ4IO +ReadMode = READ2IO + +; Define the desired WriteMode. Valid options are PP, PP2O, PP4O and PP4IO +WriteMode = PP + +; Define the desired AddressMode. Valid options are BIT24 and BIT32 +AddressMode = BIT24 + +; Define the desired Frequency. Valid options are M2, M4, M8, M16 and M32 +Frequency = M16 + +; Define the desired SPI mode. Valid options are MODE0 and MODE3 +SpiMode = MODE0 + +; Define the desired SckDelay. Valid options are in the range 0 to 255 +SckDelay = 0x80 + +; Define the desired IO level for DIO2 and DIO3 during a custom instruction. Valid options are LEVEL_HIGH and LEVEL_LOW +CustomInstructionIO2Level = LEVEL_LOW +CustomInstructionIO3Level = LEVEL_HIGH + +; Define the assigned pins for the QSPI peripheral. Valid options are those existing in your device +CSNPin = 15 +CSNPort = 1 +SCKPin = 14 +SCKPort = 1 +DIO0Pin = 12 +DIO0Port = 1 +DIO1Pin = 13 +DIO1Port = 1 + +;These two pins are not connected, but we must name something +DIO2Pin = 3 +DIO2Port = 1 +DIO3Pin = 5 +DIO3Port = 1 + +; Define the Index of the Write In Progress (WIP) bit in the status register. Valid options are in the range of 0 to 7. +WIPIndex = 0 + +; Define page size for commands. Valid sizes are PAGE256 and PAGE512. +PPSize = PAGE256 + +; Custom instructions to send to the external memory after initialization. Format is instruction code plus data to send in between optional brakets. +; These instructions will be executed each time the qspi peripheral is initiated by nrfjprog. +; To improve execution speed on consecutive interations with QSPI, you can run nrfjprog once with custom initialization, and then comment out the lines below. +; Numbers can be given in decimal, hex (starting with either 0x or 0X) and binary (starting with either 0b or 0B) formats. +; The custom instructions will be executed in the order found. + +; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) enabling the Quad Operation and the High Performance +; mode for the MX25R6435F memory present in the nRF52840 DK. +;InitializationCustomInstruction = 0x06 +;InitializationCustomInstruction = 0x01, [0x40, 0, 0x2] + +; For MX25R1635F on TTGO board, only two data lines are connected +; This example includes two commands, first a WREN (WRite ENable) and then a WRSR (WRite Satus Register) disabling Quad Operation and the High Performance +; mode. For normal operation you might want low power mode instead. +InitializationCustomInstruction = 0x06 +InitializationCustomInstruction = 0x01, [0x00, 0, 0x2] diff --git a/variants/eink/variant.h b/variants/eink/variant.h index 6e3fedd6..dad11f5b 100644 --- a/variants/eink/variant.h +++ b/variants/eink/variant.h @@ -149,7 +149,7 @@ No longer populated on PCB */ #define WIRE_INTERFACES_COUNT 1 -#define PIN_WIRE_SDA (26) // Not connected on board? +#define PIN_WIRE_SDA (26) #define PIN_WIRE_SCL (27) /* touch sensor, active high */ @@ -167,8 +167,8 @@ External serial flash WP25R1635FZUIL0 #define PIN_QSPI_CS (32 + 15) #define PIN_QSPI_IO0 (32 + 12) // MOSI if using two bit interface #define PIN_QSPI_IO1 (32 + 13) // MISO if using two bit interface -//#define PIN_QSPI_IO2 22 // WP if using two bit interface (i.e. not used) -//#define PIN_QSPI_IO3 23 // HOLD if using two bit interface (i.e. not used) +#define PIN_QSPI_IO2 (0 + 7) // WP if using two bit interface (i.e. not used) +#define PIN_QSPI_IO3 (0 + 5) // HOLD if using two bit interface (i.e. not used) // On-board QSPI Flash #define EXTERNAL_FLASH_DEVICES MX25R1635F @@ -223,7 +223,8 @@ External serial flash WP25R1635FZUIL0 */ #define PIN_GPS_WAKE (32 + 2) // An output to wake GPS, low means allow sleep, high means force wake -#define PIN_GPS_PPS (32 + 4) // Pulse per second input from the GPS +// Seems to be missing on this new board +// #define PIN_GPS_PPS (32 + 4) // Pulse per second input from the GPS #define PIN_GPS_TX (32 + 9) // This is for bits going TOWARDS the CPU #define PIN_GPS_RX (32 + 8) // This is for bits going TOWARDS the GPS From 4faff3ec6f7b33a3cc12d04f6e64fd9a3aea0a4b Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 11:41:18 +0800 Subject: [PATCH 05/15] cope with bogus NMEA gps --- src/gps/NMEAGPS.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gps/NMEAGPS.cpp b/src/gps/NMEAGPS.cpp index 6a707bd8..bd58b525 100644 --- a/src/gps/NMEAGPS.cpp +++ b/src/gps/NMEAGPS.cpp @@ -47,6 +47,8 @@ The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of s t.tm_mon = d.month() - 1; t.tm_year = d.year() - 1900; t.tm_isdst = false; + DEBUG_MSG("NMEA GPS time %d\n", t.tm_sec); + perhapsSetRTC(RTCQualityGPS, t); return true; @@ -87,11 +89,17 @@ bool NMEAGPS::lookForLocation() auto loc = reader.location.value(); latitude = toDegInt(loc.lat); longitude = toDegInt(loc.lng); - foundLocation = true; - // expect gps pos lat=37.520825, lon=-122.309162, alt=158 - DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, hdop=%g, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, - dop * 1e-2, heading * 1e-5); + // Some GPSes (Air530) seem to send a zero longitude when the current fix is bogus + if(longitude == 0) + DEBUG_MSG("Ignoring bogus NMEA position\n"); + else { + foundLocation = true; + + // expect gps pos lat=37.520825, lon=-122.309162, alt=158 + DEBUG_MSG("new NMEA GPS pos lat=%f, lon=%f, alt=%d, hdop=%g, heading=%f\n", latitude * 1e-7, longitude * 1e-7, altitude, + dop * 1e-2, heading * 1e-5); + } } return foundLocation; From a0dd051511545e4d3022be486b9a5af02eb3e98c Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 11:41:28 +0800 Subject: [PATCH 06/15] turn off eink backlight --- src/graphics/EInkDisplay.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graphics/EInkDisplay.cpp b/src/graphics/EInkDisplay.cpp index 2b530c0c..44d38f22 100644 --- a/src/graphics/EInkDisplay.cpp +++ b/src/graphics/EInkDisplay.cpp @@ -122,7 +122,8 @@ bool EInkDisplay::connect() #endif #ifdef PIN_EINK_EN - digitalWrite(PIN_EINK_EN, HIGH); + // backlight power, HIGH is backlight on, LOW is off + digitalWrite(PIN_EINK_EN, LOW); pinMode(PIN_EINK_EN, OUTPUT); #endif From 3a2c17998ed096136e0dd934a6885ac7864e5367 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 11:41:50 +0800 Subject: [PATCH 07/15] turn off nrf52 ble while debugging --- src/nrf52/main-nrf52.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrf52/main-nrf52.cpp b/src/nrf52/main-nrf52.cpp index a1a96f3b..8b7bb65b 100644 --- a/src/nrf52/main-nrf52.cpp +++ b/src/nrf52/main-nrf52.cpp @@ -51,7 +51,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) { From d1f0be215bd35da25a586d3a3078e6d7c79bdd3b Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 11:42:06 +0800 Subject: [PATCH 08/15] eink leds seem a bit busted --- variants/eink/variant.h | 12 ++++++------ variants/eink0.1/variant.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/variants/eink/variant.h b/variants/eink/variant.h index dad11f5b..bd71de3c 100644 --- a/variants/eink/variant.h +++ b/variants/eink/variant.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _VARIANT_TTGO_EINK_V1_ -#define _VARIANT_TTGO_EINK_V1_ +#ifndef _VARIANT_TTGO_EINK_V1_0_ +#define _VARIANT_TTGO_EINK_V1_0_ /** Master clock frequency */ #define VARIANT_MCK (64000000ul) @@ -99,9 +99,9 @@ extern "C" { #define NUM_ANALOG_OUTPUTS (0) // LEDs -#define PIN_LED1 (0 + 13) // green (but red on my prototype) -#define PIN_LED2 (0 + 15) // blue (but red on my prototype) -#define PIN_LED3 (0 + 14) // red (not functional on my prototype) +#define PIN_LED1 (0 + 13) // red (confirmed on 1.0 board) +#define PIN_LED2 (0 + 14) // blue (seems busted!) +#define PIN_LED3 (0 + 15) // green (seems busted!) #define LED_RED PIN_LED3 #define LED_GREEN PIN_LED1 @@ -196,7 +196,7 @@ External serial flash WP25R1635FZUIL0 * eink display pins */ -#define PIN_EINK_EN (32 + 11) +#define PIN_EINK_EN (32 + 11) // Note: this is really just backlight power #define PIN_EINK_CS (0 + 30) #define PIN_EINK_BUSY (0 + 3) #define PIN_EINK_DC (0 + 28) diff --git a/variants/eink0.1/variant.h b/variants/eink0.1/variant.h index 6e3fedd6..1b30ca21 100644 --- a/variants/eink0.1/variant.h +++ b/variants/eink0.1/variant.h @@ -16,8 +16,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _VARIANT_TTGO_EINK_V1_ -#define _VARIANT_TTGO_EINK_V1_ +#ifndef _VARIANT_TTGO_EINK_V0_1_ +#define _VARIANT_TTGO_EINK_V0_1_ /** Master clock frequency */ #define VARIANT_MCK (64000000ul) From d1be7cf14215adfd245c792c1782d1e12a596d99 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 12:55:51 +0800 Subject: [PATCH 09/15] improve hardfault handler --- src/nrf52/hardfault.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nrf52/hardfault.cpp b/src/nrf52/hardfault.cpp index 67180c83..c1a82d6a 100644 --- a/src/nrf52/hardfault.cpp +++ b/src/nrf52/hardfault.cpp @@ -16,8 +16,14 @@ static void printUsageErrorMsg(uint32_t cfsr) cfsr >>= SCB_CFSR_USGFAULTSR_Pos; // right shift to lsb if ((cfsr & (1 << 9)) != 0) FAULT_MSG("Divide by zero\n"); - if ((cfsr & (1 << 8)) != 0) + else if ((cfsr & (1 << 8)) != 0) FAULT_MSG("Unaligned\n"); + else if ((cfsr & (1 << 1)) != 0) + FAULT_MSG("Invalid state\n"); + else if ((cfsr & (1 << 0)) != 0) + FAULT_MSG("Invalid instruction\n"); + else + FAULT_MSG("FIXME add to printUsageErrorMsg!\n"); } static void printBusErrorMsg(uint32_t cfsr) @@ -71,8 +77,9 @@ extern "C" void HardFault_Impl(uint32_t stack[]) FAULT_MSG("Done with fault report - Waiting to reboot\n"); asm volatile("bkpt #01"); // Enter the debugger if one is connected - while (1) - ; + + // Don't spin, so that the debugger will let the user step to next instruction + // while (1) ; } extern "C" void HardFault_Handler(void) From fd9ffbbb881073531f6aa011bd89f4ce87432fe5 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Sat, 16 Jan 2021 13:05:33 +0800 Subject: [PATCH 10/15] fix charging indication for dumb battery sensors --- src/Power.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Power.cpp b/src/Power.cpp index 3d185cb2..82e88f8c 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -83,7 +83,7 @@ class AnalogBatteryLevel : public HasBatteryLevel /// If we see a battery voltage higher than physics allows - assume charger is pumping /// in power - virtual bool isVBUSPlug() { return getBattVoltage() > chargingVolt; } + virtual bool isVBUSPlug() { return getBattVoltage() > 1000 * chargingVolt; } /// Assume charging if we have a battery and external power is connected. /// we can't be smart enough to say 'full'? From 79dad8ec8c8dfe4bb749dd9bffdd7f3506755cd1 Mon Sep 17 00:00:00 2001 From: Andrew Mark Date: Tue, 19 Jan 2021 18:21:54 -0800 Subject: [PATCH 11/15] Set critical error and reboot when radio fails to generate tx IRQ --- src/mesh/NodeDB.cpp | 7 +++++++ src/mesh/RadioLibInterface.cpp | 10 ++++++++++ src/mesh/generated/mesh.pb.h | 3 ++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index dc13bc42..42ce71ea 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -7,6 +7,7 @@ #include "CryptoEngine.h" #include "FSCommon.h" #include "GPS.h" +#include "main.h" #include "MeshRadio.h" #include "NodeDB.h" #include "PacketHistory.h" @@ -583,8 +584,14 @@ NodeInfo *NodeDB::getOrCreateNode(NodeNum n) /// Record an error that should be reported via analytics void recordCriticalError(CriticalErrorCode code, uint32_t address) { + // Print error to screen and serial port + String lcd = String("Critical error ") + code + "!\n"; + screen->print(lcd.c_str()); DEBUG_MSG("NOTE! Recording critical error %d, address=%x\n", code, address); + + // Record error to DB myNodeInfo.error_code = code; myNodeInfo.error_address = address; myNodeInfo.error_count++; + } diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index 0266614a..f0eb53b2 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -3,6 +3,7 @@ #include "NodeDB.h" #include "SPILock.h" #include "mesh-pb-constants.h" +#include "error.h" #include #include #include @@ -67,9 +68,18 @@ bool RadioLibInterface::canSendImmediately() bool busyTx = sendingPacket != NULL; bool busyRx = isReceiving && isActivelyReceiving(); + if (busyTx || busyRx) { if (busyTx) DEBUG_MSG("Can not send yet, busyTx\n"); + // If we've been trying to send the same packet more than one minute and we haven't gotten a + // TX IRQ from the radio, the radio is probably broken. + if (busyTx && (millis() - lastTxStart > 60000)){ + DEBUG_MSG("Hardware Failure! busyTx for more than 60s\n"); + recordCriticalError(CriticalErrorCode_TransmitFailed); + if (busyTx && (millis() - lastTxStart > 65000)) // After 5s more, reboot + ESP.restart(); + } if (busyRx) DEBUG_MSG("Can not send yet, busyRx\n"); return false; diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 815fb2e2..50ae14a6 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -76,7 +76,8 @@ typedef enum _CriticalErrorCode { CriticalErrorCode_Unspecified = 4, CriticalErrorCode_UBloxInitFailed = 5, CriticalErrorCode_NoAXP192 = 6, - CriticalErrorCode_InvalidRadioSetting = 7 + CriticalErrorCode_InvalidRadioSetting = 7, + CriticalErrorCode_TransmitFailed = 8 } CriticalErrorCode; typedef enum _ChannelSettings_ModemConfig { From dd511588a2f29328cc7141901eddfcd1ed713806 Mon Sep 17 00:00:00 2001 From: Andrew Mark Date: Tue, 19 Jan 2021 20:13:19 -0800 Subject: [PATCH 12/15] Oops, let's only try to reboot ESP32 when there's an ESP32 --- src/mesh/RadioLibInterface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesh/RadioLibInterface.cpp b/src/mesh/RadioLibInterface.cpp index f0eb53b2..f2fafef7 100644 --- a/src/mesh/RadioLibInterface.cpp +++ b/src/mesh/RadioLibInterface.cpp @@ -77,8 +77,10 @@ bool RadioLibInterface::canSendImmediately() if (busyTx && (millis() - lastTxStart > 60000)){ DEBUG_MSG("Hardware Failure! busyTx for more than 60s\n"); recordCriticalError(CriticalErrorCode_TransmitFailed); +#ifndef NO_ESP32 if (busyTx && (millis() - lastTxStart > 65000)) // After 5s more, reboot ESP.restart(); +#endif } if (busyRx) DEBUG_MSG("Can not send yet, busyRx\n"); From a8480d1eaf53c9aed2b5e8632e43a0b22d45a104 Mon Sep 17 00:00:00 2001 From: IZ1IVA <75425638+IZ1IVA@users.noreply.github.com> Date: Mon, 25 Jan 2021 16:11:24 +0100 Subject: [PATCH 13/15] Update radio-settings.md Added data-rates --- docs/radio-settings.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/radio-settings.md b/docs/radio-settings.md index 2bf9ccda..7af9d79e 100644 --- a/docs/radio-settings.md +++ b/docs/radio-settings.md @@ -28,3 +28,14 @@ The maximum output power for North America is +30 dBm ERP. The band is from 902 to 928 MHz. It mentions channel number and its respective channel frequency. All the 13 channels are separated by 2.16 MHz with respect to the adjacent channels. Channel zero starts at 903.08 MHz center frequency. + +## Data-rates + +Various data-rates are selectable when configuring a channel and are inversely proportional to the theoretical range of the devices: + +| Channel setting | Data-rate | +|----------------------------|----------------------| +| Short range (but fast) | 21.875 kbps | +| Medium range (but fast) | 5.469 kbps | +| Long range (but slower) | 0.275 kbps | +| Very long range (but slow) | 0.183 kbps (default) | From 6f6dd2291efecaf9e90a2fdcae3686793254f8a7 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 28 Jan 2021 10:30:00 +0800 Subject: [PATCH 14/15] fix typo --- docs/software/crypto.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/software/crypto.md b/docs/software/crypto.md index cd9f2888..1ee7c6d5 100644 --- a/docs/software/crypto.md +++ b/docs/software/crypto.md @@ -13,7 +13,7 @@ the project developers are not cryptography experts. Therefore we ask two things Based on comments from reviewers (see below), here's some tips for usage of these radios. So you can know the level of protection offered: * It is pretty likely that the AES256 security is implemented 'correctly' and an observer will not be able to decode your messages. -* Warning: If an attacker is able to get one of the radios in their position, they could either a) extract the channel key from that device or b) use that radio to listen to new communications. +* Warning: If an attacker is able to get one of the radios in their posession, they could either a) extract the channel key from that device or b) use that radio to listen to new communications. * Warning: If an attacker is able to get the "Channel QR code/URL" that you share with others - that attacker could then be able to read any messages sent on the channel (either tomorrow or in the past - if they kept a raw copy of those broadcast packets) Possible future areas of work (if there is enough interest - post in our [forum](https://meshtastic.discourse.group) if you want this): @@ -48,4 +48,4 @@ I'm assuming that meshtastic is being used to hike in places where someone capab * I think the bigger encryption question is "what does the encryption need to do"? As it stands, an attacker who has yet to capture any of the devices cannot reasonably capture text or location data. An attacker who captures any device in the channel/mesh can read everything going to that device, everything stored on that device, and any other communication within the channel that they captured in encrypted form. If that capability basically matches your expectations, it is suitable for whatever adventures this was intended for, then, based on information publicly available or widely disclosed, the encryption is good. If those properties are distressing (like, device history is deliberately limited and you don't want a device captured today to endanger the information sent over the channel yesterday) we could talk about ways to achieve that (most likely synchronizing time and replacing the key with its own SHA256 every X hours, and ensuring the old key is not retained unnecessarily). * Two other things to keep in mind are that AES-CTR does not itself provide authenticity (e.g. an attacker can flip bits in replaying data and scramble the resulting plaintext), and that the current scheme gives some hints about transmission in the size. So, if you worry about an adversary deliberately messing-up messages or knowing the length of a text message, it looks like those might be possible. -I'm guessing that the network behaves somewhat like a store-and-forward network - or, at least, that the goal is to avoid establishing a two-way connection to transmit data. I'm afraid I haven't worked with mesh networks much, but remember studying them briefly in school about ten years ago. \ No newline at end of file +I'm guessing that the network behaves somewhat like a store-and-forward network - or, at least, that the goal is to avoid establishing a two-way connection to transmit data. I'm afraid I haven't worked with mesh networks much, but remember studying them briefly in school about ten years ago. From 6a593e01e1a812ef5e32eb6818b05b1466b5465f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 28 Jan 2021 10:30:24 +0800 Subject: [PATCH 15/15] notes on eink1.0 --- docs/software/TODO.md | 21 +++++++++++++++++++++ variants/eink/variant.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/docs/software/TODO.md b/docs/software/TODO.md index 69f22591..f6df164b 100644 --- a/docs/software/TODO.md +++ b/docs/software/TODO.md @@ -2,6 +2,27 @@ You probably don't care about this section - skip to the next one. +eink: + +* new battery level sensing +* measure current draw +* DONE: fix backlight +* USB is busted because of power enable mode? +* OHH BME280! THAT IS GREAT! +* make new screen work, ask for datasheet +* say I think you could ship this +* leds seem busted +* usb doesn't stay connected +* check GPS works +* check GPS fast locking +* send email about variants & faster flash programming - https://github.com/geeksville/Meshtastic-esp32/commit/f110225173a77326aac029321cdb6491bfa640f6 +* send PR for bootloader +* fix nrf52 time/date +* send new master bin file +* send email about low power mode problems +* support new flash chip in appload, possibly use low power mode +* swbug! stuck busy tx occurred! + For app cleanup: * use structured logging to kep logs in ram. Also send logs as packets to api clients diff --git a/variants/eink/variant.h b/variants/eink/variant.h index bd71de3c..4cdb33e4 100644 --- a/variants/eink/variant.h +++ b/variants/eink/variant.h @@ -243,6 +243,8 @@ External serial flash WP25R1635FZUIL0 #define PIN_SPI_MOSI (0 + 22) #define PIN_SPI_SCK (0 + 19) +#define PIN_PWR_EN (0 + 6) + // To debug via the segger JLINK console rather than the CDC-ACM serial device // #define USE_SEGGER