Skip to content

Commit 88cbe3f

Browse files
committed
Merge branch 'dev' of github.com:recrof/MeshCore into dev
2 parents e47755c + 99e6b75 commit 88cbe3f

File tree

16 files changed

+787
-36
lines changed

16 files changed

+787
-36
lines changed

boards/minewsemi_me25ls01.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "nrf52840_s140_v7.ld"
5+
},
6+
"core": "nRF5",
7+
"cpu": "cortex-m4",
8+
"extra_flags": "-DARDUINO_WIO_WM1110 -DNRF52840_XXAA",
9+
"f_cpu": "64000000L",
10+
"hwids": [
11+
["0x239A", "0x8029"],
12+
["0x239A", "0x0029"],
13+
["0x239A", "0x002A"],
14+
["0x239A", "0x802A"]
15+
],
16+
"usb_product": "me25ls01-BOOT",
17+
"mcu": "nrf52840",
18+
"variant": "minewsemi_me25ls01",
19+
"bsp": {
20+
"name": "adafruit"
21+
},
22+
"softdevice": {
23+
"sd_flags": "-DS140",
24+
"sd_name": "s140",
25+
"sd_version": "7.3.0",
26+
"sd_fwid": "0x0123"
27+
},
28+
"bootloader": {
29+
"settings_addr": "0xFF000"
30+
}
31+
},
32+
"connectivity": ["bluetooth"],
33+
"debug": {
34+
"jlink_device": "nRF52840_xxAA",
35+
"svd_path": "nrf52840.svd",
36+
"openocd_target": "nrf52.cfg"
37+
},
38+
"frameworks": ["arduino"],
39+
"name": "Minewsemi ME25LS01",
40+
"upload": {
41+
"maximum_ram_size": 248832,
42+
"maximum_size": 815104,
43+
"speed": 115200,
44+
"protocol": "nrfutil",
45+
"protocols": [
46+
"jlink",
47+
"nrfjprog",
48+
"nrfutil",
49+
"stlink",
50+
"cmsis-dap",
51+
"blackmagic"
52+
],
53+
"use_1200bps_touch": true,
54+
"require_upload_port": true,
55+
"wait_for_upload_port": true
56+
},
57+
"url": "https://en.minewsemi.com/lora-module/lr1110-nrf52840-me25LS01",
58+
"vendor": "MINEWSEMI"
59+
}

examples/companion_radio/MyMesh.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,17 @@ void MyMesh::queueMessage(const ContactInfo &from, uint8_t txt_type, mesh::Packe
319319
uint8_t frame[1];
320320
frame[0] = PUSH_CODE_MSG_WAITING; // send push 'tickle'
321321
_serial->writeFrame(frame, 1);
322-
} else {
323-
#ifdef DISPLAY_CLASS
324-
ui_task.soundBuzzer(UIEventType::contactMessage);
325-
#endif
326322
}
323+
327324
#ifdef DISPLAY_CLASS
328-
ui_task.newMsg(path_len, from.name, text, offline_queue_len);
325+
// we only want to show text messages on display, not cli data
326+
bool should_display = txt_type == TXT_TYPE_PLAIN || txt_type == TXT_TYPE_SIGNED_PLAIN;
327+
if (should_display) {
328+
ui_task.newMsg(path_len, from.name, text, offline_queue_len);
329+
if (!_serial->isConnected()) {
330+
ui_task.soundBuzzer(UIEventType::contactMessage);
331+
}
332+
}
329333
#endif
330334
}
331335

