mirror of https://github.com/meshcore-dev/MeshCore
162 changed files with 4131 additions and 424 deletions
@ -0,0 +1,61 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"ldscript": "nrf52840_s140_v6.ld" |
||||
|
}, |
||||
|
"core": "nRF5", |
||||
|
"cpu": "cortex-m4", |
||||
|
"extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA", |
||||
|
"f_cpu": "64000000L", |
||||
|
"hwids": [ |
||||
|
["0x239A","0x8029"], |
||||
|
["0x239A","0x0029"], |
||||
|
["0x239A","0x002A"], |
||||
|
["0x239A","0x802A"] |
||||
|
], |
||||
|
"usb_product": "HT-n5262", |
||||
|
"mcu": "nrf52840", |
||||
|
"variant": "heltec_mesh_solar", |
||||
|
"bsp": { |
||||
|
"name": "adafruit" |
||||
|
}, |
||||
|
"softdevice": { |
||||
|
"sd_flags": "-DS140", |
||||
|
"sd_name": "s140", |
||||
|
"sd_version": "6.1.1", |
||||
|
"sd_fwid": "0x00B6" |
||||
|
}, |
||||
|
"bootloader": { |
||||
|
"settings_addr": "0xFF000" |
||||
|
} |
||||
|
}, |
||||
|
"connectivity": [ |
||||
|
"bluetooth" |
||||
|
], |
||||
|
"debug": { |
||||
|
"jlink_device": "nRF52840_xxAA", |
||||
|
"svd_path": "nrf52840.svd", |
||||
|
"openocd_target": "nrf52.cfg" |
||||
|
}, |
||||
|
"frameworks": [ |
||||
|
"arduino" |
||||
|
], |
||||
|
"name": "Heltec Mesh Solar Board", |
||||
|
"upload": { |
||||
|
"maximum_ram_size": 248832, |
||||
|
"maximum_size": 815104, |
||||
|
"speed": 115200, |
||||
|
"protocol": "nrfutil", |
||||
|
"protocols": [ |
||||
|
"jlink", |
||||
|
"nrfjprog", |
||||
|
"nrfutil", |
||||
|
"stlink" |
||||
|
], |
||||
|
"use_1200bps_touch": true, |
||||
|
"require_upload_port": true, |
||||
|
"wait_for_upload_port": true |
||||
|
}, |
||||
|
"url": "https://heltec.org/", |
||||
|
"vendor": "Heltec" |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"ldscript": "esp32s3_out.ld", |
||||
|
"partitions": "default_16MB.csv", |
||||
|
"memory_type": "qio_opi" |
||||
|
}, |
||||
|
"core": "esp32", |
||||
|
"extra_flags": [ |
||||
|
"-DBOARD_HAS_PSRAM", |
||||
|
"-DARDUINO_USB_MODE=0", |
||||
|
"-DARDUINO_USB_CDC_ON_BOOT=1", |
||||
|
"-DARDUINO_RUNNING_CORE=1", |
||||
|
"-DARDUINO_EVENT_RUNNING_CORE=1" |
||||
|
], |
||||
|
"f_cpu": "240000000L", |
||||
|
"f_flash": "80000000L", |
||||
|
"flash_mode": "qio", |
||||
|
"psram_type": "opi", |
||||
|
"hwids": [ |
||||
|
["0x303A", "0x1001"], |
||||
|
["0x303A", "0x0002"] |
||||
|
], |
||||
|
"mcu": "esp32s3", |
||||
|
"variant": "heltec_vision_master_e213" |
||||
|
}, |
||||
|
"connectivity": ["wifi", "bluetooth", "lora"], |
||||
|
"debug": { |
||||
|
"openocd_target": "esp32s3.cfg" |
||||
|
}, |
||||
|
"frameworks": ["arduino", "espidf"], |
||||
|
"name": "Heltec Vision Master E213", |
||||
|
"upload": { |
||||
|
"flash_size": "16MB", |
||||
|
"maximum_ram_size": 8388608, |
||||
|
"maximum_size": 16777216, |
||||
|
"use_1200bps_touch": true, |
||||
|
"wait_for_upload_port": true, |
||||
|
"require_upload_port": true, |
||||
|
"speed": 921600 |
||||
|
}, |
||||
|
"url": "https://heltec.org/project/vision-master-e213/", |
||||
|
"vendor": "Heltec" |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"ldscript": "esp32s3_out.ld", |
||||
|
"partitions": "default_16MB.csv", |
||||
|
"memory_type": "qio_opi" |
||||
|
}, |
||||
|
"core": "esp32", |
||||
|
"extra_flags": [ |
||||
|
"-DBOARD_HAS_PSRAM", |
||||
|
"-DARDUINO_USB_MODE=0", |
||||
|
"-DARDUINO_USB_CDC_ON_BOOT=1", |
||||
|
"-DARDUINO_RUNNING_CORE=1", |
||||
|
"-DARDUINO_EVENT_RUNNING_CORE=1" |
||||
|
], |
||||
|
"f_cpu": "240000000L", |
||||
|
"f_flash": "80000000L", |
||||
|
"flash_mode": "qio", |
||||
|
"psram_type": "opi", |
||||
|
"hwids": [ |
||||
|
["0x303A", "0x1001"], |
||||
|
["0x303A", "0x0002"] |
||||
|
], |
||||
|
"mcu": "esp32s3", |
||||
|
"variant": "heltec_vision_master_e290" |
||||
|
}, |
||||
|
"connectivity": ["wifi", "bluetooth", "lora"], |
||||
|
"debug": { |
||||
|
"openocd_target": "esp32s3.cfg" |
||||
|
}, |
||||
|
"frameworks": ["arduino", "espidf"], |
||||
|
"name": "Heltec Vision Master E290", |
||||
|
"upload": { |
||||
|
"flash_size": "16MB", |
||||
|
"maximum_ram_size": 8388608, |
||||
|
"maximum_size": 16777216, |
||||
|
"use_1200bps_touch": true, |
||||
|
"wait_for_upload_port": true, |
||||
|
"require_upload_port": true, |
||||
|
"speed": 921600 |
||||
|
}, |
||||
|
"url": "https://heltec.org/project/vision-master-e290/", |
||||
|
"vendor": "Heltec" |
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <helpers/ui/DisplayDriver.h> |
||||
|
#include <helpers/ui/UIScreen.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#include <helpers/BaseSerialInterface.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#ifdef PIN_BUZZER |
||||
|
#include <helpers/ui/buzzer.h> |
||||
|
#endif |
||||
|
|
||||
|
#include "NodePrefs.h" |
||||
|
|
||||
|
enum class UIEventType { |
||||
|
none, |
||||
|
contactMessage, |
||||
|
channelMessage, |
||||
|
roomMessage, |
||||
|
newContactMessage, |
||||
|
ack |
||||
|
}; |
||||
|
|
||||
|
class AbstractUITask { |
||||
|
protected: |
||||
|
mesh::MainBoard* _board; |
||||
|
BaseSerialInterface* _serial; |
||||
|
bool _connected; |
||||
|
|
||||
|
AbstractUITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial) { |
||||
|
_connected = false; |
||||
|
} |
||||
|
|
||||
|
public: |
||||
|
void setHasConnection(bool connected) { _connected = connected; } |
||||
|
bool hasConnection() const { return _connected; } |
||||
|
uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); } |
||||
|
bool isSerialEnabled() const { return _serial->isEnabled(); } |
||||
|
void enableSerial() { _serial->enable(); } |
||||
|
void disableSerial() { _serial->disable(); } |
||||
|
virtual void msgRead(int msgcount) = 0; |
||||
|
virtual void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) = 0; |
||||
|
virtual void soundBuzzer(UIEventType bet = UIEventType::none) = 0; |
||||
|
virtual void loop() = 0; |
||||
|
}; |
||||
@ -0,0 +1,597 @@ |
|||||
|
#include "UITask.h" |
||||
|
#include <helpers/TxtDataHelpers.h> |
||||
|
#include "../MyMesh.h" |
||||
|
#include "target.h" |
||||
|
|
||||
|
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
||||
|
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
|
||||
|
|
||||
|
#ifdef PIN_STATUS_LED |
||||
|
#define LED_ON_MILLIS 20 |
||||
|
#define LED_ON_MSG_MILLIS 200 |
||||
|
#define LED_CYCLE_MILLIS 4000 |
||||
|
#endif |
||||
|
|
||||
|
#define LONG_PRESS_MILLIS 1200 |
||||
|
|
||||
|
#ifndef UI_RECENT_LIST_SIZE |
||||
|
#define UI_RECENT_LIST_SIZE 4 |
||||
|
#endif |
||||
|
|
||||
|
#define PRESS_LABEL "long press" |
||||
|
|
||||
|
#include "icons.h" |
||||
|
|
||||
|
class SplashScreen : public UIScreen { |
||||
|
UITask* _task; |
||||
|
unsigned long dismiss_after; |
||||
|
char _version_info[12]; |
||||
|
|
||||
|
public: |
||||
|
SplashScreen(UITask* task) : _task(task) { |
||||
|
// strip off dash and commit hash by changing dash to null terminator
|
||||
|
// e.g: v1.2.3-abcdef -> v1.2.3
|
||||
|
const char *ver = FIRMWARE_VERSION; |
||||
|
const char *dash = strchr(ver, '-'); |
||||
|
|
||||
|
int len = dash ? dash - ver : strlen(ver); |
||||
|
if (len >= sizeof(_version_info)) len = sizeof(_version_info) - 1; |
||||
|
memcpy(_version_info, ver, len); |
||||
|
_version_info[len] = 0; |
||||
|
|
||||
|
dismiss_after = millis() + BOOT_SCREEN_MILLIS; |
||||
|
} |
||||
|
|
||||
|
int render(DisplayDriver& display) override { |
||||
|
// meshcore logo
|
||||
|
display.setColor(DisplayDriver::BLUE); |
||||
|
int logoWidth = 128; |
||||
|
display.drawXbm((display.width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); |
||||
|
|
||||
|
// version info
|
||||
|
display.setColor(DisplayDriver::LIGHT); |
||||
|
display.setTextSize(2); |
||||
|
display.drawTextCentered(display.width()/2, 22, _version_info); |
||||
|
|
||||
|
display.setTextSize(1); |
||||
|
display.drawTextCentered(display.width()/2, 42, FIRMWARE_BUILD_DATE); |
||||
|
|
||||
|
return 1000; |
||||
|
} |
||||
|
|
||||
|
void poll() override { |
||||
|
if (millis() >= dismiss_after) { |
||||
|
_task->gotoHomeScreen(); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
class HomeScreen : public UIScreen { |
||||
|
enum HomePage { |
||||
|
FIRST, |
||||
|
RECENT, |
||||
|
RADIO, |
||||
|
BLUETOOTH, |
||||
|
ADVERT, |
||||
|
SHUTDOWN, |
||||
|
Count // keep as last
|
||||
|
}; |
||||
|
|
||||
|
UITask* _task; |
||||
|
mesh::RTCClock* _rtc; |
||||
|
SensorManager* _sensors; |
||||
|
NodePrefs* _node_prefs; |
||||
|
uint8_t _page; |
||||
|
bool _shutdown_init; |
||||
|
AdvertPath recent[UI_RECENT_LIST_SIZE]; |
||||
|
|
||||
|
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) { |
||||
|
// Convert millivolts to percentage
|
||||
|
const int minMilliVolts = 3000; // Minimum voltage (e.g., 3.0V)
|
||||
|
const int maxMilliVolts = 4200; // Maximum voltage (e.g., 4.2V)
|
||||
|
int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts); |
||||
|
if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0%
|
||||
|
if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100%
|
||||
|
|
||||
|
// battery icon
|
||||
|
int iconWidth = 24; |
||||
|
int iconHeight = 10; |
||||
|
int iconX = display.width() - iconWidth - 5; // Position the icon near the top-right corner
|
||||
|
int iconY = 0; |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
|
||||
|
// battery outline
|
||||
|
display.drawRect(iconX, iconY, iconWidth, iconHeight); |
||||
|
|
||||
|
// battery "cap"
|
||||
|
display.fillRect(iconX + iconWidth, iconY + (iconHeight / 4), 3, iconHeight / 2); |
||||
|
|
||||
|
// fill the battery based on the percentage
|
||||
|
int fillWidth = (batteryPercentage * (iconWidth - 4)) / 100; |
||||
|
display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4); |
||||
|
} |
||||
|
|
||||
|
public: |
||||
|
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs) |
||||
|
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0), _shutdown_init(false) { } |
||||
|
|
||||
|
void poll() override { |
||||
|
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
|
||||
|
_task->shutdown(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int render(DisplayDriver& display) override { |
||||
|
char tmp[80]; |
||||
|
// node name
|
||||
|
display.setCursor(0, 0); |
||||
|
display.setTextSize(1); |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
display.print(_node_prefs->node_name); |
||||
|
|
||||
|
// battery voltage
|
||||
|
renderBatteryIndicator(display, _task->getBattMilliVolts()); |
||||
|
|
||||
|
// curr page indicator
|
||||
|
int y = 14; |
||||
|
int x = display.width() / 2 - 25; |
||||
|
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) { |
||||
|
if (i == _page) { |
||||
|
display.fillRect(x-1, y-1, 3, 3); |
||||
|
} else { |
||||
|
display.fillRect(x, y, 1, 1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (_page == HomePage::FIRST) { |
||||
|
display.setColor(DisplayDriver::YELLOW); |
||||
|
display.setTextSize(2); |
||||
|
sprintf(tmp, "MSG: %d", _task->getMsgCount()); |
||||
|
display.drawTextCentered(display.width() / 2, 20, tmp); |
||||
|
|
||||
|
if (_task->hasConnection()) { |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
display.setTextSize(1); |
||||
|
display.drawTextCentered(display.width() / 2, 43, "< Connected >"); |
||||
|
} else if (the_mesh.getBLEPin() != 0) { // BT pin
|
||||
|
display.setColor(DisplayDriver::RED); |
||||
|
display.setTextSize(2); |
||||
|
sprintf(tmp, "Pin:%d", the_mesh.getBLEPin()); |
||||
|
display.drawTextCentered(display.width() / 2, 43, tmp); |
||||
|
} |
||||
|
} else if (_page == HomePage::RECENT) { |
||||
|
the_mesh.getRecentlyHeard(recent, UI_RECENT_LIST_SIZE); |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
int y = 20; |
||||
|
for (int i = 0; i < UI_RECENT_LIST_SIZE; i++, y += 11) { |
||||
|
auto a = &recent[i]; |
||||
|
if (a->name[0] == 0) continue; // empty slot
|
||||
|
display.setCursor(0, y); |
||||
|
display.print(a->name); |
||||
|
int secs = _rtc->getCurrentTime() - a->recv_timestamp; |
||||
|
if (secs < 60) { |
||||
|
sprintf(tmp, "%ds", secs); |
||||
|
} else if (secs < 60*60) { |
||||
|
sprintf(tmp, "%dm", secs / 60); |
||||
|
} else { |
||||
|
sprintf(tmp, "%dh", secs / (60*60)); |
||||
|
} |
||||
|
display.setCursor(display.width() - display.getTextWidth(tmp) - 1, y); |
||||
|
display.print(tmp); |
||||
|
} |
||||
|
} else if (_page == HomePage::RADIO) { |
||||
|
display.setColor(DisplayDriver::YELLOW); |
||||
|
display.setTextSize(1); |
||||
|
// freq / sf
|
||||
|
display.setCursor(0, 20); |
||||
|
sprintf(tmp, "FQ: %06.3f SF: %d", _node_prefs->freq, _node_prefs->sf); |
||||
|
display.print(tmp); |
||||
|
|
||||
|
display.setCursor(0, 31); |
||||
|
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); |
||||
|
display.print(tmp); |
||||
|
|
||||
|
// tx power, noise floor
|
||||
|
display.setCursor(0, 42); |
||||
|
sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm); |
||||
|
display.print(tmp); |
||||
|
display.setCursor(0, 53); |
||||
|
sprintf(tmp, "Noise floor: %d", radio_driver.getNoiseFloor()); |
||||
|
display.print(tmp); |
||||
|
} else if (_page == HomePage::BLUETOOTH) { |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
display.drawXbm((display.width() - 32) / 2, 18, |
||||
|
_task->isSerialEnabled() ? bluetooth_on : bluetooth_off, |
||||
|
32, 32); |
||||
|
display.setTextSize(1); |
||||
|
display.drawTextCentered(display.width() / 2, 64 - 11, "toggle: " PRESS_LABEL); |
||||
|
} else if (_page == HomePage::ADVERT) { |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32); |
||||
|
display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL); |
||||
|
} else if (_page == HomePage::SHUTDOWN) { |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
display.setTextSize(1); |
||||
|
if (_shutdown_init) { |
||||
|
display.drawTextCentered(display.width() / 2, 34, "shutting down..."); |
||||
|
} else { |
||||
|
display.drawXbm((display.width() - 32) / 2, 18, power_icon, 32, 32); |
||||
|
display.drawTextCentered(display.width() / 2, 64 - 11, "off: " PRESS_LABEL); |
||||
|
} |
||||
|
} |
||||
|
return 5000; // next render after 5000 ms
|
||||
|
} |
||||
|
|
||||
|
bool handleInput(char c) override { |
||||
|
if (c == KEY_LEFT) { |
||||
|
_page = (_page + HomePage::Count - 1) % HomePage::Count; |
||||
|
return true; |
||||
|
} |
||||
|
if (c == KEY_RIGHT || c == KEY_SELECT) { |
||||
|
_page = (_page + 1) % HomePage::Count; |
||||
|
if (_page == HomePage::RECENT) { |
||||
|
_task->showAlert("Recent adverts", 800); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) { |
||||
|
if (_task->isSerialEnabled()) { // toggle Bluetooth on/off
|
||||
|
_task->disableSerial(); |
||||
|
} else { |
||||
|
_task->enableSerial(); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
if (c == KEY_ENTER && _page == HomePage::ADVERT) { |
||||
|
#ifdef PIN_BUZZER |
||||
|
_task->soundBuzzer(UIEventType::ack); |
||||
|
#endif |
||||
|
if (the_mesh.advert()) { |
||||
|
_task->showAlert("Advert sent!", 1000); |
||||
|
} else { |
||||
|
_task->showAlert("Advert failed..", 1000); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) { |
||||
|
_shutdown_init = true; // need to wait for button to be released
|
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
class MsgPreviewScreen : public UIScreen { |
||||
|
UITask* _task; |
||||
|
mesh::RTCClock* _rtc; |
||||
|
|
||||
|
struct MsgEntry { |
||||
|
uint32_t timestamp; |
||||
|
char origin[62]; |
||||
|
char msg[78]; |
||||
|
}; |
||||
|
#define MAX_UNREAD_MSGS 32 |
||||
|
int num_unread; |
||||
|
MsgEntry unread[MAX_UNREAD_MSGS]; |
||||
|
|
||||
|
public: |
||||
|
MsgPreviewScreen(UITask* task, mesh::RTCClock* rtc) : _task(task), _rtc(rtc) { num_unread = 0; } |
||||
|
|
||||
|
void addPreview(uint8_t path_len, const char* from_name, const char* msg) { |
||||
|
if (num_unread >= MAX_UNREAD_MSGS) return; // full
|
||||
|
|
||||
|
auto p = &unread[num_unread++]; |
||||
|
p->timestamp = _rtc->getCurrentTime(); |
||||
|
if (path_len == 0xFF) { |
||||
|
sprintf(p->origin, "(D) %s:", from_name); |
||||
|
} else { |
||||
|
sprintf(p->origin, "(%d) %s:", (uint32_t) path_len, from_name); |
||||
|
} |
||||
|
StrHelper::strncpy(p->msg, msg, sizeof(p->msg)); |
||||
|
} |
||||
|
|
||||
|
int render(DisplayDriver& display) override { |
||||
|
char tmp[16]; |
||||
|
display.setCursor(0, 0); |
||||
|
display.setTextSize(1); |
||||
|
display.setColor(DisplayDriver::GREEN); |
||||
|
sprintf(tmp, "Unread: %d", num_unread); |
||||
|
display.print(tmp); |
||||
|
|
||||
|
auto p = &unread[0]; |
||||
|
|
||||
|
int secs = _rtc->getCurrentTime() - p->timestamp; |
||||
|
if (secs < 60) { |
||||
|
sprintf(tmp, "%ds", secs); |
||||
|
} else if (secs < 60*60) { |
||||
|
sprintf(tmp, "%dm", secs / 60); |
||||
|
} else { |
||||
|
sprintf(tmp, "%dh", secs / (60*60)); |
||||
|
} |
||||
|
display.setCursor(display.width() - display.getTextWidth(tmp) - 2, 0); |
||||
|
display.print(tmp); |
||||
|
|
||||
|
display.drawRect(0, 11, display.width(), 1); // horiz line
|
||||
|
|
||||
|
display.setCursor(0, 14); |
||||
|
display.setColor(DisplayDriver::YELLOW); |
||||
|
display.print(p->origin); |
||||
|
|
||||
|
display.setCursor(0, 25); |
||||
|
display.setColor(DisplayDriver::LIGHT); |
||||
|
display.printWordWrap(p->msg, display.width()); |
||||
|
|
||||
|
return 1000; // next render after 1000 ms
|
||||
|
} |
||||
|
|
||||
|
bool handleInput(char c) override { |
||||
|
if (c == KEY_SELECT || c == KEY_RIGHT) { |
||||
|
num_unread--; |
||||
|
if (num_unread == 0) { |
||||
|
_task->gotoHomeScreen(); |
||||
|
} else { |
||||
|
// delete first/curr item from unread queue
|
||||
|
for (int i = 0; i < num_unread; i++) { |
||||
|
unread[i] = unread[i + 1]; |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
if (c == KEY_ENTER) { |
||||
|
num_unread = 0; // clear unread queue
|
||||
|
_task->gotoHomeScreen(); |
||||
|
return true; |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) { |
||||
|
_display = display; |
||||
|
_sensors = sensors; |
||||
|
_auto_off = millis() + AUTO_OFF_MILLIS; |
||||
|
|
||||
|
#if defined(PIN_USER_BTN) |
||||
|
user_btn.begin(); |
||||
|
#endif |
||||
|
|
||||
|
_node_prefs = node_prefs; |
||||
|
if (_display != NULL) { |
||||
|
_display->turnOn(); |
||||
|
} |
||||
|
|
||||
|
#ifdef PIN_BUZZER |
||||
|
buzzer.begin(); |
||||
|
#endif |
||||
|
|
||||
|
ui_started_at = millis(); |
||||
|
_alert_expiry = 0; |
||||
|
|
||||
|
splash = new SplashScreen(this); |
||||
|
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs); |
||||
|
msg_preview = new MsgPreviewScreen(this, &rtc_clock); |
||||
|
setCurrScreen(splash); |
||||
|
} |
||||
|
|
||||
|
void UITask::showAlert(const char* text, int duration_millis) { |
||||
|
strcpy(_alert, text); |
||||
|
_alert_expiry = millis() + duration_millis; |
||||
|
} |
||||
|
|
||||
|
void UITask::soundBuzzer(UIEventType bet) { |
||||
|
#if defined(PIN_BUZZER) |
||||
|
switch(bet){ |
||||
|
case UIEventType::contactMessage: |
||||
|
// gemini's pick
|
||||
|
buzzer.play("MsgRcv3:d=4,o=6,b=200:32e,32g,32b,16c7"); |
||||
|
break; |
||||
|
case UIEventType::channelMessage: |
||||
|
buzzer.play("kerplop:d=16,o=6,b=120:32g#,32c#"); |
||||
|
break; |
||||
|
case UIEventType::ack: |
||||
|
buzzer.play("ack:d=32,o=8,b=120:c"); |
||||
|
break; |
||||
|
case UIEventType::roomMessage: |
||||
|
case UIEventType::newContactMessage: |
||||
|
case UIEventType::none: |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void UITask::msgRead(int msgcount) { |
||||
|
_msgcount = msgcount; |
||||
|
if (msgcount == 0) { |
||||
|
gotoHomeScreen(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) { |
||||
|
_msgcount = msgcount; |
||||
|
|
||||
|
((MsgPreviewScreen *) msg_preview)->addPreview(path_len, from_name, text); |
||||
|
setCurrScreen(msg_preview); |
||||
|
|
||||
|
if (_display != NULL) { |
||||
|
if (!_display->isOn()) _display->turnOn(); |
||||
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||
|
_next_refresh = 0; // trigger refresh
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void UITask::userLedHandler() { |
||||
|
#ifdef PIN_STATUS_LED |
||||
|
static int state = 0; |
||||
|
static int next_change = 0; |
||||
|
static int last_increment = 0; |
||||
|
|
||||
|
int cur_time = millis(); |
||||
|
if (cur_time > next_change) { |
||||
|
if (state == 0) { |
||||
|
state = 1; |
||||
|
if (_msgcount > 0) { |
||||
|
last_increment = LED_ON_MSG_MILLIS; |
||||
|
} else { |
||||
|
last_increment = LED_ON_MILLIS; |
||||
|
} |
||||
|
next_change = cur_time + last_increment; |
||||
|
} else { |
||||
|
state = 0; |
||||
|
next_change = cur_time + LED_CYCLE_MILLIS - last_increment; |
||||
|
} |
||||
|
digitalWrite(PIN_STATUS_LED, state); |
||||
|
} |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void UITask::setCurrScreen(UIScreen* c) { |
||||
|
curr = c; |
||||
|
_next_refresh = 0; |
||||
|
} |
||||
|
|
||||
|
/*
|
||||
|
hardware-agnostic pre-shutdown activity should be done here |
||||
|
*/ |
||||
|
void UITask::shutdown(bool restart){ |
||||
|
|
||||
|
#ifdef PIN_BUZZER |
||||
|
/* note: we have a choice here -
|
||||
|
we can do a blocking buzzer.loop() with non-deterministic consequences |
||||
|
or we can set a flag and delay the shutdown for a couple of seconds |
||||
|
while a non-blocking buzzer.loop() plays out in UITask::loop() |
||||
|
*/ |
||||
|
buzzer.shutdown(); |
||||
|
uint32_t buzzer_timer = millis(); // fail-safe shutdown
|
||||
|
while (buzzer.isPlaying() && (millis() - 2500) < buzzer_timer) |
||||
|
buzzer.loop(); |
||||
|
|
||||
|
#endif // PIN_BUZZER
|
||||
|
|
||||
|
if (restart) { |
||||
|
_board->reboot(); |
||||
|
} else { |
||||
|
_display->turnOff(); |
||||
|
_board->powerOff(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool UITask::isButtonPressed() const { |
||||
|
#ifdef PIN_USER_BTN |
||||
|
return user_btn.isPressed(); |
||||
|
#else |
||||
|
return false; |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void UITask::loop() { |
||||
|
char c = 0; |
||||
|
#if defined(PIN_USER_BTN) |
||||
|
int ev = user_btn.check(); |
||||
|
if (ev == BUTTON_EVENT_CLICK) { |
||||
|
c = checkDisplayOn(KEY_SELECT); |
||||
|
} else if (ev == BUTTON_EVENT_LONG_PRESS) { |
||||
|
c = handleLongPress(KEY_ENTER); |
||||
|
} |
||||
|
#endif |
||||
|
#if defined(WIO_TRACKER_L1) |
||||
|
ev = joystick_left.check(); |
||||
|
if (ev == BUTTON_EVENT_CLICK) { |
||||
|
c = checkDisplayOn(KEY_LEFT); |
||||
|
} else if (ev == BUTTON_EVENT_LONG_PRESS) { |
||||
|
c = handleLongPress(KEY_LEFT); |
||||
|
} |
||||
|
ev = joystick_right.check(); |
||||
|
if (ev == BUTTON_EVENT_CLICK) { |
||||
|
c = checkDisplayOn(KEY_RIGHT); |
||||
|
} else if (ev == BUTTON_EVENT_LONG_PRESS) { |
||||
|
c = handleLongPress(KEY_RIGHT); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
if (c != 0 && curr) { |
||||
|
curr->handleInput(c); |
||||
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
|
_next_refresh = 0; // trigger refresh
|
||||
|
} |
||||
|
|
||||
|
userLedHandler(); |
||||
|
|
||||
|
#ifdef PIN_BUZZER |
||||
|
if (buzzer.isPlaying()) buzzer.loop(); |
||||
|
#endif |
||||
|
|
||||
|
if (curr) curr->poll(); |
||||
|
|
||||
|
if (_display != NULL && _display->isOn()) { |
||||
|
if (millis() >= _next_refresh && curr) { |
||||
|
_display->startFrame(); |
||||
|
int delay_millis = curr->render(*_display); |
||||
|
if (millis() < _alert_expiry) { // render alert popup
|
||||
|
_display->setTextSize(1); |
||||
|
int y = _display->height() / 3; |
||||
|
int p = _display->height() / 32; |
||||
|
_display->setColor(DisplayDriver::DARK); |
||||
|
_display->fillRect(p, y, _display->width() - p*2, y); |
||||
|
_display->setColor(DisplayDriver::LIGHT); // draw box border
|
||||
|
_display->drawRect(p, y, _display->width() - p*2, y); |
||||
|
_display->drawTextCentered(_display->width() / 2, y + p*3, _alert); |
||||
|
_next_refresh = _alert_expiry; // will need refresh when alert is dismissed
|
||||
|
} else { |
||||
|
_next_refresh = millis() + delay_millis; |
||||
|
} |
||||
|
_display->endFrame(); |
||||
|
} |
||||
|
if (millis() > _auto_off) { |
||||
|
_display->turnOff(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#ifdef AUTO_SHUTDOWN_MILLIVOLTS |
||||
|
if (millis() > next_batt_chck) { |
||||
|
uint16_t milliVolts = getBattMilliVolts(); |
||||
|
if (milliVolts > 0 && milliVolts < AUTO_SHUTDOWN_MILLIVOLTS) { |
||||
|
shutdown(); |
||||
|
} |
||||
|
next_batt_chck = millis() + 8000; |
||||
|
} |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
char UITask::checkDisplayOn(char c) { |
||||
|
if (_display != NULL) { |
||||
|
if (!_display->isOn()) { |
||||
|
_display->turnOn(); // turn display on and consume event
|
||||
|
c = 0; |
||||
|
} |
||||
|
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
|
_next_refresh = 0; // trigger refresh
|
||||
|
} |
||||
|
return c; |
||||
|
} |
||||
|
|
||||
|
char UITask::handleLongPress(char c) { |
||||
|
if (millis() - ui_started_at < 8000) { // long press in first 8 seconds since startup -> CLI/rescue
|
||||
|
the_mesh.enterCLIRescue(); |
||||
|
c = 0; // consume event
|
||||
|
} |
||||
|
return c; |
||||
|
} |
||||
|
|
||||
|
/*
|
||||
|
void UITask::handleButtonTriplePress() { |
||||
|
MESH_DEBUG_PRINTLN("UITask: triple press triggered"); |
||||
|
// Toggle buzzer quiet mode
|
||||
|
#ifdef PIN_BUZZER |
||||
|
if (buzzer.isQuiet()) { |
||||
|
buzzer.quiet(false); |
||||
|
soundBuzzer(UIEventType::ack); |
||||
|
showAlert("Buzzer: ON", 600); |
||||
|
} else { |
||||
|
buzzer.quiet(true); |
||||
|
showAlert("Buzzer: OFF", 600); |
||||
|
} |
||||
|
_next_refresh = 0; // trigger refresh
|
||||
|
#endif |
||||
|
} |
||||
|
*/ |
||||
@ -0,0 +1,65 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <helpers/ui/DisplayDriver.h> |
||||
|
#include <helpers/ui/UIScreen.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#include <helpers/BaseSerialInterface.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#ifdef PIN_BUZZER |
||||
|
#include <helpers/ui/buzzer.h> |
||||
|
#endif |
||||
|
|
||||
|
#include "../AbstractUITask.h" |
||||
|
#include "../NodePrefs.h" |
||||
|
|
||||
|
class UITask : public AbstractUITask { |
||||
|
DisplayDriver* _display; |
||||
|
SensorManager* _sensors; |
||||
|
#ifdef PIN_BUZZER |
||||
|
genericBuzzer buzzer; |
||||
|
#endif |
||||
|
unsigned long _next_refresh, _auto_off; |
||||
|
NodePrefs* _node_prefs; |
||||
|
char _alert[80]; |
||||
|
unsigned long _alert_expiry; |
||||
|
int _msgcount; |
||||
|
unsigned long ui_started_at, next_batt_chck; |
||||
|
|
||||
|
UIScreen* splash; |
||||
|
UIScreen* home; |
||||
|
UIScreen* msg_preview; |
||||
|
UIScreen* curr; |
||||
|
|
||||
|
void userLedHandler(); |
||||
|
|
||||
|
// Button action handlers
|
||||
|
char checkDisplayOn(char c); |
||||
|
char handleLongPress(char c); |
||||
|
|
||||
|
void setCurrScreen(UIScreen* c); |
||||
|
|
||||
|
public: |
||||
|
|
||||
|
UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) { |
||||
|
next_batt_chck = _next_refresh = 0; |
||||
|
ui_started_at = 0; |
||||
|
curr = NULL; |
||||
|
} |
||||
|
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs); |
||||
|
|
||||
|
void gotoHomeScreen() { setCurrScreen(home); } |
||||
|
void showAlert(const char* text, int duration_millis); |
||||
|
int getMsgCount() const { return _msgcount; } |
||||
|
bool hasDisplay() const { return _display != NULL; } |
||||
|
bool isButtonPressed() const; |
||||
|
|
||||
|
// from AbstractUITask
|
||||
|
void msgRead(int msgcount) override; |
||||
|
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override; |
||||
|
void soundBuzzer(UIEventType bet = UIEventType::none) override; |
||||
|
void loop() override; |
||||
|
|
||||
|
void shutdown(bool restart = false); |
||||
|
}; |
||||
@ -0,0 +1,118 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
// 'meshcore', 128x13px
|
||||
|
static const uint8_t meshcore_logo [] = { |
||||
|
0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, |
||||
|
0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe, |
||||
|
0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc, |
||||
|
0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00, |
||||
|
0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00, |
||||
|
0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
||||
|
0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
||||
|
0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0, |
||||
|
0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00, |
||||
|
0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00, |
||||
|
0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8, |
||||
|
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8, |
||||
|
0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t bluetooth_on[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x30, 0x00, 0x00, |
||||
|
0x00, 0x3C, 0x00, 0x00, |
||||
|
0x00, 0x3E, 0x00, 0x00, |
||||
|
0x00, 0x3F, 0x80, 0x00, |
||||
|
0x00, 0x3F, 0xC0, 0x00, |
||||
|
0x00, 0x3B, 0xE0, 0x00, |
||||
|
0x30, 0x38, 0xF8, 0x00, |
||||
|
0x3C, 0x38, 0x7C, 0x00, |
||||
|
0x3E, 0x38, 0x7C, 0x00, |
||||
|
0x1F, 0xB8, 0xF8, 0x70, |
||||
|
0x07, 0xF9, 0xF0, 0x78, |
||||
|
0x03, 0xFF, 0xC0, 0x78, |
||||
|
0x00, 0xFF, 0x80, 0x3C, |
||||
|
0x00, 0x7F, 0x07, 0x1C, |
||||
|
0x00, 0x7E, 0x07, 0x1C, |
||||
|
0x03, 0xFF, 0x82, 0x1C, |
||||
|
0x03, 0xFF, 0xC0, 0x78, |
||||
|
0x07, 0xFB, 0xE0, 0x78, |
||||
|
0x0F, 0xB8, 0xF8, 0x70, |
||||
|
0x3E, 0x38, 0x7C, 0x00, |
||||
|
0x3C, 0x38, 0x7C, 0x00, |
||||
|
0x38, 0x38, 0xF8, 0x00, |
||||
|
0x00, 0x39, 0xF0, 0x00, |
||||
|
0x00, 0x3F, 0xC0, 0x00, |
||||
|
0x00, 0x3F, 0x80, 0x00, |
||||
|
0x00, 0x3E, 0x00, 0x00, |
||||
|
0x00, 0x3C, 0x00, 0x00, |
||||
|
0x00, 0x38, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t bluetooth_off[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x03, 0x80, 0x00, |
||||
|
0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x03, 0xE0, 0x00, |
||||
|
0x38, 0x03, 0xF8, 0x00, |
||||
|
0x3C, 0x03, 0xFC, 0x00, |
||||
|
0x3E, 0x03, 0xBF, 0x00, |
||||
|
0x0F, 0x83, 0x8F, 0x80, |
||||
|
0x07, 0xC3, 0x87, 0xC0, |
||||
|
0x03, 0xF0, 0x03, 0xC0, |
||||
|
0x00, 0xF8, 0x0F, 0x80, |
||||
|
0x00, 0x7C, 0x0F, 0x00, |
||||
|
0x00, 0x1F, 0x0E, 0x00, |
||||
|
0x00, 0x0F, 0x80, 0x00, |
||||
|
0x00, 0x07, 0xE0, 0x00, |
||||
|
0x00, 0x07, 0xF0, 0x00, |
||||
|
0x00, 0x0F, 0xF8, 0x00, |
||||
|
0x00, 0x3F, 0xBE, 0x00, |
||||
|
0x00, 0x7F, 0x9F, 0x00, |
||||
|
0x00, 0xFB, 0x8F, 0xC0, |
||||
|
0x03, 0xE3, 0x83, 0xE0, |
||||
|
0x03, 0xC3, 0x87, 0xF0, |
||||
|
0x03, 0x83, 0x8F, 0xFC, |
||||
|
0x00, 0x03, 0xBF, 0x3C, |
||||
|
0x00, 0x03, 0xFC, 0x1C, |
||||
|
0x00, 0x03, 0xF8, 0x00, |
||||
|
0x00, 0x03, 0xE0, 0x00, |
||||
|
0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x03, 0x80, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t power_icon[] = { |
||||
|
0x00, 0x01, 0x80, 0x00, 0x00, 0x03, 0xC0, 0x00, 0x00, 0x03, 0xC0, 0x00, |
||||
|
0x00, 0x33, 0xCC, 0x00, 0x00, 0xF3, 0xCF, 0x00, 0x01, 0xF3, 0xCF, 0x80, |
||||
|
0x03, 0xF3, 0xCF, 0xC0, 0x07, 0xF3, 0xCF, 0xE0, 0x0F, 0xE3, 0xC7, 0xF0, |
||||
|
0x1F, 0xC3, 0xC3, 0xF8, 0x1F, 0x83, 0xC1, 0xF8, 0x3F, 0x03, 0xC0, 0xFC, |
||||
|
0x3E, 0x03, 0xC0, 0x7C, 0x3E, 0x03, 0xC0, 0x7C, 0x7E, 0x01, 0x80, 0x7E, |
||||
|
0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, |
||||
|
0x7C, 0x00, 0x00, 0x3E, 0x7C, 0x00, 0x00, 0x3E, 0x3E, 0x00, 0x00, 0x7C, |
||||
|
0x3E, 0x00, 0x00, 0x7C, 0x3F, 0x00, 0x00, 0xFC, 0x1F, 0x80, 0x01, 0xF8, |
||||
|
0x1F, 0xC0, 0x03, 0xF8, 0x0F, 0xE0, 0x07, 0xF0, 0x0F, 0xF8, 0x1F, 0xF0, |
||||
|
0x07, 0xFF, 0xFF, 0xE0, 0x03, 0xFF, 0xFF, 0xC0, 0x00, 0xFF, 0xFF, 0x00, |
||||
|
0x00, 0x3F, 0xFC, 0x00, 0x00, 0x0F, 0xF0, 0x00, |
||||
|
}; |
||||
|
|
||||
|
static const uint8_t advert_icon[] = { |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x30, |
||||
|
0x1C, 0x00, 0x00, 0x38, 0x18, 0x00, 0x00, 0x18, 0x30, 0x00, 0x00, 0x0C, |
||||
|
0x30, 0x60, 0x06, 0x0C, 0x60, 0xE0, 0x07, 0x06, 0x61, 0xC0, 0x03, 0x86, |
||||
|
0xE1, 0x81, 0x81, 0x87, 0xC3, 0x07, 0xE0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, |
||||
|
0xC3, 0x0F, 0xF0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, 0xC3, 0x0F, 0xF0, 0xC3, |
||||
|
0xC3, 0x07, 0xE0, 0xC3, 0xC1, 0x83, 0xC1, 0x83, 0x61, 0x80, 0x01, 0x86, |
||||
|
0x60, 0xC0, 0x03, 0x06, 0x70, 0xE0, 0x07, 0x0E, 0x30, 0x40, 0x02, 0x0C, |
||||
|
0x38, 0x00, 0x00, 0x1C, 0x18, 0x00, 0x00, 0x18, 0x0C, 0x00, 0x00, 0x30, |
||||
|
0x04, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||||
|
}; |
||||
@ -1,8 +1,7 @@ |
|||||
#include "UITask.h" |
#include "UITask.h" |
||||
#include <Arduino.h> |
#include <Arduino.h> |
||||
#include <helpers/TxtDataHelpers.h> |
#include <helpers/TxtDataHelpers.h> |
||||
#include "NodePrefs.h" |
#include "../MyMesh.h" |
||||
#include "MyMesh.h" |
|
||||
|
|
||||
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
||||
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
|
#define BOOT_SCREEN_MILLIS 3000 // 3 seconds
|
||||
@ -0,0 +1,116 @@ |
|||||
|
#include "E290Display.h" |
||||
|
|
||||
|
#include "../../MeshCore.h" |
||||
|
|
||||
|
bool E290Display::begin() { |
||||
|
if (_init) return true; |
||||
|
|
||||
|
powerOn(); |
||||
|
display.begin(); |
||||
|
|
||||
|
// Set to landscape mode rotated 180 degrees
|
||||
|
display.setRotation(3); |
||||
|
|
||||
|
_init = true; |
||||
|
_isOn = true; |
||||
|
|
||||
|
clear(); |
||||
|
display.fastmodeOn(); // Enable fast mode for quicker (partial) updates
|
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void E290Display::powerOn() { |
||||
|
#ifdef PIN_VEXT_EN |
||||
|
pinMode(PIN_VEXT_EN, OUTPUT); |
||||
|
digitalWrite(PIN_VEXT_EN, PIN_VEXT_EN_ACTIVE); |
||||
|
delay(50); // Allow power to stabilize
|
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void E290Display::powerOff() { |
||||
|
#ifdef PIN_VEXT_EN |
||||
|
digitalWrite(PIN_VEXT_EN, !PIN_VEXT_EN_ACTIVE); // Turn off power
|
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
void E290Display::turnOn() { |
||||
|
if (!_init) begin(); |
||||
|
powerOn(); |
||||
|
_isOn = true; |
||||
|
} |
||||
|
|
||||
|
void E290Display::turnOff() { |
||||
|
powerOff(); |
||||
|
_isOn = false; |
||||
|
} |
||||
|
|
||||
|
void E290Display::clear() { |
||||
|
display.clear(); |
||||
|
} |
||||
|
|
||||
|
void E290Display::startFrame(Color bkg) { |
||||
|
// Fill screen with white first to ensure clean background
|
||||
|
display.fillRect(0, 0, width(), height(), WHITE); |
||||
|
if (bkg == LIGHT) { |
||||
|
// Fill with black if light background requested (inverted for e-ink)
|
||||
|
display.fillRect(0, 0, width(), height(), BLACK); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void E290Display::setTextSize(int sz) { |
||||
|
// The library handles text size internally
|
||||
|
display.setTextSize(sz); |
||||
|
} |
||||
|
|
||||
|
void E290Display::setColor(Color c) { |
||||
|
// implemented in individual display methods
|
||||
|
} |
||||
|
|
||||
|
void E290Display::setCursor(int x, int y) { |
||||
|
display.setCursor(x, y); |
||||
|
} |
||||
|
|
||||
|
void E290Display::print(const char *str) { |
||||
|
display.print(str); |
||||
|
} |
||||
|
|
||||
|
void E290Display::fillRect(int x, int y, int w, int h) { |
||||
|
display.fillRect(x, y, w, h, BLACK); |
||||
|
} |
||||
|
|
||||
|
void E290Display::drawRect(int x, int y, int w, int h) { |
||||
|
display.drawRect(x, y, w, h, BLACK); |
||||
|
} |
||||
|
|
||||
|
void E290Display::drawXbm(int x, int y, const uint8_t *bits, int w, int h) { |
||||
|
// Width in bytes for bitmap processing
|
||||
|
uint16_t widthInBytes = (w + 7) / 8; |
||||
|
|
||||
|
// Process the bitmap row by row
|
||||
|
for (int by = 0; by < h; by++) { |
||||
|
// Scan across the row bit by bit
|
||||
|
for (int bx = 0; bx < w; bx++) { |
||||
|
// Get the current bit using MSB ordering (like GxEPDDisplay)
|
||||
|
uint16_t byteOffset = (by * widthInBytes) + (bx / 8); |
||||
|
uint8_t bitMask = 0x80 >> (bx & 7); |
||||
|
bool bitSet = bits[byteOffset] & bitMask; |
||||
|
|
||||
|
// If the bit is set, draw the pixel
|
||||
|
if (bitSet) { |
||||
|
display.drawPixel(x + bx, y + by, BLACK); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
uint16_t E290Display::getTextWidth(const char *str) { |
||||
|
int16_t x1, y1; |
||||
|
uint16_t w, h; |
||||
|
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h); |
||||
|
return w; |
||||
|
} |
||||
|
|
||||
|
void E290Display::endFrame() { |
||||
|
display.update(); |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "DisplayDriver.h" |
||||
|
|
||||
|
#include <SPI.h> |
||||
|
#include <Wire.h> |
||||
|
#include <heltec-eink-modules.h> |
||||
|
|
||||
|
// Display driver for E290 e-ink display
|
||||
|
class E290Display : public DisplayDriver { |
||||
|
EInkDisplay_VisionMasterE290 display; |
||||
|
bool _init = false; |
||||
|
bool _isOn = false; |
||||
|
|
||||
|
public: |
||||
|
E290Display() : DisplayDriver(296, 128) {} |
||||
|
|
||||
|
bool begin(); |
||||
|
bool isOn() override { return _isOn; } |
||||
|
void turnOn() override; |
||||
|
void turnOff() override; |
||||
|
void clear() override; |
||||
|
void startFrame(Color bkg = DARK) override; |
||||
|
void setTextSize(int sz) override; |
||||
|
void setColor(Color c) override; |
||||
|
void setCursor(int x, int y) override; |
||||
|
void print(const char *str) override; |
||||
|
void fillRect(int x, int y, int w, int h) override; |
||||
|
void drawRect(int x, int y, int w, int h) override; |
||||
|
void drawXbm(int x, int y, const uint8_t *bits, int w, int h) override; |
||||
|
uint16_t getTextWidth(const char *str) override; |
||||
|
void endFrame() override; |
||||
|
|
||||
|
private: |
||||
|
void powerOn(); |
||||
|
void powerOff(); |
||||
|
}; |
||||
@ -0,0 +1,75 @@ |
|||||
|
#include "MomentaryButton.h" |
||||
|
|
||||
|
MomentaryButton::MomentaryButton(int8_t pin, int long_press_millis, bool reverse, bool pulldownup) { |
||||
|
_pin = pin; |
||||
|
_reverse = reverse; |
||||
|
_pull = pulldownup; |
||||
|
down_at = 0; |
||||
|
prev = _reverse ? HIGH : LOW; |
||||
|
cancel = 0; |
||||
|
_long_millis = long_press_millis; |
||||
|
} |
||||
|
|
||||
|
void MomentaryButton::begin() { |
||||
|
if (_pin >= 0) { |
||||
|
pinMode(_pin, _pull ? (_reverse ? INPUT_PULLUP : INPUT_PULLDOWN) : INPUT); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool MomentaryButton::isPressed() const { |
||||
|
return isPressed(digitalRead(_pin)); |
||||
|
} |
||||
|
|
||||
|
void MomentaryButton::cancelClick() { |
||||
|
cancel = 1; |
||||
|
} |
||||
|
|
||||
|
bool MomentaryButton::isPressed(int level) const { |
||||
|
if (_reverse) { |
||||
|
return level == LOW; |
||||
|
} else { |
||||
|
return level != LOW; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int MomentaryButton::check(bool repeat_click) { |
||||
|
if (_pin < 0) return BUTTON_EVENT_NONE; |
||||
|
|
||||
|
int event = BUTTON_EVENT_NONE; |
||||
|
int btn = digitalRead(_pin); |
||||
|
if (btn != prev) { |
||||
|
if (isPressed(btn)) { |
||||
|
down_at = millis(); |
||||
|
} else { |
||||
|
// button UP
|
||||
|
if (_long_millis > 0) { |
||||
|
if (down_at > 0 && (unsigned long)(millis() - down_at) < _long_millis) { // only a CLICK if still within the long_press millis
|
||||
|
event = BUTTON_EVENT_CLICK; |
||||
|
} |
||||
|
} else { |
||||
|
event = BUTTON_EVENT_CLICK; // any UP results in CLICK event when NOT using long_press feature
|
||||
|
} |
||||
|
if (event == BUTTON_EVENT_CLICK && cancel) { |
||||
|
event = BUTTON_EVENT_NONE; |
||||
|
} |
||||
|
down_at = 0; |
||||
|
} |
||||
|
prev = btn; |
||||
|
} |
||||
|
if (!isPressed(btn) && cancel) { // always clear the pending 'cancel' once button is back in UP state
|
||||
|
cancel = 0; |
||||
|
} |
||||
|
|
||||
|
if (_long_millis > 0 && down_at > 0 && (unsigned long)(millis() - down_at) >= _long_millis) { |
||||
|
event = BUTTON_EVENT_LONG_PRESS; |
||||
|
down_at = 0; |
||||
|
} |
||||
|
if (down_at > 0 && repeat_click) { |
||||
|
unsigned long diff = (unsigned long)(millis() - down_at); |
||||
|
if (diff >= 700) { |
||||
|
event = BUTTON_EVENT_CLICK; // wait 700 millis before repeating the click events
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return event; |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#define BUTTON_EVENT_NONE 0 |
||||
|
#define BUTTON_EVENT_CLICK 1 |
||||
|
#define BUTTON_EVENT_LONG_PRESS 2 |
||||
|
|
||||
|
class MomentaryButton { |
||||
|
int8_t _pin; |
||||
|
int8_t prev, cancel; |
||||
|
bool _reverse, _pull; |
||||
|
int _long_millis; |
||||
|
unsigned long down_at; |
||||
|
|
||||
|
bool isPressed(int level) const; |
||||
|
|
||||
|
public: |
||||
|
MomentaryButton(int8_t pin, int long_press_mills=0, bool reverse=false, bool pulldownup=false); |
||||
|
void begin(); |
||||
|
int check(bool repeat_click=false); // returns one of BUTTON_EVENT_*
|
||||
|
void cancelClick(); // suppress next BUTTON_EVENT_CLICK (if already in DOWN state)
|
||||
|
uint8_t getPin() { return _pin; } |
||||
|
bool isPressed() const; |
||||
|
}; |
||||
@ -0,0 +1,21 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "DisplayDriver.h" |
||||
|
|
||||
|
#define KEY_LEFT 0xB4 |
||||
|
#define KEY_UP 0xB5 |
||||
|
#define KEY_DOWN 0xB6 |
||||
|
#define KEY_RIGHT 0xB7 |
||||
|
#define KEY_SELECT 10 |
||||
|
#define KEY_ENTER 13 |
||||
|
#define KEY_BACK 27 // Esc
|
||||
|
|
||||
|
class UIScreen { |
||||
|
protected: |
||||
|
UIScreen() { } |
||||
|
public: |
||||
|
virtual int render(DisplayDriver& display) =0; // return value is number of millis until next render
|
||||
|
virtual bool handleInput(char c) { return false; } |
||||
|
virtual void poll() { } |
||||
|
}; |
||||
|
|
||||
@ -0,0 +1,77 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "MeshSolarBoard.h" |
||||
|
|
||||
|
#include <bluefruit.h> |
||||
|
#include <Wire.h> |
||||
|
|
||||
|
static BLEDfu bledfu; |
||||
|
|
||||
|
static void connect_callback(uint16_t conn_handle) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
MESH_DEBUG_PRINTLN("BLE client connected"); |
||||
|
} |
||||
|
|
||||
|
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
(void)reason; |
||||
|
|
||||
|
MESH_DEBUG_PRINTLN("BLE client disconnected"); |
||||
|
} |
||||
|
|
||||
|
void MeshSolarBoard::begin() { |
||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||
|
startup_reason = BD_STARTUP_NORMAL; |
||||
|
|
||||
|
meshSolarStart(); |
||||
|
|
||||
|
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL) |
||||
|
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL); |
||||
|
#endif |
||||
|
|
||||
|
Wire.begin(); |
||||
|
} |
||||
|
|
||||
|
bool MeshSolarBoard::startOTAUpdate(const char* id, char reply[]) { |
||||
|
// Config the peripheral connection with maximum bandwidth
|
||||
|
// more SRAM required by SoftDevice
|
||||
|
// Note: All config***() function must be called before begin()
|
||||
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); |
||||
|
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); |
||||
|
|
||||
|
Bluefruit.begin(1, 0); |
||||
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||
|
Bluefruit.setTxPower(4); |
||||
|
// Set the BLE device name
|
||||
|
Bluefruit.setName("MESH_SOLAR_OTA"); |
||||
|
|
||||
|
Bluefruit.Periph.setConnectCallback(connect_callback); |
||||
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback); |
||||
|
|
||||
|
// To be consistent OTA DFU should be added first if it exists
|
||||
|
bledfu.begin(); |
||||
|
|
||||
|
// Set up and start advertising
|
||||
|
// Advertising packet
|
||||
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
||||
|
Bluefruit.Advertising.addTxPower(); |
||||
|
Bluefruit.Advertising.addName(); |
||||
|
|
||||
|
/* Start Advertising
|
||||
|
- Enable auto advertising if disconnected |
||||
|
- Interval: fast mode = 20 ms, slow mode = 152.5 ms |
||||
|
- Timeout for fast mode is 30 seconds |
||||
|
- Start(timeout) with timeout = 0 will advertise forever (until connected) |
||||
|
|
||||
|
For recommended advertising interval |
||||
|
https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
|
*/ |
||||
|
Bluefruit.Advertising.restartOnDisconnect(true); |
||||
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
|
|
||||
|
strcpy(reply, "OK - started"); |
||||
|
return true; |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#ifdef HELTEC_MESH_SOLAR |
||||
|
#include "meshSolarApp.h" |
||||
|
#endif |
||||
|
|
||||
|
// LoRa radio module pins for Heltec T114
|
||||
|
#define P_LORA_DIO_1 20 |
||||
|
#define P_LORA_NSS 24 |
||||
|
#define P_LORA_RESET 25 |
||||
|
#define P_LORA_BUSY 17 |
||||
|
#define P_LORA_SCLK 19 |
||||
|
#define P_LORA_MISO 23 |
||||
|
#define P_LORA_MOSI 22 |
||||
|
|
||||
|
#define SX126X_DIO2_AS_RF_SWITCH true |
||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 |
||||
|
|
||||
|
|
||||
|
class MeshSolarBoard : public mesh::MainBoard { |
||||
|
protected: |
||||
|
uint8_t startup_reason; |
||||
|
|
||||
|
public: |
||||
|
void begin(); |
||||
|
uint8_t getStartupReason() const override { return startup_reason; } |
||||
|
|
||||
|
uint16_t getBattMilliVolts() override { |
||||
|
return meshSolarGetBattVoltage(); |
||||
|
} |
||||
|
|
||||
|
const char* getManufacturerName() const override { |
||||
|
return "Heltec Mesh Solar"; |
||||
|
} |
||||
|
|
||||
|
void reboot() override { |
||||
|
NVIC_SystemReset(); |
||||
|
} |
||||
|
|
||||
|
bool startOTAUpdate(const char* id, char reply[]) override; |
||||
|
}; |
||||
@ -0,0 +1,91 @@ |
|||||
|
[Heltec_mesh_solar] |
||||
|
extends = nrf52_base |
||||
|
board = heltec_mesh_solar |
||||
|
platform_packages = framework-arduinoadafruitnrf52 |
||||
|
board_build.ldscript = boards/nrf52840_s140_v6.ld |
||||
|
build_flags = ${nrf52_base.build_flags} |
||||
|
-I src/helpers/nrf52 |
||||
|
-I lib/nrf52/s140_nrf52_6.1.1_API/include |
||||
|
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52 |
||||
|
-I variants/heltec_mesh_solar |
||||
|
-D HELTEC_MESH_SOLAR |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
build_src_filter = ${nrf52_base.build_src_filter} |
||||
|
+<helpers/*.cpp> |
||||
|
+<../variants/heltec_mesh_solar> |
||||
|
lib_deps = |
||||
|
${nrf52_base.lib_deps} |
||||
|
rweather/Crypto @ ^0.4.0 |
||||
|
stevemarple/MicroNMEA @ ^2.0.6 |
||||
|
adafruit/Adafruit NeoPixel@^1.10.0 |
||||
|
https://github.com/NMIoT/meshsolar/archive/dfc5330dad443982e6cdd37a61d33fc7252f468b.zip |
||||
|
debug_tool = jlink |
||||
|
upload_protocol = nrfutil |
||||
|
|
||||
|
[env:Heltec_mesh_solar_repeater] |
||||
|
extends = Heltec_mesh_solar |
||||
|
build_src_filter = ${Heltec_mesh_solar.build_src_filter} |
||||
|
+<../examples/simple_repeater> |
||||
|
|
||||
|
build_flags = |
||||
|
${Heltec_mesh_solar.build_flags} |
||||
|
-D ADVERT_NAME='"Heltec_Mesh_Solar Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D MAX_NEIGHBOURS=8 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
|
||||
|
[env:Heltec_mesh_solar_room_server] |
||||
|
extends = Heltec_mesh_solar |
||||
|
build_src_filter = ${Heltec_mesh_solar.build_src_filter} |
||||
|
+<../examples/simple_room_server> |
||||
|
build_flags = |
||||
|
${Heltec_mesh_solar.build_flags} |
||||
|
-D ADVERT_NAME='"Heltec_Mesh_Solar Room"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D ROOM_PASSWORD='"hello"' |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
|
||||
|
[env:Heltec_mesh_solar_companion_radio_ble] |
||||
|
extends = Heltec_mesh_solar |
||||
|
build_flags = |
||||
|
${Heltec_mesh_solar.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-D BLE_PIN_CODE=123456 |
||||
|
; -D BLE_DEBUG_LOGGING=1 |
||||
|
-D OFFLINE_QUEUE_SIZE=256 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${Heltec_mesh_solar.build_src_filter} |
||||
|
+<helpers/nrf52/SerialBLEInterface.cpp> |
||||
|
+<../examples/companion_radio/*.cpp> |
||||
|
lib_deps = |
||||
|
${Heltec_mesh_solar.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:Heltec_mesh_solar_companion_radio_usb] |
||||
|
extends = Heltec_mesh_solar |
||||
|
build_flags = |
||||
|
${Heltec_mesh_solar.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
; -D BLE_PIN_CODE=123456 |
||||
|
; -D BLE_DEBUG_LOGGING=1 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${Heltec_mesh_solar.build_src_filter} |
||||
|
+<helpers/nrf52/*.cpp> |
||||
|
+<../examples/companion_radio/*.cpp> |
||||
|
lib_deps = |
||||
|
${Heltec_mesh_solar.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
@ -0,0 +1,123 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
#include <helpers/sensors/MicroNMEALocationProvider.h> |
||||
|
|
||||
|
MeshSolarBoard board; |
||||
|
|
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
VolatileRTCClock fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1); |
||||
|
SolarSensorManager sensors = SolarSensorManager(nmea); |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() { |
||||
|
rtc_clock.begin(Wire); |
||||
|
return radio.std_init(&SPI); |
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() { |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
|
|
||||
|
void SolarSensorManager::start_gps() { |
||||
|
if (!gps_active) { |
||||
|
gps_active = true; |
||||
|
_location->begin(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void SolarSensorManager::stop_gps() { |
||||
|
if (gps_active) { |
||||
|
gps_active = false; |
||||
|
_location->stop(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
bool SolarSensorManager::begin() { |
||||
|
Serial1.begin(9600); |
||||
|
|
||||
|
// We'll consider GPS detected if we see any data on Serial1
|
||||
|
gps_detected = (Serial1.available() > 0); |
||||
|
|
||||
|
if (gps_detected) { |
||||
|
MESH_DEBUG_PRINTLN("GPS detected"); |
||||
|
} else { |
||||
|
MESH_DEBUG_PRINTLN("No GPS detected"); |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
bool SolarSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) { |
||||
|
if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
|
||||
|
telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void SolarSensorManager::loop() { |
||||
|
static long next_gps_update = 0; |
||||
|
|
||||
|
_location->loop(); |
||||
|
|
||||
|
if (millis() > next_gps_update) { |
||||
|
if (_location->isValid()) { |
||||
|
node_lat = ((double)_location->getLatitude())/1000000.; |
||||
|
node_lon = ((double)_location->getLongitude())/1000000.; |
||||
|
node_altitude = ((double)_location->getAltitude()) / 1000.0; |
||||
|
MESH_DEBUG_PRINTLN("lat %f lon %f", node_lat, node_lon); |
||||
|
} |
||||
|
next_gps_update = millis() + 1000; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int SolarSensorManager::getNumSettings() const { |
||||
|
return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected
|
||||
|
} |
||||
|
|
||||
|
const char* SolarSensorManager::getSettingName(int i) const { |
||||
|
return (gps_detected && i == 0) ? "gps" : NULL; |
||||
|
} |
||||
|
|
||||
|
const char* SolarSensorManager::getSettingValue(int i) const { |
||||
|
if (gps_detected && i == 0) { |
||||
|
return gps_active ? "1" : "0"; |
||||
|
} |
||||
|
return NULL; |
||||
|
} |
||||
|
|
||||
|
bool SolarSensorManager::setSettingValue(const char* name, const char* value) { |
||||
|
if (gps_detected && strcmp(name, "gps") == 0) { |
||||
|
if (strcmp(value, "0") == 0) { |
||||
|
stop_gps(); |
||||
|
} else { |
||||
|
start_gps(); |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
return false; // not supported
|
||||
|
} |
||||
@ -0,0 +1,46 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/radiolib/RadioLibWrappers.h> |
||||
|
#include <MeshSolarBoard.h> |
||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#include <helpers/sensors/LocationProvider.h> |
||||
|
#ifdef DISPLAY_CLASS |
||||
|
#include <helpers/ui/ST7789Display.h> |
||||
|
#endif |
||||
|
|
||||
|
class SolarSensorManager : public SensorManager { |
||||
|
bool gps_active = false; |
||||
|
bool gps_detected = false; |
||||
|
LocationProvider* _location; |
||||
|
|
||||
|
void start_gps(); |
||||
|
void stop_gps(); |
||||
|
public: |
||||
|
SolarSensorManager(LocationProvider &location): _location(&location) { } |
||||
|
bool begin() override; |
||||
|
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override; |
||||
|
void loop() override; |
||||
|
int getNumSettings() const override; |
||||
|
const char* getSettingName(int i) const override; |
||||
|
const char* getSettingValue(int i) const override; |
||||
|
bool setSettingValue(const char* name, const char* value) override; |
||||
|
}; |
||||
|
|
||||
|
extern MeshSolarBoard board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern SolarSensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
extern DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,16 @@ |
|||||
|
#include "variant.h" |
||||
|
#include "wiring_constants.h" |
||||
|
#include "wiring_digital.h" |
||||
|
|
||||
|
const uint32_t g_ADigitalPinMap[] = { |
||||
|
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, 32, 33, 34, 35, 36, 37, 38, 39, |
||||
|
40, 41, 42, 43, 44, 45, 46, 47 |
||||
|
}; |
||||
|
|
||||
|
void initVariant() |
||||
|
{ |
||||
|
pinMode(PIN_USER_BTN, INPUT); |
||||
|
pinMode(BQ4050_EMERGENCY_SHUTDOWN_PIN, INPUT); |
||||
|
} |
||||
@ -0,0 +1,127 @@ |
|||||
|
/*
|
||||
|
* variant.h |
||||
|
* Copyright (C) 2023 Seeed K.K. |
||||
|
* MIT License |
||||
|
*/ |
||||
|
|
||||
|
#pragma once |
||||
|
|
||||
|
#include "WVariant.h" |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Low frequency clock source
|
||||
|
|
||||
|
#define USE_LFXO // 32.768 kHz crystal oscillator
|
||||
|
#define VARIANT_MCK (64000000ul) |
||||
|
|
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Power
|
||||
|
|
||||
|
#define NRF_APM |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Number of pins
|
||||
|
|
||||
|
#define PINS_COUNT (48) |
||||
|
#define NUM_DIGITAL_PINS (48) |
||||
|
#define NUM_ANALOG_INPUTS (1) |
||||
|
#define NUM_ANALOG_OUTPUTS (0) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// UART pin definition
|
||||
|
|
||||
|
#define PIN_SERIAL1_RX (37) |
||||
|
#define PIN_SERIAL1_TX (39) |
||||
|
|
||||
|
#define PIN_SERIAL2_RX (9) |
||||
|
#define PIN_SERIAL2_TX (10) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// I2C pin definition
|
||||
|
#define WIRE_INTERFACES_COUNT (2) |
||||
|
|
||||
|
#define PIN_WIRE_SDA (6) |
||||
|
#define PIN_WIRE_SCL (26) |
||||
|
|
||||
|
#define PIN_WIRE1_SDA (30) |
||||
|
#define PIN_WIRE1_SCL (5) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// SPI pin definition
|
||||
|
|
||||
|
#define SPI_INTERFACES_COUNT (2) |
||||
|
|
||||
|
#define PIN_SPI_MISO (23) |
||||
|
#define PIN_SPI_MOSI (22) |
||||
|
#define PIN_SPI_SCK (19) |
||||
|
#define PIN_SPI_NSS (24) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Builtin LEDs
|
||||
|
|
||||
|
#define LED_BUILTIN (12) |
||||
|
#define PIN_LED LED_BUILTIN |
||||
|
#define LED_RED LED_BUILTIN |
||||
|
#define LED_BLUE (-1) // No blue led, prevents Bluefruit flashing the green LED during advertising
|
||||
|
#define LED_PIN LED_BUILTIN |
||||
|
|
||||
|
#define LED_STATE_ON LOW |
||||
|
|
||||
|
#define PIN_NEOPIXEL (47) |
||||
|
#define NEOPIXEL_NUM (1) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Builtin buttons
|
||||
|
|
||||
|
#define PIN_BUTTON1 (42) |
||||
|
#define BUTTON_PIN PIN_BUTTON1 |
||||
|
|
||||
|
// #define PIN_BUTTON2 (11)
|
||||
|
// #define BUTTON_PIN2 PIN_BUTTON2
|
||||
|
|
||||
|
#define PIN_USER_BTN BUTTON_PIN |
||||
|
|
||||
|
#define EXTERNAL_FLASH_DEVICES MX25R1635F |
||||
|
#define EXTERNAL_FLASH_USE_QSPI |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Lora
|
||||
|
|
||||
|
#define USE_SX1262 |
||||
|
#define LORA_CS (24) |
||||
|
#define SX126X_DIO1 (20) |
||||
|
#define SX126X_BUSY (17) |
||||
|
#define SX126X_RESET (25) |
||||
|
#define SX126X_DIO2_AS_RF_SWITCH |
||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 |
||||
|
|
||||
|
#define PIN_SPI1_MISO (43) |
||||
|
#define PIN_SPI1_MOSI (41) |
||||
|
#define PIN_SPI1_SCK (40) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// Buzzer
|
||||
|
|
||||
|
// #define PIN_BUZZER (46)
|
||||
|
|
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// GPS
|
||||
|
|
||||
|
#define GPS_RESET (38) |
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
// TFT
|
||||
|
// #define PIN_TFT_SCL (40)
|
||||
|
// #define PIN_TFT_SDA (41)
|
||||
|
// #define PIN_TFT_RST (2)
|
||||
|
// #define PIN_TFT_VDD_CTL (3)
|
||||
|
// #define PIN_TFT_LEDA_CTL (15)
|
||||
|
// #define PIN_TFT_CS (11)
|
||||
|
// #define PIN_TFT_DC (12)
|
||||
|
|
||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||
|
#define BQ4050_SDA_PIN (33) // I2C data line pin
|
||||
|
#define BQ4050_SCL_PIN (32) // I2C clock line pin
|
||||
|
#define BQ4050_EMERGENCY_SHUTDOWN_PIN (35) // Emergency shutdown pin
|
||||
@ -0,0 +1,69 @@ |
|||||
|
#include "HeltecE213Board.h" |
||||
|
|
||||
|
void HeltecE213Board::begin() { |
||||
|
ESP32Board::begin(); |
||||
|
|
||||
|
pinMode(PIN_ADC_CTRL, OUTPUT); |
||||
|
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
||||
|
|
||||
|
periph_power.begin(); |
||||
|
|
||||
|
esp_reset_reason_t reason = esp_reset_reason(); |
||||
|
if (reason == ESP_RST_DEEPSLEEP) { |
||||
|
long wakeup_source = esp_sleep_get_ext1_wakeup_status(); |
||||
|
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||
|
startup_reason = BD_STARTUP_RX_PACKET; |
||||
|
} |
||||
|
|
||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); |
||||
|
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void HeltecE213Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { |
||||
|
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); |
||||
|
|
||||
|
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
|
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); |
||||
|
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); |
||||
|
|
||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS); |
||||
|
|
||||
|
if (pin_wake_btn < 0) { |
||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
|
} else { |
||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
|
} |
||||
|
|
||||
|
if (secs > 0) { |
||||
|
esp_sleep_enable_timer_wakeup(secs * 1000000); |
||||
|
} |
||||
|
|
||||
|
// Finally set ESP32 into sleep
|
||||
|
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
|
} |
||||
|
|
||||
|
void HeltecE213Board::powerOff() { |
||||
|
// TODO: re-enable this when there is a definite wake-up source pin:
|
||||
|
// enterDeepSleep(0);
|
||||
|
} |
||||
|
|
||||
|
uint16_t HeltecE213Board::getBattMilliVolts() { |
||||
|
analogReadResolution(10); |
||||
|
digitalWrite(PIN_ADC_CTRL, HIGH); |
||||
|
|
||||
|
uint32_t raw = 0; |
||||
|
for (int i = 0; i < 8; i++) { |
||||
|
raw += analogRead(PIN_VBAT_READ); |
||||
|
} |
||||
|
raw = raw / 8; |
||||
|
|
||||
|
digitalWrite(PIN_ADC_CTRL, LOW); |
||||
|
|
||||
|
return (5.42 * (3.3 / 1024.0) * raw) * 1000; |
||||
|
} |
||||
|
|
||||
|
const char* HeltecE213Board::getManufacturerName() const { |
||||
|
return "Heltec E213"; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,30 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include <helpers/RefCountedDigitalPin.h> |
||||
|
#include <helpers/ESP32Board.h> |
||||
|
#include <driver/rtc_io.h> |
||||
|
|
||||
|
// LoRa radio module pins for heltec_vision_master_e213
|
||||
|
#define P_LORA_DIO_1 14 |
||||
|
#define P_LORA_NSS 8 |
||||
|
#define P_LORA_RESET 12 |
||||
|
#define P_LORA_BUSY 13 |
||||
|
#define P_LORA_SCLK 9 |
||||
|
#define P_LORA_MISO 11 |
||||
|
#define P_LORA_MOSI 10 |
||||
|
|
||||
|
class HeltecE213Board : public ESP32Board { |
||||
|
|
||||
|
public: |
||||
|
RefCountedDigitalPin periph_power; |
||||
|
|
||||
|
HeltecE213Board() : periph_power(PIN_VEXT_EN,PIN_VEXT_EN_ACTIVE) { } |
||||
|
|
||||
|
void begin(); |
||||
|
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1); |
||||
|
void powerOff() override; |
||||
|
uint16_t getBattMilliVolts() override; |
||||
|
const char* getManufacturerName() const override ; |
||||
|
|
||||
|
}; |
||||
@ -0,0 +1,61 @@ |
|||||
|
#ifndef Pins_Arduino_h |
||||
|
#define Pins_Arduino_h |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
static const uint8_t LED_BUILTIN = 45; // LED is not populated on earliest board variant
|
||||
|
#define BUILTIN_LED LED_BUILTIN // Backward compatibility
|
||||
|
#define LED_BUILTIN LED_BUILTIN |
||||
|
|
||||
|
static const uint8_t TX = 43; |
||||
|
static const uint8_t RX = 44; |
||||
|
|
||||
|
static const uint8_t SDA = 39; |
||||
|
static const uint8_t SCL = 38; |
||||
|
|
||||
|
static const uint8_t SS = 8; |
||||
|
static const uint8_t MOSI = 10; |
||||
|
static const uint8_t MISO = 11; |
||||
|
static const uint8_t SCK = 9; |
||||
|
|
||||
|
static const uint8_t A0 = 1; |
||||
|
static const uint8_t A1 = 2; |
||||
|
static const uint8_t A2 = 3; |
||||
|
static const uint8_t A3 = 4; |
||||
|
static const uint8_t A4 = 5; |
||||
|
static const uint8_t A5 = 6; |
||||
|
static const uint8_t A6 = 7; |
||||
|
static const uint8_t A7 = 8; |
||||
|
static const uint8_t A8 = 9; |
||||
|
static const uint8_t A9 = 10; |
||||
|
static const uint8_t A10 = 11; |
||||
|
static const uint8_t A11 = 12; |
||||
|
static const uint8_t A12 = 13; |
||||
|
static const uint8_t A13 = 14; |
||||
|
static const uint8_t A14 = 15; |
||||
|
static const uint8_t A15 = 16; |
||||
|
static const uint8_t A16 = 17; |
||||
|
static const uint8_t A17 = 18; |
||||
|
static const uint8_t A18 = 19; |
||||
|
static const uint8_t A19 = 20; |
||||
|
|
||||
|
static const uint8_t T1 = 1; |
||||
|
static const uint8_t T2 = 2; |
||||
|
static const uint8_t T3 = 3; |
||||
|
static const uint8_t T4 = 4; |
||||
|
static const uint8_t T5 = 5; |
||||
|
static const uint8_t T6 = 6; |
||||
|
static const uint8_t T7 = 7; |
||||
|
static const uint8_t T8 = 8; |
||||
|
static const uint8_t T9 = 9; |
||||
|
static const uint8_t T10 = 10; |
||||
|
static const uint8_t T11 = 11; |
||||
|
static const uint8_t T12 = 12; |
||||
|
static const uint8_t T13 = 13; |
||||
|
static const uint8_t T14 = 14; |
||||
|
|
||||
|
static const uint8_t RST_LoRa = 12; |
||||
|
static const uint8_t BUSY_LoRa = 13; |
||||
|
static const uint8_t DIO1 = 14; |
||||
|
|
||||
|
#endif /* Pins_Arduino_h */ |
||||
@ -0,0 +1,84 @@ |
|||||
|
[Heltec_Vision_Master_E213_base] |
||||
|
extends = esp32_base |
||||
|
board = heltec_vision_master_e213 |
||||
|
build_flags = |
||||
|
${esp32_base.build_flags} |
||||
|
-I variants/heltec_vision_master_e213 |
||||
|
-D HELTEC_VISION_MASTER_E213 |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D P_LORA_TX_LED=45 |
||||
|
-D PIN_USER_BTN=0 |
||||
|
-D PIN_VEXT_EN=18 |
||||
|
-D PIN_VEXT_EN_ACTIVE=HIGH |
||||
|
-D PIN_VBAT_READ=7 |
||||
|
-D PIN_ADC_CTRL=46 |
||||
|
-D SX126X_DIO2_AS_RF_SWITCH=true |
||||
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
-D PIN_BOARD_SDA=39 |
||||
|
-D PIN_BOARD_SCL=38 |
||||
|
-D DISP_CS=5 |
||||
|
-D DISP_BUSY=1 |
||||
|
-D DISP_DC=2 |
||||
|
-D DISP_RST=3 |
||||
|
-D DISP_SCLK=4 |
||||
|
-D DISP_MOSI=6 |
||||
|
-D Vision_Master_E213 |
||||
|
build_src_filter = ${esp32_base.build_src_filter} |
||||
|
+<../variants/heltec_vision_master_e213> |
||||
|
lib_deps = |
||||
|
${esp32_base.lib_deps} |
||||
|
https://github.com/Quency-D/heltec-eink-modules/archive/563dd41fd850a1bc3039b8723da4f3a20fe1c800.zip |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E213_radio_ble] |
||||
|
extends = Heltec_Vision_Master_E213_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E213_base.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-D DISPLAY_CLASS=E213Display |
||||
|
-D BLE_PIN_CODE=123456 ; dynamic, random PIN |
||||
|
-D BLE_DEBUG_LOGGING=1 |
||||
|
-D OFFLINE_QUEUE_SIZE=256 |
||||
|
build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} |
||||
|
+<helpers/ui/E213Display.cpp> |
||||
|
+<helpers/esp32/*.cpp> |
||||
|
+<../examples/companion_radio> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E213_base.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E213_repeater] |
||||
|
extends = Heltec_Vision_Master_E213_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E213_base.build_flags} |
||||
|
-D DISPLAY_CLASS=E213Display |
||||
|
-D ADVERT_NAME='"Heltec E213 Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} |
||||
|
+<helpers/ui/E213Display.cpp> |
||||
|
+<../examples/simple_repeater> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E213_base.lib_deps} |
||||
|
${esp32_ota.lib_deps} |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E213_room_server] |
||||
|
extends = Heltec_Vision_Master_E213_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E213_base.build_flags} |
||||
|
-D DISPLAY_CLASS=E213Display |
||||
|
-D ADVERT_NAME='"Heltec E213 Room"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D ROOM_PASSWORD='"hello"' |
||||
|
build_src_filter = ${Heltec_Vision_Master_E213_base.build_src_filter} |
||||
|
+<helpers/ui/E213Display.cpp> |
||||
|
+<../examples/simple_room_server> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E213_base.lib_deps} |
||||
|
${esp32_ota.lib_deps} |
||||
@ -0,0 +1,53 @@ |
|||||
|
#include "target.h" |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
HeltecE213Board board; |
||||
|
|
||||
|
#if defined(P_LORA_SCLK) |
||||
|
static SPIClass spi(FSPI); |
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); |
||||
|
#else |
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); |
||||
|
#endif |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
ESP32RTCClock fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
|
||||
|
SensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() { |
||||
|
fallback_clock.begin(); |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
#if defined(P_LORA_SCLK) |
||||
|
return radio.std_init(&spi); |
||||
|
#else |
||||
|
return radio.std_init(); |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() { |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/radiolib/RadioLibWrappers.h> |
||||
|
#include <HeltecE213Board.h> |
||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#ifdef DISPLAY_CLASS |
||||
|
#include <helpers/ui/E213Display.h> |
||||
|
#endif |
||||
|
|
||||
|
extern HeltecE213Board board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern SensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
extern DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,69 @@ |
|||||
|
#include "HeltecE290Board.h" |
||||
|
|
||||
|
void HeltecE290Board::begin() { |
||||
|
ESP32Board::begin(); |
||||
|
|
||||
|
pinMode(PIN_ADC_CTRL, OUTPUT); |
||||
|
digitalWrite(PIN_ADC_CTRL, LOW); // Initially inactive
|
||||
|
|
||||
|
periph_power.begin(); |
||||
|
|
||||
|
esp_reset_reason_t reason = esp_reset_reason(); |
||||
|
if (reason == ESP_RST_DEEPSLEEP) { |
||||
|
long wakeup_source = esp_sleep_get_ext1_wakeup_status(); |
||||
|
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||
|
startup_reason = BD_STARTUP_RX_PACKET; |
||||
|
} |
||||
|
|
||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS); |
||||
|
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void HeltecE290Board::enterDeepSleep(uint32_t secs, int pin_wake_btn) { |
||||
|
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); |
||||
|
|
||||
|
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||
|
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY); |
||||
|
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1); |
||||
|
|
||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS); |
||||
|
|
||||
|
if (pin_wake_btn < 0) { |
||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||
|
} else { |
||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||
|
} |
||||
|
|
||||
|
if (secs > 0) { |
||||
|
esp_sleep_enable_timer_wakeup(secs * 1000000); |
||||
|
} |
||||
|
|
||||
|
// Finally set ESP32 into sleep
|
||||
|
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||
|
} |
||||
|
|
||||
|
void HeltecE290Board::powerOff() { |
||||
|
// TODO: re-enable this when there is a definite wake-up source pin:
|
||||
|
// enterDeepSleep(0);
|
||||
|
} |
||||
|
|
||||
|
uint16_t HeltecE290Board::getBattMilliVolts() { |
||||
|
analogReadResolution(10); |
||||
|
digitalWrite(PIN_ADC_CTRL, HIGH); |
||||
|
|
||||
|
uint32_t raw = 0; |
||||
|
for (int i = 0; i < 8; i++) { |
||||
|
raw += analogRead(PIN_VBAT_READ); |
||||
|
} |
||||
|
raw = raw / 8; |
||||
|
|
||||
|
digitalWrite(PIN_ADC_CTRL, LOW); |
||||
|
|
||||
|
return (5.42 * (3.3 / 1024.0) * raw) * 1000; |
||||
|
} |
||||
|
|
||||
|
const char* HeltecE290Board::getManufacturerName() const { |
||||
|
return "Heltec E290"; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,30 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include <helpers/RefCountedDigitalPin.h> |
||||
|
#include <helpers/ESP32Board.h> |
||||
|
#include <driver/rtc_io.h> |
||||
|
|
||||
|
// LoRa radio module pins for heltec_vision_master_e290
|
||||
|
#define P_LORA_DIO_1 14 |
||||
|
#define P_LORA_NSS 8 |
||||
|
#define P_LORA_RESET 12 |
||||
|
#define P_LORA_BUSY 13 |
||||
|
#define P_LORA_SCLK 9 |
||||
|
#define P_LORA_MISO 11 |
||||
|
#define P_LORA_MOSI 10 |
||||
|
|
||||
|
class HeltecE290Board : public ESP32Board { |
||||
|
|
||||
|
public: |
||||
|
RefCountedDigitalPin periph_power; |
||||
|
|
||||
|
HeltecE290Board() : periph_power(PIN_VEXT_EN) { } |
||||
|
|
||||
|
void begin(); |
||||
|
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1); |
||||
|
void powerOff() override; |
||||
|
uint16_t getBattMilliVolts() override; |
||||
|
const char* getManufacturerName() const override ; |
||||
|
|
||||
|
}; |
||||
@ -0,0 +1,61 @@ |
|||||
|
#ifndef Pins_Arduino_h |
||||
|
#define Pins_Arduino_h |
||||
|
|
||||
|
#include <stdint.h> |
||||
|
|
||||
|
static const uint8_t LED_BUILTIN = 45; // LED is not populated on earliest board variant
|
||||
|
#define BUILTIN_LED LED_BUILTIN // Backward compatibility
|
||||
|
#define LED_BUILTIN LED_BUILTIN |
||||
|
|
||||
|
static const uint8_t TX = 43; |
||||
|
static const uint8_t RX = 44; |
||||
|
|
||||
|
static const uint8_t SDA = 39; |
||||
|
static const uint8_t SCL = 38; |
||||
|
|
||||
|
static const uint8_t SS = 8; |
||||
|
static const uint8_t MOSI = 10; |
||||
|
static const uint8_t MISO = 11; |
||||
|
static const uint8_t SCK = 9; |
||||
|
|
||||
|
static const uint8_t A0 = 1; |
||||
|
static const uint8_t A1 = 2; |
||||
|
static const uint8_t A2 = 3; |
||||
|
static const uint8_t A3 = 4; |
||||
|
static const uint8_t A4 = 5; |
||||
|
static const uint8_t A5 = 6; |
||||
|
static const uint8_t A6 = 7; |
||||
|
static const uint8_t A7 = 8; |
||||
|
static const uint8_t A8 = 9; |
||||
|
static const uint8_t A9 = 10; |
||||
|
static const uint8_t A10 = 11; |
||||
|
static const uint8_t A11 = 12; |
||||
|
static const uint8_t A12 = 13; |
||||
|
static const uint8_t A13 = 14; |
||||
|
static const uint8_t A14 = 15; |
||||
|
static const uint8_t A15 = 16; |
||||
|
static const uint8_t A16 = 17; |
||||
|
static const uint8_t A17 = 18; |
||||
|
static const uint8_t A18 = 19; |
||||
|
static const uint8_t A19 = 20; |
||||
|
|
||||
|
static const uint8_t T1 = 1; |
||||
|
static const uint8_t T2 = 2; |
||||
|
static const uint8_t T3 = 3; |
||||
|
static const uint8_t T4 = 4; |
||||
|
static const uint8_t T5 = 5; |
||||
|
static const uint8_t T6 = 6; |
||||
|
static const uint8_t T7 = 7; |
||||
|
static const uint8_t T8 = 8; |
||||
|
static const uint8_t T9 = 9; |
||||
|
static const uint8_t T10 = 10; |
||||
|
static const uint8_t T11 = 11; |
||||
|
static const uint8_t T12 = 12; |
||||
|
static const uint8_t T13 = 13; |
||||
|
static const uint8_t T14 = 14; |
||||
|
|
||||
|
static const uint8_t RST_LoRa = 12; |
||||
|
static const uint8_t BUSY_LoRa = 13; |
||||
|
static const uint8_t DIO1 = 14; |
||||
|
|
||||
|
#endif /* Pins_Arduino_h */ |
||||
@ -0,0 +1,78 @@ |
|||||
|
[Heltec_Vision_Master_E290_base] |
||||
|
extends = esp32_base |
||||
|
board = heltec_vision_master_e290 |
||||
|
build_flags = |
||||
|
${esp32_base.build_flags} |
||||
|
-I variants/heltec_vision_master_e290 |
||||
|
-D HELTEC_VISION_MASTER_E290 |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D P_LORA_TX_LED=45 |
||||
|
-D PIN_USER_BTN=0 |
||||
|
-D PIN_VEXT_EN=18 |
||||
|
-D PIN_VEXT_EN_ACTIVE=HIGH |
||||
|
-D PIN_VBAT_READ=7 |
||||
|
-D PIN_ADC_CTRL=46 |
||||
|
-D SX126X_DIO2_AS_RF_SWITCH=true |
||||
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
-D PIN_BOARD_SDA=39 |
||||
|
-D PIN_BOARD_SCL=38 |
||||
|
-D Vision_Master_E290 |
||||
|
build_src_filter = ${esp32_base.build_src_filter} |
||||
|
+<../variants/heltec_vision_master_e290> |
||||
|
lib_deps = |
||||
|
${esp32_base.lib_deps} |
||||
|
https://github.com/Quency-D/heltec-eink-modules/archive/563dd41fd850a1bc3039b8723da4f3a20fe1c800.zip |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E290_radio_ble] |
||||
|
extends = Heltec_Vision_Master_E290_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E290_base.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-D DISPLAY_CLASS=E290Display |
||||
|
-D BLE_PIN_CODE=123456 ; dynamic, random PIN |
||||
|
-D BLE_DEBUG_LOGGING=1 |
||||
|
-D OFFLINE_QUEUE_SIZE=256 |
||||
|
build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} |
||||
|
+<helpers/ui/E290Display.cpp> |
||||
|
+<helpers/esp32/*.cpp> |
||||
|
+<../examples/companion_radio> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E290_base.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E290_repeater] |
||||
|
extends = Heltec_Vision_Master_E290_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E290_base.build_flags} |
||||
|
-D DISPLAY_CLASS=E290Display |
||||
|
-D ADVERT_NAME='"Heltec E290 Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} |
||||
|
+<helpers/ui/E290Display.cpp> |
||||
|
+<../examples/simple_repeater> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E290_base.lib_deps} |
||||
|
${esp32_ota.lib_deps} |
||||
|
|
||||
|
[env:Heltec_Vision_Master_E290_room_server] |
||||
|
extends = Heltec_Vision_Master_E290_base |
||||
|
build_flags = |
||||
|
${Heltec_Vision_Master_E290_base.build_flags} |
||||
|
-D DISPLAY_CLASS=E290Display |
||||
|
-D ADVERT_NAME='"Heltec E290 Room"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D ROOM_PASSWORD='"hello"' |
||||
|
build_src_filter = ${Heltec_Vision_Master_E290_base.build_src_filter} |
||||
|
+<helpers/ui/E290Display.cpp> |
||||
|
+<../examples/simple_room_server> |
||||
|
lib_deps = |
||||
|
${Heltec_Vision_Master_E290_base.lib_deps} |
||||
|
${esp32_ota.lib_deps} |
||||
@ -0,0 +1,53 @@ |
|||||
|
#include "target.h" |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
HeltecE290Board board; |
||||
|
|
||||
|
#if defined(P_LORA_SCLK) |
||||
|
static SPIClass spi(FSPI); |
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); |
||||
|
#else |
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); |
||||
|
#endif |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
ESP32RTCClock fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
|
||||
|
SensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() { |
||||
|
fallback_clock.begin(); |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
#if defined(P_LORA_SCLK) |
||||
|
return radio.std_init(&spi); |
||||
|
#else |
||||
|
return radio.std_init(); |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() { |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/radiolib/RadioLibWrappers.h> |
||||
|
#include <HeltecE290Board.h> |
||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/SensorManager.h> |
||||
|
#ifdef DISPLAY_CLASS |
||||
|
#include <helpers/ui/E290Display.h> |
||||
|
#endif |
||||
|
|
||||
|
extern HeltecE290Board board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern SensorManager sensors; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
extern DISPLAY_CLASS display; |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,99 @@ |
|||||
|
#ifdef XIAO_NRF52 |
||||
|
|
||||
|
#include <Arduino.h> |
||||
|
#include "ikoka_stick_nrf_board.h" |
||||
|
|
||||
|
#include <bluefruit.h> |
||||
|
#include <Wire.h> |
||||
|
|
||||
|
static BLEDfu bledfu; |
||||
|
|
||||
|
static void connect_callback(uint16_t conn_handle) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
MESH_DEBUG_PRINTLN("BLE client connected"); |
||||
|
} |
||||
|
|
||||
|
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) |
||||
|
{ |
||||
|
(void)conn_handle; |
||||
|
(void)reason; |
||||
|
|
||||
|
MESH_DEBUG_PRINTLN("BLE client disconnected"); |
||||
|
} |
||||
|
|
||||
|
void ikoka_stick_nrf_board::begin() { |
||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||
|
startup_reason = BD_STARTUP_NORMAL; |
||||
|
|
||||
|
pinMode(PIN_VBAT, INPUT); |
||||
|
pinMode(VBAT_ENABLE, OUTPUT); |
||||
|
digitalWrite(VBAT_ENABLE, HIGH); |
||||
|
|
||||
|
#ifdef PIN_USER_BTN |
||||
|
pinMode(PIN_USER_BTN, INPUT_PULLUP); |
||||
|
#endif |
||||
|
|
||||
|
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL) |
||||
|
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL); |
||||
|
#endif |
||||
|
|
||||
|
Wire.begin(); |
||||
|
|
||||
|
#ifdef P_LORA_TX_LED |
||||
|
pinMode(P_LORA_TX_LED, OUTPUT); |
||||
|
digitalWrite(P_LORA_TX_LED, HIGH); |
||||
|
#endif |
||||
|
|
||||
|
// pinMode(SX126X_POWER_EN, OUTPUT);
|
||||
|
// digitalWrite(SX126X_POWER_EN, HIGH);
|
||||
|
delay(10); // give sx1262 some time to power up
|
||||
|
} |
||||
|
|
||||
|
bool ikoka_stick_nrf_board::startOTAUpdate(const char* id, char reply[]) { |
||||
|
// Config the peripheral connection with maximum bandwidth
|
||||
|
// more SRAM required by SoftDevice
|
||||
|
// Note: All config***() function must be called before begin()
|
||||
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); |
||||
|
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); |
||||
|
|
||||
|
Bluefruit.begin(1, 0); |
||||
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||
|
Bluefruit.setTxPower(4); |
||||
|
// Set the BLE device name
|
||||
|
Bluefruit.setName("XIAO_NRF52_OTA"); |
||||
|
|
||||
|
Bluefruit.Periph.setConnectCallback(connect_callback); |
||||
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback); |
||||
|
|
||||
|
// To be consistent OTA DFU should be added first if it exists
|
||||
|
bledfu.begin(); |
||||
|
|
||||
|
// Set up and start advertising
|
||||
|
// Advertising packet
|
||||
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
||||
|
Bluefruit.Advertising.addTxPower(); |
||||
|
Bluefruit.Advertising.addName(); |
||||
|
|
||||
|
/* Start Advertising
|
||||
|
- Enable auto advertising if disconnected |
||||
|
- Interval: fast mode = 20 ms, slow mode = 152.5 ms |
||||
|
- Timeout for fast mode is 30 seconds |
||||
|
- Start(timeout) with timeout = 0 will advertise forever (until connected) |
||||
|
|
||||
|
For recommended advertising interval |
||||
|
https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
|
*/ |
||||
|
Bluefruit.Advertising.restartOnDisconnect(true); |
||||
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
|
|
||||
|
strcpy(reply, "OK - started"); |
||||
|
return true; |
||||
|
|
||||
|
|
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
#endif |
||||
@ -0,0 +1,66 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
#ifdef XIAO_NRF52 |
||||
|
|
||||
|
// redefine lora pins if using the S3 variant of SX1262 board
|
||||
|
#ifdef SX1262_XIAO_S3_VARIANT |
||||
|
#undef P_LORA_DIO_1 |
||||
|
#undef P_LORA_BUSY |
||||
|
#undef P_LORA_RESET |
||||
|
#undef P_LORA_NSS |
||||
|
#undef SX126X_RXEN |
||||
|
#define P_LORA_DIO_1 D0 |
||||
|
#define P_LORA_BUSY D1 |
||||
|
#define P_LORA_RESET D2 |
||||
|
#define P_LORA_NSS D3 |
||||
|
#define SX126X_RXEN D4 |
||||
|
#endif |
||||
|
|
||||
|
class ikoka_stick_nrf_board : public mesh::MainBoard { |
||||
|
protected: |
||||
|
uint8_t startup_reason; |
||||
|
|
||||
|
public: |
||||
|
void begin(); |
||||
|
uint8_t getStartupReason() const override { return startup_reason; } |
||||
|
|
||||
|
#if defined(P_LORA_TX_LED) |
||||
|
void onBeforeTransmit() override { |
||||
|
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
|
||||
|
} |
||||
|
void onAfterTransmit() override { |
||||
|
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
|
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
uint16_t getBattMilliVolts() override { |
||||
|
// Please read befor going further ;)
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
|
||||
|
|
||||
|
// We can't drive VBAT_ENABLE to HIGH as long
|
||||
|
// as we don't know wether we are charging or not ...
|
||||
|
// this is a 3mA loss (4/1500)
|
||||
|
digitalWrite(VBAT_ENABLE, LOW); |
||||
|
int adcvalue = 0; |
||||
|
analogReadResolution(12); |
||||
|
analogReference(AR_INTERNAL_3_0); |
||||
|
delay(10); |
||||
|
adcvalue = analogRead(PIN_VBAT); |
||||
|
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; |
||||
|
} |
||||
|
|
||||
|
const char* getManufacturerName() const override { |
||||
|
return "Ikoka Stick (Xiao-nrf52)"; |
||||
|
} |
||||
|
|
||||
|
void reboot() override { |
||||
|
NVIC_SystemReset(); |
||||
|
} |
||||
|
|
||||
|
bool startOTAUpdate(const char* id, char reply[]) override; |
||||
|
}; |
||||
|
|
||||
|
#endif |
||||
@ -0,0 +1,127 @@ |
|||||
|
[nrf52840_xiao] |
||||
|
extends = nrf52_base |
||||
|
platform_packages = |
||||
|
toolchain-gccarmnoneeabi@~1.100301.0 |
||||
|
framework-arduinoadafruitnrf52 |
||||
|
board = seeed-xiao-afruitnrf52-nrf52840 |
||||
|
board_build.ldscript = boards/nrf52840_s140_v7.ld |
||||
|
build_flags = ${nrf52_base.build_flags} |
||||
|
-D NRF52_PLATFORM -D XIAO_NRF52 |
||||
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include |
||||
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52 |
||||
|
lib_ignore = |
||||
|
BluetoothOTA |
||||
|
lvgl |
||||
|
lib5b4 |
||||
|
lib_deps = |
||||
|
${nrf52_base.lib_deps} |
||||
|
rweather/Crypto @ ^0.4.0 |
||||
|
adafruit/Adafruit INA3221 Library @ ^1.0.1 |
||||
|
adafruit/Adafruit INA219 @ ^1.2.3 |
||||
|
adafruit/Adafruit AHTX0 @ ^2.0.5 |
||||
|
adafruit/Adafruit BME280 Library @ ^2.3.0 |
||||
|
adafruit/Adafruit SSD1306 @ ^2.5.13 |
||||
|
|
||||
|
|
||||
|
[ikoka_stick_nrf] |
||||
|
extends = nrf52840_xiao |
||||
|
;board_build.ldscript = boards/nrf52840_s140_v7.ld |
||||
|
build_flags = ${nrf52840_xiao.build_flags} |
||||
|
-D P_LORA_TX_LED=11 |
||||
|
-I variants/ikoka_stick_nrf |
||||
|
-I src/helpers/nrf52 |
||||
|
-D DISPLAY_CLASS=SSD1306Display |
||||
|
-D DISPLAY_ROTATION=2 |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=9 |
||||
|
-D P_LORA_DIO_1=D1 |
||||
|
-D P_LORA_RESET=D2 |
||||
|
-D P_LORA_BUSY=D3 |
||||
|
-D P_LORA_NSS=D4 |
||||
|
-D SX126X_RXEN=D5 |
||||
|
-D SX126X_TXEN=RADIOLIB_NC |
||||
|
-D SX126X_DIO2_AS_RF_SWITCH=1 |
||||
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
-D PIN_USER_BTN=0 |
||||
|
-D PIN_WIRE_SCL=7 |
||||
|
-D PIN_WIRE_SDA=6 |
||||
|
-D ENV_INCLUDE_AHTX0=1 |
||||
|
-D ENV_INCLUDE_BME280=1 |
||||
|
-D ENV_INCLUDE_INA3221=1 |
||||
|
-D ENV_INCLUDE_INA219=1 |
||||
|
build_src_filter = ${nrf52840_xiao.build_src_filter} |
||||
|
+<helpers/*.cpp> |
||||
|
+<helpers/sensors> |
||||
|
+<helpers/ui/MomentaryButton.cpp> |
||||
|
+<helpers/ui/SSD1306Display.cpp> |
||||
|
+<../variants/ikoka_stick_nrf> |
||||
|
debug_tool = jlink |
||||
|
upload_protocol = nrfutil |
||||
|
|
||||
|
[env:ikoka_stick_nrf_companion_radio_ble] |
||||
|
extends = ikoka_stick_nrf |
||||
|
build_flags = |
||||
|
${ikoka_stick_nrf.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-D BLE_PIN_CODE=123456 |
||||
|
-D OFFLINE_QUEUE_SIZE=256 |
||||
|
-I examples/companion_radio/ui-new |
||||
|
; -D BLE_DEBUG_LOGGING=1 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${ikoka_stick_nrf.build_src_filter} |
||||
|
+<helpers/nrf52/SerialBLEInterface.cpp> |
||||
|
+<../examples/companion_radio/*.cpp> |
||||
|
+<../examples/companion_radio/ui-new/*.cpp> |
||||
|
lib_deps = |
||||
|
${ikoka_stick_nrf.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:ikoka_stick_nrf_companion_radio_usb] |
||||
|
extends = ikoka_stick_nrf |
||||
|
build_flags = |
||||
|
${ikoka_stick_nrf.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
-I examples/companion_radio/ui-new |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${ikoka_stick_nrf.build_src_filter} |
||||
|
+<helpers/nrf52/SerialBLEInterface.cpp> |
||||
|
+<../examples/companion_radio/*.cpp> |
||||
|
+<../examples/companion_radio/ui-new/*.cpp> |
||||
|
lib_deps = |
||||
|
${ikoka_stick_nrf.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:ikoka_stick_nrf_repeater] |
||||
|
extends = ikoka_stick_nrf |
||||
|
build_flags = |
||||
|
${ikoka_stick_nrf.build_flags} |
||||
|
-D ADVERT_NAME='"Ikoka Stick Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D MAX_NEIGHBOURS=8 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${ikoka_stick_nrf.build_src_filter} |
||||
|
+<helpers/ui/SSD1306Display.cpp> |
||||
|
+<../examples/simple_repeater/*.cpp> |
||||
|
|
||||
|
[env:ikoka_stick_nrf_room_server] |
||||
|
extends = ikoka_stick_nrf |
||||
|
build_flags = |
||||
|
${ikoka_stick_nrf.build_flags} |
||||
|
-D ADVERT_NAME='"Ikoka Stick Room"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${ikoka_stick_nrf.build_src_filter} |
||||
|
+<../examples/simple_room_server/*.cpp> |
||||
@ -0,0 +1,44 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
|
||||
|
ikoka_stick_nrf_board board; |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
DISPLAY_CLASS display; |
||||
|
MomentaryButton user_btn(PIN_USER_BTN, 1000, true); |
||||
|
#endif |
||||
|
|
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
VolatileRTCClock fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
EnvironmentSensorManager sensors; |
||||
|
|
||||
|
bool radio_init() { |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
return radio.std_init(&SPI); |
||||
|
} |
||||
|
|
||||
|
uint32_t radio_get_rng_seed() { |
||||
|
return radio.random(0x7FFFFFFF); |
||||
|
} |
||||
|
|
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
||||
|
radio.setFrequency(freq); |
||||
|
radio.setSpreadingFactor(sf); |
||||
|
radio.setBandwidth(bw); |
||||
|
radio.setCodingRate(cr); |
||||
|
} |
||||
|
|
||||
|
void radio_set_tx_power(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/radiolib/RadioLibWrappers.h> |
||||
|
#include <ikoka_stick_nrf_board.h> |
||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
#include <helpers/sensors/EnvironmentSensorManager.h> |
||||
|
|
||||
|
#ifdef DISPLAY_CLASS |
||||
|
#include <helpers/ui/SSD1306Display.h> |
||||
|
#include <helpers/ui/MomentaryButton.h> |
||||
|
extern DISPLAY_CLASS display; |
||||
|
extern MomentaryButton user_btn; |
||||
|
#endif |
||||
|
|
||||
|
extern ikoka_stick_nrf_board board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern EnvironmentSensorManager sensors; |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
@ -0,0 +1,86 @@ |
|||||
|
#include "variant.h" |
||||
|
#include "wiring_constants.h" |
||||
|
#include "wiring_digital.h" |
||||
|
#include "nrf.h" |
||||
|
|
||||
|
const uint32_t g_ADigitalPinMap[] = |
||||
|
{ |
||||
|
// D0 .. D10
|
||||
|
2, // D0 is P0.02 (A0)
|
||||
|
3, // D1 is P0.03 (A1)
|
||||
|
28, // D2 is P0.28 (A2)
|
||||
|
29, // D3 is P0.29 (A3)
|
||||
|
4, // D4 is P0.04 (A4,SDA)
|
||||
|
5, // D5 is P0.05 (A5,SCL)
|
||||
|
43, // D6 is P1.11 (TX)
|
||||
|
44, // D7 is P1.12 (RX)
|
||||
|
45, // D8 is P1.13 (SCK)
|
||||
|
46, // D9 is P1.14 (MISO)
|
||||
|
47, // D10 is P1.15 (MOSI)
|
||||
|
|
||||
|
// LEDs
|
||||
|
26, // D11 is P0.26 (LED RED)
|
||||
|
6, // D12 is P0.06 (LED BLUE)
|
||||
|
30, // D13 is P0.30 (LED GREEN)
|
||||
|
14, // D14 is P0.14 (READ_BAT)
|
||||
|
|
||||
|
// LSM6DS3TR
|
||||
|
40, // D15 is P1.08 (6D_PWR)
|
||||
|
27, // D16 is P0.27 (6D_I2C_SCL)
|
||||
|
7, // D17 is P0.07 (6D_I2C_SDA)
|
||||
|
11, // D18 is P0.11 (6D_INT1)
|
||||
|
|
||||
|
// MIC
|
||||
|
42, // D19 is P1.10 (MIC_PWR)
|
||||
|
32, // D20 is P1.00 (PDM_CLK)
|
||||
|
16, // D21 is P0.16 (PDM_DATA)
|
||||
|
|
||||
|
// BQ25100
|
||||
|
13, // D22 is P0.13 (HICHG)
|
||||
|
17, // D23 is P0.17 (~CHG)
|
||||
|
|
||||
|
//
|
||||
|
21, // D24 is P0.21 (QSPI_SCK)
|
||||
|
25, // D25 is P0.25 (QSPI_CSN)
|
||||
|
20, // D26 is P0.20 (QSPI_SIO_0 DI)
|
||||
|
24, // D27 is P0.24 (QSPI_SIO_1 DO)
|
||||
|
22, // D28 is P0.22 (QSPI_SIO_2 WP)
|
||||
|
23, // D29 is P0.23 (QSPI_SIO_3 HOLD)
|
||||
|
|
||||
|
// NFC
|
||||
|
9, // D30 is P0.09 (NFC1)
|
||||
|
10, // D31 is P0.10 (NFC2)
|
||||
|
|
||||
|
// VBAT
|
||||
|
31, // D32 is P0.31 (VBAT)
|
||||
|
}; |
||||
|
|
||||
|
void initVariant() |
||||
|
{ |
||||
|
// Disable reading of the BAT voltage.
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
|
||||
|
pinMode(VBAT_ENABLE, OUTPUT); |
||||
|
//digitalWrite(VBAT_ENABLE, HIGH);
|
||||
|
// This was taken from Seeed github butis not coherent with the doc,
|
||||
|
// VBAT_ENABLE should be kept to LOW to protect P0.14, (1500/500)*(4.2-3.3)+3.3 = 3.9V > 3.6V
|
||||
|
// This induces a 3mA current in the resistors :( but it's better than burning the nrf
|
||||
|
digitalWrite(VBAT_ENABLE, LOW); |
||||
|
|
||||
|
// Low charging current (50mA)
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
|
||||
|
//pinMode(PIN_CHARGING_CURRENT, INPUT);
|
||||
|
|
||||
|
// High charging current (100mA)
|
||||
|
pinMode(PIN_CHARGING_CURRENT, OUTPUT); |
||||
|
digitalWrite(PIN_CHARGING_CURRENT, LOW); |
||||
|
|
||||
|
pinMode(PIN_QSPI_CS, OUTPUT); |
||||
|
digitalWrite(PIN_QSPI_CS, HIGH); |
||||
|
|
||||
|
pinMode(LED_RED, OUTPUT); |
||||
|
digitalWrite(LED_RED, HIGH); |
||||
|
pinMode(LED_GREEN, OUTPUT); |
||||
|
digitalWrite(LED_GREEN, HIGH); |
||||
|
pinMode(LED_BLUE, OUTPUT); |
||||
|
digitalWrite(LED_BLUE, HIGH); |
||||
|
} |
||||
@ -0,0 +1,149 @@ |
|||||
|
#ifndef _IKOKA_STICK_NRF_H_ |
||||
|
#define _IKOKA_STICK_NRF_H_ |
||||
|
|
||||
|
/** Master clock frequency */ |
||||
|
#define VARIANT_MCK (64000000ul) |
||||
|
|
||||
|
#define USE_LFXO // Board uses 32khz crystal for LF
|
||||
|
//#define USE_LFRC // Board uses RC for LF
|
||||
|
|
||||
|
/*----------------------------------------------------------------------------
|
||||
|
* Headers |
||||
|
*----------------------------------------------------------------------------*/ |
||||
|
|
||||
|
#include "WVariant.h" |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" |
||||
|
{ |
||||
|
#endif // __cplusplus
|
||||
|
|
||||
|
#define PINS_COUNT (33) |
||||
|
#define NUM_DIGITAL_PINS (33) |
||||
|
#define NUM_ANALOG_INPUTS (8) |
||||
|
#define NUM_ANALOG_OUTPUTS (0) |
||||
|
|
||||
|
// LEDs
|
||||
|
#define PIN_LED (LED_RED) |
||||
|
#define LED_PWR (PINS_COUNT) |
||||
|
#define PIN_NEOPIXEL (PINS_COUNT) |
||||
|
#define NEOPIXEL_NUM (0) |
||||
|
|
||||
|
#define LED_BUILTIN (PIN_LED) |
||||
|
|
||||
|
#define LED_RED (11) |
||||
|
#define LED_GREEN (13) |
||||
|
#define LED_BLUE (12) |
||||
|
|
||||
|
#define LED_STATE_ON (1) // State when LED is litted
|
||||
|
|
||||
|
// Buttons
|
||||
|
#define PIN_BUTTON1 (PINS_COUNT) |
||||
|
|
||||
|
// Digital PINs
|
||||
|
static const uint8_t D0 = 0 ; |
||||
|
static const uint8_t D1 = 1 ; |
||||
|
static const uint8_t D2 = 2 ; |
||||
|
static const uint8_t D3 = 3 ; |
||||
|
static const uint8_t D4 = 4 ; |
||||
|
static const uint8_t D5 = 5 ; |
||||
|
static const uint8_t D6 = 6 ; |
||||
|
static const uint8_t D7 = 7 ; |
||||
|
static const uint8_t D8 = 8 ; |
||||
|
static const uint8_t D9 = 9 ; |
||||
|
static const uint8_t D10 = 10; |
||||
|
|
||||
|
#define VBAT_ENABLE (14) // Output LOW to enable reading of the BAT voltage.
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
|
||||
|
|
||||
|
#define PIN_CHARGING_CURRENT (22) // Battery Charging current
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
|
||||
|
|
||||
|
// Analog pins
|
||||
|
#define PIN_A0 (0) |
||||
|
#define PIN_A1 (1) |
||||
|
#define PIN_A2 (2) |
||||
|
#define PIN_A3 (3) |
||||
|
#define PIN_A4 (4) |
||||
|
#define PIN_A5 (5) |
||||
|
#define PIN_VBAT (32) // Read the BAT voltage.
|
||||
|
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
|
||||
|
|
||||
|
#define BAT_NOT_CHARGING (23) // LOW when charging
|
||||
|
|
||||
|
#define AREF_VOLTAGE (3.0) |
||||
|
#define ADC_MULTIPLIER (3.0F) // 1M, 512k divider bridge
|
||||
|
|
||||
|
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 (12) |
||||
|
|
||||
|
// Other pins
|
||||
|
#define PIN_NFC1 (30) |
||||
|
#define PIN_NFC2 (31) |
||||
|
|
||||
|
// Serial interfaces
|
||||
|
#define PIN_SERIAL1_RX (7) |
||||
|
#define PIN_SERIAL1_TX (6) |
||||
|
|
||||
|
// SPI Interfaces
|
||||
|
#define SPI_INTERFACES_COUNT (2) |
||||
|
|
||||
|
#define PIN_SPI_MISO (9) |
||||
|
#define PIN_SPI_MOSI (10) |
||||
|
#define PIN_SPI_SCK (8) |
||||
|
|
||||
|
#define PIN_SPI1_MISO (25) |
||||
|
#define PIN_SPI1_MOSI (26) |
||||
|
#define PIN_SPI1_SCK (29) |
||||
|
|
||||
|
// Lora SPI is on SPI0
|
||||
|
#define P_LORA_SCLK PIN_SPI_SCK |
||||
|
#define P_LORA_MISO PIN_SPI_MISO |
||||
|
#define P_LORA_MOSI PIN_SPI_MOSI |
||||
|
|
||||
|
// Wire Interfaces
|
||||
|
#define WIRE_INTERFACES_COUNT (1) |
||||
|
|
||||
|
// #define PIN_WIRE_SDA (17) // 4 and 5 are used for the sx1262 !
|
||||
|
// #define PIN_WIRE_SCL (16) // use WIRE1_SDA
|
||||
|
|
||||
|
static const uint8_t SDA = PIN_WIRE_SDA; |
||||
|
static const uint8_t SCL = PIN_WIRE_SCL; |
||||
|
|
||||
|
//#define PIN_WIRE1_SDA (17)
|
||||
|
//#define PIN_WIRE1_SCL (16)
|
||||
|
#define PIN_LSM6DS3TR_C_POWER (15) |
||||
|
#define PIN_LSM6DS3TR_C_INT1 (18) |
||||
|
|
||||
|
// PDM Interfaces
|
||||
|
#define PIN_PDM_PWR (19) |
||||
|
#define PIN_PDM_CLK (20) |
||||
|
#define PIN_PDM_DIN (21) |
||||
|
|
||||
|
// QSPI Pins
|
||||
|
#define PIN_QSPI_SCK (24) |
||||
|
#define PIN_QSPI_CS (25) |
||||
|
#define PIN_QSPI_IO0 (26) |
||||
|
#define PIN_QSPI_IO1 (27) |
||||
|
#define PIN_QSPI_IO2 (28) |
||||
|
#define PIN_QSPI_IO3 (29) |
||||
|
|
||||
|
// On-board QSPI Flash
|
||||
|
#define EXTERNAL_FLASH_DEVICES (P25Q16H) |
||||
|
#define EXTERNAL_FLASH_USE_QSPI |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
/*----------------------------------------------------------------------------
|
||||
|
* Arduino objects - C++ only |
||||
|
*----------------------------------------------------------------------------*/ |
||||
|
|
||||
|
#endif |
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue