mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge pull request #1465 from recrof/rak3112-port
initial RAK 3112 support
This commit is contained in:
commit
f0269c9bff
4 changed files with 409 additions and 0 deletions
96
variants/rak3112/RAK3112Board.h
Normal file
96
variants/rak3112/RAK3112Board.h
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <helpers/RefCountedDigitalPin.h>
|
||||||
|
#include <helpers/ESP32Board.h>
|
||||||
|
|
||||||
|
// built-ins
|
||||||
|
#ifndef PIN_VBAT_READ
|
||||||
|
#define PIN_VBAT_READ 1
|
||||||
|
#endif
|
||||||
|
#ifndef PIN_ADC_CTRL
|
||||||
|
#define PIN_ADC_CTRL 36
|
||||||
|
#endif
|
||||||
|
#define PIN_ADC_CTRL_ACTIVE LOW
|
||||||
|
#define PIN_ADC_CTRL_INACTIVE HIGH
|
||||||
|
#define ADC_MULTIPLIER (3 * 1.73 * 1.187 * 1000)
|
||||||
|
#define BATTERY_SAMPLES 8
|
||||||
|
|
||||||
|
#include <driver/rtc_io.h>
|
||||||
|
|
||||||
|
class RAK3112Board : public ESP32Board {
|
||||||
|
private:
|
||||||
|
bool adc_active_state;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RefCountedDigitalPin periph_power;
|
||||||
|
|
||||||
|
RAK3112Board() : periph_power(PIN_VEXT_EN) { }
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
ESP32Board::begin();
|
||||||
|
|
||||||
|
// Auto-detect correct ADC_CTRL pin polarity (different for boards >3.2)
|
||||||
|
pinMode(PIN_ADC_CTRL, INPUT);
|
||||||
|
adc_active_state = !digitalRead(PIN_ADC_CTRL);
|
||||||
|
|
||||||
|
pinMode(PIN_ADC_CTRL, OUTPUT);
|
||||||
|
digitalWrite(PIN_ADC_CTRL, !adc_active_state); // Initially inactive
|
||||||
|
|
||||||
|
periph_power.begin();
|
||||||
|
|
||||||
|
esp_reset_reason_t reason = esp_reset_reason();
|
||||||
|
if (reason == ESP_RST_DEEPSLEEP) {
|
||||||
|
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
|
||||||
|
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
|
||||||
|
startup_reason = BD_STARTUP_RX_PACKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
|
||||||
|
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) {
|
||||||
|
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||||
|
|
||||||
|
// Make sure the DIO1 and NSS GPIOs are hold on required levels during deep sleep
|
||||||
|
rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
|
||||||
|
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);
|
||||||
|
|
||||||
|
rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);
|
||||||
|
|
||||||
|
if (pin_wake_btn < 0) {
|
||||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
|
||||||
|
} else {
|
||||||
|
esp_sleep_enable_ext1_wakeup( (1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secs > 0) {
|
||||||
|
esp_sleep_enable_timer_wakeup(secs * 1000000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally set ESP32 into sleep
|
||||||
|
esp_deep_sleep_start(); // CPU halts here and never returns!
|
||||||
|
}
|
||||||
|
|
||||||
|
void powerOff() override {
|
||||||
|
enterDeepSleep(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 "RAK 3112";
|
||||||
|
}
|
||||||
|
};
|
||||||
223
variants/rak3112/platformio.ini
Normal file
223
variants/rak3112/platformio.ini
Normal file
|
|
@ -0,0 +1,223 @@
|
||||||
|
[rak3112]
|
||||||
|
extends = esp32_base
|
||||||
|
board = esp32-s3-devkitc-1
|
||||||
|
build_flags =
|
||||||
|
${esp32_base.build_flags}
|
||||||
|
${sensor_base.build_flags}
|
||||||
|
-I variants/rak3112
|
||||||
|
-D RAK_3112=1
|
||||||
|
-D ESP32_CPU_FREQ=80
|
||||||
|
-D P_LORA_DIO_1=47
|
||||||
|
-D P_LORA_NSS=7
|
||||||
|
-D P_LORA_RESET=8
|
||||||
|
-D P_LORA_BUSY=48
|
||||||
|
-D P_LORA_SCLK=5
|
||||||
|
-D P_LORA_MISO=3
|
||||||
|
-D P_LORA_MOSI=6
|
||||||
|
-D RADIO_CLASS=CustomSX1262
|
||||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper
|
||||||
|
-D LORA_TX_POWER=22
|
||||||
|
-D P_LORA_TX_LED=46
|
||||||
|
-D PIN_BOARD_SDA=9
|
||||||
|
-D PIN_BOARD_SCL=40
|
||||||
|
-D PIN_USER_BTN=-1
|
||||||
|
-D PIN_VEXT_EN=14
|
||||||
|
-D SX126X_DIO2_AS_RF_SWITCH=true
|
||||||
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8
|
||||||
|
-D SX126X_CURRENT_LIMIT=140
|
||||||
|
-D SX126X_RX_BOOSTED_GAIN=1
|
||||||
|
-D PIN_GPS_RX=43
|
||||||
|
-D PIN_GPS_TX=44
|
||||||
|
; -D PIN_GPS_EN=26
|
||||||
|
build_src_filter = ${esp32_base.build_src_filter}
|
||||||
|
+<../variants/rak3112>
|
||||||
|
+<helpers/sensors>
|
||||||
|
lib_deps =
|
||||||
|
${esp32_base.lib_deps}
|
||||||
|
${sensor_base.lib_deps}
|
||||||
|
|
||||||
|
[env:RAK3112_repeater]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D ADVERT_NAME='"RAK3112 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 = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<../examples/simple_repeater>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
${esp32_ota.lib_deps}
|
||||||
|
bakercp/CRC32 @ ^2.0.0
|
||||||
|
|
||||||
|
[env:RAK3112_repeater_bridge_rs232]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D ADVERT_NAME='"RS232 Bridge"'
|
||||||
|
-D ADVERT_LAT=0.0
|
||||||
|
-D ADVERT_LON=0.0
|
||||||
|
-D ADMIN_PASSWORD='"password"'
|
||||||
|
-D MAX_NEIGHBOURS=50
|
||||||
|
-D WITH_RS232_BRIDGE=Serial2
|
||||||
|
-D WITH_RS232_BRIDGE_RX=5
|
||||||
|
-D WITH_RS232_BRIDGE_TX=6
|
||||||
|
; -D BRIDGE_DEBUG=1
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/bridges/RS232Bridge.cpp>
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<../examples/simple_repeater>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
${esp32_ota.lib_deps}
|
||||||
|
|
||||||
|
[env:RAK3112_repeater_bridge_espnow]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D ADVERT_NAME='"ESPNow Bridge"'
|
||||||
|
-D ADVERT_LAT=0.0
|
||||||
|
-D ADVERT_LON=0.0
|
||||||
|
-D ADMIN_PASSWORD='"password"'
|
||||||
|
-D MAX_NEIGHBOURS=50
|
||||||
|
-D WITH_ESPNOW_BRIDGE=1
|
||||||
|
; -D BRIDGE_DEBUG=1
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/bridges/ESPNowBridge.cpp>
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<../examples/simple_repeater>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
${esp32_ota.lib_deps}
|
||||||
|
|
||||||
|
[env:RAK3112_room_server]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D ADVERT_NAME='"RAK3112 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 = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<../examples/simple_room_server>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
${esp32_ota.lib_deps}
|
||||||
|
|
||||||
|
[env:RAK3112_terminal_chat]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=1
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<../examples/simple_secure_chat/main.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
|
[env:RAK3112_companion_radio_usb]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-I examples/companion_radio/ui-new
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=40
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
; NOTE: DO NOT ENABLE --> -D MESH_PACKET_LOGGING=1
|
||||||
|
; NOTE: DO NOT ENABLE --> -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
+<../examples/companion_radio/ui-new/*.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
|
[env:RAK3112_companion_radio_ble]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-I examples/companion_radio/ui-new
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=40
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D BLE_PIN_CODE=123456 ; dynamic, random PIN
|
||||||
|
-D AUTO_SHUTDOWN_MILLIVOLTS=3400
|
||||||
|
-D BLE_DEBUG_LOGGING=1
|
||||||
|
-D OFFLINE_QUEUE_SIZE=256
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
+<helpers/esp32/*.cpp>
|
||||||
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
+<../examples/companion_radio/ui-new/*.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
|
[env:RAK3112_companion_radio_wifi]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-I examples/companion_radio/ui-new
|
||||||
|
-D MAX_CONTACTS=350
|
||||||
|
-D MAX_GROUP_CHANNELS=40
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
-D WIFI_DEBUG_LOGGING=1
|
||||||
|
-D WIFI_SSID='"myssid"'
|
||||||
|
-D WIFI_PWD='"mypwd"'
|
||||||
|
-D OFFLINE_QUEUE_SIZE=256
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<helpers/ui/MomentaryButton.cpp>
|
||||||
|
+<helpers/esp32/*.cpp>
|
||||||
|
+<../examples/companion_radio/*.cpp>
|
||||||
|
+<../examples/companion_radio/ui-new/*.cpp>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
densaugeo/base64 @ ~1.4.0
|
||||||
|
|
||||||
|
[env:RAK3112_sensor]
|
||||||
|
extends = rak3112
|
||||||
|
build_flags =
|
||||||
|
${rak3112.build_flags}
|
||||||
|
-D ADVERT_NAME='"RAK3112 v3 Sensor"'
|
||||||
|
-D ADVERT_LAT=0.0
|
||||||
|
-D ADVERT_LON=0.0
|
||||||
|
-D ADMIN_PASSWORD='"password"'
|
||||||
|
-D ENV_PIN_SDA=33
|
||||||
|
-D ENV_PIN_SCL=34
|
||||||
|
-D DISPLAY_CLASS=SSD1306Display
|
||||||
|
; -D MESH_PACKET_LOGGING=1
|
||||||
|
; -D MESH_DEBUG=1
|
||||||
|
build_src_filter = ${rak3112.build_src_filter}
|
||||||
|
+<helpers/ui/SSD1306Display.cpp>
|
||||||
|
+<../examples/simple_sensor>
|
||||||
|
lib_deps =
|
||||||
|
${rak3112.lib_deps}
|
||||||
|
${esp32_ota.lib_deps}
|
||||||
60
variants/rak3112/target.cpp
Normal file
60
variants/rak3112/target.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "target.h"
|
||||||
|
|
||||||
|
RAK3112Board board;
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
|
static SPIClass spi;
|
||||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
|
||||||
|
#else
|
||||||
|
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WRAPPER_CLASS radio_driver(radio, board);
|
||||||
|
|
||||||
|
ESP32RTCClock fallback_clock;
|
||||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||||
|
|
||||||
|
#if ENV_INCLUDE_GPS
|
||||||
|
#include <helpers/sensors/MicroNMEALocationProvider.h>
|
||||||
|
MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1);
|
||||||
|
EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
|
||||||
|
#else
|
||||||
|
EnvironmentSensorManager sensors;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DISPLAY_CLASS
|
||||||
|
DISPLAY_CLASS display;
|
||||||
|
MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool radio_init() {
|
||||||
|
fallback_clock.begin();
|
||||||
|
rtc_clock.begin(Wire);
|
||||||
|
|
||||||
|
#if defined(P_LORA_SCLK)
|
||||||
|
return radio.std_init(&spi);
|
||||||
|
#else
|
||||||
|
return radio.std_init();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
30
variants/rak3112/target.h
Normal file
30
variants/rak3112/target.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define RADIOLIB_STATIC_ONLY 1
|
||||||
|
#include <RadioLib.h>
|
||||||
|
#include <helpers/radiolib/RadioLibWrappers.h>
|
||||||
|
#include <RAK3112Board.h>
|
||||||
|
#include <helpers/radiolib/CustomSX1262Wrapper.h>
|
||||||
|
#include <helpers/AutoDiscoverRTCClock.h>
|
||||||
|
#include <helpers/SensorManager.h>
|
||||||
|
#include <helpers/sensors/EnvironmentSensorManager.h>
|
||||||
|
#ifdef DISPLAY_CLASS
|
||||||
|
#include <helpers/ui/SSD1306Display.h>
|
||||||
|
#include <helpers/ui/MomentaryButton.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern RAK3112Board board;
|
||||||
|
extern WRAPPER_CLASS radio_driver;
|
||||||
|
extern AutoDiscoverRTCClock rtc_clock;
|
||||||
|
extern EnvironmentSensorManager sensors;
|
||||||
|
|
||||||
|
#ifdef DISPLAY_CLASS
|
||||||
|
extern DISPLAY_CLASS display;
|
||||||
|
extern MomentaryButton user_btn;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
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…
Add table
Add a link
Reference in a new issue