src/helpers/CustomLR1110.h

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,58 @@ class CustomLR1110 : public LR1110 {
1010
CustomLR1110(Module *mod) : LR1110(mod) { }
1111

1212
RadioLibTime_t getTimeOnAir(size_t len) override {
13-
uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << this->spreadingFactor) / (this->bandwidthKhz * 10) ;
14-
uint8_t sfCoeff1_x4 = 17; // (4.25 * 4)
15-
uint8_t sfCoeff2 = 8;
16-
if(this->spreadingFactor == 5 || this->spreadingFactor == 6) {
17-
sfCoeff1_x4 = 25; // 6.25 * 4
18-
sfCoeff2 = 0;
19-
}
20-
uint8_t sfDivisor = 4*this->spreadingFactor;
21-
if(symbolLength_us >= 16000) {
22-
sfDivisor = 4*(this->spreadingFactor - 2);
23-
}
24-
const int8_t bitsPerCrc = 16;
25-
const int8_t N_symbol_header = this->headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0;
26-
27-
// numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8)
28-
int16_t bitCount = (int16_t) 8 * len + this->crcTypeLoRa * bitsPerCrc - 4 * this->spreadingFactor + sfCoeff2 + N_symbol_header;
29-
if(bitCount < 0) {
30-
bitCount = 0;
31-
}
32-
// add (sfDivisor) - 1 to the numerator to give integer CEIL(...)
33-
uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor);
34-
35-
// preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit
36-
uint32_t nSymbol_x4 = (this->preambleLengthLoRa + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (this->codingRate + 4) * 4;
37-
38-
return((symbolLength_us * nSymbol_x4) / 4);
13+
// calculate number of symbols
14+
float N_symbol = 0;
15+
if(this->codingRate <= RADIOLIB_LR11X0_LORA_CR_4_8_SHORT) {
16+
// legacy coding rate - nice and simple
17+
// get SF coefficients
18+
float coeff1 = 0;
19+
int16_t coeff2 = 0;
20+
int16_t coeff3 = 0;
21+
if(this->spreadingFactor < 7) {
22+
// SF5, SF6
23+
coeff1 = 6.25;
24+
coeff2 = 4*this->spreadingFactor;
25+
coeff3 = 4*this->spreadingFactor;
26+
} else if(this->spreadingFactor < 11) {
27+
// SF7. SF8, SF9, SF10
28+
coeff1 = 4.25;
29+
coeff2 = 4*this->spreadingFactor + 8;
30+
coeff3 = 4*this->spreadingFactor;
31+
} else {
32+
// SF11, SF12
33+
coeff1 = 4.25;
34+
coeff2 = 4*this->spreadingFactor + 8;
35+
coeff3 = 4*(this->spreadingFactor - 2);
3936
}
4037

38+
// get CRC length
39+
int16_t N_bitCRC = 16;
40+
if(this->crcTypeLoRa == RADIOLIB_LR11X0_LORA_CRC_DISABLED) {
41+
N_bitCRC = 0;
42+
}
43+
44+
// get header length
45+
int16_t N_symbolHeader = 20;
46+
if(this->headerType == RADIOLIB_LR11X0_LORA_HEADER_IMPLICIT) {
47+
N_symbolHeader = 0;
48+
}
49+
50+
// calculate number of LoRa preamble symbols - NO! Lora preamble is already in symbols
51+
// uint32_t N_symbolPreamble = (this->preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((this->preambleLengthLoRa & 0xF0) >> 4));
52+
53+
// calculate the number of symbols - nope
54+
// N_symbol = (float)N_symbolPreamble + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRate + 4);
55+
// calculate the number of symbols - using only preamblelora because it's already in symbols
56+
N_symbol = (float)preambleLengthLoRa + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRate + 4);
57+
} else {
58+
// long interleaving - not needed for this modem
59+
}
60+
61+
// get time-on-air in us
62+
return(((uint32_t(1) << this->spreadingFactor) / this->bandwidthKhz) * N_symbol * 1000.0f);
63+
}
64+
4165
bool isReceiving() {
4266
uint16_t irq = getIrqStatus();
4367
bool detected = ((irq & LR1110_IRQ_HEADER_VALID) || (irq & LR1110_IRQ_HAS_PREAMBLE));
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#include <Arduino.h>
2+
#include "MinewsemiME25LS01Board.h"
3+
#include <Wire.h>
4+
5+
#include <bluefruit.h>
6+
7+
void MinewsemiME25LS01Board::begin() {
8+
// for future use, sub-classes SHOULD call this from their begin()
9+
startup_reason = BD_STARTUP_NORMAL;
10+
btn_prev_state = HIGH;
11+
12+
pinMode(PIN_VBAT_READ, INPUT);
13+
14+
sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
15+
16+
#ifdef BUTTON_PIN
17+
pinMode(BUTTON_PIN, INPUT);
18+
pinMode(LED_PIN, OUTPUT);
19+
#endif
20+
21+
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
22+
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
23+
#endif
24+
25+
Wire.begin();
26+
27+
#ifdef P_LORA_TX_LED
28+
pinMode(P_LORA_TX_LED, OUTPUT);
29+
digitalWrite(P_LORA_TX_LED, LOW);
30+
#endif
31+
32+
delay(10); // give sx1262 some time to power up
33+
}
34+
35+
static BLEDfu bledfu;
36+
37+
static void connect_callback(uint16_t conn_handle) {
38+
(void)conn_handle;
39+
MESH_DEBUG_PRINTLN("BLE client connected");
40+
}
41+
42+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
43+
(void)conn_handle;
44+
(void)reason;
45+
46+
MESH_DEBUG_PRINTLN("BLE client disconnected");
47+
}
48+
49+
50+
bool MinewsemiME25LS01Board::startOTAUpdate(const char* id, char reply[]) {
51+
// Config the peripheral connection with maximum bandwidth
52+
// more SRAM required by SoftDevice
53+
// Note: All config***() function must be called before begin()
54+
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
55+
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
56+
57+
Bluefruit.begin(1, 0);
58+
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
59+
Bluefruit.setTxPower(4);
60+
// Set the BLE device name
61+
Bluefruit.setName("Minewsemi_OTA");
62+
63+
Bluefruit.Periph.setConnectCallback(connect_callback);
64+
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
65+
66+
// To be consistent OTA DFU should be added first if it exists
67+
bledfu.begin();
68+
69+
// Set up and start advertising
70+
// Advertising packet
71+
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
72+
Bluefruit.Advertising.addTxPower();
73+
Bluefruit.Advertising.addName();
74+
75+
/* Start Advertising
76+
- Enable auto advertising if disconnected
77+
- Interval: fast mode = 20 ms, slow mode = 152.5 ms
78+
- Timeout for fast mode is 30 seconds
79+
- Start(timeout) with timeout = 0 will advertise forever (until connected)
80+
81+
For recommended advertising interval
82+
https://developer.apple.com/library/content/qa/qa1931/_index.html
83+
*/
84+
Bluefruit.Advertising.restartOnDisconnect(true);
85+
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
86+
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
87+
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
88+
89+
strcpy(reply, "OK - started");
90+
return true;
91+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#pragma once
2+
3+
#include <MeshCore.h>
4+
#include <Arduino.h>
5+
6+
// LoRa and SPI pins
7+
8+
#define P_LORA_DIO_1 (32 + 12) // P1.12
9+
#define P_LORA_NSS (32 + 13) // P1.13
10+
#define P_LORA_RESET (32 + 11) // P1.11
11+
#define P_LORA_BUSY (32 + 10) // P1.10
12+
#define P_LORA_SCLK (32 + 15) // P1.15
13+
#define P_LORA_MISO (0 + 29) // P0.29
14+
#define P_LORA_MOSI (0 + 2) // P0.2
15+
16+
#define LR11X0_DIO_AS_RF_SWITCH true
17+
#define LR11X0_DIO3_TCXO_VOLTAGE 1.6
18+
19+
#define PIN_VBAT_READ BATTERY_PIN
20+
#define ADC_MULTIPLIER (1.815f) // dependent on voltage divider resistors. TODO: more accurate battery tracking
21+
22+
23+
class MinewsemiME25LS01Board : public mesh::MainBoard {
24+
protected:
25+
uint8_t startup_reason;
26+
uint8_t btn_prev_state;
27+
28+
public:
29+
void begin();
30+
31+
#define BATTERY_SAMPLES 8
32+
33+
uint16_t getBattMilliVolts() override {
34+
analogReadResolution(12);
35+
36+
uint32_t raw = 0;
37+
for (int i = 0; i < BATTERY_SAMPLES; i++) {
38+
raw += analogRead(PIN_VBAT_READ);
39+
}
40+
raw = raw / BATTERY_SAMPLES;
41+
return (ADC_MULTIPLIER * raw);
42+
}
43+
44+
uint8_t getStartupReason() const override { return startup_reason; }
45+
46+
const char* getManufacturerName() const override {
47+
return "Minewsemi";
48+
}
49+
50+
void powerOff() override {
51+
#ifdef HAS_GPS
52+
digitalWrite(GPS_VRTC_EN, LOW);
53+
digitalWrite(GPS_RESET, LOW);
54+
digitalWrite(GPS_SLEEP_INT, LOW);
55+
digitalWrite(GPS_RTC_INT, LOW);
56+
pinMode(GPS_RESETB, OUTPUT);
57+
digitalWrite(GPS_RESETB, LOW);
58+
#endif
59+
60+
#ifdef BUZZER_EN
61+
digitalWrite(BUZZER_EN, LOW);
62+
#endif
63+
64+
#ifdef LED_PIN
65+
digitalWrite(LED_PIN, LOW);
66+
#endif
67+
#ifdef BUTTON_PIN
68+
nrf_gpio_cfg_sense_input(digitalPinToInterrupt(BUTTON_PIN), NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_HIGH);
69+
#endif
70+
sd_power_system_off();
71+
}
72+
73+
#if defined(P_LORA_TX_LED)
74+
void onBeforeTransmit() override {
75+
digitalWrite(P_LORA_TX_LED, HIGH);// turn TX LED on
76+
}
77+
void onAfterTransmit() override {
78+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
79+
}
80+
#endif
81+
82+
83+
void reboot() override {
84+
NVIC_SystemReset();
85+
}
86+
87+
bool startOTAUpdate(const char* id, char reply[]) override;
88+
};

src/helpers/nrf52/SerialBLEInterface.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ void SerialBLEInterface::begin(const char* device_name, uint32_t pin_code) {
1818
}
1919

2020
void SerialBLEInterface::startAdv() {
21+
Bluefruit.Advertising.stop(); // always clean restart
22+
Bluefruit.Advertising.clearData(); // clear advertising data
23+
Bluefruit.ScanResponse.clearData(); // clear scan response data
24+
2125
// Advertising packet
2226
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
2327
Bluefruit.Advertising.addTxPower();
@@ -38,7 +42,7 @@ void SerialBLEInterface::startAdv() {
3842
* For recommended advertising interval
3943
* https://developer.apple.com/library/content/qa/qa1931/_index.html
4044
*/
41-
Bluefruit.Advertising.restartOnDisconnect(true);
45+
Bluefruit.Advertising.restartOnDisconnect(false); // don't restart automatically as already beeing done in checkRecvFrame()
4246
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
4347
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
4448
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <helpers/ui/DisplayDriver.h>
4+
5+
class NullDisplayDriver : public DisplayDriver {
6+
public:
7+
NullDisplayDriver() : DisplayDriver(128, 64) { }
8+
bool begin() { return false; } // not present
9+
10+
bool isOn() override { return false; }
11+
void turnOn() override { }
12+
void turnOff() override { }
13+
void clear() override { }
14+
void startFrame(Color bkg = DARK) override { }
15+
void setTextSize(int sz) override { }
16+
void setColor(Color c) override { }
17+
void setCursor(int x, int y) override { }
18+
void print(const char* str) override { }
19+
void fillRect(int x, int y, int w, int h) override { }
20+
void drawRect(int x, int y, int w, int h) override { }
21+
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { }
22+
uint16_t getTextWidth(const char* str) override { return 0; }
23+
void endFrame() { }
24+
};

0 commit comments

Comments
 (0)