Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions boards/thinknode_m4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"build": {
"arduino": {
"ldscript": "nrf52840_s140_v6.ld"
},
"core": "nRF5",
"cpu": "cortex-m4",
"extra_flags": "-DNRF52840_XXAA",
"f_cpu": "64000000L",
"hwids": [
[
"0x239A",
"0x4405"
],
[
"0x239A",
"0x0029"
],
[
"0x239A",
"0x002A"
]
],
"usb_product": "elecrow_thinknode_m4",
"mcu": "nrf52840",
"variant": "ELECROW-ThinkNode-M4",
"bsp": {
"name": "adafruit"
},
"softdevice": {
"sd_flags": "-DS140",
"sd_name": "s140",
"sd_version": "6.1.1",
"sd_fwid": "0x00B6"
},
"bootloader": {
"settings_addr": "0xFF000"
}
},
"connectivity": [
"bluetooth"
],
"debug": {
"jlink_device": "nRF52840_xxAA",
"onboard_tools": [
"jlink"
],
"svd_path": "nrf52840.svd",
"openocd_target": "nrf52.cfg"
},
"frameworks": [
"arduino"
],
"name": "elecrow nrf",
"upload": {
"maximum_ram_size": 235520,
"maximum_size": 815104,
"speed": 115200,
"use_1200bps_touch": true,
"require_upload_port": true,
"wait_for_upload_port": true,
"protocol": "nrfutil",
"protocols": [
"jlink",
"nrfjprog",
"nrfutil",
"stlink"
]
},
"url": "https://github.com/Elecrow-RD",
"vendor": "ELECROW"
}
46 changes: 46 additions & 0 deletions variants/thinknode_m4/ThinkNodeM4Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <Arduino.h>
#include "ThinkNodeM4Board.h"
#include <Wire.h>

#include <bluefruit.h>

void ThinkNodeM4Board::begin() {
NRF52Board::begin();
btn_prev_state = HIGH;

Wire.begin();
battery_serial->begin(4800);

delay(10); // give sx1262 some time to power up
}

uint16_t ThinkNodeM4Board::getBattMilliVolts() {
int tentatives = 10;
uint8_t data[5];
uint8_t b;

if (battery_serial->available() < 10)
return bat_level_mv;

// discard old data
while (battery_serial->available() > 10)
battery_serial->read();

// synchronize
while((b = battery_serial->read()) != 0xFE) {
if (tentatives-- == 0) {
MESH_DEBUG_PRINTLN("Could not find battery frame start %x", b);
return bat_level_mv;
}
}
battery_serial->readBytes(data, 5);

if (data[4] != 0xFD) {
MESH_DEBUG_PRINTLN("Invalid battery frame end %x", data[4]);
return bat_level_mv;
}
bat_level_percent = data[0];
//MESH_DEBUG_PRINTLN("Battery level %d\%", bat_level_percent);
bat_level_mv = 2 * (data[1]*1000. + data[2]*10. + data[3]/10.);
return bat_level_mv;
}
75 changes: 75 additions & 0 deletions variants/thinknode_m4/ThinkNodeM4Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include <Arduino.h>
#include <MeshCore.h>
#include <helpers/NRF52Board.h>

