mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-04-05 21:05:44 -04:00
Compare commits
184 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
de35a9dda0 | ||
![]() |
e230c73ee0 | ||
![]() |
6bbcaa0ba9 | ||
![]() |
9473b9df82 | ||
![]() |
2ee0e4eb13 | ||
![]() |
926e32ec99 | ||
![]() |
16090f73e4 | ||
![]() |
919bddb703 | ||
![]() |
458e40ce9a | ||
![]() |
3ae8982e93 | ||
![]() |
4bdd30daac | ||
![]() |
49d023379f | ||
![]() |
01a27cfd9b | ||
![]() |
48bce4ea15 | ||
![]() |
3379217e19 | ||
![]() |
9b792862b9 | ||
![]() |
68349aaa70 | ||
![]() |
3e98ea14d2 | ||
![]() |
01e346f21f | ||
![]() |
3fab6d4cdb | ||
![]() |
ebf5b54957 | ||
![]() |
4e627d6e6b | ||
![]() |
113b2f1081 | ||
![]() |
733a792d72 | ||
![]() |
ea33f0cba7 | ||
![]() |
7066b4de6f | ||
![]() |
6b815c47d4 | ||
![]() |
f447998c35 | ||
![]() |
2d2d90847a | ||
![]() |
13266c96db | ||
![]() |
7e30648968 | ||
![]() |
32fc5afee2 | ||
![]() |
3073677b82 | ||
![]() |
2119d381b3 | ||
![]() |
cbe95b10d6 | ||
![]() |
6f0c849cb3 | ||
![]() |
6eaacb7f99 | ||
![]() |
8cf6e9cb40 | ||
![]() |
7a505f73e3 | ||
![]() |
b4b1d13dc9 | ||
![]() |
becc3d0e3d | ||
![]() |
95895f3756 | ||
![]() |
c1b3b4f416 | ||
![]() |
62cd3977c7 | ||
![]() |
7235fa6c3f | ||
![]() |
7720fa5192 | ||
![]() |
d0041281bd | ||
![]() |
71e73580f7 | ||
![]() |
6e7370acdc | ||
![]() |
434f55b240 | ||
![]() |
06b4fba603 | ||
![]() |
c5ed792280 | ||
![]() |
5671cd7288 | ||
![]() |
f466cabe61 | ||
![]() |
8b8502e8e0 | ||
![]() |
dbebb4080a | ||
![]() |
7adc3e2a0d | ||
![]() |
218a38adb7 | ||
![]() |
729a4099e5 | ||
![]() |
9c7a04b66c | ||
![]() |
2b93b1b9e7 | ||
![]() |
58f6a3d6a3 | ||
![]() |
a796e56dd9 | ||
![]() |
aa7bb49b30 | ||
![]() |
254225e917 | ||
![]() |
ae47b89b53 | ||
![]() |
498652f583 | ||
![]() |
c04067446d | ||
![]() |
4ab42c4269 | ||
![]() |
7ce2ed6155 | ||
![]() |
5ec063c939 | ||
![]() |
08651f92f7 | ||
![]() |
e40532ed35 | ||
![]() |
1dab538d8f | ||
![]() |
c39164e272 | ||
![]() |
b667e825f8 | ||
![]() |
0545847e40 | ||
![]() |
df6463144f | ||
![]() |
42be6640de | ||
![]() |
01fcaadea5 | ||
![]() |
bc9ce056ee | ||
![]() |
0057852b6c | ||
![]() |
b7b9fb0c04 | ||
![]() |
564e2f26f3 | ||
![]() |
9ba243ee1f | ||
![]() |
eb168d4734 | ||
![]() |
217db4bcd3 | ||
![]() |
b9cd4d7751 | ||
![]() |
b02989e07a | ||
![]() |
b891932353 | ||
![]() |
35a4b6ff4e | ||
![]() |
4e251cd186 | ||
![]() |
a663707a69 | ||
![]() |
a5a3ca28fa | ||
![]() |
421f2d5db3 | ||
![]() |
6bf06ca94e | ||
![]() |
315bcb02a0 | ||
![]() |
52fbe558d4 | ||
![]() |
470f4f4d09 | ||
![]() |
653845ad31 | ||
![]() |
9174dbd34a | ||
![]() |
abde6561b5 | ||
![]() |
6a43bf51ef | ||
![]() |
f9234733e2 | ||
![]() |
6c82de161c | ||
![]() |
571e7d7105 | ||
![]() |
2604b44d64 | ||
![]() |
786c9990fb | ||
![]() |
2263b20b81 | ||
![]() |
d599109562 | ||
![]() |
aba9a317dd | ||
![]() |
d88f231332 | ||
![]() |
d012c37146 | ||
![]() |
3e4bb282f8 | ||
![]() |
315bc1c037 | ||
![]() |
9445fc8992 | ||
![]() |
33f7dde92e | ||
![]() |
df7410e683 | ||
![]() |
9f6f2fc000 | ||
![]() |
4b48f41c38 | ||
![]() |
9fdd886d00 | ||
![]() |
5ac30b0fa7 | ||
![]() |
ead6b41259 | ||
![]() |
5fbac58550 | ||
![]() |
9edc2224e7 | ||
![]() |
7f998e6436 | ||
![]() |
711f9c6eac | ||
![]() |
707608fd33 | ||
![]() |
982a755464 | ||
![]() |
34e872b25d | ||
![]() |
a3e15bed1b | ||
![]() |
da1207ceee | ||
![]() |
12b32b99f9 | ||
![]() |
76eaae8554 | ||
![]() |
8c0900e2d0 | ||
![]() |
389745ad33 | ||
![]() |
1de5f3c796 | ||
![]() |
7a8a1b5dee | ||
![]() |
c51335a1df | ||
![]() |
2e6db2f818 | ||
![]() |
16b06406f2 | ||
![]() |
2ab1d4b1ac | ||
![]() |
335c6cbc5c | ||
![]() |
2ede362cb3 | ||
![]() |
1bd7de8f97 | ||
![]() |
0e04754d7a | ||
![]() |
cb192d47ed | ||
![]() |
03893c2793 | ||
![]() |
ed04513a7a | ||
![]() |
8639765679 | ||
![]() |
407120265a | ||
![]() |
42eb68137d | ||
![]() |
68008283a2 | ||
![]() |
22372855b3 | ||
![]() |
c55d907045 | ||
![]() |
30f92c0f3f | ||
![]() |
d61d14e117 | ||
![]() |
5807cfdb96 | ||
![]() |
d7511d430e | ||
![]() |
ffb951172f | ||
![]() |
3fe5affb51 | ||
![]() |
94215c4bce | ||
![]() |
960599c35a | ||
![]() |
bfc215b2a3 | ||
![]() |
e8dd7dbc93 | ||
![]() |
9ce280f207 | ||
![]() |
1a2e42d93c | ||
![]() |
c9f658e966 | ||
![]() |
e4deac3060 | ||
![]() |
940262e2c6 | ||
![]() |
49a524e8d5 | ||
![]() |
e993da9e0f | ||
![]() |
4615765039 | ||
![]() |
15a1d53c61 | ||
![]() |
05c337c057 | ||
![]() |
a37a03fe3b | ||
![]() |
9556f0b91b | ||
![]() |
1ac3a6c2c8 | ||
![]() |
6974a50d10 | ||
![]() |
bd887f7de2 | ||
![]() |
fef27b194c | ||
![]() |
2c93b2a1de | ||
![]() |
8bdd85e648 | ||
![]() |
bb38290120 |
8
.github/ISSUE_TEMPLATE/🐛-bug-report.md
vendored
8
.github/ISSUE_TEMPLATE/🐛-bug-report.md
vendored
@ -15,7 +15,11 @@ Before creating a bug report on this issue tracker, you **must** read the [Contr
|
||||
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), delete this section from your bug report.
|
||||
|
||||
**Describe the Bug**
|
||||
A clear and concise description of what the bug is.
|
||||
First of all: Is this really a bug? Is it reproducible?
|
||||
|
||||
If this is a request for help because something is not working as you expected, stop right here, and go to the [discussions](https://github.com/markqvist/Reticulum/discussions) instead, where you can post your questions and get help from other users.
|
||||
|
||||
If this really is a bug or issue with the software, remove this section of the template, and provide **a clear and concise description of what the bug is**.
|
||||
|
||||
**To Reproduce**
|
||||
Describe in detail how to reproduce the bug.
|
||||
@ -24,7 +28,7 @@ Describe in detail how to reproduce the bug.
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Logs & Screenshots**
|
||||
Please include any relevant log output. If applicable, also add screenshots to help explain your problem.
|
||||
Please include any relevant log output. If applicable, also add screenshots to help explain your problem. In most cases, without any relevant log output, we will not be able to determine the cause of the bug, or reproduce it.
|
||||
|
||||
**System Information**
|
||||
- OS and version
|
||||
|
@ -1,5 +1,21 @@
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Boards.h"
|
||||
|
||||
#if PLATFORM != PLATFORM_NRF52
|
||||
#if HAS_BLE
|
||||
|
||||
#include "BLESerial.h"
|
||||
@ -132,4 +148,5 @@ void BLESerial::SetupSerialService() {
|
||||
|
||||
BLESerial::BLESerial() { }
|
||||
|
||||
#endif
|
||||
#endif
|
17
BLESerial.h
17
BLESerial.h
@ -1,5 +1,21 @@
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Boards.h"
|
||||
|
||||
#if PLATFORM != PLATFORM_NRF52
|
||||
#if HAS_BLE
|
||||
|
||||
#include <Arduino.h>
|
||||
@ -113,4 +129,5 @@ private:
|
||||
bool started = false;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
109
Bluetooth.h
109
Bluetooth.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -34,7 +34,8 @@
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
#include <bluefruit.h>
|
||||
#include <math.h>
|
||||
BLEUart SerialBT;
|
||||
#define BLE_RX_BUF 6144
|
||||
BLEUart SerialBT(BLE_RX_BUF);
|
||||
BLEDis bledis;
|
||||
BLEBas blebas;
|
||||
#endif
|
||||
@ -351,8 +352,9 @@ char bt_devname[11];
|
||||
display_unblank();
|
||||
if (bt_state == BT_STATE_OFF) bt_start();
|
||||
|
||||
bt_debond_all();
|
||||
bt_update_passkey();
|
||||
bt_security_setup();
|
||||
//bt_debond_all();
|
||||
//bt_update_passkey();
|
||||
|
||||
bt_allow_pairing = true;
|
||||
bt_pairing_started = millis();
|
||||
@ -381,6 +383,8 @@ char bt_devname[11];
|
||||
}
|
||||
}
|
||||
|
||||
void bt_flush() { if (bt_state == BT_STATE_CONNECTED) { SerialBT.flushTXD(); } }
|
||||
|
||||
void bt_disable_pairing() {
|
||||
bt_allow_pairing = false;
|
||||
bt_ssp_pin = 0;
|
||||
@ -388,34 +392,66 @@ char bt_devname[11];
|
||||
}
|
||||
|
||||
void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||
bt_disable_pairing();
|
||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
||||
|
||||
ble_gap_conn_sec_mode_t security = connection->getSecureMode();
|
||||
|
||||
// On the NRF52 it is not possible with the Arduino library to reject
|
||||
// requests from devices with no IO capabilities, which would allow
|
||||
// bypassing pin entry through pairing using the "just works" mode.
|
||||
// Therefore, we must check the security level of the connection after
|
||||
// pairing to ensure "just works" has not been used. If it has, we need
|
||||
// to disconnect, unpair and delete any bonding information immediately.
|
||||
// Settings on the SerialBT service should prevent unauthorised access to
|
||||
// the serial port anyway, but this is still wise to do regardless.
|
||||
//
|
||||
// Note: It may be nice to have this done in the BLESecurity class in the
|
||||
// future, but as it stands right now I'd have to fork the BSP to do
|
||||
// that, which I don't fancy doing. Impact on security is likely minimal.
|
||||
// Requires investigation.
|
||||
|
||||
if (security.sm == 1 && security.lv >= 3) {
|
||||
bt_state = BT_STATE_CONNECTED;
|
||||
cable_state = CABLE_STATE_DISCONNECTED;
|
||||
bt_disable_pairing();
|
||||
} else {
|
||||
bt_ssp_pin = 0;
|
||||
if (connection->bonded()) {
|
||||
connection->removeBondKey();
|
||||
}
|
||||
connection->disconnect();
|
||||
}
|
||||
} else {
|
||||
bt_ssp_pin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
// multiply by tens however many times needed to make numbers appear in order
|
||||
bt_ssp_pin += ((int)passkey[i] - 48) * pow(10, 5-i);
|
||||
}
|
||||
kiss_indicate_btpin();
|
||||
if (match_request) {
|
||||
if (bt_allow_pairing) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
// multiply by tens however many times needed to make numbers appear in order
|
||||
bt_ssp_pin += ((int)passkey[i] - 48) * pow(10, 5-i);
|
||||
}
|
||||
kiss_indicate_btpin();
|
||||
if (bt_allow_pairing) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void bt_connect_callback(uint16_t conn_handle) {
|
||||
bt_state = BT_STATE_CONNECTED;
|
||||
cable_state = CABLE_STATE_DISCONNECTED;
|
||||
bt_state = BT_STATE_CONNECTED;
|
||||
cable_state = CABLE_STATE_DISCONNECTED;
|
||||
|
||||
BLEConnection* conn = Bluefruit.Connection(conn_handle);
|
||||
conn->requestPHY(BLE_GAP_PHY_2MBPS);
|
||||
conn->requestMtuExchange(512+3);
|
||||
conn->requestDataLengthUpdate();
|
||||
}
|
||||
|
||||
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
bt_state = BT_STATE_ON;
|
||||
if (reason != BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||
bt_state = BT_STATE_ON;
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_setup_hw() {
|
||||
@ -432,12 +468,19 @@ char bt_devname[11];
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
Bluefruit.autoConnLed(false);
|
||||
if (Bluefruit.begin()) {
|
||||
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
|
||||
Bluefruit.Security.setIOCaps(true, true, false);
|
||||
Bluefruit.setTxPower(8); // Check bluefruit.h for supported values
|
||||
Bluefruit.Security.setIOCaps(true, false, false); // display, yes; yes / no, no; keyboard, no
|
||||
// This device is indeed capable of yes / no through the pairing mode
|
||||
// being set, but I have chosen to set it thus to force the input of the
|
||||
// pin on the device initiating the pairing.
|
||||
|
||||
Bluefruit.Security.setMITM(true);
|
||||
Bluefruit.Security.setPairPasskeyCallback(bt_passkey_callback);
|
||||
Bluefruit.Periph.setConnectCallback(bt_connect_callback);
|
||||
Bluefruit.Security.setSecuredCallback(bt_connect_callback);
|
||||
Bluefruit.Periph.setDisconnectCallback(bt_disconnect_callback);
|
||||
Bluefruit.Security.setPairCompleteCallback(bt_pairing_complete);
|
||||
Bluefruit.Periph.setConnInterval(6, 12); // 7.5 - 15 ms
|
||||
|
||||
const ble_gap_addr_t gap_addr = Bluefruit.getAddr();
|
||||
char *data = (char*)malloc(BT_DEV_ADDR_LEN+1);
|
||||
for (int i = 0; i < BT_DEV_ADDR_LEN; i++) {
|
||||
@ -468,11 +511,13 @@ char bt_devname[11];
|
||||
// start device information service
|
||||
bledis.begin();
|
||||
|
||||
SerialBT.bufferTXD(true); // enable buffering
|
||||
|
||||
SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
|
||||
SerialBT.begin();
|
||||
|
||||
blebas.begin();
|
||||
|
||||
// non-connectable advertising
|
||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.Advertising.addTxPower();
|
||||
|
||||
@ -490,13 +535,13 @@ char bt_devname[11];
|
||||
}
|
||||
|
||||
bool bt_init() {
|
||||
bt_state = BT_STATE_OFF;
|
||||
if (bt_setup_hw()) {
|
||||
if (bt_enabled && !console_active) bt_start();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
bt_state = BT_STATE_OFF;
|
||||
if (bt_setup_hw()) {
|
||||
if (bt_enabled && !console_active) bt_start();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void bt_enable_pairing() {
|
||||
|
440
Boards.h
440
Boards.h
@ -27,21 +27,91 @@
|
||||
#define MCU_ESP32 0x81
|
||||
#define MCU_NRF52 0x71
|
||||
|
||||
#define BOARD_RNODE 0x31
|
||||
#define BOARD_HMBRW 0x32
|
||||
// Products, boards and models ////
|
||||
#define PRODUCT_RNODE 0x03 // RNode devices
|
||||
#define BOARD_RNODE 0x31 // Original v1.0 RNode
|
||||
#define MODEL_A4 0xA4 // RNode v1.0, 433 MHz
|
||||
#define MODEL_A9 0xA9 // RNode v1.0, 868 MHz
|
||||
|
||||
#define BOARD_RNODE_NG_20 0x40 // RNode hardware revision v2.0
|
||||
#define MODEL_A3 0xA3 // RNode v2.0, 433 MHz
|
||||
#define MODEL_A8 0xA8 // RNode v2.0, 868 MHz
|
||||
|
||||
#define BOARD_RNODE_NG_21 0x41 // RNode hardware revision v2.1
|
||||
#define MODEL_A2 0xA2 // RNode v2.1, 433 MHz
|
||||
#define MODEL_A7 0xA7 // RNode v2.1, 868 MHz
|
||||
|
||||
#define BOARD_T3S3 0x42 // T3S3 devices
|
||||
#define MODEL_A1 0xA1 // T3S3, 433 MHz with SX1268
|
||||
#define MODEL_A5 0xA5 // T3S3, 433 MHz with SX1278
|
||||
#define MODEL_A6 0xA6 // T3S3, 868 MHz with SX1262
|
||||
#define MODEL_AA 0xAA // T3S3, 868 MHz with SX1276
|
||||
#define MODEL_AC 0xAC // T3S3, 2.4 GHz with SX1280 and PA
|
||||
|
||||
#define PRODUCT_TBEAM 0xE0 // T-Beam devices
|
||||
#define BOARD_TBEAM 0x33
|
||||
#define MODEL_E4 0xE4 // T-Beam SX1278, 433 Mhz
|
||||
#define MODEL_E9 0xE9 // T-Beam SX1276, 868 Mhz
|
||||
#define MODEL_E3 0xE3 // T-Beam SX1268, 433 Mhz
|
||||
#define MODEL_E8 0xE8 // T-Beam SX1262, 868 Mhz
|
||||
|
||||
#define PRODUCT_TDECK_V1 0xD0
|
||||
#define BOARD_TDECK 0x3B
|
||||
#define MODEL_D4 0xD4 // LilyGO T-Deck, 433 MHz
|
||||
#define MODEL_D9 0xD9 // LilyGO T-Deck, 868 MHz
|
||||
|
||||
#define PRODUCT_TBEAM_S_V1 0xEA
|
||||
#define BOARD_TBEAM_S_V1 0x3D
|
||||
#define MODEL_DB 0xDB // LilyGO T-Beam Supreme, 433 MHz
|
||||
#define MODEL_DC 0xDC // LilyGO T-Beam Supreme, 868 MHz
|
||||
|
||||
#define PRODUCT_T32_10 0xB2
|
||||
#define BOARD_LORA32_V1_0 0x39
|
||||
#define MODEL_BA 0xBA // LilyGO T3 v1.0, 433 MHz
|
||||
#define MODEL_BB 0xBB // LilyGO T3 v1.0, 868 MHz
|
||||
|
||||
#define PRODUCT_T32_20 0xB0
|
||||
#define BOARD_LORA32_V2_0 0x36
|
||||
#define MODEL_B3 0xB3 // LilyGO T3 v2.0, 433 MHz
|
||||
#define MODEL_B8 0xB8 // LilyGO T3 v2.0, 868 MHz
|
||||
|
||||
#define PRODUCT_T32_21 0xB1
|
||||
#define BOARD_LORA32_V2_1 0x37
|
||||
#define MODEL_B4 0xB4 // LilyGO T3 v2.1, 433 MHz
|
||||
#define MODEL_B9 0xB9 // LilyGO T3 v2.1, 868 MHz
|
||||
|
||||
#define PRODUCT_H32_V2 0xC0 // Board code 0x38
|
||||
#define BOARD_HELTEC32_V2 0x38
|
||||
#define MODEL_C4 0xC4 // Heltec Lora32 v2, 433 MHz
|
||||
#define MODEL_C9 0xC9 // Heltec Lora32 v2, 868 MHz
|
||||
|
||||
#define PRODUCT_H32_V3 0xC1
|
||||
#define BOARD_HELTEC32_V3 0x3A
|
||||
#define MODEL_C5 0xC5 // Heltec Lora32 v3, 433 MHz
|
||||
#define MODEL_CA 0xCA // Heltec Lora32 v3, 868 MHz
|
||||
|
||||
#define PRODUCT_HELTEC_T114 0xC2 // Heltec Mesh Node T114
|
||||
#define BOARD_HELTEC_T114 0x3C
|
||||
#define MODEL_C6 0xC6 // Heltec Mesh Node T114, 470-510 MHz
|
||||
#define MODEL_C7 0xC7 // Heltec Mesh Node T114, 863-928 MHz
|
||||
|
||||
#define PRODUCT_TECHO 0x15 // LilyGO T-Echo devices
|
||||
#define BOARD_TECHO 0x44
|
||||
#define MODEL_16 0x16 // T-Echo 433 MHz
|
||||
#define MODEL_17 0x17 // T-Echo 868/915 MHz
|
||||
|
||||
#define PRODUCT_RAK4631 0x10
|
||||
#define BOARD_RAK4631 0x51
|
||||
#define MODEL_11 0x11 // RAK4631, 433 Mhz
|
||||
#define MODEL_12 0x12 // RAK4631, 868 Mhz
|
||||
|
||||
#define PRODUCT_HMBRW 0xF0
|
||||
#define BOARD_HMBRW 0x32
|
||||
#define BOARD_HUZZAH32 0x34
|
||||
#define BOARD_GENERIC_ESP32 0x35
|
||||
#define BOARD_LORA32_V2_0 0x36
|
||||
#define BOARD_LORA32_V2_1 0x37
|
||||
#define BOARD_LORA32_V1_0 0x39
|
||||
#define BOARD_HELTEC32_V2 0x38
|
||||
#define BOARD_HELTEC32_V3 0x3A
|
||||
#define BOARD_RNODE_NG_20 0x40
|
||||
#define BOARD_RNODE_NG_21 0x41
|
||||
#define BOARD_RNODE_NG_22 0x42
|
||||
#define BOARD_GENERIC_NRF52 0x50
|
||||
#define BOARD_RAK4631 0x51
|
||||
#define MODEL_FE 0xFE // Homebrew board, max 17dBm output power
|
||||
#define MODEL_FF 0xFF // Homebrew board, max 14dBm output power
|
||||
|
||||
#if defined(__AVR_ATmega1284P__)
|
||||
#define PLATFORM PLATFORM_AVR
|
||||
@ -155,6 +225,10 @@
|
||||
#define I2C_SDA 21
|
||||
#define I2C_SCL 22
|
||||
#define PMU_IRQ 35
|
||||
|
||||
#define HAS_INPUT true
|
||||
const int pin_btn_usr1 = 38;
|
||||
|
||||
const int pin_cs = 18;
|
||||
const int pin_reset = 23;
|
||||
const int pin_led_rx = 2;
|
||||
@ -164,6 +238,7 @@
|
||||
#define HAS_TCXO true
|
||||
#define HAS_BUSY true
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define OCP_TUNED 0x38
|
||||
const int pin_busy = 32;
|
||||
const int pin_dio = 33;
|
||||
const int pin_tcxo_enable = -1;
|
||||
@ -238,6 +313,13 @@
|
||||
#define HAS_BLUETOOTH true
|
||||
#define HAS_CONSOLE true
|
||||
#define HAS_EEPROM true
|
||||
#define HAS_INPUT true
|
||||
#define HAS_SLEEP true
|
||||
#define PIN_WAKEUP GPIO_NUM_0
|
||||
#define WAKEUP_LEVEL 0
|
||||
|
||||
const int pin_btn_usr1 = 0;
|
||||
|
||||
const int pin_cs = 18;
|
||||
const int pin_reset = 14;
|
||||
const int pin_dio = 26;
|
||||
@ -261,6 +343,7 @@
|
||||
#define HAS_SLEEP true
|
||||
#define PIN_WAKEUP GPIO_NUM_0
|
||||
#define WAKEUP_LEVEL 0
|
||||
#define OCP_TUNED 0x38
|
||||
|
||||
const int pin_btn_usr1 = 0;
|
||||
|
||||
@ -335,14 +418,82 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
#define IS_ESP32S3 true
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_CONSOLE true
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
#define HAS_PMU true
|
||||
#define HAS_NP false
|
||||
#define HAS_SD false
|
||||
#define HAS_EEPROM true
|
||||
|
||||
#define HAS_INPUT true
|
||||
#define HAS_SLEEP true
|
||||
#define PIN_WAKEUP GPIO_NUM_0
|
||||
#define WAKEUP_LEVEL 0
|
||||
const int pin_btn_usr1 = 0;
|
||||
|
||||
const int pin_cs = 7;
|
||||
const int pin_reset = 8;
|
||||
const int pin_sclk = 5;
|
||||
const int pin_mosi = 6;
|
||||
const int pin_miso = 3;
|
||||
|
||||
#if MODEM == SX1262
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_TCXO true
|
||||
const int pin_busy = 34;
|
||||
const int pin_dio = 33;
|
||||
const int pin_tcxo_enable = -1;
|
||||
#elif MODEM == SX1280
|
||||
#define CONFIG_QUEUE_SIZE 6144
|
||||
#define DIO2_AS_RF_SWITCH false
|
||||
#define HAS_BUSY true
|
||||
#define HAS_TCXO true
|
||||
#define HAS_PA true
|
||||
const int pa_max_input = 3;
|
||||
|
||||
#define HAS_RF_SWITCH_RX_TX true
|
||||
const int pin_rxen = 21;
|
||||
const int pin_txen = 10;
|
||||
|
||||
const int pin_busy = 36;
|
||||
const int pin_dio = 9;
|
||||
const int pin_tcxo_enable = -1;
|
||||
#else
|
||||
const int pin_dio = 9;
|
||||
#endif
|
||||
|
||||
const int pin_np = 38;
|
||||
const int pin_dac = 25;
|
||||
const int pin_adc = 1;
|
||||
|
||||
const int SD_MISO = 2;
|
||||
const int SD_MOSI = 11;
|
||||
const int SD_CLK = 14;
|
||||
const int SD_CS = 13;
|
||||
|
||||
#if HAS_NP == false
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
const int pin_led_rx = 37;
|
||||
const int pin_led_tx = 37;
|
||||
#else
|
||||
const int pin_led_rx = 37;
|
||||
const int pin_led_tx = 37;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
#define IS_ESP32S3 true
|
||||
#define MODEM SX1262
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_TCXO true
|
||||
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_DISPLAY false
|
||||
#define HAS_CONSOLE false
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
@ -355,35 +506,90 @@
|
||||
#define HAS_SLEEP true
|
||||
#define PIN_WAKEUP GPIO_NUM_0
|
||||
#define WAKEUP_LEVEL 0
|
||||
// #define PIN_DISP_SLEEP 21
|
||||
// #define DISP_SLEEP_LEVEL HIGH
|
||||
|
||||
const int pin_poweron = 10;
|
||||
const int pin_btn_usr1 = 0;
|
||||
|
||||
const int pin_cs = 7;
|
||||
const int pin_reset = 8;
|
||||
const int pin_sclk = 5;
|
||||
const int pin_mosi = 6;
|
||||
const int pin_miso = 3;
|
||||
const int pin_cs = 9;
|
||||
const int pin_reset = 17;
|
||||
const int pin_sclk = 40;
|
||||
const int pin_mosi = 41;
|
||||
const int pin_miso = 38;
|
||||
const int pin_tcxo_enable = -1;
|
||||
|
||||
const int pin_dio = 33;
|
||||
const int pin_busy = 34;
|
||||
const int pin_dio = 45;
|
||||
const int pin_busy = 13;
|
||||
|
||||
const int pin_np = 38;
|
||||
const int pin_dac = 25;
|
||||
const int pin_adc = 1;
|
||||
const int SD_MISO = 38;
|
||||
const int SD_MOSI = 41;
|
||||
const int SD_CLK = 40;
|
||||
const int SD_CS = 39;
|
||||
|
||||
const int DISPLAY_DC = 11;
|
||||
const int DISPLAY_CS = 12;
|
||||
const int DISPLAY_MISO = 38;
|
||||
const int DISPLAY_MOSI = 41;
|
||||
const int DISPLAY_CLK = 40;
|
||||
const int DISPLAY_BL_PIN = 42;
|
||||
|
||||
const int SD_MISO = 2;
|
||||
const int SD_MOSI = 11;
|
||||
const int SD_CLK = 14;
|
||||
const int SD_CS = 13;
|
||||
#if HAS_NP == false
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
const int pin_led_rx = 37;
|
||||
const int pin_led_tx = 37;
|
||||
const int pin_led_rx = 43;
|
||||
const int pin_led_tx = 43;
|
||||
#else
|
||||
const int pin_led_rx = 37;
|
||||
const int pin_led_tx = 37;
|
||||
const int pin_led_rx = 43;
|
||||
const int pin_led_tx = 43;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
#define IS_ESP32S3 true
|
||||
#define MODEM SX1262
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_TCXO true
|
||||
#define OCP_TUNED 0x38
|
||||
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_CONSOLE true
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
#define HAS_PMU true
|
||||
#define HAS_NP false
|
||||
#define HAS_SD false
|
||||
#define HAS_EEPROM true
|
||||
|
||||
#define HAS_INPUT true
|
||||
#define HAS_SLEEP false
|
||||
|
||||
#define PMU_IRQ 40
|
||||
#define I2C_SCL 41
|
||||
#define I2C_SDA 42
|
||||
|
||||
const int pin_btn_usr1 = 0;
|
||||
|
||||
const int pin_cs = 10;
|
||||
const int pin_reset = 5;
|
||||
const int pin_sclk = 12;
|
||||
const int pin_mosi = 11;
|
||||
const int pin_miso = 13;
|
||||
const int pin_tcxo_enable = -1;
|
||||
const int pin_dio = 1;
|
||||
const int pin_busy = 4;
|
||||
|
||||
const int SD_MISO = 37;
|
||||
const int SD_MOSI = 35;
|
||||
const int SD_CLK = 36;
|
||||
const int SD_CS = 47;
|
||||
|
||||
const int IMU_CS = 34;
|
||||
|
||||
#if HAS_NP == false
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
const int pin_led_rx = 43;
|
||||
const int pin_led_tx = 43;
|
||||
#else
|
||||
const int pin_led_rx = 43;
|
||||
const int pin_led_tx = 43;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -394,7 +600,7 @@
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
#if BOARD_MODEL == BOARD_RAK4631
|
||||
#define HAS_EEPROM false
|
||||
#define HAS_DISPLAY false
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
#define HAS_CONSOLE false
|
||||
@ -404,6 +610,7 @@
|
||||
#define HAS_TCXO true
|
||||
#define HAS_RF_SWITCH_RX_TX true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_INPUT true
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define CONFIG_UART_BUFFER_SIZE 6144
|
||||
#define CONFIG_QUEUE_SIZE 6144
|
||||
@ -413,8 +620,11 @@
|
||||
#define BLE_MANUFACTURER "RAK Wireless"
|
||||
#define BLE_MODEL "RAK4640"
|
||||
|
||||
const int pin_btn_usr1 = 9;
|
||||
|
||||
// Following pins are for the sx1262
|
||||
const int pin_rxen = 37;
|
||||
const int pin_txen = -1;
|
||||
const int pin_reset = 38;
|
||||
const int pin_cs = 42;
|
||||
const int pin_sclk = 43;
|
||||
@ -426,12 +636,154 @@
|
||||
const int pin_led_tx = LED_GREEN;
|
||||
const int pin_tcxo_enable = -1;
|
||||
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
#define _PINNUM(port, pin) ((port) * 32 + (pin))
|
||||
#define MODEM SX1262
|
||||
#define HAS_EEPROM false
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
#define HAS_CONSOLE false
|
||||
#define HAS_PMU true
|
||||
#define HAS_NP false
|
||||
#define HAS_SD false
|
||||
#define HAS_TCXO true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_INPUT true
|
||||
#define HAS_SLEEP true
|
||||
#define BLE_MANUFACTURER "LilyGO"
|
||||
#define BLE_MODEL "T-Echo"
|
||||
|
||||
#define HAS_INPUT true
|
||||
#define EEPROM_SIZE 296
|
||||
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
||||
|
||||
#define CONFIG_UART_BUFFER_SIZE 32768
|
||||
#define CONFIG_QUEUE_SIZE 6144
|
||||
#define CONFIG_QUEUE_MAX_LENGTH 200
|
||||
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_BACKLIGHT true
|
||||
#define DISPLAY_SCALE 1
|
||||
|
||||
#define LED_ON LOW
|
||||
#define LED_OFF HIGH
|
||||
#define PIN_LED_GREEN _PINNUM(1, 1)
|
||||
#define PIN_LED_RED _PINNUM(1, 3)
|
||||
#define PIN_LED_BLUE _PINNUM(0, 14)
|
||||
#define PIN_VEXT_EN _PINNUM(0, 12)
|
||||
|
||||
const int pin_disp_cs = 30;
|
||||
const int pin_disp_dc = 28;
|
||||
const int pin_disp_reset = 2;
|
||||
const int pin_disp_busy = 3;
|
||||
const int pin_disp_en = -1;
|
||||
const int pin_disp_sck = 31;
|
||||
const int pin_disp_mosi = 29;
|
||||
const int pin_disp_miso = -1;
|
||||
const int pin_backlight = 43;
|
||||
|
||||
const int pin_btn_usr1 = _PINNUM(1, 10);
|
||||
const int pin_btn_touch = _PINNUM(0, 11);
|
||||
|
||||
const int pin_reset = 25;
|
||||
const int pin_cs = 24;
|
||||
const int pin_sclk = 19;
|
||||
const int pin_mosi = 22;
|
||||
const int pin_miso = 23;
|
||||
const int pin_busy = 17;
|
||||
const int pin_dio = 20;
|
||||
const int pin_tcxo_enable = 21;
|
||||
const int pin_led_rx = PIN_LED_BLUE;
|
||||
const int pin_led_tx = PIN_LED_RED;
|
||||
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
#define MODEM SX1262
|
||||
#define HAS_EEPROM false
|
||||
#define HAS_DISPLAY true
|
||||
#define HAS_BLUETOOTH false
|
||||
#define HAS_BLE true
|
||||
#define HAS_CONSOLE false
|
||||
#define HAS_PMU true
|
||||
#define HAS_NP true
|
||||
#define HAS_SD false
|
||||
#define HAS_TCXO true
|
||||
#define HAS_BUSY true
|
||||
#define HAS_INPUT true
|
||||
#define HAS_SLEEP true
|
||||
#define DIO2_AS_RF_SWITCH true
|
||||
#define CONFIG_UART_BUFFER_SIZE 6144
|
||||
#define CONFIG_QUEUE_SIZE 6144
|
||||
#define CONFIG_QUEUE_MAX_LENGTH 200
|
||||
#define EEPROM_SIZE 296
|
||||
#define EEPROM_OFFSET EEPROM_SIZE-EEPROM_RESERVED
|
||||
#define BLE_MANUFACTURER "Heltec"
|
||||
#define BLE_MODEL "T114"
|
||||
|
||||
#define PIN_T114_ADC_EN 6
|
||||
#define PIN_VEXT_EN 21
|
||||
|
||||
// LED
|
||||
#define LED_T114_GREEN 3
|
||||
#define PIN_T114_LED 14
|
||||
#define NP_M 1
|
||||
const int pin_np = PIN_T114_LED;
|
||||
|
||||
// SPI
|
||||
#define PIN_T114_MOSI 22
|
||||
#define PIN_T114_MISO 23
|
||||
#define PIN_T114_SCK 19
|
||||
#define PIN_T114_SS 24
|
||||
|
||||
// SX1262
|
||||
#define PIN_T114_RST 25
|
||||
#define PIN_T114_DIO1 20
|
||||
#define PIN_T114_BUSY 17
|
||||
|
||||
// TFT
|
||||
#define DISPLAY_SCALE 2
|
||||
#define PIN_T114_TFT_MOSI 9
|
||||
#define PIN_T114_TFT_MISO 11 // not connected
|
||||
#define PIN_T114_TFT_SCK 8
|
||||
#define PIN_T114_TFT_SS 11
|
||||
#define PIN_T114_TFT_DC 12
|
||||
#define PIN_T114_TFT_RST 2
|
||||
#define PIN_T114_TFT_EN 3
|
||||
#define PIN_T114_TFT_BLGT 15
|
||||
|
||||
// pins for buttons on Heltec T114
|
||||
const int pin_btn_usr1 = 42;
|
||||
|
||||
// pins for sx1262 on Heltec T114
|
||||
const int pin_reset = PIN_T114_RST;
|
||||
const int pin_cs = PIN_T114_SS;
|
||||
const int pin_sclk = PIN_T114_SCK;
|
||||
const int pin_mosi = PIN_T114_MOSI;
|
||||
const int pin_miso = PIN_T114_MISO;
|
||||
const int pin_busy = PIN_T114_BUSY;
|
||||
const int pin_dio = PIN_T114_DIO1;
|
||||
const int pin_led_rx = 35;
|
||||
const int pin_led_tx = 35;
|
||||
const int pin_tcxo_enable = -1;
|
||||
|
||||
// pins for ST7789 display on Heltec T114
|
||||
const int DISPLAY_DC = PIN_T114_TFT_DC;
|
||||
const int DISPLAY_CS = PIN_T114_TFT_SS;
|
||||
const int DISPLAY_MISO = PIN_T114_TFT_MISO;
|
||||
const int DISPLAY_MOSI = PIN_T114_TFT_MOSI;
|
||||
const int DISPLAY_CLK = PIN_T114_TFT_SCK;
|
||||
const int DISPLAY_BL_PIN = PIN_T114_TFT_BLGT;
|
||||
const int DISPLAY_RST = PIN_T114_TFT_RST;
|
||||
|
||||
#else
|
||||
#error An unsupported nRF board was selected. Cannot compile RNode firmware.
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef DISPLAY_SCALE
|
||||
#define DISPLAY_SCALE 1
|
||||
#endif
|
||||
|
||||
#ifndef HAS_RF_SWITCH_RX_TX
|
||||
const int pin_rxen = -1;
|
||||
const int pin_txen = -1;
|
||||
@ -441,8 +793,26 @@
|
||||
const int pin_busy = -1;
|
||||
#endif
|
||||
|
||||
#ifndef LED_ON
|
||||
#define LED_ON HIGH
|
||||
#endif
|
||||
|
||||
#ifndef LED_OFF
|
||||
#define LED_OFF LOW
|
||||
#endif
|
||||
|
||||
#ifndef DIO2_AS_RF_SWITCH
|
||||
#define DIO2_AS_RF_SWITCH false
|
||||
#endif
|
||||
|
||||
// Default OCP value if not specified
|
||||
// in board configuration
|
||||
#ifndef OCP_TUNED
|
||||
#define OCP_TUNED 0x38
|
||||
#endif
|
||||
|
||||
#ifndef NP_M
|
||||
#define NP_M 0.15
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
83
Config.h
83
Config.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -20,7 +20,7 @@
|
||||
#define CONFIG_H
|
||||
|
||||
#define MAJ_VERS 0x01
|
||||
#define MIN_VERS 0x4b
|
||||
#define MIN_VERS 0x51
|
||||
|
||||
#define MODE_HOST 0x11
|
||||
#define MODE_TNC 0x12
|
||||
@ -67,28 +67,55 @@
|
||||
const int rssi_offset = 157;
|
||||
|
||||
// Default LoRa settings
|
||||
const int lora_rx_turnaround_ms = 66;
|
||||
const int lora_post_tx_yield_slots = 6;
|
||||
uint32_t post_tx_yield_timeout = 0;
|
||||
#define LORA_PREAMBLE_SYMBOLS_HW 4
|
||||
#define LORA_PREAMBLE_SYMBOLS_MIN 18
|
||||
#define LORA_PREAMBLE_TARGET_MS 15
|
||||
#define LORA_CAD_SYMBOLS 3
|
||||
int csma_slot_ms = 50;
|
||||
float csma_p_min = 0.1;
|
||||
float csma_p_max = 0.8;
|
||||
uint8_t csma_p = 0;
|
||||
#define PHY_HEADER_LORA_SYMBOLS 20
|
||||
#define PHY_CRC_LORA_BITS 16
|
||||
#define LORA_PREAMBLE_SYMBOLS_MIN 18
|
||||
#define LORA_PREAMBLE_TARGET_MS 24
|
||||
#define LORA_PREAMBLE_FAST_DELTA 18
|
||||
#define LORA_FAST_THRESHOLD_BPS 30E3
|
||||
#define LORA_LIMIT_THRESHOLD_BPS 60E3
|
||||
long lora_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;
|
||||
long lora_preamble_time_ms = 0;
|
||||
long lora_header_time_ms = 0;
|
||||
float lora_symbol_time_ms = 0.0;
|
||||
float lora_symbol_rate = 0.0;
|
||||
float lora_us_per_byte = 0.0;
|
||||
bool lora_low_datarate = false;
|
||||
bool lora_limit_rate = false;
|
||||
|
||||
int lora_sf = 0;
|
||||
int lora_cr = 5;
|
||||
int lora_txp = 0xFF;
|
||||
uint32_t lora_bw = 0;
|
||||
uint32_t lora_freq = 0;
|
||||
uint32_t lora_bitrate = 0;
|
||||
long lora_preamble_symbols = 6;
|
||||
float lora_symbol_time_ms = 0.0;
|
||||
float lora_symbol_rate = 0.0;
|
||||
float lora_us_per_byte = 0.0;
|
||||
// CSMA Parameters
|
||||
#define CSMA_SIFS_MS 0
|
||||
#define CSMA_POST_TX_YIELD_SLOTS 3
|
||||
#define CSMA_SLOT_MAX_MS 100
|
||||
#define CSMA_SLOT_MIN_MS 24
|
||||
#define CSMA_SLOT_MIN_FAST_DELTA 18
|
||||
#define CSMA_SLOT_SYMBOLS 12
|
||||
#define CSMA_CW_BANDS 4
|
||||
#define CSMA_CW_MIN 0
|
||||
#define CSMA_CW_PER_BAND_WINDOWS 15
|
||||
#define CSMA_BAND_1_MAX_AIRTIME 7
|
||||
#define CSMA_BAND_N_MIN_AIRTIME 85
|
||||
#define CSMA_INFR_THRESHOLD_DB 12
|
||||
bool interference_detected = false;
|
||||
bool avoid_interference = true;
|
||||
int csma_slot_ms = CSMA_SLOT_MIN_MS;
|
||||
unsigned long difs_ms = CSMA_SIFS_MS + 2*csma_slot_ms;
|
||||
unsigned long difs_wait_start = -1;
|
||||
unsigned long cw_wait_start = -1;
|
||||
unsigned long cw_wait_target = -1;
|
||||
unsigned long cw_wait_passed = 0;
|
||||
int csma_cw = -1;
|
||||
uint8_t cw_band = 1;
|
||||
uint8_t cw_min = 0;
|
||||
uint8_t cw_max = CSMA_CW_PER_BAND_WINDOWS;
|
||||
|
||||
// LoRa settings
|
||||
int lora_sf = 0;
|
||||
int lora_cr = 5;
|
||||
int lora_txp = 0xFF;
|
||||
uint32_t lora_bw = 0;
|
||||
uint32_t lora_freq = 0;
|
||||
uint32_t lora_bitrate = 0;
|
||||
|
||||
// Operational variables
|
||||
bool radio_locked = true;
|
||||
@ -100,12 +127,15 @@
|
||||
bool pmu_ready = false;
|
||||
bool promisc = false;
|
||||
bool implicit = false;
|
||||
bool memory_low = false;
|
||||
uint8_t implicit_l = 0;
|
||||
|
||||
uint8_t op_mode = MODE_HOST;
|
||||
uint8_t model = 0x00;
|
||||
uint8_t hwrev = 0x00;
|
||||
|
||||
#define NOISE_FLOOR_SAMPLES 64
|
||||
int noise_floor = -292;
|
||||
int current_rssi = -292;
|
||||
int last_rssi = -292;
|
||||
uint8_t last_rssi_raw = 0x00;
|
||||
@ -163,11 +193,6 @@
|
||||
uint32_t last_status_update = 0;
|
||||
uint32_t last_dcd = 0;
|
||||
|
||||
// Status flags
|
||||
const uint8_t SIG_DETECT = 0x01;
|
||||
const uint8_t SIG_SYNCED = 0x02;
|
||||
const uint8_t RX_ONGOING = 0x04;
|
||||
|
||||
// Power management
|
||||
#define BATTERY_STATE_UNKNOWN 0x00
|
||||
#define BATTERY_STATE_DISCHARGING 0x01
|
||||
@ -182,11 +207,13 @@
|
||||
uint8_t battery_state = 0x00;
|
||||
uint8_t display_intensity = 0xFF;
|
||||
uint8_t display_addr = 0xFF;
|
||||
volatile bool display_updating = false;
|
||||
bool display_blanking_enabled = false;
|
||||
bool display_diagnostics = true;
|
||||
bool device_init_done = false;
|
||||
bool eeprom_ok = false;
|
||||
bool firmware_update_mode = false;
|
||||
bool serial_in_frame = false;
|
||||
|
||||
// Boot flags
|
||||
#define START_FROM_BOOTLOADER 0x01
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
|
Binary file not shown.
@ -4,10 +4,10 @@ import sys
|
||||
import shutil
|
||||
|
||||
packages = {
|
||||
"rns": "rns-0.8.1-py3-none-any.whl",
|
||||
"nomadnet": "nomadnet-0.5.3-py3-none-any.whl",
|
||||
"lxmf": "lxmf-0.5.4-py3-none-any.whl",
|
||||
"rnsh": "rnsh-0.1.4-py3-none-any.whl",
|
||||
"rns": "rns-0.9.1-py3-none-any.whl",
|
||||
"nomadnet": "nomadnet-0.5.7-py3-none-any.whl",
|
||||
"lxmf": "lxmf-0.6.0-py3-none-any.whl",
|
||||
"rnsh": "rnsh-0.1.5-py3-none-any.whl",
|
||||
}
|
||||
|
||||
DEFAULT_TITLE = "RNode Bootstrap Console"
|
||||
@ -174,15 +174,21 @@ mf.write(help_redirect)
|
||||
mf.close()
|
||||
|
||||
def optimise_manual(path):
|
||||
pm = 100
|
||||
pm = 90
|
||||
scale_imgs = [
|
||||
("_images/board_rnodev2.png", pm),
|
||||
("_images/board_rnode.png", pm),
|
||||
("_images/board_heltec32.png", pm),
|
||||
("_images/board_heltec32v20.png", pm),
|
||||
("_images/board_heltec32v30.png", pm),
|
||||
("_images/board_t3v21.png", pm),
|
||||
("_images/board_t3v20.png", pm),
|
||||
("_images/sideband_devices.webp", pm),
|
||||
("_images/board_t3v10.png", pm),
|
||||
("_images/board_t3s3.png", pm),
|
||||
("_images/board_tbeam.png", pm),
|
||||
("_images/board_tdeck.png", pm),
|
||||
("_images/board_rak4631.png", pm),
|
||||
("_images/board_tbeam_supreme.png", pm),
|
||||
("_images/sideband_devices.webp", pm),
|
||||
("_images/nomadnet_3.png", pm),
|
||||
("_images/meshchat_1.webp", pm),
|
||||
("_images/radio_is5ac.png", pm),
|
||||
@ -195,7 +201,7 @@ def optimise_manual(path):
|
||||
import shlex
|
||||
for i,s in scale_imgs:
|
||||
fp = path+"/"+i
|
||||
resize = "convert "+fp+" -resize "+str(s)+" "+fp
|
||||
resize = "convert "+fp+" -quality 25 -resize "+str(s)+" "+fp
|
||||
print(resize)
|
||||
subprocess.call(shlex.split(resize), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
[title]: <> (How To Make Your Own RNodes)
|
||||
[image]: <> (images/g3p.webp)
|
||||
[excerpt]: <> (This article will outline the general process, and provide the information you need, for building your own RNode from a few basic modules. The RNode will be functionally identical to a commercially purchased board.)
|
||||
<div class="article_date">{DATE}</div>
|
||||
# How To Make Your Own RNodes
|
||||
|
||||
This article will outline the general process, and provide the information you need, for building your own RNode from a few basic modules. The RNode will be functionally identical to a purchased device.
|
||||
@ -31,10 +30,9 @@ Currently, the RNode firmware supports a variety of different microcontrollers,
|
||||
|
||||
Regarding the LoRa transceiver module, there is going to be an almost overwhelming amount of options to choose from. To narrow it down, here are the essential characteristics to look for:
|
||||
|
||||
- The RNode firmware needs a module based on the **Semtech SX1276** or **Semtech SX1278** LoRa transceiver IC. These come in several different variants, for all frequency bands from about 150 MHz to about 1100 MHz.
|
||||
- Support for **SX1262**, **SX1268** and **SX1280**-based modules is coming soon, but until that is released, only **SX1276** and **SX1278** modules will work.
|
||||
- The RNode firmware needs a module based on the **Semtech SX1276**, **Semtech SX1278**, **SX1262**, **SX1268** and **SX1280** LoRa transceiver ICs. These come in several different variants, for all frequency bands from about 150 MHz to 2500 MHz.
|
||||
- The module *must* expose the direct SPI bus to the transceiver chip. UART based modules that add their own communications layer will not work.
|
||||
- The module must also expose the *reset* line of the chip, and provide the **DIO0** interrupt signal *from* the chip.
|
||||
- The module must also expose the *reset* line of the chip, and provide the **DIO0** (or other relevant) interrupt signal *from* the chip.
|
||||
- As mentioned above, the module must be logic-level compatible with the microcontroller you are using, unless you want to add a level-shifter. Resistor divider arrays will most likely not work here, due to the bus speeds required.
|
||||
|
||||
Keeping those things in mind, you should be able to select a suitable combination of microcontroller board and transceiver module.
|
||||
@ -56,12 +54,17 @@ In the photo above I used an Adafruit Feather ESP32 board and a ModTronix inAir4
|
||||
9. Connect the *DIO0* pin of the transceiver module to the *DIO0 interrupt pin* of the microcontroller board.
|
||||
10. You can optionally connect transmit and receiver LEDs to the corresponding pins of the microcontroller board.
|
||||
|
||||
The pin layouts of your transceiver module and microcontroller board will vary, but you can look up the correct pin assignments for your processor type and board layout in the `Config.h` file of the [RNode Firmware]({ASSET_PATH}pkg/rnode_firmware.zip).
|
||||
The pin layouts of your transceiver module and microcontroller board will vary, but you can look up the correct pin assignments for your processor type and board layout in the [Config.h](https://github.com/markqvist/RNode_Firmware/blob/master/Config.h) file of the [RNode Firmware](https://unsigned.io/rnode_firmware).
|
||||
|
||||
## Loading the Firmware
|
||||
Once the hardware is assembled, you are ready to load the firmware onto the board and configure the configuration parameters in the boards EEPROM. Luckily, this process is completely automated by the [RNode Configuration Utility]({ASSET_PATH}m/using.html#the-rnodeconf-utility).
|
||||
### Loading the Firmware
|
||||
Once the hardware is assembled, you are ready to load the firmware onto the board and configure the configuration parameters in the boards EEPROM. Luckily, this process is completely automated by the [RNode Configuration Utility](https://markqvist.github.io/Reticulum/manual/using.html#the-rnodeconf-utility). To prepare for loading the firmware, make sure that `python` and `pip` is installed on your system, then install the `rns` package (which includes the `rnodeconf` program) by issuing the command:
|
||||
|
||||
The `rnodeconf` program is included in the `rns` package. Please read [these instructions]({ASSET_PATH}s_rns.html) for more information on how to install it from this repository, or from the Internet. If installation goes well, you can now move on to the next step.
|
||||
|
||||
```txt
|
||||
pip install rns
|
||||
```
|
||||
|
||||
If installation goes well, you can now move on to the next step.
|
||||
|
||||
> *Take Care*: A LoRa transceiver module **must** be connected to the board for the firmware to start and accept commands. If the firmware does not verify that the correct transceiver is available on the SPI bus, execution is stopped, and the board will not accept commands. If you find the board unresponsive after installing the firmware, or EEPROM configuration fails, double-check your transceiver module wiring!
|
||||
|
||||
@ -73,24 +76,6 @@ rnodeconf --autoinstall
|
||||
|
||||
The installer will now ask you to insert the device you want to set up, scan for connected serial ports, and ask you a number of questions regarding the device. When it has the information it needs, it will install the correct firmware and configure the necessary parameters in the device EEPROM for it to function properly.
|
||||
|
||||
> **Please Note!** If you are connected to the Internet while installing, the autoinstaller will automatically download any needed firmware files to a local cache before installing.
|
||||
|
||||
> If you do not have an active Internet connection while installing, you can extract and use the firmware from this device instead. This will **only** work if you are building the same type of RNode as the device you are extracting from, as the firmware has to match the targeted board and hardware configuration.
|
||||
|
||||
If you need to extract the firmware from an existing RNode, run the following command:
|
||||
|
||||
```
|
||||
rnodeconf --extract
|
||||
```
|
||||
|
||||
If `rnodeconf` finds a working RNode, it will extract and save the firmware from the device for later use. You can then run the auto-installer with the `--use-extracted` option to use the locally extracted file:
|
||||
|
||||
```
|
||||
rnodeconf --autoinstall --use-extracted
|
||||
```
|
||||
|
||||
This also works for updating the firmware on existing RNodes, so you can extract a newer firmware from one RNode, and deploy it onto other RNodes using the same method. Just use the `--update` option instead of `--autoinstall`.
|
||||
|
||||
If the install goes well, you will be greated with a success message telling you that your device is now ready. To confirm everything is OK, you can query the device info with:
|
||||
|
||||
```txt
|
||||
|
88
Device.h
88
Device.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -36,6 +36,8 @@
|
||||
#define APPLICATION_START 0x26000
|
||||
|
||||
#define USER_DATA_START 0xED000
|
||||
|
||||
#define IMG_SIZE_START 0xFF008
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -141,6 +143,13 @@ void device_save_firmware_hash() {
|
||||
}
|
||||
|
||||
#if MCU_VARIANT == MCU_NRF52
|
||||
uint32_t retrieve_application_size() {
|
||||
uint8_t bytes[4];
|
||||
memcpy(bytes, (const void*)IMG_SIZE_START, 4);
|
||||
uint32_t fw_len = bytes[0] | bytes[1] << 8 | bytes[2] << 16 | bytes[3] << 24;
|
||||
return fw_len;
|
||||
}
|
||||
|
||||
void calculate_region_hash(unsigned long long start, unsigned long long end, uint8_t* return_hash) {
|
||||
// this function calculates the hash digest of a region of memory,
|
||||
// currently it is only designed to work for the application region
|
||||
@ -152,16 +161,12 @@ void calculate_region_hash(unsigned long long start, unsigned long long end, uin
|
||||
|
||||
hash.begin(CRYS_HASH_SHA256_mode);
|
||||
|
||||
bool finish = false;
|
||||
uint8_t size;
|
||||
bool application = true;
|
||||
int end_count = 0;
|
||||
unsigned long length = 0;
|
||||
|
||||
while (start < end - 1 ) {
|
||||
while (start < end ) {
|
||||
const void* src = (const void*)start;
|
||||
if (start + CHUNK_SIZE >= end) {
|
||||
size = (end - 1) - start;
|
||||
size = end - start;
|
||||
}
|
||||
else {
|
||||
size = CHUNK_SIZE;
|
||||
@ -169,74 +174,9 @@ void calculate_region_hash(unsigned long long start, unsigned long long end, uin
|
||||
|
||||
memcpy(chunk, src, CHUNK_SIZE);
|
||||
|
||||
// check if we've reached the end of the program
|
||||
// if we're checking the application region
|
||||
if (application) {
|
||||
for (int i = 0; i < CHUNK_SIZE; i++) {
|
||||
if (chunk[i] == 0xFF) {
|
||||
bool matched = true;
|
||||
end_count = 1;
|
||||
// check if rest of chunk is FFs as well, only if FF is not
|
||||
// at the end of chunk
|
||||
if (i < CHUNK_SIZE - 1) {
|
||||
for (int x = 0; x < CHUNK_SIZE - i; x++) {
|
||||
if (chunk[i+x] != 0xFF) {
|
||||
matched = false;
|
||||
break;
|
||||
}
|
||||
end_count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
while (end_count < END_SECTION_SIZE) {
|
||||
// check if bytes in next chunk up to total
|
||||
// required are also FFs
|
||||
for (int x = 1; x <= ceil(END_SECTION_SIZE / CHUNK_SIZE); x++) {
|
||||
const void* src_next = (const void*)start + CHUNK_SIZE*x;
|
||||
if ((END_SECTION_SIZE - end_count) > CHUNK_SIZE) {
|
||||
size = CHUNK_SIZE;
|
||||
} else {
|
||||
size = END_SECTION_SIZE - end_count;
|
||||
}
|
||||
memcpy(chunk_next, src_next, size);
|
||||
for (int y = 0; y < size; y++) {
|
||||
if (chunk_next[y] != 0xFF) {
|
||||
matched = false;
|
||||
break;
|
||||
}
|
||||
end_count++;
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!matched) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
finish = true;
|
||||
size = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (finish) {
|
||||
hash.update(chunk, size);
|
||||
length += size;
|
||||
break;
|
||||
} else {
|
||||
hash.update(chunk, size);
|
||||
}
|
||||
hash.update(chunk, size);
|
||||
|
||||
start += CHUNK_SIZE;
|
||||
length += CHUNK_SIZE;
|
||||
}
|
||||
hash.end(return_hash);
|
||||
}
|
||||
@ -257,7 +197,7 @@ void device_validate_partitions() {
|
||||
esp_partition_get_sha256(esp_ota_get_running_partition(), dev_firmware_hash);
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
// todo, add bootloader, partition table, or softdevice?
|
||||
calculate_region_hash(APPLICATION_START, USER_DATA_START, dev_firmware_hash);
|
||||
calculate_region_hash(APPLICATION_START, APPLICATION_START+retrieve_application_size(), dev_firmware_hash);
|
||||
#endif
|
||||
#if VALIDATE_FIRMWARE
|
||||
for (uint8_t i = 0; i < DEV_HASH_LEN; i++) {
|
||||
|
562
Display.h
562
Display.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -14,12 +14,35 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "Graphics.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#if BOARD_MODEL != BOARD_TECHO
|
||||
#if BOARD_MODEL == BOARD_TDECK
|
||||
#include <Adafruit_ST7789.h>
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
#include "ST7789.h"
|
||||
#define COLOR565(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3))
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
#include <Adafruit_SH110X.h>
|
||||
#else
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#endif
|
||||
|
||||
#else
|
||||
void (*display_callback)();
|
||||
void display_add_callback(void (*callback)()) { display_callback = callback; }
|
||||
void busyCallback(const void* p) { display_callback(); }
|
||||
#define SSD1306_BLACK GxEPD_BLACK
|
||||
#define SSD1306_WHITE GxEPD_WHITE
|
||||
#include <GxEPD2_BW.h>
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
#include "Fonts/Org_01.h"
|
||||
#define DISP_W 128
|
||||
#define DISP_H 64
|
||||
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_20 || BOARD_MODEL == BOARD_LORA32_V2_0
|
||||
#define DISP_RST -1
|
||||
#define DISP_ADDR 0x3C
|
||||
@ -37,14 +60,31 @@
|
||||
#define DISP_ADDR 0x3C
|
||||
#define SCL_OLED 18
|
||||
#define SDA_OLED 17
|
||||
#elif BOARD_MODEL == BOARD_RAK4631
|
||||
// RAK1921/SSD1306
|
||||
#define DISP_RST -1
|
||||
#define DISP_ADDR 0x3C
|
||||
#define SCL_OLED 14
|
||||
#define SDA_OLED 13
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
||||
#define DISP_RST -1
|
||||
#define DISP_ADDR 0x3C
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
#define DISP_RST 21
|
||||
#define DISP_ADDR 0x3C
|
||||
#define SCL_OLED 17
|
||||
#define SDA_OLED 18
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
SPIClass displaySPI = SPIClass(NRF_SPIM0, pin_disp_miso, pin_disp_sck, pin_disp_mosi);
|
||||
#define DISP_W 128
|
||||
#define DISP_H 64
|
||||
#define DISP_ADDR -1
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
#define DISP_RST -1
|
||||
#define DISP_ADDR 0x3C
|
||||
#define SCL_OLED 18
|
||||
#define SDA_OLED 17
|
||||
#define DISP_CUSTOM_ADDR false
|
||||
#else
|
||||
#define DISP_RST -1
|
||||
#define DISP_ADDR 0x3C
|
||||
@ -53,7 +93,29 @@
|
||||
|
||||
#define SMALL_FONT &Org_01
|
||||
|
||||
Adafruit_SSD1306 display(DISP_W, DISP_H, &Wire, DISP_RST);
|
||||
#if BOARD_MODEL == BOARD_TDECK
|
||||
Adafruit_ST7789 display = Adafruit_ST7789(DISPLAY_CS, DISPLAY_DC, -1);
|
||||
#define SSD1306_WHITE ST77XX_WHITE
|
||||
#define SSD1306_BLACK ST77XX_BLACK
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
ST7789Spi display(&SPI1, DISPLAY_RST, DISPLAY_DC, DISPLAY_CS);
|
||||
#define SSD1306_WHITE ST77XX_WHITE
|
||||
#define SSD1306_BLACK ST77XX_BLACK
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64, &Wire, -1);
|
||||
#define SSD1306_WHITE SH110X_WHITE
|
||||
#define SSD1306_BLACK SH110X_BLACK
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(pin_disp_cs, pin_disp_dc, pin_disp_reset, pin_disp_busy));
|
||||
uint32_t last_epd_refresh = 0;
|
||||
uint32_t last_epd_full_refresh = 0;
|
||||
#define REFRESH_PERIOD 300000
|
||||
#else
|
||||
Adafruit_SSD1306 display(DISP_W, DISP_H, &Wire, DISP_RST);
|
||||
#endif
|
||||
|
||||
float disp_target_fps = 7;
|
||||
float epd_update_fps = 0.5;
|
||||
|
||||
#define DISP_MODE_UNKNOWN 0x00
|
||||
#define DISP_MODE_LANDSCAPE 0x01
|
||||
@ -68,8 +130,10 @@ uint32_t last_unblank_event = 0;
|
||||
uint32_t display_blanking_timeout = DISPLAY_BLANKING_TIMEOUT;
|
||||
uint8_t display_unblank_intensity = display_intensity;
|
||||
bool display_blanked = false;
|
||||
uint8_t disp_target_fps = 7;
|
||||
bool display_tx = false;
|
||||
bool recondition_display = false;
|
||||
int disp_update_interval = 1000/disp_target_fps;
|
||||
int epd_update_interval = 1000/disp_target_fps;
|
||||
uint32_t last_page_flip = 0;
|
||||
int page_interval = 4000;
|
||||
bool device_signatures_ok();
|
||||
@ -87,25 +151,90 @@ int p_as_y = 0;
|
||||
GFXcanvas1 stat_area(64, 64);
|
||||
GFXcanvas1 disp_area(64, 64);
|
||||
|
||||
void fillRect(int16_t x, int16_t y, int16_t width, int16_t height, uint16_t colour);
|
||||
|
||||
void update_area_positions() {
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
p_ad_x = 0;
|
||||
p_ad_y = 0;
|
||||
p_as_x = 0;
|
||||
p_as_y = 64;
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
p_ad_x = 0;
|
||||
p_ad_y = 0;
|
||||
p_as_x = 64;
|
||||
p_as_y = 0;
|
||||
}
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
p_ad_x = 16;
|
||||
p_ad_y = 64;
|
||||
p_as_x = 16;
|
||||
p_as_y = p_ad_y+126;
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
p_ad_x = 0;
|
||||
p_ad_y = 96;
|
||||
p_as_x = 126;
|
||||
p_as_y = p_ad_y;
|
||||
}
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
p_ad_x = 61;
|
||||
p_ad_y = 36;
|
||||
p_as_x = 64;
|
||||
p_as_y = 64+36;
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
p_ad_x = 0;
|
||||
p_ad_y = 0;
|
||||
p_as_x = 64;
|
||||
p_as_y = 0;
|
||||
}
|
||||
#else
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
p_ad_x = 0 * DISPLAY_SCALE;
|
||||
p_ad_y = 0 * DISPLAY_SCALE;
|
||||
p_as_x = 0 * DISPLAY_SCALE;
|
||||
p_as_y = 64 * DISPLAY_SCALE;
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
p_ad_x = 0 * DISPLAY_SCALE;
|
||||
p_ad_y = 0 * DISPLAY_SCALE;
|
||||
p_as_x = 64 * DISPLAY_SCALE;
|
||||
p_as_y = 0 * DISPLAY_SCALE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t display_contrast = 0x00;
|
||||
void set_contrast(Adafruit_SSD1306 *display, uint8_t contrast) {
|
||||
#if BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
void set_contrast(Adafruit_SH1106G *display, uint8_t value) {
|
||||
}
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
void set_contrast(ST7789Spi *display, uint8_t value) { }
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
void set_contrast(void *display, uint8_t value) {
|
||||
if (value == 0) { analogWrite(pin_backlight, 0); }
|
||||
else { analogWrite(pin_backlight, value); }
|
||||
}
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
void set_contrast(Adafruit_ST7789 *display, uint8_t value) {
|
||||
static uint8_t level = 0;
|
||||
static uint8_t steps = 16;
|
||||
if (value > 15) value = 15;
|
||||
if (value == 0) {
|
||||
digitalWrite(DISPLAY_BL_PIN, 0);
|
||||
delay(3);
|
||||
level = 0;
|
||||
return;
|
||||
}
|
||||
if (level == 0) {
|
||||
digitalWrite(DISPLAY_BL_PIN, 1);
|
||||
level = steps;
|
||||
delayMicroseconds(30);
|
||||
}
|
||||
int from = steps - level;
|
||||
int to = steps - value;
|
||||
int num = (steps + to - from) % steps;
|
||||
for (int i = 0; i < num; i++) {
|
||||
digitalWrite(DISPLAY_BL_PIN, 0);
|
||||
digitalWrite(DISPLAY_BL_PIN, 1);
|
||||
}
|
||||
level = value;
|
||||
}
|
||||
#else
|
||||
void set_contrast(Adafruit_SSD1306 *display, uint8_t contrast) {
|
||||
display->ssd1306_command(SSD1306_SETCONTRAST);
|
||||
display->ssd1306_command(contrast);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool display_init() {
|
||||
#if HAS_DISPLAY
|
||||
@ -114,7 +243,7 @@ bool display_init() {
|
||||
digitalWrite(pin_display_en, LOW);
|
||||
delay(50);
|
||||
digitalWrite(pin_display_en, HIGH);
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
Wire.begin(SDA_OLED, SCL_OLED);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V2
|
||||
Wire.begin(SDA_OLED, SCL_OLED);
|
||||
@ -136,13 +265,33 @@ bool display_init() {
|
||||
delay(50);
|
||||
digitalWrite(pin_display_en, HIGH);
|
||||
Wire.begin(SDA_OLED, SCL_OLED);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
pinMode(PIN_T114_TFT_EN, OUTPUT);
|
||||
digitalWrite(PIN_T114_TFT_EN, LOW);
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
display.init(0, true, 10, false, displaySPI, SPISettings(4000000, MSBFIRST, SPI_MODE0));
|
||||
display.setPartialWindow(0, 0, DISP_W, DISP_H);
|
||||
display.epd2.setBusyCallback(busyCallback);
|
||||
#if HAS_BACKLIGHT
|
||||
pinMode(pin_backlight, OUTPUT);
|
||||
analogWrite(pin_backlight, 0);
|
||||
#endif
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
Wire.begin(SDA_OLED, SCL_OLED);
|
||||
#endif
|
||||
|
||||
#if HAS_EEPROM
|
||||
uint8_t display_rotation = EEPROM.read(eeprom_addr(ADDR_CONF_DROT));
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
uint8_t display_rotation = eeprom_read(eeprom_addr(ADDR_CONF_DROT));
|
||||
#endif
|
||||
if (display_rotation < 0 or display_rotation > 3) display_rotation = 0xFF;
|
||||
|
||||
#if DISP_CUSTOM_ADDR == true
|
||||
#if HAS_EEPROM
|
||||
uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
|
||||
uint8_t display_address = EEPROM.read(eeprom_addr(ADDR_CONF_DADR));
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
uint8_t display_address = eeprom_read(eeprom_addr(ADDR_CONF_DADR));
|
||||
uint8_t display_address = eeprom_read(eeprom_addr(ADDR_CONF_DADR));
|
||||
#endif
|
||||
if (display_address == 0xFF) display_address = DISP_ADDR;
|
||||
#else
|
||||
@ -159,63 +308,129 @@ bool display_init() {
|
||||
display_blanking_timeout = db_timeout*1000;
|
||||
}
|
||||
}
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
if (eeprom_read(eeprom_addr(ADDR_CONF_BSET)) == CONF_OK_BYTE) {
|
||||
uint8_t db_timeout = eeprom_read(eeprom_addr(ADDR_CONF_DBLK));
|
||||
if (db_timeout == 0x00) {
|
||||
display_blanking_enabled = false;
|
||||
} else {
|
||||
display_blanking_enabled = true;
|
||||
display_blanking_timeout = db_timeout*1000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!display.begin(SSD1306_SWITCHCAPVCC, display_address)) {
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
// Don't check if display is actually connected
|
||||
if(false) {
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
display.init(240, 320);
|
||||
display.setSPISpeed(80e6);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
display.init();
|
||||
// set white as default pixel colour for Heltec T114
|
||||
display.setRGB(COLOR565(0xFF, 0xFF, 0xFF));
|
||||
if (false) {
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
if (!display.begin(display_address, true)) {
|
||||
#else
|
||||
if (!display.begin(SSD1306_SWITCHCAPVCC, display_address)) {
|
||||
#endif
|
||||
return false;
|
||||
} else {
|
||||
set_contrast(&display, display_contrast);
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_20
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_1
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
display.setRotation(0);
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
display.setRotation(0);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V2
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(1);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
// Antenna conx up
|
||||
display.setRotation(1);
|
||||
// USB-C up
|
||||
// display.setRotation(3);
|
||||
#else
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#endif
|
||||
if (display_rotation != 0xFF) {
|
||||
if (display_rotation == 0 || display_rotation == 2) {
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
} else {
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
}
|
||||
display.setRotation(display_rotation);
|
||||
} else {
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_20
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_1
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
display.setRotation(0);
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
display.setRotation(0);
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(1);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V2
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(1);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(1);
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(1);
|
||||
#elif BOARD_MODEL == BOARD_RAK4631
|
||||
disp_mode = DISP_MODE_LANDSCAPE;
|
||||
display.setRotation(0);
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#else
|
||||
disp_mode = DISP_MODE_PORTRAIT;
|
||||
display.setRotation(3);
|
||||
#endif
|
||||
}
|
||||
|
||||
update_area_positions();
|
||||
for (int i = 0; i < WATERFALL_SIZE; i++) {
|
||||
waterfall[i] = 0;
|
||||
}
|
||||
|
||||
for (int i = 0; i < WATERFALL_SIZE; i++) { waterfall[i] = 0; }
|
||||
|
||||
last_page_flip = millis();
|
||||
|
||||
stat_area.cp437(true);
|
||||
disp_area.cp437(true);
|
||||
|
||||
#if BOARD_MODEL != BOARD_HELTEC_T114
|
||||
display.cp437(true);
|
||||
#endif
|
||||
|
||||
#if HAS_EEPROM
|
||||
#if MCU_VARIANT != MCU_NRF52
|
||||
display_intensity = EEPROM.read(eeprom_addr(ADDR_CONF_DINT));
|
||||
#else
|
||||
display_intensity = eeprom_read(eeprom_addr(ADDR_CONF_DINT));
|
||||
display_intensity = EEPROM.read(eeprom_addr(ADDR_CONF_DINT));
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
display_intensity = eeprom_read(eeprom_addr(ADDR_CONF_DINT));
|
||||
#endif
|
||||
display_unblank_intensity = display_intensity;
|
||||
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
#if HAS_BACKLIGHT
|
||||
if (display_intensity == 0) { analogWrite(pin_backlight, 0); }
|
||||
else { analogWrite(pin_backlight, display_intensity); }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BOARD_MODEL == BOARD_TDECK
|
||||
display.fillScreen(SSD1306_BLACK);
|
||||
#endif
|
||||
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
// Enable backlight led (display is always black without this)
|
||||
fillRect(p_ad_x, p_ad_y, 128, 128, SSD1306_BLACK);
|
||||
fillRect(p_as_x, p_as_y, 128, 128, SSD1306_BLACK);
|
||||
pinMode(PIN_T114_TFT_BLGT, OUTPUT);
|
||||
digitalWrite(PIN_T114_TFT_BLGT, LOW);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
@ -223,6 +438,60 @@ bool display_init() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draws a line on the screen
|
||||
void drawLine(int16_t x, int16_t y, int16_t width, int16_t height, uint16_t colour) {
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
if(colour == SSD1306_WHITE){
|
||||
display.setColor(WHITE);
|
||||
} else if(colour == SSD1306_BLACK) {
|
||||
display.setColor(BLACK);
|
||||
}
|
||||
display.drawLine(x, y, width, height);
|
||||
#else
|
||||
display.drawLine(x, y, width, height, colour);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draws a filled rectangle on the screen
|
||||
void fillRect(int16_t x, int16_t y, int16_t width, int16_t height, uint16_t colour) {
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
if(colour == SSD1306_WHITE){
|
||||
display.setColor(WHITE);
|
||||
} else if(colour == SSD1306_BLACK) {
|
||||
display.setColor(BLACK);
|
||||
}
|
||||
display.fillRect(x, y, width, height);
|
||||
#else
|
||||
display.fillRect(x, y, width, height, colour);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draws a bitmap to the display and auto scales it based on the boards configured DISPLAY_SCALE
|
||||
void drawBitmap(int16_t startX, int16_t startY, const uint8_t* bitmap, int16_t bitmapWidth, int16_t bitmapHeight, uint16_t foregroundColour, uint16_t backgroundColour) {
|
||||
#if DISPLAY_SCALE == 1
|
||||
display.drawBitmap(startX, startY, bitmap, bitmapWidth, bitmapHeight, foregroundColour, backgroundColour);
|
||||
#else
|
||||
for(int16_t row = 0; row < bitmapHeight; row++){
|
||||
for(int16_t col = 0; col < bitmapWidth; col++){
|
||||
|
||||
// determine index and bitmask
|
||||
int16_t index = row * ((bitmapWidth + 7) / 8) + (col / 8);
|
||||
uint8_t bitmask = 1 << (7 - (col % 8));
|
||||
|
||||
// check if the current pixel is set in the bitmap
|
||||
if(bitmap[index] & bitmask){
|
||||
// draw a scaled rectangle for the foreground pixel
|
||||
fillRect(startX + col * DISPLAY_SCALE, startY + row * DISPLAY_SCALE, DISPLAY_SCALE, DISPLAY_SCALE, foregroundColour);
|
||||
} else {
|
||||
// draw a scaled rectangle for the background pixel
|
||||
fillRect(startX + col * DISPLAY_SCALE, startY + row * DISPLAY_SCALE, DISPLAY_SCALE, DISPLAY_SCALE, backgroundColour);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void draw_cable_icon(int px, int py) {
|
||||
if (cable_state == CABLE_STATE_DISCONNECTED) {
|
||||
stat_area.drawBitmap(px, py, bm_cable+0*32, 16, 16, SSD1306_WHITE, SSD1306_BLACK);
|
||||
@ -340,8 +609,13 @@ void draw_quality_bars(int px, int py) {
|
||||
}
|
||||
}
|
||||
|
||||
#define S_RSSI_MIN -135.0
|
||||
#define S_RSSI_MAX -75.0
|
||||
#if MODE == SX1280
|
||||
#define S_RSSI_MIN -105.0
|
||||
#define S_RSSI_MAX -65.0
|
||||
#else
|
||||
#define S_RSSI_MIN -135.0
|
||||
#define S_RSSI_MAX -75.0
|
||||
#endif
|
||||
#define S_RSSI_SPAN (S_RSSI_MAX-S_RSSI_MIN)
|
||||
void draw_signal_bars(int px, int py) {
|
||||
stat_area.fillRect(px, py, 13, 7, SSD1306_BLACK);
|
||||
@ -366,6 +640,11 @@ void draw_signal_bars(int px, int py) {
|
||||
}
|
||||
}
|
||||
|
||||
#if MODEM == SX1280
|
||||
#define WF_TX_SIZE 5
|
||||
#else
|
||||
#define WF_TX_SIZE 5
|
||||
#endif
|
||||
#define WF_RSSI_MAX -60
|
||||
#define WF_RSSI_MIN -135
|
||||
#define WF_RSSI_SPAN (WF_RSSI_MAX-WF_RSSI_MIN)
|
||||
@ -375,9 +654,16 @@ void draw_waterfall(int px, int py) {
|
||||
if (rssi_val < WF_RSSI_MIN) rssi_val = WF_RSSI_MIN;
|
||||
if (rssi_val > WF_RSSI_MAX) rssi_val = WF_RSSI_MAX;
|
||||
int rssi_normalised = ((rssi_val - WF_RSSI_MIN)*(1.0/WF_RSSI_SPAN))*WF_PIXEL_WIDTH;
|
||||
|
||||
waterfall[waterfall_head++] = rssi_normalised;
|
||||
if (waterfall_head >= WATERFALL_SIZE) waterfall_head = 0;
|
||||
if (display_tx) {
|
||||
for (uint8_t i; i < WF_TX_SIZE; i++) {
|
||||
waterfall[waterfall_head++] = -1;
|
||||
if (waterfall_head >= WATERFALL_SIZE) waterfall_head = 0;
|
||||
}
|
||||
display_tx = false;
|
||||
} else {
|
||||
waterfall[waterfall_head++] = rssi_normalised;
|
||||
if (waterfall_head >= WATERFALL_SIZE) waterfall_head = 0;
|
||||
}
|
||||
|
||||
stat_area.fillRect(px,py,WF_PIXEL_WIDTH, WATERFALL_SIZE, SSD1306_BLACK);
|
||||
for (int i = 0; i < WATERFALL_SIZE; i++){
|
||||
@ -385,6 +671,11 @@ void draw_waterfall(int px, int py) {
|
||||
int ws = waterfall[wi];
|
||||
if (ws > 0) {
|
||||
stat_area.drawLine(px, py+i, px+ws-1, py+i, SSD1306_WHITE);
|
||||
} else if (ws == -1) {
|
||||
uint8_t o = i%2;
|
||||
for (uint8_t ti = 0; ti < WF_PIXEL_WIDTH/2; ti++) {
|
||||
stat_area.drawPixel(px+ti*2+o, py+i, SSD1306_WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -412,22 +703,22 @@ void draw_stat_area() {
|
||||
|
||||
void update_stat_area() {
|
||||
if (eeprom_ok && !firmware_update_mode && !console_active) {
|
||||
|
||||
|
||||
draw_stat_area();
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
display.drawBitmap(p_as_x, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
drawBitmap(p_as_x, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
display.drawBitmap(p_as_x+2, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
if (device_init_done && !disp_ext_fb) display.drawLine(p_as_x, 0, p_as_x, 64, SSD1306_WHITE);
|
||||
drawBitmap(p_as_x+2, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
if (device_init_done && !disp_ext_fb) drawLine(p_as_x, 0, p_as_x, 64, SSD1306_WHITE);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (firmware_update_mode) {
|
||||
display.drawBitmap(p_as_x, p_as_y, bm_updating, stat_area.width(), stat_area.height(), SSD1306_BLACK, SSD1306_WHITE);
|
||||
drawBitmap(p_as_x, p_as_y, bm_updating, stat_area.width(), stat_area.height(), SSD1306_BLACK, SSD1306_WHITE);
|
||||
} else if (console_active && device_init_done) {
|
||||
display.drawBitmap(p_as_x, p_as_y, bm_console, stat_area.width(), stat_area.height(), SSD1306_BLACK, SSD1306_WHITE);
|
||||
drawBitmap(p_as_x, p_as_y, bm_console, stat_area.width(), stat_area.height(), SSD1306_BLACK, SSD1306_WHITE);
|
||||
if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
display.drawLine(p_as_x, 0, p_as_x, 64, SSD1306_WHITE);
|
||||
drawLine(p_as_x, 0, p_as_x, 64, SSD1306_WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -524,7 +815,7 @@ void draw_disp_area() {
|
||||
if (!modem_installed) {
|
||||
disp_area.drawBitmap(0, 37, bm_no_radio, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK);
|
||||
} else {
|
||||
disp_area.drawBitmap(0, 37, bm_hwfail, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK);
|
||||
disp_area.drawBitmap(0, 37, bm_conf_missing, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK);
|
||||
}
|
||||
}
|
||||
} else if (bt_state == BT_STATE_PAIRING and bt_ssp_pin != 0) {
|
||||
@ -587,27 +878,65 @@ void draw_disp_area() {
|
||||
|
||||
void update_disp_area() {
|
||||
draw_disp_area();
|
||||
display.drawBitmap(p_ad_x, p_ad_y, disp_area.getBuffer(), disp_area.width(), disp_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
|
||||
drawBitmap(p_ad_x, p_ad_y, disp_area.getBuffer(), disp_area.width(), disp_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
if (device_init_done && !firmware_update_mode && !disp_ext_fb) {
|
||||
display.drawLine(0, 0, 0, 63, SSD1306_WHITE);
|
||||
drawLine(0, 0, 0, 63, SSD1306_WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void update_display(bool blank = false) {
|
||||
if (display_blanking_enabled && millis()-last_unblank_event >= display_blanking_timeout) {
|
||||
blank = true;
|
||||
display_blanked = true;
|
||||
if (display_intensity != 0) {
|
||||
display_unblank_intensity = display_intensity;
|
||||
void display_recondition() {
|
||||
#if PLATFORM == PLATFORM_ESP32
|
||||
for (uint8_t iy = 0; iy < disp_area.height(); iy++) {
|
||||
unsigned char rand_seg [] = {random(0xFF),random(0xFF),random(0xFF),random(0xFF),random(0xFF),random(0xFF),random(0xFF),random(0xFF)};
|
||||
stat_area.drawBitmap(0, iy, rand_seg, 64, 1, SSD1306_WHITE, SSD1306_BLACK);
|
||||
disp_area.drawBitmap(0, iy, rand_seg, 64, 1, SSD1306_WHITE, SSD1306_BLACK);
|
||||
}
|
||||
display_intensity = 0;
|
||||
|
||||
drawBitmap(p_ad_x, p_ad_y, disp_area.getBuffer(), disp_area.width(), disp_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
if (disp_mode == DISP_MODE_PORTRAIT) {
|
||||
drawBitmap(p_as_x, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
} else if (disp_mode == DISP_MODE_LANDSCAPE) {
|
||||
drawBitmap(p_as_x, p_as_y, stat_area.getBuffer(), stat_area.width(), stat_area.height(), SSD1306_WHITE, SSD1306_BLACK);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool epd_blanked = false;
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
void epd_blank(bool full_update = true) {
|
||||
display.setFullWindow();
|
||||
display.fillScreen(SSD1306_WHITE);
|
||||
display.display(full_update);
|
||||
}
|
||||
|
||||
void epd_black(bool full_update = true) {
|
||||
display.setFullWindow();
|
||||
display.fillScreen(SSD1306_BLACK);
|
||||
display.display(full_update);
|
||||
}
|
||||
#endif
|
||||
|
||||
void update_display(bool blank = false) {
|
||||
display_updating = true;
|
||||
if (blank == true) {
|
||||
last_disp_update = millis()-disp_update_interval-1;
|
||||
} else {
|
||||
display_blanked = false;
|
||||
if (display_unblank_intensity != 0x00) {
|
||||
display_intensity = display_unblank_intensity;
|
||||
display_unblank_intensity = 0x00;
|
||||
if (display_blanking_enabled && millis()-last_unblank_event >= display_blanking_timeout) {
|
||||
blank = true;
|
||||
display_blanked = true;
|
||||
if (display_intensity != 0) {
|
||||
display_unblank_intensity = display_intensity;
|
||||
}
|
||||
display_intensity = 0;
|
||||
} else {
|
||||
display_blanked = false;
|
||||
if (display_unblank_intensity != 0x00) {
|
||||
display_intensity = display_unblank_intensity;
|
||||
display_unblank_intensity = 0x00;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -617,23 +946,70 @@ void update_display(bool blank = false) {
|
||||
display_contrast = display_intensity;
|
||||
set_contrast(&display, display_contrast);
|
||||
}
|
||||
display.clearDisplay();
|
||||
display.display();
|
||||
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
if (!epd_blanked) {
|
||||
epd_blank();
|
||||
epd_blanked = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
display.clear();
|
||||
display.display();
|
||||
#elif BOARD_MODEL != BOARD_TDECK && BOARD_MODEL != BOARD_TECHO
|
||||
display.clearDisplay();
|
||||
display.display();
|
||||
#else
|
||||
// TODO: Clear screen
|
||||
#endif
|
||||
|
||||
last_disp_update = millis();
|
||||
}
|
||||
|
||||
} else {
|
||||
if (millis()-last_disp_update >= disp_update_interval) {
|
||||
uint32_t current = millis();
|
||||
if (display_contrast != display_intensity) {
|
||||
display_contrast = display_intensity;
|
||||
set_contrast(&display, display_contrast);
|
||||
}
|
||||
display.clearDisplay();
|
||||
update_stat_area();
|
||||
update_disp_area();
|
||||
display.display();
|
||||
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
display.clear();
|
||||
#elif BOARD_MODEL != BOARD_TDECK && BOARD_MODEL != BOARD_TECHO
|
||||
display.clearDisplay();
|
||||
#endif
|
||||
|
||||
if (recondition_display) {
|
||||
disp_target_fps = 30;
|
||||
disp_update_interval = 1000/disp_target_fps;
|
||||
display_recondition();
|
||||
} else {
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
display.setFullWindow();
|
||||
display.fillScreen(SSD1306_WHITE);
|
||||
#endif
|
||||
|
||||
update_stat_area();
|
||||
update_disp_area();
|
||||
}
|
||||
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
if (current-last_epd_refresh >= epd_update_interval) {
|
||||
if (current-last_epd_full_refresh >= REFRESH_PERIOD) { display.display(false); last_epd_full_refresh = millis(); }
|
||||
else { display.display(true); }
|
||||
last_epd_refresh = millis();
|
||||
epd_blanked = false;
|
||||
}
|
||||
#elif BOARD_MODEL != BOARD_TDECK
|
||||
display.display();
|
||||
#endif
|
||||
|
||||
last_disp_update = millis();
|
||||
}
|
||||
}
|
||||
display_updating = false;
|
||||
}
|
||||
|
||||
void display_unblank() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -45,6 +45,7 @@
|
||||
#define CMD_STAT_CHTM 0x25
|
||||
#define CMD_STAT_PHYPRM 0x26
|
||||
#define CMD_STAT_BAT 0x27
|
||||
#define CMD_STAT_CSMA 0x28
|
||||
#define CMD_BLINK 0x30
|
||||
#define CMD_RANDOM 0x40
|
||||
|
||||
@ -52,12 +53,16 @@
|
||||
#define CMD_FB_READ 0x42
|
||||
#define CMD_FB_WRITE 0x43
|
||||
#define CMD_FB_READL 0x44
|
||||
#define CMD_DISP_READ 0x66
|
||||
#define CMD_DISP_INT 0x45
|
||||
#define CMD_DISP_ADDR 0x63
|
||||
#define CMD_DISP_BLNK 0x64
|
||||
#define CMD_DISP_ROT 0x67
|
||||
#define CMD_DISP_RCND 0x68
|
||||
#define CMD_NP_INT 0x65
|
||||
#define CMD_BT_CTRL 0x46
|
||||
#define CMD_BT_PIN 0x62
|
||||
#define CMD_DIS_IA 0x69
|
||||
|
||||
#define CMD_BOARD 0x47
|
||||
#define CMD_PLATFORM 0x48
|
||||
@ -93,6 +98,8 @@
|
||||
#define ERROR_TXFAILED 0x02
|
||||
#define ERROR_EEPROM_LOCKED 0x03
|
||||
#define ERROR_QUEUE_FULL 0x04
|
||||
#define ERROR_MEMORY_LOW 0x05
|
||||
#define ERROR_MODEM_TIMEOUT 0x06
|
||||
|
||||
// Serial framing variables
|
||||
size_t frame_len;
|
||||
|
19
Graphics.h
19
Graphics.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -311,6 +311,23 @@ const unsigned char bm_hwfail [] PROGMEM = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
const unsigned char bm_conf_missing [] PROGMEM = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0x33, 0x87, 0x0c, 0xcc, 0xe1, 0xff, 0xff,
|
||||
0xe2, 0x33, 0x3e, 0x7c, 0xc4, 0xcf, 0xff, 0xff, 0xe0, 0x33, 0x8f, 0x1c, 0xc0, 0xc9, 0xff, 0xff,
|
||||
0xe5, 0x33, 0xe7, 0xcc, 0xc8, 0xc9, 0xff, 0xff, 0xe7, 0x33, 0x0e, 0x1c, 0xcc, 0xe3, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf9, 0xff, 0xf1, 0xe3, 0x99, 0x86, 0x70, 0xff, 0xf6, 0xff,
|
||||
0xe4, 0xc9, 0x89, 0x9e, 0x67, 0xff, 0xf6, 0xff, 0xe7, 0xc9, 0x81, 0x86, 0x64, 0xff, 0xef, 0x7f,
|
||||
0xe4, 0xc9, 0x91, 0x9e, 0x64, 0xff, 0xe9, 0x7f, 0xf1, 0xe3, 0x99, 0x9e, 0x71, 0xff, 0xd9, 0xbf,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd9, 0xbf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb9, 0xdf,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb9, 0xdf, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xef,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x79, 0xef, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xf9, 0xf7,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x0f,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
const unsigned char bm_no_radio [] PROGMEM = {
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0xc7, 0x0e, 0x71, 0xfc, 0xce, 0x38, 0x7f,
|
||||
|
134
Makefile
134
Makefile
@ -1,4 +1,4 @@
|
||||
# Copyright (C) 2023, Mark Qvist
|
||||
# Copyright (C) 2024, Mark Qvist
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -33,6 +33,8 @@ prep-esp32:
|
||||
arduino-cli core update-index --config-file arduino-cli.yaml
|
||||
arduino-cli core install esp32:esp32@$(ARDUINO_ESP_CORE_VER) --config-file arduino-cli.yaml
|
||||
arduino-cli lib install "Adafruit SSD1306"
|
||||
arduino-cli lib install "Adafruit SH110X"
|
||||
arduino-cli lib install "Adafruit ST7735 and ST7789 Library"
|
||||
arduino-cli lib install "Adafruit NeoPixel"
|
||||
arduino-cli lib install "XPowersLib"
|
||||
arduino-cli lib install "Crypto"
|
||||
@ -44,6 +46,11 @@ prep-samd:
|
||||
prep-nrf:
|
||||
arduino-cli core update-index --config-file arduino-cli.yaml
|
||||
arduino-cli core install rakwireless:nrf52 --config-file arduino-cli.yaml
|
||||
arduino-cli core install Heltec_nRF52:Heltec_nRF52 --config-file arduino-cli.yaml
|
||||
arduino-cli core install adafruit:nrf52 --config-file arduino-cli.yaml
|
||||
arduino-cli lib install "GxEPD2"
|
||||
arduino-cli config set library.enable_unsafe_install true
|
||||
arduino-cli lib install --git-url https://github.com/liamcottle/esp8266-oled-ssd1306#e16cee124fe26490cb14880c679321ad8ac89c95
|
||||
pip install adafruit-nrfutil --upgrade
|
||||
|
||||
console-site:
|
||||
@ -74,7 +81,19 @@ firmware-tbeam_sx126x: check_bt_buffers
|
||||
arduino-cli compile --log --fqbn esp32:esp32:t-beam -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x33\" \"-DMODEM=0x03\""
|
||||
|
||||
firmware-t3s3:
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\""
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x03\""
|
||||
|
||||
firmware-t3s3_sx127x:
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\""
|
||||
|
||||
firmware-t3s3_sx1280_pa:
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x04\""
|
||||
|
||||
firmware-tdeck:
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\""
|
||||
|
||||
firmware-tbeam_supreme:
|
||||
arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=-DBOARD_MODEL=0x3D"
|
||||
|
||||
firmware-lora32_v10: check_bt_buffers
|
||||
arduino-cli compile --log --fqbn esp32:esp32:ttgo-lora32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x39\""
|
||||
@ -118,6 +137,12 @@ firmware-genericesp32: check_bt_buffers
|
||||
firmware-rak4631:
|
||||
arduino-cli compile --log --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\""
|
||||
|
||||
firmware-heltec_t114:
|
||||
arduino-cli compile --log --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3C\""
|
||||
|
||||
firmware-techo:
|
||||
arduino-cli compile --log --fqbn adafruit:nrf52:pca10056 -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x44\""
|
||||
|
||||
upload:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn unsignedio:avr:rnode
|
||||
|
||||
@ -125,11 +150,18 @@ upload-mega2560:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega
|
||||
|
||||
upload-tbeam:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:t-beam
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.t-beam/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-tbeam_sx1262:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:t-beam
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.t-beam/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
#@sleep 3
|
||||
#python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-lora32_v10:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32
|
||||
@ -153,18 +185,32 @@ upload-lora32_v21:
|
||||
python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-heltec32_v2:
|
||||
arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:heltec_wifi_lora_32_V2
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:heltec_wifi_lora_32_V2
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyUSB1 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin)
|
||||
rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V2/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-heltec32_v3:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:heltec_wifi_lora_32_V3
|
||||
arduino-cli upload -p /dev/ttyUSB1 --fqbn esp32:esp32:heltec_wifi_lora_32_V3
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyUSB0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin)
|
||||
rnodeconf /dev/ttyUSB1 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.heltec_wifi_lora_32_V3/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyUSB1 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-tdeck:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-tbeam_supreme:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32-s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-rnode_ng_20:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:ttgo-lora32
|
||||
@ -181,17 +227,11 @@ upload-rnode_ng_21:
|
||||
python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-t3s3:
|
||||
@echo
|
||||
@echo Put board into flashing mode by holding BOOT button while momentarily pressing the RESET button. Hit enter when done.
|
||||
@read
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3
|
||||
@sleep 2
|
||||
python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
@echo
|
||||
@echo Press the RESET button on the board now, and hit enter
|
||||
@read
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin)
|
||||
@sleep 3
|
||||
python ./Release/esptool/esptool.py --chip esp32s3 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||
|
||||
upload-featheresp32:
|
||||
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:featheresp32
|
||||
@ -202,12 +242,22 @@ upload-featheresp32:
|
||||
|
||||
upload-rak4631:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn rakwireless:nrf52:WisCoreRAK4631Board
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes from_device /dev/ttyACM0)
|
||||
|
||||
upload-heltec_t114:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262
|
||||
@sleep 1
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes from_device /dev/ttyACM0)
|
||||
|
||||
upload-techo:
|
||||
arduino-cli upload -p /dev/ttyACM0 --fqbn adafruit:nrf52:pca10056
|
||||
@sleep 6
|
||||
rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes from_device /dev/ttyACM0)
|
||||
|
||||
release: release-all
|
||||
|
||||
release-all: console-site spiffs-image release-rnode release-tbeam release-tbeam_sx1262 release-lora32_v10 release-lora32_v20 release-lora32_v21 release-lora32_v10_extled release-lora32_v20_extled release-lora32_v21_extled release-lora32_v21_tcxo release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v3 release-heltec32_v2_extled release-rnode_ng_20 release-rnode_ng_21 release-t3s3 release-hashes
|
||||
release-all: console-site spiffs-image release-tbeam release-tbeam_sx1262 release-lora32_v10 release-lora32_v20 release-lora32_v21 release-lora32_v10_extled release-lora32_v20_extled release-lora32_v21_extled release-lora32_v21_tcxo release-featheresp32 release-genericesp32 release-heltec32_v2 release-heltec32_v3 release-heltec32_v2_extled release-heltec_t114 release-techo release-rnode_ng_20 release-rnode_ng_21 release-t3s3 release-t3s3_sx127x release-t3s3_sx1280_pa release-tdeck release-tbeam_supreme release-rak4631 release-hashes
|
||||
|
||||
release-hashes:
|
||||
python ./release_hashes.py > ./Release/release.json
|
||||
@ -344,7 +394,7 @@ release-rnode_ng_21: check_bt_buffers
|
||||
rm -r build
|
||||
|
||||
release-t3s3:
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\""
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x03\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3.boot_app0
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_t3s3.bin
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_t3s3.bootloader
|
||||
@ -352,6 +402,42 @@ release-t3s3:
|
||||
zip --junk-paths ./Release/rnode_firmware_t3s3.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3.boot_app0 build/rnode_firmware_t3s3.bin build/rnode_firmware_t3s3.bootloader build/rnode_firmware_t3s3.partitions
|
||||
rm -r build
|
||||
|
||||
release-t3s3_sx1280_pa:
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x04\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3_sx1280_pa.boot_app0
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_t3s3_sx1280_pa.bin
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_t3s3_sx1280_pa.bootloader
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_t3s3_sx1280_pa.partitions
|
||||
zip --junk-paths ./Release/rnode_firmware_t3s3_sx1280_pa.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3_sx1280_pa.boot_app0 build/rnode_firmware_t3s3_sx1280_pa.bin build/rnode_firmware_t3s3_sx1280_pa.bootloader build/rnode_firmware_t3s3_sx1280_pa.partitions
|
||||
rm -r build
|
||||
|
||||
release-t3s3_sx127x:
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x42\" \"-DMODEM=0x01\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_t3s3_sx127x.boot_app0
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_t3s3_sx127x.bin
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_t3s3_sx127x.bootloader
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_t3s3_sx127x.partitions
|
||||
zip --junk-paths ./Release/rnode_firmware_t3s3_sx127x.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_t3s3_sx127x.boot_app0 build/rnode_firmware_t3s3_sx127x.bin build/rnode_firmware_t3s3_sx127x.bootloader build/rnode_firmware_t3s3_sx127x.partitions
|
||||
rm -r build
|
||||
|
||||
release-tdeck:
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3B\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tdeck.boot_app0
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_tdeck.bin
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tdeck.bootloader
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tdeck.partitions
|
||||
zip --junk-paths ./Release/rnode_firmware_tdeck.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tdeck.boot_app0 build/rnode_firmware_tdeck.bin build/rnode_firmware_tdeck.bootloader build/rnode_firmware_tdeck.partitions
|
||||
rm -r build
|
||||
|
||||
release-tbeam_supreme:
|
||||
arduino-cli compile --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3D\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_tbeam_supreme.boot_app0
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin build/rnode_firmware_tbeam_supreme.bin
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.bootloader.bin build/rnode_firmware_tbeam_supreme.bootloader
|
||||
cp build/esp32.esp32.esp32s3/RNode_Firmware.ino.partitions.bin build/rnode_firmware_tbeam_supreme.partitions
|
||||
zip --junk-paths ./Release/rnode_firmware_tbeam_supreme.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_tbeam_supreme.boot_app0 build/rnode_firmware_tbeam_supreme.bin build/rnode_firmware_tbeam_supreme.bootloader build/rnode_firmware_tbeam_supreme.partitions
|
||||
rm -r build
|
||||
|
||||
release-featheresp32: check_bt_buffers
|
||||
arduino-cli compile --fqbn esp32:esp32:featheresp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x34\""
|
||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_featheresp32.boot_app0
|
||||
@ -379,3 +465,13 @@ release-rak4631:
|
||||
arduino-cli compile --fqbn rakwireless:nrf52:WisCoreRAK4631Board -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x51\""
|
||||
cp build/rakwireless.nrf52.WisCoreRAK4631Board/RNode_Firmware.ino.hex build/rnode_firmware_rak4631.hex
|
||||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_rak4631.hex Release/rnode_firmware_rak4631.zip
|
||||
|
||||
release-heltec_t114:
|
||||
arduino-cli compile --fqbn Heltec_nRF52:Heltec_nRF52:HT-n5262 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3C\""
|
||||
cp build/Heltec_nRF52.Heltec_nRF52.HT-n5262/RNode_Firmware.ino.hex build/rnode_firmware_heltec_t114.hex
|
||||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_heltec_t114.hex Release/rnode_firmware_heltec_t114.zip
|
||||
|
||||
release-techo:
|
||||
arduino-cli compile --log --fqbn adafruit:nrf52:pca10056 -e --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x44\""
|
||||
cp build/adafruit.nrf52.pca10056/RNode_Firmware.ino.hex build/rnode_firmware_techo.hex
|
||||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_techo.hex Release/rnode_firmware_techo.zip
|
||||
|
209
Power.h
209
Power.h
@ -1,9 +1,28 @@
|
||||
#if BOARD_MODEL == BOARD_TBEAM
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#if BOARD_MODEL == BOARD_TBEAM || BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
#include <XPowersLib.h>
|
||||
XPowersLibInterface* PMU = NULL;
|
||||
|
||||
#ifndef PMU_WIRE_PORT
|
||||
#define PMU_WIRE_PORT Wire
|
||||
#if BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
#define PMU_WIRE_PORT Wire1
|
||||
#else
|
||||
#define PMU_WIRE_PORT Wire
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BAT_V_MIN 3.15
|
||||
@ -43,6 +62,38 @@
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
#define BAT_V_MIN 3.15
|
||||
#define BAT_V_MAX 4.217
|
||||
#define BAT_V_CHG 4.48
|
||||
#define BAT_V_FLOAT 4.33
|
||||
#define BAT_SAMPLES 5
|
||||
const uint8_t pin_vbat = 1;
|
||||
float bat_p_samples[BAT_SAMPLES];
|
||||
float bat_v_samples[BAT_SAMPLES];
|
||||
uint8_t bat_samples_count = 0;
|
||||
int bat_discharging_samples = 0;
|
||||
int bat_charging_samples = 0;
|
||||
int bat_charged_samples = 0;
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
#define BAT_V_MIN 3.15
|
||||
#define BAT_V_MAX 4.3
|
||||
#define BAT_V_CHG 4.48
|
||||
#define BAT_V_FLOAT 4.33
|
||||
#define BAT_SAMPLES 5
|
||||
const uint8_t pin_vbat = 4;
|
||||
float bat_p_samples[BAT_SAMPLES];
|
||||
float bat_v_samples[BAT_SAMPLES];
|
||||
uint8_t bat_samples_count = 0;
|
||||
int bat_discharging_samples = 0;
|
||||
int bat_charging_samples = 0;
|
||||
int bat_charged_samples = 0;
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
#define BAT_V_MIN 3.15
|
||||
#define BAT_V_MAX 4.3
|
||||
@ -60,6 +111,39 @@
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
#define BAT_V_MIN 3.15
|
||||
#define BAT_V_MAX 4.165
|
||||
#define BAT_V_CHG 4.48
|
||||
#define BAT_V_FLOAT 4.33
|
||||
#define BAT_SAMPLES 7
|
||||
const uint8_t pin_vbat = 4;
|
||||
const uint8_t pin_ctrl = 6;
|
||||
float bat_p_samples[BAT_SAMPLES];
|
||||
float bat_v_samples[BAT_SAMPLES];
|
||||
uint8_t bat_samples_count = 0;
|
||||
int bat_discharging_samples = 0;
|
||||
int bat_charging_samples = 0;
|
||||
int bat_charged_samples = 0;
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
#define BAT_V_MIN 3.15
|
||||
#define BAT_V_MAX 4.16
|
||||
#define BAT_V_CHG 4.48
|
||||
#define BAT_V_FLOAT 4.33
|
||||
#define BAT_SAMPLES 7
|
||||
const uint8_t pin_vbat = 4;
|
||||
float bat_p_samples[BAT_SAMPLES];
|
||||
float bat_v_samples[BAT_SAMPLES];
|
||||
uint8_t bat_samples_count = 0;
|
||||
int bat_discharging_samples = 0;
|
||||
int bat_charging_samples = 0;
|
||||
int bat_charged_samples = 0;
|
||||
bool bat_voltage_dropping = false;
|
||||
float bat_delay_v = 0;
|
||||
float bat_state_change_v = 0;
|
||||
#endif
|
||||
|
||||
uint32_t last_pmu_update = 0;
|
||||
@ -70,14 +154,20 @@ uint8_t pmu_rc = 0;
|
||||
void kiss_indicate_battery();
|
||||
|
||||
void measure_battery() {
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_HELTEC32_V3 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_HELTEC_T114 || BOARD_MODEL == BOARD_TECHO
|
||||
battery_installed = true;
|
||||
battery_indeterminate = true;
|
||||
|
||||
#if BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) * 0.0041;
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) / 4095.0*6.7828;
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) * 0.017165;
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) * 0.007067;
|
||||
#else
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) / 4095.0*2.0*3.3*1.1;
|
||||
float battery_measurement = (float)(analogRead(pin_vbat)) / 4095.0*7.26;
|
||||
#endif
|
||||
|
||||
bat_v_samples[bat_samples_count%BAT_SAMPLES] = battery_measurement;
|
||||
@ -135,16 +225,21 @@ void measure_battery() {
|
||||
if (bat_voltage_dropping && battery_voltage < BAT_V_FLOAT) {
|
||||
battery_state = BATTERY_STATE_DISCHARGING;
|
||||
} else {
|
||||
battery_state = BATTERY_STATE_CHARGING;
|
||||
if (battery_percent < 100.0) {
|
||||
battery_state = BATTERY_STATE_CHARGING;
|
||||
} else {
|
||||
battery_state = BATTERY_STATE_CHARGED;
|
||||
}
|
||||
}
|
||||
|
||||
#if MCU_VARIANT == MCU_NRF52
|
||||
if (bt_state != BT_STATE_OFF) { blebas.write(battery_percent); }
|
||||
#endif
|
||||
|
||||
// if (bt_state == BT_STATE_CONNECTED) {
|
||||
// SerialBT.printf("Bus voltage %.3fv. Unfiltered %.3fv.", battery_voltage, bat_v_samples[BAT_SAMPLES-1]);
|
||||
// if (bat_voltage_dropping) {
|
||||
// SerialBT.printf(" Voltage is dropping. Percentage %.1f%%.", battery_percent);
|
||||
// } else {
|
||||
// SerialBT.printf(" Voltage is not dropping. Percentage %.1f%%.", battery_percent);
|
||||
// }
|
||||
// if (bat_voltage_dropping) { SerialBT.printf(" Voltage is dropping. Percentage %.1f%%.", battery_percent); }
|
||||
// else { SerialBT.printf(" Voltage is not dropping. Percentage %.1f%%.", battery_percent); }
|
||||
// if (battery_state == BATTERY_STATE_DISCHARGING) { SerialBT.printf(" Battery discharging. delay_v %.3fv", bat_delay_v); }
|
||||
// if (battery_state == BATTERY_STATE_CHARGING) { SerialBT.printf(" Battery charging. delay_v %.3fv", bat_delay_v); }
|
||||
// if (battery_state == BATTERY_STATE_CHARGED) { SerialBT.print(" Battery is charged."); }
|
||||
@ -152,7 +247,7 @@ void measure_battery() {
|
||||
// }
|
||||
}
|
||||
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
#elif BOARD_MODEL == BOARD_TBEAM || BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
if (PMU) {
|
||||
float discharge_current = 0;
|
||||
float charge_current = 0;
|
||||
@ -249,35 +344,33 @@ void update_pmu() {
|
||||
}
|
||||
|
||||
bool init_pmu() {
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1
|
||||
#if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_TECHO
|
||||
pinMode(pin_vbat, INPUT);
|
||||
return true;
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
pinMode(pin_ctrl,OUTPUT);
|
||||
digitalWrite(pin_ctrl, LOW);
|
||||
return true;
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
pinMode(pin_ctrl,OUTPUT);
|
||||
digitalWrite(pin_ctrl, HIGH);
|
||||
return true;
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
Wire.begin(I2C_SDA, I2C_SCL);
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT);
|
||||
if (!PMU->init()) {
|
||||
Serial.println("Warning: Failed to find AXP2101 power management");
|
||||
delete PMU;
|
||||
PMU = NULL;
|
||||
} else {
|
||||
Serial.println("AXP2101 PMU init succeeded, using AXP2101 PMU");
|
||||
}
|
||||
}
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP192(PMU_WIRE_PORT);
|
||||
if (!PMU->init()) {
|
||||
Serial.println("Warning: Failed to find AXP192 power management");
|
||||
delete PMU;
|
||||
PMU = NULL;
|
||||
} else {
|
||||
Serial.println("AXP192 PMU init succeeded, using AXP192 PMU");
|
||||
}
|
||||
}
|
||||
|
||||
@ -382,6 +475,86 @@ bool init_pmu() {
|
||||
// Set the time of pressing the button to turn off
|
||||
PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S);
|
||||
|
||||
return true;
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
Wire1.begin(I2C_SDA, I2C_SCL);
|
||||
|
||||
if (!PMU) {
|
||||
PMU = new XPowersAXP2101(PMU_WIRE_PORT);
|
||||
if (!PMU->init()) {
|
||||
delete PMU;
|
||||
PMU = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PMU) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* gnss module power channel
|
||||
* The default ALDO4 is off, you need to turn on the GNSS power first, otherwise it will be invalid during
|
||||
* initialization
|
||||
*/
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO4, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO4);
|
||||
|
||||
// lora radio power channel
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO3, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO3);
|
||||
|
||||
// m.2 interface
|
||||
PMU->setPowerChannelVoltage(XPOWERS_DCDC3, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_DCDC3);
|
||||
|
||||
/**
|
||||
* ALDO2 cannot be turned off.
|
||||
* It is a necessary condition for sensor communication.
|
||||
* It must be turned on to properly access the sensor and screen
|
||||
* It is also responsible for the power supply of PCF8563
|
||||
*/
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO2, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO2);
|
||||
|
||||
// 6-axis , magnetometer ,bme280 , oled screen power channel
|
||||
PMU->setPowerChannelVoltage(XPOWERS_ALDO1, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_ALDO1);
|
||||
|
||||
// sdcard power channle
|
||||
PMU->setPowerChannelVoltage(XPOWERS_BLDO1, 3300);
|
||||
PMU->enablePowerOutput(XPOWERS_BLDO1);
|
||||
|
||||
// PMU->setPowerChannelVoltage(XPOWERS_DCDC4, 3300);
|
||||
// PMU->enablePowerOutput(XPOWERS_DCDC4);
|
||||
|
||||
// not use channel
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC2); // not elicited
|
||||
PMU->disablePowerOutput(XPOWERS_DCDC5); // not elicited
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO1); // Invalid power channel, it does not exist
|
||||
PMU->disablePowerOutput(XPOWERS_DLDO2); // Invalid power channel, it does not exist
|
||||
PMU->disablePowerOutput(XPOWERS_VBACKUP);
|
||||
|
||||
// Configure charging
|
||||
PMU->setChargeTargetVoltage(XPOWERS_AXP2101_CHG_VOL_4V2);
|
||||
PMU->setChargerConstantCurr(XPOWERS_AXP2101_CHG_CUR_500MA);
|
||||
// TODO: Reset
|
||||
PMU->setChargingLedMode(XPOWERS_CHG_LED_CTRL_CHG);
|
||||
|
||||
// Set the time of pressing the button to turn off
|
||||
PMU->setPowerKeyPressOffTime(XPOWERS_POWEROFF_4S);
|
||||
PMU->setPowerKeyPressOnTime(XPOWERS_POWERON_128MS);
|
||||
|
||||
// disable all axp chip interrupt
|
||||
PMU->disableIRQ(XPOWERS_AXP2101_ALL_IRQ);
|
||||
PMU->clearIrqStatus();
|
||||
|
||||
// It is necessary to disable the detection function of the TS pin on the board
|
||||
// without the battery temperature detection function, otherwise it will cause abnormal charging
|
||||
PMU->disableTSPinMeasure();
|
||||
PMU->enableVbusVoltageMeasure();
|
||||
PMU->enableBattVoltageMeasure();
|
||||
|
||||
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
35
README.md
35
README.md
@ -1,4 +1,4 @@
|
||||
***Important!** This repository is currently functioning as a stable reference for the default RNode Firmware, and only receives bugfix and security updates. Further development, new features and expanded board support is now happening at the [RNode Firmware Community Edition](https://github.com/liberatedsystems/RNode_Firmware_CE) repository, and is maintained by [Liberated Systems](https://github.com/liberatedsystems). Thanks for all contributions so far!*
|
||||
***Important!** This repository is currently functioning as a stable reference for the default RNode Firmware, and only receives bugfix and security updates. Further development, new features and expanded board support is now happening at the [RNode Firmware Community Edition](https://github.com/liberatedsystems/RNode_Firmware_CE) repository, and is maintained by [Liberated Embedded Systems](https://github.com/liberatedsystems). Thanks for all contributions so far!*
|
||||
|
||||
# RNode Firmware
|
||||
|
||||
@ -16,15 +16,7 @@ The RNode system is primarily software, which *transforms* different kinds of av
|
||||
|
||||
## Latest Release
|
||||
|
||||
The latest release, installable through `rnodeconf`, is version `1.72`. This release brings the following changes:
|
||||
|
||||
- Added support for flashing T3S3 boards
|
||||
- Added deep sleep support on T3S3
|
||||
- Various quality updates for nRF / RAK4631
|
||||
- Fixed a bug with antenna switch utilisation on RAK4631
|
||||
- Updated console image to include latest packages
|
||||
|
||||
You must have at least version `2.1.3` of `rnodeconf` installed to update the RNode Firmware to version `1.72`. Get it by updating the `rns` package to at least version `0.7.5`.
|
||||
The latest release, installable through `rnodeconf`, is version `1.81`. You must have at least version `2.4.0` of `rnodeconf` installed to update the RNode Firmware to version `1.81`. Get it by updating the `rns` package to at least version `0.9.0`.
|
||||
|
||||
## A Self-Replicating System
|
||||
|
||||
@ -70,24 +62,28 @@ It's easy to create your own RNodes from one of the supported development boards
|
||||
|
||||
The RNode Firmware supports the following boards:
|
||||
|
||||
- Handheld v2.x RNodes from [unsigned.io](https://unsigned.io/shop/product/handheld-rnode)
|
||||
- Original v1.x RNodes from [unsigned.io](https://unsigned.io/shop/product/rnode)
|
||||
- LilyGO T-Beam v1.1 devices with SX1276/8 LoRa chips
|
||||
- LilyGO T-Beam v1.1 devices with SX1262/8 LoRa chips
|
||||
- LilyGO T-Beam Supreme devices
|
||||
- LilyGO T-Deck devices (currently display is disabled)
|
||||
- LilyGO LoRa32 v1.0 devices
|
||||
- LilyGO LoRa32 v2.0 devices
|
||||
- LilyGO LoRa32 v2.1 devices (with and without TCXO)
|
||||
- LilyGO T3S3 devices with SX1276/8 LoRa chips
|
||||
- LilyGO T3S3 devices with SX1262/8 LoRa chips
|
||||
- LilyGO T3S3 devices with SX1280 LoRa chips
|
||||
- LilyGO T-Echo devices
|
||||
- Heltec LoRa32 v2 devices
|
||||
- Heltec LoRa32 v3 devices
|
||||
- Heltec T114 devices
|
||||
- RAK4631 devices
|
||||
- Homebrew RNodes based on ATmega1284p boards
|
||||
- Homebrew RNodes based on ATmega2560 boards
|
||||
- Homebrew RNodes based on Adafruit Feather ESP32 boards
|
||||
- Homebrew RNodes based on generic ESP32 boards
|
||||
|
||||
## Supported Transceiver Modules
|
||||
The RNode Firmware supports all transceiver modules based on **Semtech SX1276** or **Semtech SX1278** chips, that have an **SPI interface** and expose the **DIO_0** interrupt pin from the chip.
|
||||
|
||||
Support for **SX1262**, **SX1268** and **SX1280** is being implemented. Please support the project with donations if you want this faster!
|
||||
The RNode Firmware supports all transceiver modules based on Semtech **SX1276**, **SX1278**, **SX1262**, **SX1268** and **SX1280** chips, that have an **SPI interface** and expose the relevant **DIO** interrupt pins from the chip.
|
||||
|
||||
## Getting Started Fast
|
||||
You can download and flash the firmware to all the supported boards using the [RNode Config Utility](https://github.com/markqvist/rnodeconfigutil). All firmware releases are now handled and installed directly through the `rnodeconf` utility, which is included in the `rns` package. It can be installed via `pip`:
|
||||
@ -100,6 +96,8 @@ pip install rns --upgrade
|
||||
rnodeconf --autoinstall
|
||||
```
|
||||
|
||||
For most of the supported device types, it is also possible to use [Liam Cottle's Web-based RNode Flasher](https://liamcottle.github.io/rnode-flasher/). This option may be easier if you're not familiar with using a command line interface.
|
||||
|
||||
For more detailed instruction and in-depth guides, you can have a look at some of these resources:
|
||||
|
||||
- Create a [basic RNode from readily available development boards](https://unsigned.io/guides/2022_01_25_installing-rnode-firmware-on-supported-devices.html)
|
||||
@ -107,7 +105,12 @@ For more detailed instruction and in-depth guides, you can have a look at some o
|
||||
- Learn the basics on how to [create and build your own RNode designs](https://unsigned.io/guides/2022_01_26_how-to-make-your-own-rnodes.html) from scratch
|
||||
- Once you've got the hang of it, start building RNodes for your community, or [even for selling them](https://unsigned.io/sell_rnodes.html)
|
||||
|
||||
If you would rather just buy a pre-made unit, you can visit [my shop](https://unsigned.io/shop) and purchase my particular version of the [Handheld RNode](https://unsigned.io/shop/handheld-rnode/), which I can assure you is made to the highest quality, and with a lot of care.
|
||||
If you would rather just buy a pre-made unit, you can visit one of the community vendors that produce and sell RNodes:
|
||||
|
||||
- [Liberated Embedded Systems](https://store.liberatedsystems.co.uk/)
|
||||
- [Simply Equipped](https://simplyequipped.com/)
|
||||
|
||||
If you'd like to have your shop added to this list, let me know.
|
||||
|
||||
## Support RNode Development
|
||||
You can help support the continued development of open, free and private communications systems by donating via one of the following channels:
|
||||
|
File diff suppressed because it is too large
Load Diff
99
ROM.h
99
ROM.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -14,75 +14,42 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef ROM_H
|
||||
#define ROM_H
|
||||
#define ROM_H
|
||||
#define CHECKSUMMED_SIZE 0x0B
|
||||
|
||||
#define CHECKSUMMED_SIZE 0x0B
|
||||
// ROM address map ///////////////
|
||||
#define ADDR_PRODUCT 0x00
|
||||
#define ADDR_MODEL 0x01
|
||||
#define ADDR_HW_REV 0x02
|
||||
#define ADDR_SERIAL 0x03
|
||||
#define ADDR_MADE 0x07
|
||||
#define ADDR_CHKSUM 0x0B
|
||||
#define ADDR_SIGNATURE 0x1B
|
||||
#define ADDR_INFO_LOCK 0x9B
|
||||
|
||||
#define PRODUCT_RNODE 0x03
|
||||
#define PRODUCT_HMBRW 0xF0
|
||||
#define PRODUCT_TBEAM 0xE0
|
||||
#define PRODUCT_T32_10 0xB2
|
||||
#define PRODUCT_T32_20 0xB0
|
||||
#define PRODUCT_T32_21 0xB1
|
||||
#define PRODUCT_H32_V2 0xC0
|
||||
#define PRODUCT_H32_V3 0xC1
|
||||
#define PRODUCT_RAK4631 0x10
|
||||
#define MODEL_11 0x11
|
||||
#define MODEL_12 0x12
|
||||
#define MODEL_A1 0xA1
|
||||
#define MODEL_A6 0xA6
|
||||
#define MODEL_A4 0xA4
|
||||
#define MODEL_A9 0xA9
|
||||
#define MODEL_A3 0xA3
|
||||
#define MODEL_A8 0xA8
|
||||
#define MODEL_A2 0xA2
|
||||
#define MODEL_A7 0xA7
|
||||
#define MODEL_B3 0xB3
|
||||
#define MODEL_B8 0xB8
|
||||
#define MODEL_B4 0xB4
|
||||
#define MODEL_B9 0xB9
|
||||
#define MODEL_BA 0xBA
|
||||
#define MODEL_BB 0xBB
|
||||
#define MODEL_C4 0xC4
|
||||
#define MODEL_C9 0xC9
|
||||
#define MODEL_C5 0xC5
|
||||
#define MODEL_CA 0xCA
|
||||
#define MODEL_E4 0xE4
|
||||
#define MODEL_E9 0xE9
|
||||
#define MODEL_E3 0xE3
|
||||
#define MODEL_E8 0xE8
|
||||
#define MODEL_FE 0xFE
|
||||
#define MODEL_FF 0xFF
|
||||
#define ADDR_CONF_SF 0x9C
|
||||
#define ADDR_CONF_CR 0x9D
|
||||
#define ADDR_CONF_TXP 0x9E
|
||||
#define ADDR_CONF_BW 0x9F
|
||||
#define ADDR_CONF_FREQ 0xA3
|
||||
#define ADDR_CONF_OK 0xA7
|
||||
|
||||
#define ADDR_PRODUCT 0x00
|
||||
#define ADDR_MODEL 0x01
|
||||
#define ADDR_HW_REV 0x02
|
||||
#define ADDR_SERIAL 0x03
|
||||
#define ADDR_MADE 0x07
|
||||
#define ADDR_CHKSUM 0x0B
|
||||
#define ADDR_SIGNATURE 0x1B
|
||||
#define ADDR_INFO_LOCK 0x9B
|
||||
#define ADDR_CONF_BT 0xB0
|
||||
#define ADDR_CONF_DSET 0xB1
|
||||
#define ADDR_CONF_DINT 0xB2
|
||||
#define ADDR_CONF_DADR 0xB3
|
||||
#define ADDR_CONF_DBLK 0xB4
|
||||
#define ADDR_CONF_DROT 0xB8
|
||||
#define ADDR_CONF_PSET 0xB5
|
||||
#define ADDR_CONF_PINT 0xB6
|
||||
#define ADDR_CONF_BSET 0xB7
|
||||
#define ADDR_CONF_DIA 0xB9
|
||||
|
||||
#define ADDR_CONF_SF 0x9C
|
||||
#define ADDR_CONF_CR 0x9D
|
||||
#define ADDR_CONF_TXP 0x9E
|
||||
#define ADDR_CONF_BW 0x9F
|
||||
#define ADDR_CONF_FREQ 0xA3
|
||||
#define ADDR_CONF_OK 0xA7
|
||||
|
||||
#define ADDR_CONF_BT 0xB0
|
||||
#define ADDR_CONF_DSET 0xB1
|
||||
#define ADDR_CONF_DINT 0xB2
|
||||
#define ADDR_CONF_DADR 0xB3
|
||||
#define ADDR_CONF_DBLK 0xB4
|
||||
#define ADDR_CONF_PSET 0xB5
|
||||
#define ADDR_CONF_PINT 0xB6
|
||||
#define ADDR_CONF_BSET 0xB7
|
||||
#define INFO_LOCK_BYTE 0x73
|
||||
#define CONF_OK_BYTE 0x73
|
||||
#define BT_ENABLE_BYTE 0x73
|
||||
|
||||
#define INFO_LOCK_BYTE 0x73
|
||||
#define CONF_OK_BYTE 0x73
|
||||
#define BT_ENABLE_BYTE 0x73
|
||||
|
||||
#define EEPROM_RESERVED 200
|
||||
#define EEPROM_RESERVED 200
|
||||
//////////////////////////////////
|
||||
|
||||
#endif
|
||||
|
Binary file not shown.
440
ST7789.h
Normal file
440
ST7789.h
Normal file
@ -0,0 +1,440 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
* Copyright (c) 2018 by Fabrice Weinberg
|
||||
* Copyright (c) 2024 by Heltec AutoMation
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ST7789Spi_h
|
||||
#define ST7789Spi_h
|
||||
|
||||
#include "OLEDDisplay.h"
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
#define ST_CMD_DELAY 0x80 // special signifier for command lists
|
||||
|
||||
#define ST77XX_NOP 0x00
|
||||
#define ST77XX_SWRESET 0x01
|
||||
#define ST77XX_RDDID 0x04
|
||||
#define ST77XX_RDDST 0x09
|
||||
|
||||
#define ST77XX_SLPIN 0x10
|
||||
#define ST77XX_SLPOUT 0x11
|
||||
#define ST77XX_PTLON 0x12
|
||||
#define ST77XX_NORON 0x13
|
||||
|
||||
#define ST77XX_INVOFF 0x20
|
||||
#define ST77XX_INVON 0x21
|
||||
#define ST77XX_DISPOFF 0x28
|
||||
#define ST77XX_DISPON 0x29
|
||||
#define ST77XX_CASET 0x2A
|
||||
#define ST77XX_RASET 0x2B
|
||||
#define ST77XX_RAMWR 0x2C
|
||||
#define ST77XX_RAMRD 0x2E
|
||||
|
||||
#define ST77XX_PTLAR 0x30
|
||||
#define ST77XX_TEOFF 0x34
|
||||
#define ST77XX_TEON 0x35
|
||||
#define ST77XX_MADCTL 0x36
|
||||
#define ST77XX_COLMOD 0x3A
|
||||
|
||||
#define ST77XX_MADCTL_MY 0x80
|
||||
#define ST77XX_MADCTL_MX 0x40
|
||||
#define ST77XX_MADCTL_MV 0x20
|
||||
#define ST77XX_MADCTL_ML 0x10
|
||||
#define ST77XX_MADCTL_RGB 0x00
|
||||
|
||||
#define ST77XX_RDID1 0xDA
|
||||
#define ST77XX_RDID2 0xDB
|
||||
#define ST77XX_RDID3 0xDC
|
||||
#define ST77XX_RDID4 0xDD
|
||||
|
||||
// Some ready-made 16-bit ('565') color settings:
|
||||
#define ST77XX_BLACK 0x0000
|
||||
#define ST77XX_WHITE 0xFFFF
|
||||
#define ST77XX_RED 0xF800
|
||||
#define ST77XX_GREEN 0x07E0
|
||||
#define ST77XX_BLUE 0x001F
|
||||
#define ST77XX_CYAN 0x07FF
|
||||
#define ST77XX_MAGENTA 0xF81F
|
||||
#define ST77XX_YELLOW 0xFFE0
|
||||
#define ST77XX_ORANGE 0xFC00
|
||||
|
||||
#define LED_A_ON LOW
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#undef LED_A_ON
|
||||
#define LED_A_ON HIGH
|
||||
#define rtos_free free
|
||||
#define rtos_malloc malloc
|
||||
//SPIClass SPI1(HSPI);
|
||||
#endif
|
||||
class ST7789Spi : public OLEDDisplay {
|
||||
private:
|
||||
uint8_t _rst;
|
||||
uint8_t _dc;
|
||||
uint8_t _cs;
|
||||
uint8_t _ledA;
|
||||
int _miso;
|
||||
int _mosi;
|
||||
int _clk;
|
||||
SPIClass * _spi;
|
||||
SPISettings _spiSettings;
|
||||
uint16_t _RGB=0xFFFF;
|
||||
uint8_t _buffheight;
|
||||
public:
|
||||
/* pass _cs as -1 to indicate "do not use CS pin", for cases where it is hard wired low */
|
||||
ST7789Spi(SPIClass *spiClass,uint8_t _rst, uint8_t _dc, uint8_t _cs, OLEDDISPLAY_GEOMETRY g = GEOMETRY_RAWMODE,uint16_t width=240,uint16_t height=320,int mosi=-1,int miso=-1,int clk=-1) {
|
||||
this->_spi = spiClass;
|
||||
this->_rst = _rst;
|
||||
this->_dc = _dc;
|
||||
this->_cs = _cs;
|
||||
this->_mosi=mosi;
|
||||
this->_miso=miso;
|
||||
this->_clk=clk;
|
||||
//this->_ledA = _ledA;
|
||||
_spiSettings = SPISettings(40000000, MSBFIRST, SPI_MODE0);
|
||||
setGeometry(g,width,height);
|
||||
}
|
||||
|
||||
bool connect(){
|
||||
this->_buffheight=displayHeight / 8;
|
||||
this->_buffheight+=displayHeight % 8 ? 1:0;
|
||||
pinMode(_cs, OUTPUT);
|
||||
pinMode(_dc, OUTPUT);
|
||||
//pinMode(_ledA, OUTPUT);
|
||||
if (_cs != (uint8_t) -1) {
|
||||
pinMode(_cs, OUTPUT);
|
||||
}
|
||||
pinMode(_rst, OUTPUT);
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
_spi->begin(_clk,_miso,_mosi,-1);
|
||||
#else
|
||||
_spi->begin();
|
||||
#endif
|
||||
_spi->setClockDivider (SPI_CLOCK_DIV2);
|
||||
|
||||
// Pulse Reset low for 10ms
|
||||
digitalWrite(_rst, HIGH);
|
||||
delay(1);
|
||||
digitalWrite(_rst, LOW);
|
||||
delay(10);
|
||||
digitalWrite(_rst, HIGH);
|
||||
_spi->begin ();
|
||||
//digitalWrite(_ledA, LED_A_ON);
|
||||
return true;
|
||||
}
|
||||
|
||||
void display(void) {
|
||||
#ifdef OLEDDISPLAY_DOUBLE_BUFFER
|
||||
|
||||
uint16_t minBoundY = UINT16_MAX;
|
||||
uint16_t maxBoundY = 0;
|
||||
|
||||
uint16_t minBoundX = UINT16_MAX;
|
||||
uint16_t maxBoundX = 0;
|
||||
|
||||
uint16_t x, y;
|
||||
|
||||
// Calculate the Y bounding box of changes
|
||||
// and copy buffer[pos] to buffer_back[pos];
|
||||
for (y = 0; y < _buffheight; y++) {
|
||||
for (x = 0; x < displayWidth; x++) {
|
||||
//Serial.printf("x %d y %d\r\n",x,y);
|
||||
uint16_t pos = x + y * displayWidth;
|
||||
if (buffer[pos] != buffer_back[pos]) {
|
||||
minBoundY = min(minBoundY, y);
|
||||
maxBoundY = max(maxBoundY, y);
|
||||
minBoundX = min(minBoundX, x);
|
||||
maxBoundX = max(maxBoundX, x);
|
||||
}
|
||||
buffer_back[pos] = buffer[pos];
|
||||
}
|
||||
yield();
|
||||
}
|
||||
|
||||
// If the minBoundY wasn't updated
|
||||
// we can savely assume that buffer_back[pos] == buffer[pos]
|
||||
// holdes true for all values of pos
|
||||
if (minBoundY == UINT16_MAX) return;
|
||||
|
||||
set_CS(LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
|
||||
for (y = minBoundY; y <= maxBoundY; y++)
|
||||
{
|
||||
for(int temp = 0; temp<8;temp++)
|
||||
{
|
||||
//setAddrWindow(minBoundX,y*8+temp,maxBoundX-minBoundX+1,1);
|
||||
setAddrWindow(minBoundX,y*8+temp,maxBoundX-minBoundX+1,1);
|
||||
//setAddrWindow(y*8+temp,minBoundX,1,maxBoundX-minBoundX+1);
|
||||
uint32_t const pixbufcount = maxBoundX-minBoundX+1;
|
||||
uint16_t *pixbuf = (uint16_t *)rtos_malloc(2 * pixbufcount);
|
||||
for (x = minBoundX; x <= maxBoundX; x++)
|
||||
{
|
||||
pixbuf[x-minBoundX] = ((buffer[x + y * displayWidth]>>temp)&0x01)==1?_RGB:0;
|
||||
}
|
||||
#ifdef ESP_PLATFORM
|
||||
_spi->transferBytes((uint8_t *)pixbuf, NULL, 2 * pixbufcount);
|
||||
#else
|
||||
_spi->transfer(pixbuf, NULL, 2 * pixbufcount);
|
||||
#endif
|
||||
rtos_free(pixbuf);
|
||||
}
|
||||
}
|
||||
_spi->endTransaction();
|
||||
set_CS(HIGH);
|
||||
|
||||
#else
|
||||
set_CS(LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
uint8_t x, y;
|
||||
for (y = 0; y < _buffheight; y++)
|
||||
{
|
||||
for(int temp = 0; temp<8;temp++)
|
||||
{
|
||||
//setAddrWindow(minBoundX,y*8+temp,maxBoundX-minBoundX+1,1);
|
||||
//setAddrWindow(minBoundX,y*8+temp,maxBoundX-minBoundX+1,1);
|
||||
setAddrWindow(y*8+temp,0,1,displayWidth);
|
||||
uint32_t const pixbufcount = displayWidth;
|
||||
uint16_t *pixbuf = (uint16_t *)rtos_malloc(2 * pixbufcount);
|
||||
for (x = 0; x < displayWidth; x++)
|
||||
{
|
||||
pixbuf[x] = ((buffer[x + y * displayWidth]>>temp)&0x01)==1?_RGB:0;
|
||||
}
|
||||
#ifdef ESP_PLATFORM
|
||||
_spi->transferBytes((uint8_t *)pixbuf, NULL, 2 * pixbufcount);
|
||||
#else
|
||||
_spi->transfer(pixbuf, NULL, 2 * pixbufcount);
|
||||
#endif
|
||||
rtos_free(pixbuf);
|
||||
}
|
||||
}
|
||||
_spi->endTransaction();
|
||||
set_CS(HIGH);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void resetOrientation() {
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
virtual void flipScreenVertically() {
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MY;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
virtual void mirrorScreen() {
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX|ST77XX_MADCTL_MY;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
virtual void setRotation(uint8_t r) {
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX;
|
||||
if (r == 1) { madctl = 0xC0; }
|
||||
if (r == 2) { madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MY; }
|
||||
if (r == 3) { madctl = 0x00; }
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void setRGB(uint16_t c)
|
||||
{
|
||||
|
||||
this->_RGB=0x00|c>>8|c<<8&0xFF00;
|
||||
}
|
||||
|
||||
void displayOn(void) {
|
||||
//sendCommand(DISPLAYON);
|
||||
}
|
||||
|
||||
void displayOff(void) {
|
||||
//sendCommand(DISPLAYOFF);
|
||||
}
|
||||
|
||||
//#define ST77XX_MADCTL_MY 0x80
|
||||
//#define ST77XX_MADCTL_MX 0x40
|
||||
//#define ST77XX_MADCTL_MV 0x20
|
||||
//#define ST77XX_MADCTL_ML 0x10
|
||||
protected:
|
||||
// Send all the init commands
|
||||
virtual void sendInitCommands()
|
||||
{
|
||||
sendCommand(ST77XX_SWRESET); // 1: Software reset, no args, w/delay
|
||||
delay(150);
|
||||
|
||||
sendCommand(ST77XX_SLPOUT); // 2: Out of sleep mode, no args, w/delay
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_COLMOD); // 3: Set color mode, 16-bit color
|
||||
WriteData(0x55);
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_MADCTL); // 4: Mem access ctrl (directions), Row/col addr, bottom-top refresh
|
||||
WriteData(0x08);
|
||||
|
||||
sendCommand(ST77XX_CASET); // 5: Column addr set,
|
||||
WriteData(0x00);
|
||||
WriteData(0x00); // XSTART = 0
|
||||
WriteData(0x00);
|
||||
WriteData(240); // XEND = 240
|
||||
|
||||
sendCommand(ST77XX_RASET); // 6: Row addr set,
|
||||
WriteData(0x00);
|
||||
WriteData(0x00); // YSTART = 0
|
||||
WriteData(320>>8);
|
||||
WriteData(320&0xFF); // YSTART = 320
|
||||
|
||||
sendCommand(ST77XX_SLPOUT); // 7: hack
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_NORON); // 8: Normal display on, no args, w/delay
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_DISPON); // 9: Main screen turn on, no args, delay
|
||||
delay(10);
|
||||
|
||||
sendCommand(ST77XX_INVON); // 10: invert
|
||||
delay(10);
|
||||
|
||||
//uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MX;
|
||||
uint8_t madctl = ST77XX_MADCTL_RGB|ST77XX_MADCTL_MV|ST77XX_MADCTL_MX;
|
||||
sendCommand(ST77XX_MADCTL);
|
||||
WriteData(madctl);
|
||||
delay(10);
|
||||
setRGB(ST77XX_GREEN);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {
|
||||
x += (320-displayWidth)/2;
|
||||
y += (240-displayHeight)/2;
|
||||
uint32_t xa = ((uint32_t)x << 16) | (x + w - 1);
|
||||
uint32_t ya = ((uint32_t)y << 16) | (y + h - 1);
|
||||
|
||||
writeCommand(ST77XX_CASET); // Column addr set
|
||||
SPI_WRITE32(xa);
|
||||
|
||||
writeCommand(ST77XX_RASET); // Row addr set
|
||||
SPI_WRITE32(ya);
|
||||
|
||||
writeCommand(ST77XX_RAMWR); // write to RAM
|
||||
}
|
||||
int getBufferOffset(void) {
|
||||
return 0;
|
||||
}
|
||||
inline void set_CS(bool level) {
|
||||
if (_cs != (uint8_t) -1) {
|
||||
digitalWrite(_cs, level);
|
||||
}
|
||||
};
|
||||
inline void sendCommand(uint8_t com) __attribute__((always_inline)){
|
||||
set_CS(HIGH);
|
||||
digitalWrite(_dc, LOW);
|
||||
set_CS(LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
_spi->transfer(com);
|
||||
_spi->endTransaction();
|
||||
set_CS(HIGH);
|
||||
digitalWrite(_dc, HIGH);
|
||||
}
|
||||
|
||||
inline void WriteData(uint8_t data) __attribute__((always_inline)){
|
||||
digitalWrite(_cs, LOW);
|
||||
_spi->beginTransaction(_spiSettings);
|
||||
_spi->transfer(data);
|
||||
_spi->endTransaction();
|
||||
digitalWrite(_cs, HIGH);
|
||||
}
|
||||
void SPI_WRITE32(uint32_t l)
|
||||
{
|
||||
_spi->transfer(l >> 24);
|
||||
_spi->transfer(l >> 16);
|
||||
_spi->transfer(l >> 8);
|
||||
_spi->transfer(l);
|
||||
}
|
||||
void writeCommand(uint8_t cmd) {
|
||||
digitalWrite(_dc, LOW);
|
||||
_spi->transfer(cmd);
|
||||
digitalWrite(_dc, HIGH);
|
||||
}
|
||||
|
||||
// Private functions
|
||||
void setGeometry(OLEDDISPLAY_GEOMETRY g, uint16_t width, uint16_t height) {
|
||||
this->geometry = g;
|
||||
|
||||
switch (g) {
|
||||
case GEOMETRY_128_128:
|
||||
this->displayWidth = 128;
|
||||
this->displayHeight = 128;
|
||||
break;
|
||||
case GEOMETRY_128_64:
|
||||
this->displayWidth = 128;
|
||||
this->displayHeight = 64;
|
||||
break;
|
||||
case GEOMETRY_128_32:
|
||||
this->displayWidth = 128;
|
||||
this->displayHeight = 32;
|
||||
break;
|
||||
case GEOMETRY_64_48:
|
||||
this->displayWidth = 64;
|
||||
this->displayHeight = 48;
|
||||
break;
|
||||
case GEOMETRY_64_32:
|
||||
this->displayWidth = 64;
|
||||
this->displayHeight = 32;
|
||||
break;
|
||||
case GEOMETRY_RAWMODE:
|
||||
this->displayWidth = width > 0 ? width : 128;
|
||||
this->displayHeight = height > 0 ? height : 64;
|
||||
break;
|
||||
}
|
||||
uint8_t tmp=displayHeight % 8;
|
||||
uint8_t _buffheight=displayHeight / 8;
|
||||
|
||||
if(tmp!=0)
|
||||
_buffheight++;
|
||||
this->displayBufferSize = displayWidth * _buffheight ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
377
Utilities.h
377
Utilities.h
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2023, Mark Qvist
|
||||
// Copyright (C) 2024, Mark Qvist
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#if HAS_EEPROM
|
||||
#if HAS_EEPROM
|
||||
#include <EEPROM.h>
|
||||
#elif PLATFORM == PLATFORM_NRF52
|
||||
#include <Adafruit_LittleFS.h>
|
||||
@ -74,7 +74,7 @@ uint8_t eeprom_read(uint32_t mapped_addr);
|
||||
#if BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
//https://github.com/espressif/esp-idf/issues/8855
|
||||
#include "hal/wdt_hal.h"
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
#include "hal/wdt_hal.h"
|
||||
#else
|
||||
#include "hal/wdt_hal.h"
|
||||
@ -106,7 +106,6 @@ uint8_t boot_vector = 0x00;
|
||||
#if HAS_NP == true
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#define NUMPIXELS 1
|
||||
#define NP_M 0.15
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, pin_np, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
uint8_t npr = 0;
|
||||
@ -120,10 +119,23 @@ uint8_t boot_vector = 0x00;
|
||||
}
|
||||
|
||||
void led_init() {
|
||||
if (EEPROM.read(eeprom_addr(ADDR_CONF_PSET)) == CONF_OK_BYTE) {
|
||||
uint8_t int_val = EEPROM.read(eeprom_addr(ADDR_CONF_PINT));
|
||||
led_set_intensity(int_val);
|
||||
}
|
||||
#if BOARD_MODEL == BOARD_HELTEC_T114
|
||||
// Enable vext power supply to neopixel
|
||||
pinMode(PIN_VEXT_EN, OUTPUT);
|
||||
digitalWrite(PIN_VEXT_EN, HIGH);
|
||||
#endif
|
||||
|
||||
#if MCU_VARIANT == MCU_NRF52
|
||||
if (eeprom_read(eeprom_addr(ADDR_CONF_PSET)) == CONF_OK_BYTE) {
|
||||
uint8_t int_val = eeprom_read(eeprom_addr(ADDR_CONF_PINT));
|
||||
led_set_intensity(int_val);
|
||||
}
|
||||
#else
|
||||
if (EEPROM.read(eeprom_addr(ADDR_CONF_PSET)) == CONF_OK_BYTE) {
|
||||
uint8_t int_val = EEPROM.read(eeprom_addr(ADDR_CONF_PINT));
|
||||
led_set_intensity(int_val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void npset(uint8_t r, uint8_t g, uint8_t b) {
|
||||
@ -159,43 +171,73 @@ uint8_t boot_vector = 0x00;
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif MCU_VARIANT == MCU_ESP32
|
||||
#if HAS_NP == true
|
||||
void led_rx_on() { npset(0, 0, 0xFF); }
|
||||
void led_rx_off() { npset(0, 0, 0); }
|
||||
void led_tx_on() { npset(0xFF, 0x50, 0x00); }
|
||||
void led_tx_off() { npset(0, 0, 0); }
|
||||
void led_id_on() { npset(0x90, 0, 0x70); }
|
||||
void led_id_off() { npset(0, 0, 0); }
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_20
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
void led_rx_on() { }
|
||||
void led_rx_off() { }
|
||||
void led_tx_on() { }
|
||||
void led_tx_off() { }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
void led_rx_on() { }
|
||||
void led_rx_off() { }
|
||||
void led_tx_on() { }
|
||||
void led_tx_off() { }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#else
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#endif
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
@ -203,11 +245,15 @@ uint8_t boot_vector = 0x00;
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#else
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#endif
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V2
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
@ -215,40 +261,76 @@ uint8_t boot_vector = 0x00;
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#else
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#endif
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_1
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_HUZZAH32
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_GENERIC_ESP32
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#endif
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
#if BOARD_MODEL == BOARD_RAK4631
|
||||
#if HAS_NP == true
|
||||
void led_rx_on() { npset(0, 0, 0xFF); }
|
||||
void led_rx_off() { npset(0, 0, 0); }
|
||||
void led_tx_on() { npset(0xFF, 0x50, 0x00); }
|
||||
void led_tx_off() { npset(0, 0, 0); }
|
||||
void led_id_on() { npset(0x90, 0, 0x70); }
|
||||
void led_id_off() { npset(0, 0, 0); }
|
||||
#elif BOARD_MODEL == BOARD_RAK4631
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||
#endif
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
// Heltec T114 pulls pins LOW to turn on
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, LOW); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, HIGH); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, LOW); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, HIGH); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
void led_rx_on() { digitalWrite(pin_led_rx, LED_ON); }
|
||||
void led_rx_off() { digitalWrite(pin_led_rx, LED_OFF); }
|
||||
void led_tx_on() { digitalWrite(pin_led_tx, LED_ON); }
|
||||
void led_tx_off() { digitalWrite(pin_led_tx, LED_OFF); }
|
||||
void led_id_on() { }
|
||||
void led_id_off() { }
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void hard_reset(void) {
|
||||
@ -401,6 +483,19 @@ void led_indicate_warning(int cycles) {
|
||||
}
|
||||
led_rx_off();
|
||||
}
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
void led_indicate_info(int cycles) {
|
||||
bool forever = (cycles == 0) ? true : false;
|
||||
cycles = forever ? 1 : cycles;
|
||||
while(cycles > 0) {
|
||||
led_rx_off();
|
||||
delay(100);
|
||||
led_rx_on();
|
||||
delay(100);
|
||||
if (!forever) cycles--;
|
||||
}
|
||||
led_rx_off();
|
||||
}
|
||||
#else
|
||||
void led_indicate_info(int cycles) {
|
||||
bool forever = (cycles == 0) ? true : false;
|
||||
@ -427,8 +522,8 @@ unsigned long led_standby_ticks = 0;
|
||||
#elif MCU_VARIANT == MCU_ESP32
|
||||
|
||||
#if HAS_NP == true
|
||||
int led_standby_lng = 100;
|
||||
int led_standby_cut = 200;
|
||||
int led_standby_lng = 200;
|
||||
int led_standby_cut = 100;
|
||||
int led_standby_min = 0;
|
||||
int led_standby_max = 375+led_standby_lng;
|
||||
int led_notready_min = 0;
|
||||
@ -453,6 +548,8 @@ unsigned long led_standby_ticks = 0;
|
||||
#endif
|
||||
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
int led_standby_lng = 200;
|
||||
int led_standby_cut = 100;
|
||||
uint8_t led_standby_min = 200;
|
||||
uint8_t led_standby_max = 255;
|
||||
uint8_t led_notready_min = 0;
|
||||
@ -508,7 +605,7 @@ int8_t led_standby_direction = 0;
|
||||
} else {
|
||||
led_standby_intensity = led_standby_ti;
|
||||
}
|
||||
npset(0x00, 0x00, led_standby_intensity);
|
||||
npset(led_standby_intensity/3, led_standby_intensity/3, led_standby_intensity/3);
|
||||
}
|
||||
}
|
||||
|
||||
@ -552,9 +649,17 @@ int8_t led_standby_direction = 0;
|
||||
}
|
||||
led_standby_value += led_standby_direction;
|
||||
if (led_standby_value > 253) {
|
||||
led_tx_on();
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
led_rx_on();
|
||||
#else
|
||||
led_tx_on();
|
||||
#endif
|
||||
} else {
|
||||
led_tx_off();
|
||||
#if BOARD_MODEL == BOARD_TECHO
|
||||
led_rx_off();
|
||||
#else
|
||||
led_tx_off();
|
||||
#endif
|
||||
}
|
||||
#if BOARD_MODEL == BOARD_LORA32_V2_1
|
||||
#if defined(EXTERNAL_LEDS)
|
||||
@ -658,6 +763,12 @@ void serial_write(uint8_t byte) {
|
||||
Serial.write(byte);
|
||||
} else {
|
||||
SerialBT.write(byte);
|
||||
#if MCU_VARIANT == MCU_NRF52 && HAS_BLE
|
||||
// This ensures that the TX buffer is flushed after a frame is queued in serial.
|
||||
// serial_in_frame is used to ensure that the flush only happens at the end of the frame
|
||||
if (serial_in_frame && byte == FEND) { SerialBT.flushTXD(); serial_in_frame = false; }
|
||||
else if (!serial_in_frame && byte == FEND) { serial_in_frame = true; }
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
Serial.write(byte);
|
||||
@ -712,7 +823,7 @@ void kiss_indicate_stat_tx() {
|
||||
}
|
||||
|
||||
void kiss_indicate_stat_rssi() {
|
||||
uint8_t packet_rssi_val = (uint8_t)(last_rssi+rssi_offset);
|
||||
uint8_t packet_rssi_val = (uint8_t)(last_rssi+rssi_offset);
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_STAT_RSSI);
|
||||
escaped_serial_write(packet_rssi_val);
|
||||
@ -800,11 +911,14 @@ void kiss_indicate_lt_alock() {
|
||||
}
|
||||
|
||||
void kiss_indicate_channel_stats() {
|
||||
#if MCU_VARIANT == MCU_ESP32
|
||||
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
||||
uint16_t ats = (uint16_t)(airtime*100*100);
|
||||
uint16_t atl = (uint16_t)(longterm_airtime*100*100);
|
||||
uint16_t cls = (uint16_t)(total_channel_util*100*100);
|
||||
uint16_t cll = (uint16_t)(longterm_channel_util*100*100);
|
||||
uint8_t crs = (uint8_t)(current_rssi+rssi_offset);
|
||||
uint8_t nfl = (uint8_t)(noise_floor+rssi_offset);
|
||||
uint8_t ntf = 0xFF; if (interference_detected) { ntf = (uint8_t)(current_rssi+rssi_offset); }
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_STAT_CHTM);
|
||||
escaped_serial_write(ats>>8);
|
||||
@ -815,35 +929,46 @@ void kiss_indicate_channel_stats() {
|
||||
escaped_serial_write(cls);
|
||||
escaped_serial_write(cll>>8);
|
||||
escaped_serial_write(cll);
|
||||
escaped_serial_write(crs);
|
||||
escaped_serial_write(nfl);
|
||||
escaped_serial_write(ntf);
|
||||
serial_write(FEND);
|
||||
#endif
|
||||
}
|
||||
|
||||
void kiss_indicate_csma_stats() {
|
||||
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_STAT_CSMA);
|
||||
escaped_serial_write(cw_band);
|
||||
escaped_serial_write(cw_min);
|
||||
escaped_serial_write(cw_max);
|
||||
serial_write(FEND);
|
||||
#endif
|
||||
}
|
||||
|
||||
void kiss_indicate_phy_stats() {
|
||||
#if MCU_VARIANT == MCU_ESP32
|
||||
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
||||
uint16_t lst = (uint16_t)(lora_symbol_time_ms*1000);
|
||||
uint16_t lsr = (uint16_t)(lora_symbol_rate);
|
||||
uint16_t prs = (uint16_t)(lora_preamble_symbols+4);
|
||||
uint16_t prt = (uint16_t)((lora_preamble_symbols+4)*lora_symbol_time_ms);
|
||||
uint16_t prs = (uint16_t)(lora_preamble_symbols);
|
||||
uint16_t prt = (uint16_t)(lora_preamble_time_ms);
|
||||
uint16_t cst = (uint16_t)(csma_slot_ms);
|
||||
uint16_t dft = (uint16_t)(difs_ms);
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_STAT_PHYPRM);
|
||||
escaped_serial_write(lst>>8);
|
||||
escaped_serial_write(lst);
|
||||
escaped_serial_write(lsr>>8);
|
||||
escaped_serial_write(lsr);
|
||||
escaped_serial_write(prs>>8);
|
||||
escaped_serial_write(prs);
|
||||
escaped_serial_write(prt>>8);
|
||||
escaped_serial_write(prt);
|
||||
escaped_serial_write(cst>>8);
|
||||
escaped_serial_write(cst);
|
||||
escaped_serial_write(lst>>8); escaped_serial_write(lst);
|
||||
escaped_serial_write(lsr>>8); escaped_serial_write(lsr);
|
||||
escaped_serial_write(prs>>8); escaped_serial_write(prs);
|
||||
escaped_serial_write(prt>>8); escaped_serial_write(prt);
|
||||
escaped_serial_write(cst>>8); escaped_serial_write(cst);
|
||||
escaped_serial_write(dft>>8); escaped_serial_write(dft);
|
||||
serial_write(FEND);
|
||||
#endif
|
||||
}
|
||||
|
||||
void kiss_indicate_battery() {
|
||||
#if MCU_VARIANT == MCU_ESP32
|
||||
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_STAT_BAT);
|
||||
escaped_serial_write(battery_state);
|
||||
@ -956,6 +1081,20 @@ void kiss_indicate_fb() {
|
||||
serial_write(FEND);
|
||||
}
|
||||
|
||||
void kiss_indicate_disp() {
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_DISP_READ);
|
||||
#if HAS_DISPLAY
|
||||
uint8_t *da = disp_area.getBuffer();
|
||||
uint8_t *sa = stat_area.getBuffer();
|
||||
for (int i = 0; i < 512; i++) { escaped_serial_write(da[i]); }
|
||||
for (int i = 0; i < 512; i++) { escaped_serial_write(sa[i]); }
|
||||
#else
|
||||
serial_write(0xFF);
|
||||
#endif
|
||||
serial_write(FEND);
|
||||
}
|
||||
|
||||
void kiss_indicate_ready() {
|
||||
serial_write(FEND);
|
||||
serial_write(CMD_READY);
|
||||
@ -1032,22 +1171,33 @@ void setPreamble() {
|
||||
|
||||
void updateBitrate() {
|
||||
#if MCU_VARIANT == MCU_ESP32 || MCU_VARIANT == MCU_NRF52
|
||||
if (radio_online) {
|
||||
if (!radio_online) { lora_bitrate = 0; }
|
||||
else {
|
||||
lora_symbol_rate = (float)lora_bw/(float)(pow(2, lora_sf));
|
||||
lora_symbol_time_ms = (1.0/lora_symbol_rate)*1000.0;
|
||||
lora_bitrate = (uint32_t)(lora_sf * ( (4.0/(float)lora_cr) / ((float)(pow(2, lora_sf))/((float)lora_bw/1000.0)) ) * 1000.0);
|
||||
lora_us_per_byte = 1000000.0/((float)lora_bitrate/8.0);
|
||||
// csma_slot_ms = lora_symbol_time_ms*10;
|
||||
float target_preamble_symbols = (LORA_PREAMBLE_TARGET_MS/lora_symbol_time_ms)-LORA_PREAMBLE_SYMBOLS_HW;
|
||||
if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) {
|
||||
target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN;
|
||||
} else {
|
||||
target_preamble_symbols = ceil(target_preamble_symbols);
|
||||
}
|
||||
lora_preamble_symbols = (long)target_preamble_symbols;
|
||||
setPreamble();
|
||||
} else {
|
||||
lora_bitrate = 0;
|
||||
|
||||
bool fast_rate = lora_bitrate > LORA_FAST_THRESHOLD_BPS;
|
||||
lora_limit_rate = lora_bitrate > LORA_LIMIT_THRESHOLD_BPS;
|
||||
|
||||
int csma_slot_min_ms = CSMA_SLOT_MIN_MS;
|
||||
float lora_preamble_target_ms = LORA_PREAMBLE_TARGET_MS;
|
||||
if (fast_rate) { csma_slot_min_ms -= CSMA_SLOT_MIN_FAST_DELTA;
|
||||
lora_preamble_target_ms -= LORA_PREAMBLE_FAST_DELTA; }
|
||||
|
||||
csma_slot_ms = lora_symbol_time_ms*CSMA_SLOT_SYMBOLS;
|
||||
if (csma_slot_ms > CSMA_SLOT_MAX_MS) { csma_slot_ms = CSMA_SLOT_MAX_MS; }
|
||||
if (csma_slot_ms < CSMA_SLOT_MIN_MS) { csma_slot_ms = csma_slot_min_ms; }
|
||||
difs_ms = CSMA_SIFS_MS + 2*csma_slot_ms;
|
||||
|
||||
float target_preamble_symbols = lora_preamble_target_ms/lora_symbol_time_ms;
|
||||
if (target_preamble_symbols < LORA_PREAMBLE_SYMBOLS_MIN) { target_preamble_symbols = LORA_PREAMBLE_SYMBOLS_MIN; }
|
||||
else { target_preamble_symbols = (ceil)(target_preamble_symbols); }
|
||||
|
||||
lora_preamble_symbols = (long)target_preamble_symbols; setPreamble();
|
||||
lora_preamble_time_ms = (ceil)(lora_preamble_symbols * lora_symbol_time_ms);
|
||||
lora_header_time_ms = (ceil)(PHY_HEADER_LORA_SYMBOLS * lora_symbol_time_ms);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1081,15 +1231,23 @@ void setTXPower() {
|
||||
if (model == MODEL_11) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
if (model == MODEL_12) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
|
||||
if (model == MODEL_C6) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
if (model == MODEL_C7) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
|
||||
if (model == MODEL_A1) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A2) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A3) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
if (model == MODEL_A4) LoRa->setTxPower(lora_txp, PA_OUTPUT_RFO_PIN);
|
||||
if (model == MODEL_A5) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A6) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A7) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A8) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_A9) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_AA) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_AC) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
|
||||
if (model == MODEL_BA) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_BB) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_B3) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_B4) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_B8) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
@ -1097,6 +1255,14 @@ void setTXPower() {
|
||||
|
||||
if (model == MODEL_C4) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_C9) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_C5) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_CA) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
|
||||
if (model == MODEL_D4) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_D9) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
|
||||
if (model == MODEL_DB) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_DC) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
|
||||
if (model == MODEL_E4) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
if (model == MODEL_E9) LoRa->setTxPower(lora_txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||
@ -1136,13 +1302,7 @@ void setFrequency() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getRandom() {
|
||||
if (radio_online) {
|
||||
return LoRa->random();
|
||||
} else {
|
||||
return 0x00;
|
||||
}
|
||||
}
|
||||
uint8_t getRandom() { return random(0xFF); }
|
||||
|
||||
void promisc_enable() {
|
||||
promisc = true;
|
||||
@ -1153,35 +1313,32 @@ void promisc_disable() {
|
||||
}
|
||||
|
||||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||
bool eeprom_begin() {
|
||||
InternalFS.begin();
|
||||
bool eeprom_begin() {
|
||||
InternalFS.begin();
|
||||
|
||||
file.open(EEPROM_FILE, FILE_O_READ);
|
||||
|
||||
// if file doesn't exist
|
||||
if (!file) {
|
||||
if (file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
||||
// initialise the file with empty content
|
||||
uint8_t empty_content[EEPROM_SIZE] = {0};
|
||||
file.write(empty_content, EEPROM_SIZE);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
return true;
|
||||
}
|
||||
file.open(EEPROM_FILE, FILE_O_READ);
|
||||
if (!file) {
|
||||
if (file.open(EEPROM_FILE, FILE_O_WRITE)) {
|
||||
for (uint32_t mapped_addr = 0; mapped_addr < EEPROM_SIZE; mapped_addr++) { file.seek(mapped_addr); file.write(0xFF); }
|
||||
eeprom_flush();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t eeprom_read(uint32_t mapped_addr) {
|
||||
uint8_t byte;
|
||||
void* byte_ptr = &byte;
|
||||
file.seek(mapped_addr);
|
||||
file.read(byte_ptr, 1);
|
||||
return byte;
|
||||
}
|
||||
uint8_t eeprom_read(uint32_t mapped_addr) {
|
||||
uint8_t byte;
|
||||
void* byte_ptr = &byte;
|
||||
file.seek(mapped_addr);
|
||||
file.read(byte_ptr, 1);
|
||||
return byte;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool eeprom_info_locked() {
|
||||
@ -1239,7 +1396,6 @@ void kiss_dump_eeprom() {
|
||||
|
||||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||
void eeprom_flush() {
|
||||
// sync file contents to flash
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
written_bytes = 0;
|
||||
@ -1266,19 +1422,7 @@ void eeprom_update(int mapped_addr, uint8_t byte) {
|
||||
file.write(byte);
|
||||
}
|
||||
written_bytes++;
|
||||
|
||||
if ((mapped_addr - eeprom_addr(0)) == ADDR_INFO_LOCK) {
|
||||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||
// have to do a flush because we're only writing 1 byte and it syncs after 4
|
||||
eeprom_flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (written_bytes >= 4) {
|
||||
file.close();
|
||||
file.open(EEPROM_FILE, FILE_O_WRITE);
|
||||
written_bytes = 0;
|
||||
}
|
||||
eeprom_flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1291,9 +1435,13 @@ void eeprom_write(uint8_t addr, uint8_t byte) {
|
||||
}
|
||||
|
||||
void eeprom_erase() {
|
||||
for (int addr = 0; addr < EEPROM_RESERVED; addr++) {
|
||||
eeprom_update(eeprom_addr(addr), 0xFF);
|
||||
}
|
||||
#if !HAS_EEPROM && MCU_VARIANT == MCU_NRF52
|
||||
InternalFS.format();
|
||||
#else
|
||||
for (int addr = 0; addr < EEPROM_RESERVED; addr++) {
|
||||
eeprom_update(eeprom_addr(addr), 0xFF);
|
||||
}
|
||||
#endif
|
||||
hard_reset();
|
||||
}
|
||||
|
||||
@ -1310,18 +1458,18 @@ bool eeprom_lock_set() {
|
||||
}
|
||||
|
||||
bool eeprom_product_valid() {
|
||||
#if HAS_EEPROM
|
||||
uint8_t rval = EEPROM.read(eeprom_addr(ADDR_PRODUCT));
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
uint8_t rval = eeprom_read(eeprom_addr(ADDR_PRODUCT));
|
||||
#endif
|
||||
#if HAS_EEPROM
|
||||
uint8_t rval = EEPROM.read(eeprom_addr(ADDR_PRODUCT));
|
||||
#elif MCU_VARIANT == MCU_NRF52
|
||||
uint8_t rval = eeprom_read(eeprom_addr(ADDR_PRODUCT));
|
||||
#endif
|
||||
|
||||
#if PLATFORM == PLATFORM_AVR
|
||||
if (rval == PRODUCT_RNODE || rval == PRODUCT_HMBRW) {
|
||||
#elif PLATFORM == PLATFORM_ESP32
|
||||
if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2 || rval == PRODUCT_H32_V3) {
|
||||
if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2 || rval == PRODUCT_H32_V3 || rval == PRODUCT_TDECK_V1 || rval == PRODUCT_TBEAM_S_V1) {
|
||||
#elif PLATFORM == PLATFORM_NRF52
|
||||
if (rval == PRODUCT_RAK4631 || rval == PRODUCT_HMBRW) {
|
||||
if (rval == PRODUCT_RAK4631 || rval == PRODUCT_HELTEC_T114 || rval == PRODUCT_TECHO || rval == PRODUCT_HMBRW) {
|
||||
#else
|
||||
if (false) {
|
||||
#endif
|
||||
@ -1343,12 +1491,18 @@ bool eeprom_model_valid() {
|
||||
if (model == MODEL_A3 || model == MODEL_A8) {
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_21
|
||||
if (model == MODEL_A2 || model == MODEL_A7) {
|
||||
#elif BOARD_MODEL == BOARD_RNODE_NG_22
|
||||
if (model == MODEL_A1 || model == MODEL_A6) {
|
||||
#elif BOARD_MODEL == BOARD_T3S3
|
||||
if (model == MODEL_A1 || model == MODEL_A6 || model == MODEL_A5 || model == MODEL_AA || model == MODEL_AC) {
|
||||
#elif BOARD_MODEL == BOARD_HMBRW
|
||||
if (model == MODEL_FF || model == MODEL_FE) {
|
||||
#elif BOARD_MODEL == BOARD_TBEAM
|
||||
if (model == MODEL_E4 || model == MODEL_E9 || model == MODEL_E3 || model == MODEL_E8) {
|
||||
#elif BOARD_MODEL == BOARD_TDECK
|
||||
if (model == MODEL_D4 || model == MODEL_D9) {
|
||||
#elif BOARD_MODEL == BOARD_TECHO
|
||||
if (model == MODEL_16 || model == MODEL_17) {
|
||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||
if (model == MODEL_DB || model == MODEL_DC) {
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
||||
if (model == MODEL_BA || model == MODEL_BB) {
|
||||
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
||||
@ -1359,6 +1513,8 @@ bool eeprom_model_valid() {
|
||||
if (model == MODEL_C4 || model == MODEL_C9) {
|
||||
#elif BOARD_MODEL == BOARD_HELTEC32_V3
|
||||
if (model == MODEL_C5 || model == MODEL_CA) {
|
||||
#elif BOARD_MODEL == BOARD_HELTEC_T114
|
||||
if (model == MODEL_C6 || model == MODEL_C7) {
|
||||
#elif BOARD_MODEL == BOARD_RAK4631
|
||||
if (model == MODEL_11 || model == MODEL_12) {
|
||||
#elif BOARD_MODEL == BOARD_HUZZAH32
|
||||
@ -1454,6 +1610,21 @@ void db_conf_save(uint8_t val) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void drot_conf_save(uint8_t val) {
|
||||
#if HAS_DISPLAY
|
||||
if (val >= 0x00 and val <= 0x03) {
|
||||
eeprom_update(eeprom_addr(ADDR_CONF_DROT), val);
|
||||
hard_reset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void dia_conf_save(uint8_t val) {
|
||||
if (val > 0x00) { eeprom_update(eeprom_addr(ADDR_CONF_DIA), 0x01); }
|
||||
else { eeprom_update(eeprom_addr(ADDR_CONF_DIA), 0x00); }
|
||||
hard_reset();
|
||||
}
|
||||
|
||||
void np_int_conf_save(uint8_t p_int) {
|
||||
eeprom_update(eeprom_addr(ADDR_CONF_PSET), CONF_OK_BYTE);
|
||||
eeprom_update(eeprom_addr(ADDR_CONF_PINT), p_int);
|
||||
|
@ -2,4 +2,6 @@ board_manager:
|
||||
additional_urls:
|
||||
- https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
|
||||
- https://raw.githubusercontent.com/RAKwireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless_index.json
|
||||
- https://github.com/HelTecAutomation/Heltec_nRF52/releases/download/1.7.0/package_heltec_nrf_index.json
|
||||
- https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
|
||||
- http://unsigned.io/arduino/package_unsignedio_UnsignedBoards_index.json
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2023, Mark Qvist
|
||||
# Copyright (C) 2024, Mark Qvist
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -20,6 +20,7 @@ import sys
|
||||
import RNS
|
||||
import json
|
||||
import hashlib
|
||||
import subprocess
|
||||
|
||||
major_version = None
|
||||
minor_version = None
|
||||
@ -27,9 +28,23 @@ target_version = None
|
||||
|
||||
target_file = os.path.join(sys.argv[1])
|
||||
|
||||
firmware_data = open(target_file, "rb").read()
|
||||
calc_hash = hashlib.sha256(firmware_data[0:-32]).digest()
|
||||
part_hash = firmware_data[-32:]
|
||||
if sys.argv[1] == "from_device":
|
||||
from_device = True
|
||||
else:
|
||||
from_device = False
|
||||
|
||||
if calc_hash == part_hash:
|
||||
print(RNS.hexrep(part_hash, delimit=False))
|
||||
if not from_device:
|
||||
firmware_data = open(target_file, "rb").read()
|
||||
calc_hash = hashlib.sha256(firmware_data[0:-32]).digest()
|
||||
part_hash = firmware_data[-32:]
|
||||
|
||||
if calc_hash == part_hash:
|
||||
print(RNS.hexrep(part_hash, delimit=False))
|
||||
|
||||
else:
|
||||
try:
|
||||
cmdresult = subprocess.run(["rnodeconf", sys.argv[2], "-L"], stdout=subprocess.PIPE).stdout.decode('utf-8')
|
||||
part_hash = cmdresult.split("The actual firmware hash is: ")[1].replace("\n", "")
|
||||
print(part_hash)
|
||||
except Exception as e:
|
||||
print("Could not get partition hash from device: "+str(e))
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/python
|
||||
|
||||
# Copyright (C) 2023, Mark Qvist
|
||||
# Copyright (C) 2024, Mark Qvist
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
921
sx126x.cpp
921
sx126x.cpp
File diff suppressed because it is too large
Load Diff
13
sx126x.h
13
sx126x.h
@ -1,9 +1,6 @@
|
||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||
// Copyright Sandeep Mistry, Mark Qvist and Jacob Eva.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Modifications and additions copyright 2023 by Mark Qvist
|
||||
// Obviously still under the MIT license.
|
||||
|
||||
#ifndef SX126X_H
|
||||
#define SX126X_H
|
||||
|
||||
@ -17,6 +14,7 @@
|
||||
#define LORA_DEFAULT_RXEN_PIN -1
|
||||
#define LORA_DEFAULT_TXEN_PIN -1
|
||||
#define LORA_DEFAULT_BUSY_PIN -1
|
||||
#define LORA_MODEM_TIMEOUT_MS 20E3
|
||||
|
||||
#define PA_OUTPUT_RFO_PIN 0
|
||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||
@ -35,6 +33,7 @@ public:
|
||||
|
||||
int parsePacket(int size = 0);
|
||||
int packetRssi();
|
||||
int packetRssi(uint8_t pkt_snr_raw);
|
||||
int currentRssi();
|
||||
uint8_t packetRssiRaw();
|
||||
uint8_t currentRssiRaw();
|
||||
@ -67,9 +66,9 @@ public:
|
||||
long getSignalBandwidth();
|
||||
void setSignalBandwidth(long sbw);
|
||||
void setCodingRate4(int denominator);
|
||||
void setPreambleLength(long length);
|
||||
void setPreambleLength(long preamble_symbols);
|
||||
void setSyncWord(uint16_t sw);
|
||||
uint8_t modemStatus();
|
||||
bool dcd();
|
||||
void enableCrc();
|
||||
void disableCrc();
|
||||
void enableTCXO();
|
||||
@ -82,7 +81,7 @@ public:
|
||||
void executeOpcodeRead(uint8_t opcode, uint8_t *buffer, uint8_t size);
|
||||
void writeBuffer(const uint8_t* buffer, size_t size);
|
||||
void readBuffer(uint8_t* buffer, size_t size);
|
||||
void setPacketParams(long preamble, uint8_t headermode, uint8_t length, uint8_t crc);
|
||||
void setPacketParams(long preamble_symbols, uint8_t headermode, uint8_t payload_length, uint8_t crc);
|
||||
|
||||
void setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, int ldro);
|
||||
|
||||
|
119
sx127x.cpp
119
sx127x.cpp
@ -1,9 +1,6 @@
|
||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||
// Copyright Sandeep Mistry, Mark Qvist and Jacob Eva.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Modifications and additions copyright 2023 by Mark Qvist
|
||||
// Obviously still under the MIT license.
|
||||
|
||||
#include "Boards.h"
|
||||
|
||||
#if MODEM == SX1276
|
||||
@ -81,10 +78,7 @@ extern SPIClass SPI;
|
||||
sx127x::sx127x() :
|
||||
_spiSettings(8E6, MSBFIRST, SPI_MODE0),
|
||||
_ss(LORA_DEFAULT_SS_PIN), _reset(LORA_DEFAULT_RESET_PIN), _dio0(LORA_DEFAULT_DIO0_PIN),
|
||||
_frequency(0),
|
||||
_packetIndex(0),
|
||||
_preinit_done(false),
|
||||
_onReceive(NULL) { setTimeout(0); }
|
||||
_frequency(0), _packetIndex(0), _preinit_done(false), _onReceive(NULL) { setTimeout(0); }
|
||||
|
||||
void sx127x::setSPIFrequency(uint32_t frequency) { _spiSettings = SPISettings(frequency, MSBFIRST, SPI_MODE0); }
|
||||
void sx127x::setPins(int ss, int reset, int dio0, int busy) { _ss = ss; _reset = reset; _dio0 = dio0; _busy = busy; }
|
||||
@ -92,7 +86,6 @@ uint8_t ISR_VECT sx127x::readRegister(uint8_t address) { return singleTransfer(a
|
||||
void sx127x::writeRegister(uint8_t address, uint8_t value) { singleTransfer(address | 0x80, value); }
|
||||
void sx127x::standby() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_STDBY_7X); }
|
||||
void sx127x::sleep() { writeRegister(REG_OP_MODE_7X, MODE_LONG_RANGE_MODE_7X | MODE_SLEEP_7X); }
|
||||
uint8_t sx127x::modemStatus() { return readRegister(REG_MODEM_STAT_7X); }
|
||||
void sx127x::setSyncWord(uint8_t sw) { writeRegister(REG_SYNC_WORD_7X, sw); }
|
||||
void sx127x::enableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) | 0x04); }
|
||||
void sx127x::disableCrc() { writeRegister(REG_MODEM_CONFIG_2_7X, readRegister(REG_MODEM_CONFIG_2_7X) & 0xfb); }
|
||||
@ -106,7 +99,12 @@ void sx127x::flush() { }
|
||||
bool sx127x::preInit() {
|
||||
pinMode(_ss, OUTPUT);
|
||||
digitalWrite(_ss, HIGH);
|
||||
SPI.begin();
|
||||
|
||||
#if BOARD_MODEL == BOARD_T3S3
|
||||
SPI.begin(pin_sclk, pin_miso, pin_mosi, pin_cs);
|
||||
#else
|
||||
SPI.begin();
|
||||
#endif
|
||||
|
||||
// Check modem version
|
||||
uint8_t version;
|
||||
@ -118,7 +116,6 @@ bool sx127x::preInit() {
|
||||
}
|
||||
|
||||
if (version != 0x12) { return false; }
|
||||
|
||||
_preinit_done = true;
|
||||
return true;
|
||||
}
|
||||
@ -139,8 +136,6 @@ uint8_t ISR_VECT sx127x::singleTransfer(uint8_t address, uint8_t value) {
|
||||
int sx127x::begin(long frequency) {
|
||||
if (_reset != -1) {
|
||||
pinMode(_reset, OUTPUT);
|
||||
|
||||
// Perform reset
|
||||
digitalWrite(_reset, LOW);
|
||||
delay(10);
|
||||
digitalWrite(_reset, HIGH);
|
||||
@ -148,19 +143,16 @@ int sx127x::begin(long frequency) {
|
||||
}
|
||||
|
||||
if (_busy != -1) { pinMode(_busy, INPUT); }
|
||||
|
||||
if (!_preinit_done) {
|
||||
if (!preInit()) { return false; }
|
||||
}
|
||||
if (!_preinit_done) { if (!preInit()) { return false; } }
|
||||
|
||||
sleep();
|
||||
setFrequency(frequency);
|
||||
|
||||
// set base addresses
|
||||
// Set base addresses
|
||||
writeRegister(REG_FIFO_TX_BASE_ADDR_7X, 0);
|
||||
writeRegister(REG_FIFO_RX_BASE_ADDR_7X, 0);
|
||||
|
||||
// set LNA boost and auto AGC
|
||||
// Set LNA boost and auto AGC
|
||||
writeRegister(REG_LNA_7X, readRegister(REG_LNA_7X) | 0x03);
|
||||
writeRegister(REG_MODEM_CONFIG_3_7X, 0x04);
|
||||
|
||||
@ -173,20 +165,13 @@ int sx127x::begin(long frequency) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void sx127x::end() {
|
||||
sleep();
|
||||
SPI.end();
|
||||
_preinit_done = false;
|
||||
}
|
||||
void sx127x::end() { sleep(); SPI.end(); _preinit_done = false; }
|
||||
|
||||
int sx127x::beginPacket(int implicitHeader) {
|
||||
standby();
|
||||
|
||||
if (implicitHeader) {
|
||||
implicitHeaderMode();
|
||||
} else {
|
||||
explicitHeaderMode();
|
||||
}
|
||||
if (implicitHeader) { implicitHeaderMode(); }
|
||||
else { explicitHeaderMode(); }
|
||||
|
||||
// Reset FIFO address and payload length
|
||||
writeRegister(REG_FIFO_ADDR_PTR_7X, 0);
|
||||
@ -209,6 +194,14 @@ int sx127x::endPacket() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool sx127x::dcd() {
|
||||
bool carrier_detected = false;
|
||||
uint8_t status = readRegister(REG_MODEM_STAT_7X);
|
||||
if ((status & SIG_DETECT) == SIG_DETECT) { carrier_detected = true; }
|
||||
if ((status & SIG_SYNCED) == SIG_SYNCED) { carrier_detected = true; }
|
||||
return carrier_detected;
|
||||
}
|
||||
|
||||
uint8_t sx127x::currentRssiRaw() {
|
||||
uint8_t rssi = readRegister(REG_RSSI_VALUE_7X);
|
||||
return rssi;
|
||||
@ -225,30 +218,42 @@ uint8_t sx127x::packetRssiRaw() {
|
||||
return pkt_rssi_value;
|
||||
}
|
||||
|
||||
int ISR_VECT sx127x::packetRssi(uint8_t pkt_snr_raw) {
|
||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE_7X) - RSSI_OFFSET;
|
||||
int pkt_snr = ((int8_t)pkt_snr_raw)*0.25;
|
||||
|
||||
if (_frequency < 820E6) pkt_rssi -= 7;
|
||||
|
||||
if (pkt_snr < 0) {
|
||||
pkt_rssi += pkt_snr;
|
||||
} else {
|
||||
// Slope correction is (16/15)*pkt_rssi,
|
||||
// this estimation looses one floating point
|
||||
// operation, and should be precise enough.
|
||||
pkt_rssi = (int)(1.066 * pkt_rssi);
|
||||
}
|
||||
return pkt_rssi;
|
||||
}
|
||||
|
||||
int ISR_VECT sx127x::packetRssi() {
|
||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE_7X) - RSSI_OFFSET;
|
||||
int pkt_snr = packetSnr();
|
||||
int pkt_rssi = (int)readRegister(REG_PKT_RSSI_VALUE_7X) - RSSI_OFFSET;
|
||||
int pkt_snr = packetSnr();
|
||||
|
||||
if (_frequency < 820E6) pkt_rssi -= 7;
|
||||
if (_frequency < 820E6) pkt_rssi -= 7;
|
||||
|
||||
if (pkt_snr < 0) {
|
||||
pkt_rssi += pkt_snr;
|
||||
} else {
|
||||
// Slope correction is (16/15)*pkt_rssi,
|
||||
// this estimation looses one floating point
|
||||
// operation, and should be precise enough.
|
||||
pkt_rssi = (int)(1.066 * pkt_rssi);
|
||||
}
|
||||
return pkt_rssi;
|
||||
if (pkt_snr < 0) { pkt_rssi += pkt_snr; }
|
||||
else {
|
||||
// Slope correction is (16/15)*pkt_rssi,
|
||||
// this estimation looses one floating point
|
||||
// operation, and should be precise enough.
|
||||
pkt_rssi = (int)(1.066 * pkt_rssi);
|
||||
}
|
||||
return pkt_rssi;
|
||||
}
|
||||
|
||||
uint8_t ISR_VECT sx127x::packetSnrRaw() {
|
||||
return readRegister(REG_PKT_SNR_VALUE_7X);
|
||||
}
|
||||
uint8_t ISR_VECT sx127x::packetSnrRaw() { return readRegister(REG_PKT_SNR_VALUE_7X); }
|
||||
|
||||
float ISR_VECT sx127x::packetSnr() {
|
||||
return ((int8_t)readRegister(REG_PKT_SNR_VALUE_7X)) * 0.25;
|
||||
}
|
||||
float ISR_VECT sx127x::packetSnr() { return ((int8_t)readRegister(REG_PKT_SNR_VALUE_7X)) * 0.25; }
|
||||
|
||||
long sx127x::packetFrequencyError() {
|
||||
int32_t freqError = 0;
|
||||
@ -271,17 +276,13 @@ long sx127x::packetFrequencyError() {
|
||||
size_t sx127x::write(uint8_t byte) { return write(&byte, sizeof(byte)); }
|
||||
|
||||
size_t sx127x::write(const uint8_t *buffer, size_t size) {
|
||||
int currentLength = readRegister(REG_PAYLOAD_LENGTH_7X);
|
||||
if ((currentLength + size) > MAX_PKT_LENGTH) {
|
||||
size = MAX_PKT_LENGTH - currentLength;
|
||||
}
|
||||
int currentLength = readRegister(REG_PAYLOAD_LENGTH_7X);
|
||||
if ((currentLength + size) > MAX_PKT_LENGTH) { size = MAX_PKT_LENGTH - currentLength; }
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
writeRegister(REG_FIFO_7X, buffer[i]);
|
||||
}
|
||||
for (size_t i = 0; i < size; i++) { writeRegister(REG_FIFO_7X, buffer[i]); }
|
||||
writeRegister(REG_PAYLOAD_LENGTH_7X, currentLength + size);
|
||||
|
||||
writeRegister(REG_PAYLOAD_LENGTH_7X, currentLength + size);
|
||||
return size;
|
||||
return size;
|
||||
}
|
||||
|
||||
int ISR_VECT sx127x::available() { return (readRegister(REG_RX_NB_BYTES_7X) - _packetIndex); }
|
||||
@ -446,19 +447,23 @@ void sx127x::setCodingRate4(int denominator) {
|
||||
writeRegister(REG_MODEM_CONFIG_1_7X, (readRegister(REG_MODEM_CONFIG_1_7X) & 0xf1) | (cr << 1));
|
||||
}
|
||||
|
||||
void sx127x::setPreambleLength(long length) {
|
||||
void sx127x::setPreambleLength(long preamble_symbols) {
|
||||
long length = preamble_symbols - 4;
|
||||
writeRegister(REG_PREAMBLE_MSB_7X, (uint8_t)(length >> 8));
|
||||
writeRegister(REG_PREAMBLE_LSB_7X, (uint8_t)(length >> 0));
|
||||
}
|
||||
|
||||
extern bool lora_low_datarate;
|
||||
void sx127x::handleLowDataRate() {
|
||||
int sf = (readRegister(REG_MODEM_CONFIG_2_7X) >> 4);
|
||||
if ( long( (1<<sf) / (getSignalBandwidth()/1000)) > 16) {
|
||||
// Set auto AGC and LowDataRateOptimize
|
||||
writeRegister(REG_MODEM_CONFIG_3_7X, (1<<3)|(1<<2));
|
||||
lora_low_datarate = true;
|
||||
} else {
|
||||
// Only set auto AGC
|
||||
writeRegister(REG_MODEM_CONFIG_3_7X, (1<<2));
|
||||
lora_low_datarate = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
15
sx127x.h
15
sx127x.h
@ -1,9 +1,6 @@
|
||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||
// Copyright Sandeep Mistry, Mark Qvist and Jacob Eva.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Modifications and additions copyright 2023 by Mark Qvist
|
||||
// Obviously still under the MIT license.
|
||||
|
||||
#ifndef SX1276_H
|
||||
#define SX1276_H
|
||||
|
||||
@ -21,6 +18,11 @@
|
||||
|
||||
#define RSSI_OFFSET 157
|
||||
|
||||
// Modem status flags
|
||||
#define SIG_DETECT 0x01
|
||||
#define SIG_SYNCED 0x02
|
||||
#define RX_ONGOING 0x04
|
||||
|
||||
class sx127x : public Stream {
|
||||
public:
|
||||
sx127x();
|
||||
@ -33,6 +35,7 @@ public:
|
||||
|
||||
int parsePacket(int size = 0);
|
||||
int packetRssi();
|
||||
int packetRssi(uint8_t pkt_snr_raw);
|
||||
int currentRssi();
|
||||
uint8_t packetRssiRaw();
|
||||
uint8_t currentRssiRaw();
|
||||
@ -65,9 +68,9 @@ public:
|
||||
long getSignalBandwidth();
|
||||
void setSignalBandwidth(long sbw);
|
||||
void setCodingRate4(int denominator);
|
||||
void setPreambleLength(long length);
|
||||
void setPreambleLength(long preamble_symbols);
|
||||
void setSyncWord(uint8_t sw);
|
||||
uint8_t modemStatus();
|
||||
bool dcd();
|
||||
void enableCrc();
|
||||
void disableCrc();
|
||||
void enableTCXO();
|
||||
|
1044
sx128x.cpp
1044
sx128x.cpp
File diff suppressed because it is too large
Load Diff
48
sx128x.h
48
sx128x.h
@ -1,9 +1,6 @@
|
||||
// Copyright (c) Sandeep Mistry. All rights reserved.
|
||||
// Copyright Sandeep Mistry, Mark Qvist and Jacob Eva.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
// Modifications and additions copyright 2023 by Mark Qvist
|
||||
// Obviously still under the MIT license.
|
||||
|
||||
#ifndef SX128X_H
|
||||
#define SX128X_H
|
||||
|
||||
@ -11,17 +8,16 @@
|
||||
#include <SPI.h>
|
||||
#include "Modem.h"
|
||||
|
||||
#define LORA_DEFAULT_SS_PIN 10
|
||||
#define LORA_DEFAULT_RESET_PIN 9
|
||||
#define LORA_DEFAULT_DIO0_PIN 2
|
||||
#define LORA_DEFAULT_SS_PIN 10
|
||||
#define LORA_DEFAULT_RESET_PIN 9
|
||||
#define LORA_DEFAULT_DIO0_PIN 2
|
||||
#define LORA_DEFAULT_RXEN_PIN -1
|
||||
#define LORA_DEFAULT_TXEN_PIN -1
|
||||
#define LORA_DEFAULT_BUSY_PIN -1
|
||||
|
||||
#define PA_OUTPUT_RFO_PIN 0
|
||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||
|
||||
#define RSSI_OFFSET 157
|
||||
#define LORA_MODEM_TIMEOUT_MS 15E3
|
||||
#define PA_OUTPUT_RFO_PIN 0
|
||||
#define PA_OUTPUT_PA_BOOST_PIN 1
|
||||
#define RSSI_OFFSET 157
|
||||
|
||||
class sx128x : public Stream {
|
||||
public:
|
||||
@ -29,12 +25,14 @@ public:
|
||||
|
||||
int begin(unsigned long frequency);
|
||||
void end();
|
||||
void reset();
|
||||
|
||||
int beginPacket(int implicitHeader = false);
|
||||
int endPacket();
|
||||
|
||||
int parsePacket(int size = 0);
|
||||
int packetRssi();
|
||||
int packetRssi(uint8_t pkt_snr_raw);
|
||||
int currentRssi();
|
||||
uint8_t packetRssiRaw();
|
||||
uint8_t currentRssiRaw();
|
||||
@ -55,21 +53,24 @@ public:
|
||||
void onReceive(void(*callback)(int));
|
||||
|
||||
void receive(int size = 0);
|
||||
void idle();
|
||||
void standby();
|
||||
void sleep();
|
||||
|
||||
bool preInit();
|
||||
uint8_t getTxPower();
|
||||
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
|
||||
uint32_t getFrequency();
|
||||
void setFrequency(unsigned long frequency);
|
||||
void setFrequency(uint32_t frequency);
|
||||
void setSpreadingFactor(int sf);
|
||||
long getSignalBandwidth();
|
||||
void setSignalBandwidth(long sbw);
|
||||
uint8_t getSpreadingFactor();
|
||||
uint32_t getSignalBandwidth();
|
||||
void setSignalBandwidth(uint32_t sbw);
|
||||
void setCodingRate4(int denominator);
|
||||
void setPreambleLength(long length);
|
||||
uint8_t getCodingRate4();
|
||||
void setPreambleLength(long preamble_symbols);
|
||||
void setSyncWord(int sw);
|
||||
uint8_t modemStatus();
|
||||
bool dcd();
|
||||
void clearIRQStatus();
|
||||
void enableCrc();
|
||||
void disableCrc();
|
||||
void enableTCXO();
|
||||
@ -83,15 +84,12 @@ public:
|
||||
void executeOpcodeRead(uint8_t opcode, uint8_t *buffer, uint8_t size);
|
||||
void writeBuffer(const uint8_t* buffer, size_t size);
|
||||
void readBuffer(uint8_t* buffer, size_t size);
|
||||
void setPacketParams(uint32_t preamble, uint8_t headermode, uint8_t length, uint8_t crc);
|
||||
void setPacketParams(uint32_t target_preamble_symbols, uint8_t headermode, uint8_t payload_length, uint8_t crc);
|
||||
void setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr);
|
||||
|
||||
// deprecated
|
||||
void crc() { enableCrc(); }
|
||||
void noCrc() { disableCrc(); }
|
||||
|
||||
byte random();
|
||||
|
||||
void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN, int busy = LORA_DEFAULT_BUSY_PIN, int rxen = LORA_DEFAULT_RXEN_PIN, int txen = LORA_DEFAULT_TXEN_PIN);
|
||||
void setSPIFrequency(uint32_t frequency);
|
||||
|
||||
@ -101,6 +99,7 @@ private:
|
||||
void explicitHeaderMode();
|
||||
void implicitHeaderMode();
|
||||
|
||||
bool getPacketValidity();
|
||||
void handleDio0Rise();
|
||||
|
||||
uint8_t readRegister(uint16_t address);
|
||||
@ -135,8 +134,11 @@ private:
|
||||
int _fifo_rx_addr_ptr;
|
||||
uint8_t _packet[256];
|
||||
bool _preinit_done;
|
||||
bool _tcxo;
|
||||
bool _radio_online;
|
||||
int _rxPacketLength;
|
||||
void (*_onReceive)(int);
|
||||
uint32_t _bitrate;
|
||||
void (*_receive_callback)(int);
|
||||
};
|
||||
|
||||
extern sx128x sx128x_modem;
|
||||
|
Loading…
x
Reference in New Issue
Block a user