Skip to content

Commit c0194d8

Browse files
authored
Merge pull request meshcore-dev#1492 from oltaco/meshtiny
Support for Meshtiny
2 parents fedf703 + 5a20e86 commit c0194d8

File tree

8 files changed

+481
-0
lines changed

8 files changed

+481
-0
lines changed

boards/meshtiny.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"build": {
3+
"arduino": {
4+
"ldscript": "nrf52840_s140_v6.ld"
5+
},
6+
"core": "nRF5",
7+
"cpu": "cortex-m4",
8+
"extra_flags": "-DARDUINO_NRF52840_FEATHER -DNRF52840_XXAA",
9+
"f_cpu": "64000000L",
10+
"hwids": [
11+
[
12+
"0x239A",
13+
"0x8029"
14+
],
15+
[
16+
"0x239A",
17+
"0x0029"
18+
],
19+
[
20+
"0x239A",
21+
"0x002A"
22+
],
23+
[
24+
"0x239A",
25+
"0x802A"
26+
]
27+
],
28+
"usb_product": "Meshtiny",
29+
"mcu": "nrf52840",
30+
"variant": "meshtiny",
31+
"bsp": {
32+
"name": "adafruit"
33+
},
34+
"softdevice": {
35+
"sd_flags": "-DS140",
36+
"sd_name": "s140",
37+
"sd_version": "6.1.1",
38+
"sd_fwid": "0x00B6"
39+
},
40+
"bootloader": {
41+
"settings_addr": "0xFF000"
42+
}
43+
},
44+
"connectivity": [
45+
"bluetooth"
46+
],
47+
"debug": {
48+
"jlink_device": "nRF52840_xxAA",
49+
"svd_path": "nrf52840.svd",
50+
"openocd_target": "nrf52840-mdk-rs"
51+
},
52+
"frameworks": [
53+
"arduino",
54+
"freertos"
55+
],
56+
"name": "Meshtiny",
57+
"upload": {
58+
"maximum_ram_size": 248832,
59+
"maximum_size": 815104,
60+
"speed": 115200,
61+
"protocol": "nrfutil",
62+
"protocols": [
63+
"jlink",
64+
"nrfjprog",
65+
"nrfutil",
66+
"stlink"
67+
],
68+
"use_1200bps_touch": true,
69+
"require_upload_port": true,
70+
"wait_for_upload_port": true
71+
},
72+
"url": "https://shop.mtoolstec.com/product/meshtiny",
73+
"vendor": "MTools Tec"
74+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "MeshtinyBoard.h"
2+
3+
#include <Arduino.h>
4+
#include <Wire.h>
5+
#include <bluefruit.h>
6+
7+
static BLEDfu bledfu;
8+
9+
static void connect_callback(uint16_t conn_handle) {
10+
(void)conn_handle;
11+
MESH_DEBUG_PRINTLN("BLE client connected");
12+
}
13+
14+
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
15+
(void)conn_handle;
16+
(void)reason;
17+
18+
MESH_DEBUG_PRINTLN("BLE client disconnected");
19+
}
20+
21+
void MeshtinyBoard::begin() {
22+
NRF52BoardDCDC::begin();
23+
btn_prev_state = HIGH;
24+
25+
pinMode(PIN_VBAT_READ, INPUT); // VBAT ADC input
26+
27+
// Set all button pins to INPUT_PULLUP
28+
pinMode(PIN_BUTTON1, INPUT_PULLUP);
29+
pinMode(PIN_BUTTON2, INPUT_PULLUP);
30+
pinMode(PIN_BUTTON3, INPUT_PULLUP);
31+
pinMode(PIN_BUTTON4, INPUT_PULLUP);
32+
33+
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL)
34+
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL);
35+
#endif
36+
37+
Wire.begin();
38+
39+
pinMode(SX126X_POWER_EN, OUTPUT);
40+
digitalWrite(SX126X_POWER_EN, HIGH);
41+
delay(10); // give sx1262 some time to power up
42+
}
43+
44+