class ThinkNodeM4Board : public NRF52BoardDCDC {
protected:
#if NRF52_POWER_MANAGEMENT
void initiateShutdown(uint8_t reason) override;
#endif
uint8_t btn_prev_state;
HardwareSerial * battery_serial;
uint16_t bat_level_mv = 0;
uint8_t bat_level_percent =0;

public:
ThinkNodeM4Board() : NRF52Board("THINKNODE_M3_OTA"), battery_serial(&Serial2) {}
void begin();
uint16_t getBattMilliVolts() override;

#ifdef P_LORA_TX_LED
void onBeforeTransmit() override {
digitalWrite(P_LORA_TX_LED, LED_STATE_ON); // turn TX LED on
}
void onAfterTransmit() override {
digitalWrite(P_LORA_TX_LED, !LED_STATE_ON); // turn TX LED off
}
#endif

const char* getManufacturerName() const override {
return "Elecrow ThinkNode M4";
}

int buttonStateChanged() {
#ifdef BUTTON_PIN
uint8_t v = digitalRead(BUTTON_PIN);
if (v != btn_prev_state) {
btn_prev_state = v;
return (v == USER_BTN_PRESSED) ? 1 : -1;
}
#endif
return 0;
}

void shutdownPeripherals() override {
// shutdown common peripherals
NRF52Board::shutdownPeripherals();

#ifdef LED_STATUS
digitalWrite(LED_STATUS, HIGH);
#endif
#ifdef BUTTON_PIN
while(!digitalRead(BUTTON_PIN));
#endif
#ifdef LED_STATUS
digitalWrite(LED_STATUS, LOW);
#endif

digitalWrite(LED_BAT1, LOW);
digitalWrite(LED_BAT2, LOW);
digitalWrite(LED_BAT3, LOW);
digitalWrite(LED_BAT4, LOW);
digitalWrite(LED_STATUS, LOW);
digitalWrite(LED_PIN, LOW);

digitalWrite(PIN_PWR_EN, LOW);
digitalWrite(I2C_POWER, !I2C_POWER_ACTIVE);
digitalWrite(PIN_GPS_POWER, !GPS_POWER_ACTIVE);

#ifdef BUTTON_PIN
nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW);
#endif
}
};
130 changes: 130 additions & 0 deletions variants/thinknode_m4/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
[ThinkNode_M4]
extends = nrf52_base
board = thinknode_m4
board_build.ldscript = boards/nrf52840_s140_v6.ld
build_flags = ${nrf52_base.build_flags}
-I src/helpers/nrf52
-I lib/nrf52/s140_nrf52_6.1.1_API/include
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
-I variants/thinknode_m4
-I src/helpers/ui
-D THINKNODE_M4
-D PIN_USER_BTN=4
-D PIN_STATUS_LED=LED_STATUS
-D RADIO_CLASS=CustomLR1110
-D WRAPPER_CLASS=CustomLR1110Wrapper
-D LORA_TX_POWER=22
-D RF_SWITCH_TABLE
-D RX_BOOSTED_GAIN=true
-D P_LORA_BUSY=26
-D P_LORA_SCLK=6
-D P_LORA_NSS=27
-D P_LORA_DIO_1=12
-D P_LORA_MISO=8
-D P_LORA_MOSI=7
-D P_LORA_RESET=40
-D P_LORA_TX_LED=LED_TX
-D LR11X0_DIO_AS_RF_SWITCH=true
-D LR11X0_DIO3_TCXO_VOLTAGE=1.6
-D ENV_INCLUDE_GPS=1
; -D MESH_DEBUG=1
; -D GPS_NMEA_DEBUG=1
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<../variants/thinknode_m4>
+<helpers/sensors>
debug_tool = stlink
upload_protocol = nrfutil
lib_deps= ${nrf52_base.lib_deps}

[env:ThinkNode_M4_repeater]
extends = ThinkNode_M4
build_flags = ${ThinkNode_M4.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"ThinkNode_M4 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
build_src_filter = ${ThinkNode_M4.build_src_filter}
+<../examples/simple_repeater>
lib_deps = ${ThinkNode_M4.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6

[env:ThinkNode_M4_room_server]
extends = ThinkNode_M4
build_flags = ${ThinkNode_M4.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"ThinkNode_M4 Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ROOM_PASSWORD='"hello"'
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
-D RF_SWITCH_TABLE
build_src_filter = ${ThinkNode_M4.build_src_filter}
+<../examples/simple_room_server>
lib_deps = ${ThinkNode_M4.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6

[env:ThinkNode_M4_companion_radio_usb]
extends = ThinkNode_M4
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${ThinkNode_M4.build_flags}
-I examples/companion_radio/ui-orig
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=NullDisplayDriver
-D PIN_BUZZER=23
-D PIN_BUZZER_EN=36
-D ENABLE_USB_INTERFACE
build_src_filter = ${ThinkNode_M4.build_src_filter}
+<helpers/ui/buzzer.cpp>
+<helpers/ui/NullDisplayDriver.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps = ${ThinkNode_M4.lib_deps}
densaugeo/base64 @ ~1.4.0
stevemarple/MicroNMEA @ ^2.0.6
end2endzone/NonBlockingRTTTL@^1.3.0

[env:ThinkNode_M4_companion_radio_ble]
extends = ThinkNode_M4
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${ThinkNode_M4.build_flags}
-I examples/companion_radio/ui-orig
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
-D BLE_PIN_CODE=123456
-D BLE_TX_POWER=0
; -D BLE_DEBUG_LOGGING=1
; -D MESH_PACKET_LOGGING=1
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=NullDisplayDriver
-D PIN_BUZZER=23
-D PIN_BUZZER_EN=36
build_src_filter = ${ThinkNode_M4.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/ui/buzzer.cpp>
+<helpers/ui/NullDisplayDriver.cpp>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps = ${ThinkNode_M4.lib_deps}
densaugeo/base64 @ ~1.4.0
stevemarple/MicroNMEA @ ^2.0.6
end2endzone/NonBlockingRTTTL@^1.3.0

[env:ThinkNode_M4_kiss_modem]
extends = ThinkNode_M4
build_src_filter = ${ThinkNode_M4.build_src_filter}
+<../examples/kiss_modem/>
lib_deps = ${ThinkNode_M4.lib_deps}
stevemarple/MicroNMEA @ ^2.0.6
Loading
Loading