Skip to content
Draft
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/muzi_base_duo.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": "-DARDUINO_NRF52840_MUZI_BASE_DUO -DNRF52840_XXAA",
"f_cpu": "64000000L",
"hwids": [
[
"0x239A",
"0x4405"
],
[
"0x239A",
"0x0029"
],
[
"0x239A",
"0x002A"
]
],
"usb_product": "muzi_base_duo",
"mcu": "nrf52840",
"variant": "MUZI_BASE_DUO",
"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": "Muzi Base Duo",
"upload": {
"maximum_ram_size": 248832,
"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/muzi-works",
"vendor": "MuziWorks"
}
40 changes: 40 additions & 0 deletions variants/muzi_base_duo/muzi_base_duoBoard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <Arduino.h>
#include <Wire.h>

#include "muzi_base_duoBoard.h"

#ifdef NRF52_POWER_MANAGEMENT
const PowerMgtConfig power_config = {
.lpcomp_ain_channel = PWRMGT_LPCOMP_AIN,
.lpcomp_refsel = PWRMGT_LPCOMP_REFSEL,
.voltage_bootlock = PWRMGT_VOLTAGE_BOOTLOCK
};

void muzi_base_duoBoard::initiateShutdown(uint8_t reason) {
// Disable LoRa module power before shutdown
if (reason == SHUTDOWN_REASON_LOW_VOLTAGE ||
reason == SHUTDOWN_REASON_BOOT_PROTECT) {
configureVoltageWake(power_config.lpcomp_ain_channel, power_config.lpcomp_refsel);
}

enterSystemOff(reason);
}
#endif // NRF52_POWER_MANAGEMENT

void muzi_base_duoBoard::begin() {
NRF52BoardDCDC::begin();

pinMode(PIN_VBAT_READ, INPUT);

#ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT_PULLUP);
#endif

#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
Wire.setPins(PIN_BOARD_SDA, PIN_BOARD_SCL);
#endif
#ifdef NRF52_POWER_MANAGEMENT
checkBootVoltage(&power_config);
#endif
delay(10); // give sx1262 some time to power up
}
37 changes: 37 additions & 0 deletions variants/muzi_base_duo/muzi_base_duoBoard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

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