variants/meshtiny/MeshtinyBoard.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#pragma once
2+
3+
#include <Arduino.h>
4+
#include <MeshCore.h>
5+
#include <helpers/NRF52Board.h>
6+
7+
class MeshtinyBoard : public NRF52BoardDCDC, public NRF52BoardOTA {
8+
protected:
9+
uint8_t btn_prev_state;
10+
11+
public:
12+
MeshtinyBoard() : NRF52BoardOTA("Meshtiny OTA") {}
13+
void begin();
14+
15+
#if defined(P_LORA_TX_LED)
16+
void onBeforeTransmit() override {
17+
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED on
18+
}
19+
void onAfterTransmit() override {
20+
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED off
21+
}
22+
#endif
23+
24+
uint16_t getBattMilliVolts() override {
25+
int adcvalue = 0;
26+
analogReadResolution(12);
27+
analogReference(AR_INTERNAL_3_0);
28+
delay(10);
29+
adcvalue = analogRead(PIN_VBAT_READ);
30+
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
31+
}
32+
33+
const char *getManufacturerName() const override { return "Meshtiny"; }
34+
35+
void reboot() override { NVIC_SystemReset(); }
36+
37+
void powerOff() override {
38+
39+
#ifdef PIN_USER_BTN
40+
while (digitalRead(PIN_USER_BTN) == LOW) {
41+
delay(10);
42+
}
43+
#endif
44+
45+
#ifdef PIN_3V3_EN
46+
pinMode(PIN_3V3_EN, OUTPUT);
47+
digitalWrite(PIN_3V3_EN, LOW);
48+
#endif
49+
50+
51+
#ifdef PIN_LED1
52+
digitalWrite(PIN_LED1, LOW);
53+
#endif
54+
55+
#ifdef PIN_LED2
56+
digitalWrite(PIN_LED2, LOW);
57+
#endif
58+
59+
#ifdef PIN_USER_BTN
60+
nrf_gpio_cfg_sense_input(g_ADigitalPinMap[PIN_USER_BTN], NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
61+
#endif
62+
63+
sd_power_system_off();
64+
}
65+
66+
};

variants/meshtiny/platformio.ini

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[Meshtiny]
2+
extends = nrf52_base
3+
board = meshtiny
4+
board_build.ldscript = boards/nrf52840_s140_v6.ld
5+
build_flags = ${nrf52_base.build_flags}
6+
-I lib/nrf52/s140_nrf52_6.1.1_API/include
7+
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
8+
-I variants/meshtiny
9+
-D RADIO_CLASS=CustomSX1262
10+
-D WRAPPER_CLASS=CustomSX1262Wrapper
11+
-D LORA_TX_POWER=22
12+
-D SX126X_CURRENT_LIMIT=140
13+
-D SX126X_RX_BOOSTED_GAIN=1
14+
-D PIN_3V3_EN=34
15+
-D MESHTINY
16+
-D UI_HAS_JOYSTICK
17+
build_src_filter = ${nrf52_base.build_src_filter}
18+
+<../variants/meshtiny>
19+
+<helpers/ui/SSD1306Display.cpp>
20+
+<helpers/ui/buzzer.cpp>
21+
+<helpers/sensors>
22+
lib_deps =
23+
${nrf52_base.lib_deps}
24+
adafruit/Adafruit SSD1306 @ ^2.5.13
25+
end2endzone/NonBlockingRTTTL@^1.3.0
26+
27+
[env:Meshtiny_companion_radio_usb]
28+
extends = Meshtiny
29+
build_flags =
30+
${Meshtiny.build_flags}
31+
-I examples/companion_radio/ui-new
32+
-D MESHTINY
33+
-D PIN_BUZZER=30
34+
-D DISPLAY_CLASS=SSD1306Display
35+
-D MAX_CONTACTS=350
36+
-D MAX_GROUP_CHANNELS=40
37+
-D OFFLINE_QUEUE_SIZE=256
38+
; -D MESH_PACKET_LOGGING=1
39+
; -D MESH_DEBUG=1
40+
build_src_filter = ${Meshtiny.build_src_filter}
41+
+<../examples/companion_radio/*.cpp>
42+
+<../examples/companion_radio/ui-new/*.cpp>
43+
lib_deps =
44+
${Meshtiny.lib_deps}
45+
densaugeo/base64 @ ~1.4.0
46+
47+
[env:Meshtiny_companion_radio_ble]
48+
extends = Meshtiny
49+
build_flags =
50+
${Meshtiny.build_flags}
51+
-I examples/companion_radio/ui-new
52+
-D MESHTINY
53+
-D PIN_BUZZER=30
54+
-D DISPLAY_CLASS=SSD1306Display
55+
-D MAX_CONTACTS=350
56+
-D MAX_GROUP_CHANNELS=40
57+
-D BLE_PIN_CODE=123456
58+
-D OFFLINE_QUEUE_SIZE=256
59+
; -D MESH_PACKET_LOGGING=1
60+
; -D MESH_DEBUG=1
61+
; -D BLE_DEBUG_LOGGING=1
62+
build_src_filter = ${Meshtiny.build_src_filter}
63+
+<helpers/nrf52/SerialBLEInterface.cpp>
64+
+<../examples/companion_radio/*.cpp>
65+
+<../examples/companion_radio/ui-new/*.cpp>
66+
lib_deps =
67+
${Meshtiny.lib_deps}
68+
densaugeo/base64 @ ~1.4.0

variants/meshtiny/target.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "target.h"
2+
3+
#include <Arduino.h>
4+
#include <helpers/ArduinoHelpers.h>
5+
6+
MeshtinyBoard board;
7+
8+
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
9+
10+
WRAPPER_CLASS radio_driver(radio, board);
11+
12+
VolatileRTCClock fallback_clock;
13+
AutoDiscoverRTCClock rtc_clock(fallback_clock);
14+
EnvironmentSensorManager sensors = EnvironmentSensorManager();
15+
16+
#ifdef DISPLAY_CLASS
17+
DISPLAY_CLASS display;
18+
MomentaryButton user_btn(ENCODER_PRESS, 1000, true, true);
19+
MomentaryButton joystick_left(ENCODER_LEFT, 1000, true, true);
20+
MomentaryButton joystick_right(ENCODER_RIGHT, 1000, true, true);
21+
MomentaryButton back_btn(PIN_SIDE_BUTTON, 1000, true, true);
22+
#endif
23+
24+
bool radio_init() {
25+
rtc_clock.begin(Wire);
26+
return radio.std_init(&SPI);
27+
}
28+
29+
uint32_t radio_get_rng_seed() {
30+
return radio.random(0x7FFFFFFF);
31+
}
32+
33+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
34+
radio.setFrequency(freq);
35+
radio.setSpreadingFactor(sf);
36+
radio.setBandwidth(bw);
37+
radio.setCodingRate(cr);
38+
}
39+
40+
void radio_set_tx_power(uint8_t dbm) {
41+
radio.setOutputPower(dbm);
42+
}
43+
44+
mesh::LocalIdentity radio_new_identity() {
45+
RadioNoiseListener rng(radio);
46+
return mesh::LocalIdentity(&rng); // create new random identity
47+
}

variants/meshtiny/target.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#define RADIOLIB_STATIC_ONLY 1
4+
#include <MeshtinyBoard.h>
5+
#include <RadioLib.h>
6+
#include <helpers/ArduinoHelpers.h>
7+
#include <helpers/AutoDiscoverRTCClock.h>
8+
#include <helpers/radiolib/CustomSX1262Wrapper.h>
9+
#include <helpers/radiolib/RadioLibWrappers.h>
10+
#ifdef DISPLAY_CLASS
11+
#include <helpers/ui/MomentaryButton.h>
12+
#include <helpers/ui/SSD1306Display.h>
13+
#endif
14+
#include <helpers/sensors/EnvironmentSensorManager.h>
15+
16+
extern MeshtinyBoard board;
17+
extern WRAPPER_CLASS radio_driver;
18+
extern AutoDiscoverRTCClock rtc_clock;
19+
extern EnvironmentSensorManager sensors;
20+
21+
#ifdef DISPLAY_CLASS
22+
extern DISPLAY_CLASS display;
23+
extern MomentaryButton user_btn;
24+
extern MomentaryButton joystick_left;
25+
extern MomentaryButton joystick_right;
26+
extern MomentaryButton back_btn;
27+
#endif
28+
29+
bool radio_init();
30+
uint32_t radio_get_rng_seed();
31+
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
32+
void radio_set_tx_power(uint8_t dbm);
33+
mesh::LocalIdentity radio_new_identity();

variants/meshtiny/variant.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright (c) 2014-2015 Arduino LLC. All right reserved.
3+
Copyright (c) 2016 Sandeep Mistry All right reserved.
4+
Copyright (c) 2018, Adafruit Industries (adafruit.com)
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
See the GNU Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
*/
20+
21+
#include "variant.h"
22+
23+
#include "nrf.h"
24+
#include "wiring_constants.h"
25+
#include "wiring_digital.h"
26+
27+
const uint32_t g_ADigitalPinMap[] = {
28+
// P0
29+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
30+
29, 30, 31,
31+
32+
// P1
33+
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
34+
};
35+
36+
void initVariant() {
37+
// LED1 & LED2
38+
#ifdef PIN_LED1
39+
pinMode(PIN_LED1, OUTPUT);
40+
ledOff(PIN_LED1);
41+
#endif
42+
43+
#ifdef PIN_LED2
44+
pinMode(PIN_LED2, OUTPUT);
45+
ledOff(PIN_LED2);
46+
#endif
47+
48+
// 3V3 Power Rail - nothing connected on meshtiny
49+
pinMode(PIN_3V3_EN, OUTPUT);
50+
digitalWrite(PIN_3V3_EN, LOW);
51+
}

0 commit comments

Comments
 (0)