mirror of https://github.com/meshcore-dev/MeshCore
Browse Source
- Companion Radio over USB Serial - Repeater - Room Server - Terminal Chatpull/217/head
13 changed files with 442 additions and 2 deletions
@ -0,0 +1,42 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "PicoWBoard.h" |
||||
|
|
||||
|
//#include <bluefruit.h>
|
||||
|
#include <Wire.h> |
||||
|
|
||||
|
//static BLEDfu bledfu;
|
||||
|
|
||||
|
static void connect_callback(uint16_t conn_handle) { |
||||
|
(void)conn_handle; |
||||
|
MESH_DEBUG_PRINTLN("BLE client connected"); |
||||
|
} |
||||
|
|
||||
|
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) { |
||||
|
(void)conn_handle; |
||||
|
(void)reason; |
||||
|
|
||||
|
MESH_DEBUG_PRINTLN("BLE client disconnected"); |
||||
|
} |
||||
|
|
||||
|
void PicoWBoard::begin() { |
||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||
|
startup_reason = BD_STARTUP_NORMAL; |
||||
|
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 |
||||
|
|
||||
|
Wire.begin(); |
||||
|
|
||||
|
//pinMode(SX126X_POWER_EN, OUTPUT);
|
||||
|
//digitalWrite(SX126X_POWER_EN, HIGH);
|
||||
|
delay(10); // give sx1262 some time to power up
|
||||
|
} |
||||
|
|
||||
|
bool PicoWBoard::startOTAUpdate(const char* id, char reply[]) { |
||||
|
return false; |
||||
|
} |
||||
@ -0,0 +1,64 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
// LoRa radio module pins for PicoW
|
||||
|
#define P_LORA_DIO_1 20 |
||||
|
#define P_LORA_NSS 3 |
||||
|
#define P_LORA_RESET 15 |
||||
|
#define P_LORA_BUSY 2 |
||||
|
#define P_LORA_SCLK 10 |
||||
|
#define P_LORA_MISO 12 |
||||
|
#define P_LORA_MOSI 11 |
||||
|
//#define SX126X_POWER_EN ??? // Not Sure
|
||||
|
|
||||
|
#define SX126X_DIO2_AS_RF_SWITCH true |
||||
|
#define SX126X_DIO3_TCXO_VOLTAGE 1.8 |
||||
|
|
||||
|
// built-ins
|
||||
|
#define PIN_VBAT_READ 26 |
||||
|
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000) // MT Uses 3.1
|
||||
|
#define PIN_LED_BUILTIN LED_BUILTIN |
||||
|
|
||||
|
class PicoWBoard : public mesh::MainBoard { |
||||
|
protected: |
||||
|
uint8_t startup_reason; |
||||
|
|
||||
|
public: |
||||
|
void begin(); |
||||
|
uint8_t getStartupReason() const override { return startup_reason; } |
||||
|
|
||||
|
void onBeforeTransmit() override { |
||||
|
digitalWrite(LED_BUILTIN, HIGH); // turn TX LED on
|
||||
|
} |
||||
|
|
||||
|
void onAfterTransmit() override { |
||||
|
digitalWrite(LED_BUILTIN, LOW); // turn TX LED off
|
||||
|
} |
||||
|
|
||||
|
#define BATTERY_SAMPLES 8 |
||||
|
|
||||
|
uint16_t getBattMilliVolts() override { |
||||
|
analogReadResolution(12); |
||||
|
|
||||
|
uint32_t raw = 0; |
||||
|
for (int i = 0; i < BATTERY_SAMPLES; i++) { |
||||
|
raw += analogRead(PIN_VBAT_READ); |
||||
|
} |
||||
|
raw = raw / BATTERY_SAMPLES; |
||||
|
|
||||
|
return (ADC_MULTIPLIER * raw) / 4096; |
||||
|
} |
||||
|
|
||||
|
const char* getManufacturerName() const override { |
||||
|
return "Pico W"; |
||||
|
} |
||||
|
|
||||
|
void reboot() override { |
||||
|
//NVIC_SystemReset();
|
||||
|
rp2040.reboot(); |
||||
|
} |
||||
|
|
||||
|
bool startOTAUpdate(const char* id, char reply[]) override; |
||||
|
}; |
||||
@ -0,0 +1,103 @@ |
|||||
|
[picow] |
||||
|
extends = rp2040_base |
||||
|
platform = https://github.com/maxgerhardt/platform-raspberrypi.git |
||||
|
board = rpipicow |
||||
|
board_build.core = earlephilhower |
||||
|
board_build.filesystem_size = 0.5m |
||||
|
build_flags = ${rp2040_base.build_flags} |
||||
|
-I variants/picow |
||||
|
; -D PICOW |
||||
|
; -D HW_SPI1_DEVICE |
||||
|
-D SX126X_CURRENT_LIMIT=130 |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
build_src_filter = ${rp2040_base.build_src_filter} |
||||
|
+<helpers/rp2040/*.cpp> |
||||
|
+<../variants/picow> |
||||
|
lib_deps = ${rp2040_base.lib_deps} |
||||
|
|
||||
|
[env:PicoW_Repeater] |
||||
|
extends = picow |
||||
|
build_flags = ${picow.build_flags} |
||||
|
-D ADVERT_NAME='"PicoW Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${picow.build_src_filter} |
||||
|
+<../examples/simple_repeater> |
||||
|
|
||||
|
[env:PicoW_room_server] |
||||
|
extends = picow |
||||
|
build_flags = ${picow.build_flags} |
||||
|
-D ADVERT_NAME='"Test 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 |
||||
|
build_src_filter = ${picow.build_src_filter} |
||||
|
+<../examples/simple_room_server> |
||||
|
|
||||
|
[env:PicoW_companion_radio_usb] |
||||
|
extends = picow |
||||
|
build_flags = ${picow.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=8 |
||||
|
; -D ENABLE_PRIVATE_KEY_IMPORT=1 |
||||
|
; -D ENABLE_PRIVATE_KEY_EXPORT=1 |
||||
|
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1 |
||||
|
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${picow.build_src_filter} |
||||
|
+<../examples/companion_radio> |
||||
|
lib_deps = ${picow.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
; [env:PicoW_companion_radio_ble] |
||||
|
; extends = picow |
||||
|
; build_flags = ${picow.build_flags} |
||||
|
; -D MAX_CONTACTS=100 |
||||
|
; -D MAX_GROUP_CHANNELS=8 |
||||
|
; -D BLE_PIN_CODE=123456 |
||||
|
; -D BLE_DEBUG_LOGGING=1 |
||||
|
; ; -D ENABLE_PRIVATE_KEY_IMPORT=1 |
||||
|
; ; -D ENABLE_PRIVATE_KEY_EXPORT=1 |
||||
|
; ; -D MESH_PACKET_LOGGING=1 |
||||
|
; ; -D MESH_DEBUG=1 |
||||
|
; build_src_filter = ${picow.build_src_filter} |
||||
|
; +<../examples/companion_radio> |
||||
|
; lib_deps = ${picow.lib_deps} |
||||
|
; densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
; [env:PicoW_companion_radio_wifi] |
||||
|
; extends = picow |
||||
|
; build_flags = ${picow.build_flags} |
||||
|
; -D MAX_CONTACTS=100 |
||||
|
; -D MAX_GROUP_CHANNELS=8 |
||||
|
; -D WIFI_DEBUG_LOGGING=1 |
||||
|
; -D WIFI_SSID='"myssid"' |
||||
|
; -D WIFI_PWD='"mypwd"' |
||||
|
; ; -D ENABLE_PRIVATE_KEY_IMPORT=1 |
||||
|
; ; -D ENABLE_PRIVATE_KEY_EXPORT=1 |
||||
|
; ; -D MESH_PACKET_LOGGING=1 |
||||
|
; ; -D MESH_DEBUG=1 |
||||
|
; build_src_filter = ${picow.build_src_filter} |
||||
|
; +<../examples/companion_radio> |
||||
|
; lib_deps = ${picow.lib_deps} |
||||
|
; densaugeo/base64 @ ~1.4.0 |
||||
|
|
||||
|
[env:PicoW_terminal_chat] |
||||
|
extends = picow |
||||
|
build_flags = ${picow.build_flags} |
||||
|
-D MAX_CONTACTS=100 |
||||
|
-D MAX_GROUP_CHANNELS=1 |
||||
|
-D MESH_PACKET_LOGGING=1 |
||||
|
-D MESH_DEBUG=1 |
||||
|
build_src_filter = ${picow.build_src_filter} |
||||
|
+<../examples/simple_secure_chat/main.cpp> |
||||
|
lib_deps = ${picow.lib_deps} |
||||
|
densaugeo/base64 @ ~1.4.0 |
||||
@ -0,0 +1,73 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
|
||||
|
PicoWBoard board; |
||||
|
|
||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI1); |
||||
|
|
||||
|
WRAPPER_CLASS radio_driver(radio, board); |
||||
|
|
||||
|
VolatileRTCClock fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
|
||||
|
#ifndef LORA_CR |
||||
|
#define LORA_CR 5 |
||||
|
#endif |
||||
|
|
||||
|
bool radio_init() { |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
#ifdef SX126X_DIO3_TCXO_VOLTAGE |
||||
|
float tcxo = SX126X_DIO3_TCXO_VOLTAGE; |
||||
|
#else |
||||
|
float tcxo = 1.6f; |
||||
|
#endif |
||||
|
|
||||
|
SPI1.setMISO(P_LORA_MISO); |
||||
|
//SPI1.setCS(P_LORA_NSS); // Setting CS results in freeze
|
||||
|
SPI1.setSCK(P_LORA_SCLK); |
||||
|
SPI1.setMOSI(P_LORA_MOSI); |
||||
|
|
||||
|
SPI1.begin(); |
||||
|
int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo); |
||||
|
if (status != RADIOLIB_ERR_NONE) { |
||||
|
Serial.print("ERROR: radio init failed: "); |
||||
|
Serial.println(status); |
||||
|
return false; // fail
|
||||
|
} |
||||
|
|
||||
|
radio.setCRC(1); |
||||
|
|
||||
|
#ifdef SX126X_CURRENT_LIMIT |
||||
|
radio.setCurrentLimit(SX126X_CURRENT_LIMIT); |
||||
|
#endif |
||||
|
#ifdef SX126X_DIO2_AS_RF_SWITCH |
||||
|
radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH); |
||||
|
#endif |
||||
|
#ifdef SX126X_RX_BOOSTED_GAIN |
||||
|
radio.setRxBoostedGainMode(SX126X_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(uint8_t dbm) { |
||||
|
radio.setOutputPower(dbm); |
||||
|
} |
||||
|
|
||||
|
mesh::LocalIdentity radio_new_identity() { |
||||
|
RadioNoiseListener rng(radio); |
||||
|
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/RadioLibWrappers.h> |
||||
|
#include <helpers/rp2040/PicoWBoard.h> |
||||
|
#include <helpers/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
|
||||
|
extern PicoWBoard board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
|
||||
|
bool radio_init(); |
||||
|
uint32_t radio_get_rng_seed(); |
||||
|
void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr); |
||||
|
void radio_set_tx_power(uint8_t dbm); |
||||
|
mesh::LocalIdentity radio_new_identity(); |
||||
Loading…
Reference in new issue