class muzi_base_duoBoard : public NRF52BoardDCDC {
protected:
#ifdef NRF52_POWER_MANAGEMENT
void initiateShutdown(uint8_t reason) override;
#endif

public:
muzi_base_duoBoard() : NRF52Board("MUZI_BASE_DUO_OTA") {}
void begin();

#define BATTERY_SAMPLES 8

uint16_t getBattMilliVolts() override {
analogReadResolution(12);
analogReference(AR_INTERNAL_3_0);
delay(1);

uint32_t raw = 0;
for (int i = 0; i < BATTERY_SAMPLES; i++) {
raw += analogRead(PIN_VBAT_READ);
}
raw = raw / BATTERY_SAMPLES;

// ADC_MULTIPLIER is the voltage divider ratio
return (raw * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
}

const char* getManufacturerName() const override {
return "Muzi Base Duo";
}
};
119 changes: 119 additions & 0 deletions variants/muzi_base_duo/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
[muzi_base_duo]
extends = nrf52_base
board = muzi_base_duo
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/muzi_base_duo
-I src/helpers/ui
-D muzi_base_duo
-D NRF52_POWER_MANAGEMENT
-D PIN_USER_BTN=PIN_BUTTON1
-D USER_BTN_PRESSED=LOW
-D PIN_STATUS_LED=35
-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=LORA_BUSY ; P0.7
-D P_LORA_SCLK=LORA_SCLK ; P0.11
-D P_LORA_NSS=LORA_NSS ; P0.12
-D P_LORA_DIO_1=LORA_DIO_1 ; P1.1
-D P_LORA_MISO=LORA_MISO ; P1.8
-D P_LORA_MOSI=LORA_MOSI ; P0.9
-D P_LORA_RESET=LORA_RESET ; P1.10
-D LR11X0_DIO_AS_RF_SWITCH=true
-D LR11X0_DIO3_TCXO_VOLTAGE=3.0
-D QSPIFLASH=1
; -D ENV_INCLUDE_GPS=1
build_src_filter = ${nrf52_base.build_src_filter}
+<helpers/*.cpp>
+<helpers/sensors>
+<helpers/nrf52/muzi_base_duo.cpp>
+<../variants/muzi_base_duo>
debug_tool = jlink
upload_protocol = nrfutil

[env:muzi_base_duo_repeater]
extends = muzi_base_duo
build_flags = ${muzi_base_duo.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"muzi_base_duo 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 = ${muzi_base_duo.build_src_filter}
+<../examples/simple_repeater>
lib_deps = ${muzi_base_duo.lib_deps}
; stevemarple/MicroNMEA @ ^2.0.6

[env:muzi_base_duo_room_server]
extends = muzi_base_duo
build_flags = ${muzi_base_duo.build_flags}
-I examples/companion_radio/ui-orig
-D ADVERT_NAME='"muzi_base_duo 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 = ${muzi_base_duo.build_src_filter}
+<../examples/simple_room_server>
lib_deps = ${muzi_base_duo.lib_deps}
; stevemarple/MicroNMEA @ ^2.0.6

[env:muzi_base_duo_companion_radio_usb]
extends = muzi_base_duo
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${muzi_base_duo.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

build_src_filter = ${muzi_base_duo.build_src_filter}
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps = ${muzi_base_duo.lib_deps}
densaugeo/base64 @ ~1.4.0
; stevemarple/MicroNMEA @ ^2.0.6
end2endzone/NonBlockingRTTTL@^1.3.0

[env:muzi_base_duo_companion_radio_ble]
extends = muzi_base_duo
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 708608
build_flags = ${muzi_base_duo.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 QSPIFLASH=1
; -D BLE_DEBUG_LOGGING=1
; -D MESH_PACKET_LOGGING=1
; -D MESH_DEBUG=1
-D OFFLINE_QUEUE_SIZE=256
-D DISPLAY_CLASS=NullDisplayDriver
-D ADVERT_NAME='"@@MAC"'
build_src_filter = ${muzi_base_duo.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
+<helpers/sensors>
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-orig/*.cpp>
lib_deps = ${muzi_base_duo.lib_deps}
densaugeo/base64 @ ~1.4.0
; stevemarple/MicroNMEA @ ^2.0.6
end2endzone/NonBlockingRTTTL@^1.3.0
95 changes: 95 additions & 0 deletions variants/muzi_base_duo/target.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include <Arduino.h>
#include "target.h"
#include "variant.h"
// #include <helpers/sensors/MicroNMEALocationProvider.h>

muzi_base_duoBoard board;

RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);

WRAPPER_CLASS radio_driver(radio, board);

VolatileRTCClock rtc_clock;
// MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);

EnvironmentSensorManager sensors; // only enable environment sensors. GPS is disabled.
#ifdef DISPLAY_CLASS
NullDisplayDriver display;
#endif

#ifndef LORA_CR
#define LORA_CR 5
#endif

#ifdef RF_SWITCH_TABLE
static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = {
RADIOLIB_LR11X0_DIO5,
RADIOLIB_LR11X0_DIO6,
RADIOLIB_LR11X0_DIO7,
RADIOLIB_LR11X0_DIO8,
RADIOLIB_NC
};

static const Module::RfSwitchMode_t rfswitch_table[] = {
// mode DIO5 DIO6 DIO7 DIO8
{ LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }},
{ LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }},
{ LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }},
{ LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }},
{ LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }},
{ LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }},
{ LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }},
END_OF_MODE_TABLE,
};
#endif

bool radio_init() {
//rtc_clock.begin(Wire);

#ifdef LR11X0_DIO3_TCXO_VOLTAGE
float tcxo = LR11X0_DIO3_TCXO_VOLTAGE;
#else
float tcxo = 1.6f;
#endif

SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
SPI.begin();
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
if (status != RADIOLIB_ERR_NONE) {
Serial.print("ERROR: radio init failed: ");
Serial.println(status);
return false; // fail
}

radio.setCRC(2);
radio.explicitHeader();

#ifdef RF_SWITCH_TABLE
radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);
#endif
#ifdef RX_BOOSTED_GAIN
radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
#endif

return true; // success
}

uint32_t radio_get_rng_seed() {
return radio.random(0x7FFFFFFF);
}

void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
radio.setFrequency(freq);
radio.setSpreadingFactor(sf);
radio.setBandwidth(bw);
radio.setCodingRate(cr);
}

void radio_set_tx_power(int8_t dbm) {
radio.setOutputPower(dbm);
}

mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}
Loading