Merge pull request #503 from geeksville/ppr1

Ppr1
1.2-legacy
Kevin Hester 2020-10-27 22:26:18 -07:00 zatwierdzone przez GitHub
commit 17763034a0
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
33 zmienionych plików z 954 dodań i 131 usunięć

Wyświetl plik

@ -2,7 +2,20 @@
set -e
# dependencies
# apt install srecord
BOOTDIR=/home/kevinh/development/meshtastic/Adafruit_nRF52_Bootloader
BOARD=othernet_ppr1
BOOTVER=0.3.2
BOOTNUM=128
BOOTSHA=gc01b9ea
SDCODE=s113
SDVER=7.2.0
PROJ=ppr1
# FIXME for nRF52840 use 0xff000, for nRF52833 use 0x7f000
BOOTSET=0x7f000
nrfjprog --eraseall -f nrf52
@ -11,12 +24,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
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 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

Wyświetl plik

@ -1,3 +1,3 @@
JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52840_XXAA
JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52832_XXAA

Wyświetl plik

@ -0,0 +1,3 @@
JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52833_XXAA

Wyświetl plik

@ -1,3 +1,3 @@
JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52832_XXAA
JLinkGDBServerCLExe -if SWD -select USB -port 2331 -device NRF52840_XXAA

Wyświetl plik

@ -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/

2
bin/view-map.sh 100755
Wyświetl plik

@ -0,0 +1,2 @@
echo using amap tool to display memory map
amap .pio/build/output.map

Wyświetl plik

@ -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": [
[

Wyświetl plik

@ -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"
}

46
boards/ppr1.json 100644
Wyświetl plik

@ -0,0 +1,46 @@
{
"build": {
"arduino": {
"ldscript": "nrf52833_s113_v7.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": "-DS113",
"sd_name": "s113",
"sd_version": "7.2.0",
"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"
}

Wyświetl plik

@ -5,8 +5,24 @@
## RAK815
TODO:
### PPR1 TODO
* 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?)
* 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
* 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

Wyświetl plik

@ -237,6 +237,15 @@ 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}
; Prototype eink/nrf52840/sx1262 device
[env:eink]
extends = nrf52_base
@ -272,7 +281,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]

Wyświetl plik

@ -139,6 +139,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// -----------------------------------------------------------------------------
#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.
@ -146,7 +147,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// 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

Wyświetl plik

@ -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();

Wyświetl plik

@ -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
@ -25,8 +25,37 @@ 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
#ifdef PIN_GPS_EN
digitalWrite(PIN_GPS_EN, PIN_GPS_EN);
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();
@ -36,6 +65,27 @@ 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, GPS_WAKE_ACTIVE);
pinMode(PIN_GPS_WAKE, OUTPUT);
#endif
}
void GPS::sleep() {
#ifdef PIN_GPS_WAKE
digitalWrite(PIN_GPS_WAKE, GPS_WAKE_ACTIVE ? 0 : 1);
pinMode(PIN_GPS_WAKE, OUTPUT);
#endif
}
/// Record that we have a GPS
void GPS::setConnected()
{

Wyświetl plik

@ -72,13 +72,13 @@ 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() {}
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
*

Wyświetl plik

@ -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
@ -102,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);
}

Wyświetl plik

@ -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);

Wyświetl plik

@ -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.
@ -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,8 @@ void Screen::setup()
displayWidth = dispdev.width();
displayHeight = dispdev.height();
ui.setTimePerTransition(300); // msecs
ui.setTimePerTransition(SCREEN_TRANSITION_MSECS);
ui.setIndicatorPosition(BOTTOM);
// Defines where the first frame is located in the bar.
ui.setIndicatorDirection(LEFT_RIGHT);
@ -661,7 +663,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
@ -874,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
}

Wyświetl plik

@ -6,6 +6,8 @@
#ifdef USE_SH1106
#include <SH1106Wire.h>
#elif defined(USE_ST7567)
#include <ST7567Wire.h>
#else
#include <SSD1306Wire.h>
#endif
@ -19,6 +21,11 @@
#include "power.h"
#include <string>
// 0 to 255, though particular variants might define different defaults
#ifndef BRIGHTNESS_DEFAULT
#define BRIGHTNESS_DEFAULT 150
#endif
namespace graphics
{
@ -97,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.
//
@ -250,6 +257,8 @@ class Screen : public concurrency::OSThread
EInkDisplay dispdev;
#elif defined(USE_SH1106)
SH1106Wire dispdev;
#elif defined(USE_ST7567)
ST7567Wire dispdev;
#else
SSD1306Wire dispdev;
#endif

Wyświetl plik

@ -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

Wyświetl plik

@ -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;
@ -173,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
}
@ -190,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;
}
@ -203,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;
@ -245,11 +256,18 @@ 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, LCD is at address 0x3F
pinMode(PIN_LCD_RESET, OUTPUT);
digitalWrite(PIN_LCD_RESET, 0);
delay(1);
digitalWrite(PIN_LCD_RESET, 1);
delay(1);
#endif
scanI2Cdevice();
// Buttons & LED
buttonThread = new ButtonThread();
#ifdef LED_PIN
@ -263,7 +281,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
@ -289,43 +307,43 @@ 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 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();
@ -335,11 +353,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
@ -394,7 +412,6 @@ void setup()
// Initialize Wifi
initWifi();
if (!rIf)
recordCriticalError(ErrNoRadio);

Wyświetl plik

@ -6,7 +6,6 @@
#include "graphics/Screen.h"
extern bool axp192_found;
extern bool ssd1306_found;
extern bool isCharging;
extern bool isUSBPowered;

Wyświetl plik

@ -1,6 +1,11 @@
#include "SX1262Interface.h"
#include <configuration.h>
// 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();

Wyświetl plik

@ -0,0 +1,100 @@
#include "BQ25713.h"
#include "configuration.h"
#include <Wire.h>
#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

Wyświetl plik

@ -0,0 +1,22 @@
#pragma once
#include <Arduino.h>
/**
* 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);
};

Wyświetl plik

@ -1,53 +0,0 @@
#include <OLEDDisplay.h>
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 <UC1701.h>
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

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -0,0 +1,178 @@
/*
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
use hardware spi controller for lcd - not bitbang
*/
/*----------------------------------------------------------------------------
* 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 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
#ifdef __cplusplus
}
#endif
/*----------------------------------------------------------------------------
* Arduino objects - C++ only
*----------------------------------------------------------------------------*/
#endif

Wyświetl plik

@ -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

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -0,0 +1,179 @@
/*
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 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 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
// 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
*/
#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
*----------------------------------------------------------------------------*/