2020-02-01 08:30:53 -08:00
/*
TTGO T - BEAM Tracker for The Things Network
Copyright ( C ) 2018 by Xose Pérez < xose dot perez at gmail dot com >
This code requires LMIC library by Matthijs Kooijman
https : //github.com/matthijskooijman/arduino-lmic
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program 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 General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# pragma once
# include <Arduino.h>
// -----------------------------------------------------------------------------
// Version
// -----------------------------------------------------------------------------
2020-02-18 16:18:01 -08:00
// If app version is not specified we assume we are not being invoked by the build script
2020-02-14 14:00:08 -08:00
# ifndef APP_VERSION
2020-04-19 08:33:59 -07:00
# error APP_VERSION, HW_VERSION, and HW_VERSION_countryname must be set by the build environment
//#define APP_VERSION 0.0.0 // this def normally comes from build-all.sh
//#define HW_VERSION 1.0 - US // normally comes from build-all.sh and contains the region code
2020-02-14 14:00:08 -08:00
# endif
2020-02-18 16:18:01 -08:00
2020-02-01 08:30:53 -08:00
// -----------------------------------------------------------------------------
// Configuration
// -----------------------------------------------------------------------------
2020-02-03 20:18:36 -08:00
// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled)
2020-02-05 22:13:27 -08:00
// we don't support jtag on the ttgo - access to gpio 12 is a PITA
2020-03-27 13:20:52 -07:00
# ifdef ARDUINO_HELTEC_WIFI_LORA_32_V2
2020-02-06 21:26:40 -08:00
//#define USE_JTAG
2020-02-05 22:13:27 -08:00
# endif
2020-02-03 20:18:36 -08:00
2020-03-03 08:23:58 -08:00
# define REQUIRE_RADIO true // If true, we will fail to start if the radio is not found
2020-02-01 08:30:53 -08:00
2020-05-12 17:57:51 -07:00
/// Convert a preprocessor name into a quoted string
2020-03-03 08:23:58 -08:00
# define xstr(s) str(s)
# define str(s) #s
2020-02-01 08:30:53 -08:00
2020-05-12 17:57:51 -07:00
/// Convert a preprocessor name into a quoted string and if that string is empty use "unset"
# define optstr(s) (xstr(s)[0] ? xstr(s) : "unset")
2020-05-10 12:33:17 -07:00
# ifdef NRF52840_XXAA // All of the NRF52 targets are configured using variant.h, so this section shouldn't need to be
// board specific
2020-02-01 08:30:53 -08:00
2020-05-10 12:33:17 -07:00
//
// Standard definitions for NRF52 targets
//
2020-02-01 08:30:53 -08:00
2020-05-10 12:33:17 -07:00
# define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
2020-03-19 20:15:51 -07:00
2020-05-10 12:33:17 -07:00
// We bind to the GPS using variant.h instead for this platform (Serial1)
2020-04-14 20:22:27 -07:00
2020-05-10 12:33:17 -07:00
// FIXME, not yet ready for NRF52
# define RTC_DATA_ATTR
2020-04-14 20:22:27 -07:00
2020-05-10 12:33:17 -07:00
# define LED_PIN PIN_LED1 // LED1 on nrf52840-DK
# define BUTTON_PIN PIN_BUTTON1
2020-02-01 08:30:53 -08:00
2020-05-10 12:33:17 -07:00
// FIXME, use variant.h defs for all of this!!! (even on the ESP32 targets)
2020-06-05 17:30:09 -07:00
# elif defined(CubeCell_BoardPlus)
//
// Standard definitions for CubeCell targets
//
# define NO_ESP32 // Don't use ESP32 libs (mainly bluetooth)
// FIXME, not yet ready for NRF52
# define RTC_DATA_ATTR
2020-06-16 17:01:50 -07:00
# define LED_PIN -1 // FIXME totally bogus
# define BUTTON_PIN -1
2020-06-05 17:30:09 -07:00
2020-05-10 12:33:17 -07:00
# else
//
// Standard definitions for ESP32 targets
//
2020-02-01 08:30:53 -08:00
2020-05-10 12:33:17 -07:00
# define GPS_SERIAL_NUM 1
2020-03-03 08:23:58 -08:00
# define GPS_RX_PIN 34
2020-02-03 20:18:36 -08:00
# ifdef USE_JTAG
2020-03-03 08:23:58 -08:00
# define GPS_TX_PIN -1
2020-02-03 20:18:36 -08:00
# else
2020-03-03 08:23:58 -08:00
# define GPS_TX_PIN 12
2020-02-01 08:30:53 -08:00
# endif
// -----------------------------------------------------------------------------
// LoRa SPI
// -----------------------------------------------------------------------------
2020-03-03 08:23:58 -08:00
# define SCK_GPIO 5
# define MISO_GPIO 19
# define MOSI_GPIO 27
# define NSS_GPIO 18
2020-02-01 14:23:21 -08:00
2020-05-10 12:33:17 -07:00
# endif
// -----------------------------------------------------------------------------
// OLED
// -----------------------------------------------------------------------------
# define SSD1306_ADDRESS 0x3C
2020-06-14 10:28:23 +02:00
// 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.
//#define USE_SH1106
2020-05-10 12:33:17 -07:00
// 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
// DEBUG LED
# define LED_INVERTED 0 // define as 1 if LED is active low (on)
// -----------------------------------------------------------------------------
// GPS
// -----------------------------------------------------------------------------
# define GPS_BAUDRATE 9600
2020-03-28 15:31:22 -07:00
# if defined(TBEAM_V10)
2020-02-24 11:21:34 -08:00
// This string must exactly match the case used in release file names or the android updater won't work
2020-03-27 16:55:19 -07:00
# define HW_VENDOR "tbeam"
2020-02-01 14:23:21 -08:00
2020-03-14 18:48:15 -07:00
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
2020-03-03 08:23:58 -08:00
# define I2C_SDA 21
# define I2C_SCL 22
2020-02-01 14:23:21 -08:00
2020-06-25 09:45:21 -07:00
# define BUTTON_PIN 38 // The middle button GPIO on the T-Beam
# define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed
2020-02-01 14:23:21 -08:00
2020-02-05 15:37:58 -08:00
# ifndef USE_JTAG
2020-03-03 08:23:58 -08:00
# define RESET_GPIO 14
2020-02-05 15:37:58 -08:00
# endif
2020-03-31 21:56:35 -07:00
# define RF95_IRQ_GPIO 26
2020-03-03 08:23:58 -08:00
# define DIO1_GPIO 33 // Note: not really used on this board
# define DIO2_GPIO 32 // Note: not really used on this board
2020-02-12 09:13:49 -08:00
2020-03-03 08:23:58 -08:00
// Leave undefined to disable our PMU IRQ handler
# define PMU_IRQ 35
2020-02-01 14:23:21 -08:00
2020-04-24 14:55:51 -07:00
# define AXP192_SLAVE_ADDRESS 0x34
2020-03-28 15:31:22 -07:00
# elif defined(TBEAM_V07)
// This string must exactly match the case used in release file names or the android updater won't work
# define HW_VENDOR "tbeam0.7"
// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep
# define I2C_SDA 21
# define I2C_SCL 22
# define BUTTON_PIN 39
# ifndef USE_JTAG
# define RESET_GPIO 23
# endif
2020-03-31 21:56:35 -07:00
# define RF95_IRQ_GPIO 26
2020-03-28 15:31:22 -07:00
# define DIO1_GPIO 33 // Note: not really used on this board
# define DIO2_GPIO 32 // Note: not really used on this board
// This board has different GPS pins than all other boards
# undef GPS_RX_PIN
# undef GPS_TX_PIN
2020-07-03 07:41:22 +02:00
# define GPS_RX_PIN 12
# define GPS_TX_PIN 15
2020-03-28 15:31:22 -07:00
2020-03-27 13:20:52 -07:00
# elif defined(ARDUINO_HELTEC_WIFI_LORA_32_V2)
2020-02-24 11:21:34 -08:00
// This string must exactly match the case used in release file names or the android updater won't work
2020-03-27 16:55:19 -07:00
# define HW_VENDOR "heltec"
2020-02-03 20:18:36 -08:00
2020-06-15 11:38:15 -06:00
// the default ESP32 Pin of 15 is the Oled SCL, set to 36 and 37 and works fine.
2020-06-16 17:01:50 -07:00
// Tested on Neo6m module.
2020-06-15 11:38:15 -06:00
# undef GPS_RX_PIN
# undef GPS_TX_PIN
# define GPS_RX_PIN 36
# define GPS_TX_PIN 37
2020-03-27 16:55:19 -07:00
# ifndef USE_JTAG // gpio15 is TDO for JTAG, so no I2C on this board while doing jtag
# define I2C_SDA 4 // I2C pins for this board
2020-03-03 08:23:58 -08:00
# define I2C_SCL 15
2020-02-04 07:31:32 -08:00
# endif
2020-02-01 14:23:21 -08:00
2020-03-27 16:55:19 -07:00
# define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
2020-02-01 14:23:21 -08:00
2020-03-03 08:23:58 -08:00
# define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
2020-03-27 16:55:19 -07:00
# define LED_PIN 25 // If defined we will blink this LED
# define BUTTON_PIN 0 // If defined, this will be used for user button presses
2020-02-01 14:23:21 -08:00
2020-02-05 15:37:58 -08:00
# ifndef USE_JTAG
2020-03-27 16:55:19 -07:00
# define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
2020-02-05 15:37:58 -08:00
# endif
2020-03-31 21:56:35 -07:00
# define RF95_IRQ_GPIO 26
2020-03-27 16:55:19 -07:00
# define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
# define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
2020-07-14 16:16:49 +02:00
# elif defined(TLORA_V1)
2020-03-27 16:55:19 -07:00
// This string must exactly match the case used in release file names or the android updater won't work
2020-07-14 16:16:49 +02:00
# define HW_VENDOR "tlora-v1"
2020-06-24 12:15:50 +02:00
# undef GPS_RX_PIN
# undef GPS_TX_PIN
# define GPS_RX_PIN 36
# define GPS_TX_PIN 37
2020-03-27 16:55:19 -07:00
2020-04-09 20:44:15 -04:00
# define I2C_SDA 4 // I2C pins for this board
# define I2C_SCL 15
2020-03-27 16:55:19 -07:00
# define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
// #define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
# define LED_PIN 2 // If defined we will blink this LED
# define BUTTON_PIN 0 // If defined, this will be used for user button presses
2020-03-31 21:56:35 -07:00
# define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
# define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
# define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
# define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
2020-07-14 16:16:49 +02:00
# elif defined(TLORA_V2)
2020-03-27 16:55:19 -07:00
// This string must exactly match the case used in release file names or the android updater won't work
2020-07-14 16:16:49 +02:00
# define HW_VENDOR "tlora-v2"
2020-03-27 16:55:19 -07:00
2020-06-25 09:45:21 -07:00
# undef GPS_RX_PIN
# undef GPS_TX_PIN
# define GPS_RX_PIN 36
# define GPS_TX_PIN 13 // per @eugene
2020-04-09 20:44:15 -04:00
# define I2C_SDA 21 // I2C pins for this board
# define I2C_SCL 22
2020-03-27 16:55:19 -07:00
# define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
# define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
2020-03-28 14:45:33 -07:00
# define LED_PIN 25 // If defined we will blink this LED
2020-07-14 16:16:49 +02:00
# define BUTTON_PIN 0 // If defined, this will be used for user button presses, if your board doesn't have a physical switch, you can wire one between this pin and ground
2020-03-27 16:55:19 -07:00
2020-05-10 12:33:17 -07:00
# define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
# define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
# define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
# define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
2020-07-14 16:16:49 +02:00
# elif defined(TLORA_V2_1_16)
// This string must exactly match the case used in release file names or the android updater won't work
# define HW_VENDOR "tlora-v2-1-1.6"
# undef GPS_RX_PIN
# undef GPS_TX_PIN
# define GPS_RX_PIN 36
# define GPS_TX_PIN 39
# define I2C_SDA 21 // I2C pins for this board
# define I2C_SCL 22
# define RESET_OLED 16 // If defined, this pin will be used to reset the display controller
# define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost
# define LED_PIN 25 // If defined we will blink this LED
# define BUTTON_PIN 12 // If defined, this will be used for user button presses, if your board doesn't have a physical switch, you can wire one between this pin and ground
# define RESET_GPIO 23 // If defined, this pin will be used to reset the LORA radio
# define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
# define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
# define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
2020-05-10 12:33:17 -07:00
# endif
2020-04-27 07:39:50 -07:00
2020-05-10 12:33:17 -07:00
# ifdef ARDUINO_NRF52840_PCA10056
2020-04-27 07:39:50 -07:00
2020-03-31 21:56:35 -07:00
// This string must exactly match the case used in release file names or the android updater won't work
2020-05-10 12:33:17 -07:00
# define HW_VENDOR "nrf52dk"
2020-04-14 20:22:27 -07:00
// This board uses 0 to be mean LED on
# undef LED_INVERTED
# define LED_INVERTED 1
2020-05-10 12:33:17 -07:00
// Uncomment to confirm if we can build the RF95 driver for NRF52
2020-04-29 14:54:03 -07:00
#if 0
2020-04-23 18:47:27 -07:00
# define RESET_GPIO 14 // If defined, this pin will be used to reset the LORA radio
# define RF95_IRQ_GPIO 26 // IRQ line for the LORA radio
# define DIO1_GPIO 35 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
# define DIO2_GPIO 34 // DIO1 & DIO2 are not currently used, but they must be assigned to a pin number
2020-04-29 14:54:03 -07:00
# endif
2020-04-23 18:47:27 -07:00
2020-05-10 12:33:17 -07:00
# elif defined(ARDUINO_NRF52840_PPR)
# define HW_VENDOR "ppr"
2020-02-01 14:23:21 -08:00
# endif
2020-04-23 16:20:07 -07:00
// -----------------------------------------------------------------------------
// DEBUG
// -----------------------------------------------------------------------------
2020-04-24 08:05:56 -07:00
# define SERIAL_BAUD 921600 // Serial debug baud rate
2020-05-21 21:17:53 -07:00
# include "SerialConsole.h"
# define DEBUG_PORT console // Serial debug port
2020-06-05 17:30:09 -07:00
// What platforms should use SEGGER?
# ifdef NRF52_SERIES
2020-04-23 16:20:07 -07:00
# define USE_SEGGER
2020-06-10 14:36:11 -07:00
# else
# define SERIAL0_RX_GPIO 3 // Always GPIO3 on ESP32
2020-04-23 16:20:07 -07:00
# endif
2020-06-05 17:30:09 -07:00
2020-04-23 16:20:07 -07:00
# ifdef USE_SEGGER
# include "SEGGER_RTT.h"
# define DEBUG_MSG(...) SEGGER_RTT_printf(0, __VA_ARGS__)
# else
# ifdef DEBUG_PORT
# define DEBUG_MSG(...) DEBUG_PORT.printf(__VA_ARGS__)
# else
# define DEBUG_MSG(...)
# endif
# endif
2020-02-01 08:30:53 -08:00
// -----------------------------------------------------------------------------
// AXP192 (Rev1-specific options)
// -----------------------------------------------------------------------------
2020-03-03 08:23:58 -08:00
# define GPS_POWER_CTRL_CH 3
# define LORA_POWER_CTRL_CH 2