mirror of https://github.com/meshcore-dev/MeshCore
committed by
GitHub
8 changed files with 472 additions and 0 deletions
@ -0,0 +1,60 @@ |
|||||
|
{ |
||||
|
"build": { |
||||
|
"arduino": { |
||||
|
"ldscript": "nrf52840_s140_v7.ld" |
||||
|
}, |
||||
|
"core": "nRF5", |
||||
|
"cpu": "cortex-m4", |
||||
|
"extra_flags": "-DARDUINO_Seeed_XIAO_nRF52840 -DNRF52840_XXAA -DSEEED_XIAO_NRF52840 ", |
||||
|
"f_cpu": "64000000L", |
||||
|
"hwids": [ |
||||
|
[ "0x2886", "0x0059" ] |
||||
|
], |
||||
|
"mcu": "nrf52840", |
||||
|
"variant": "Seeed_XIAO_nRF52840", |
||||
|
"softdevice": { |
||||
|
"sd_flags": "-DS140", |
||||
|
"sd_name": "s140", |
||||
|
"sd_version": "7.3.0", |
||||
|
"sd_fwid": "0x0123" |
||||
|
}, |
||||
|
"bsp": { |
||||
|
"name": "adafruit" |
||||
|
}, |
||||
|
"bootloader": { |
||||
|
"settings_addr": "0xFF000" |
||||
|
}, |
||||
|
"usb_product": "XIAO nRF52840" |
||||
|
}, |
||||
|
"connectivity": [ |
||||
|
"bluetooth" |
||||
|
], |
||||
|
"debug": { |
||||
|
"jlink_device": "nRF52840_xxAA", |
||||
|
"openocd_target": "nrf52.cfg", |
||||
|
"svd_path": "nrf52840.svd" |
||||
|
}, |
||||
|
"frameworks": [ |
||||
|
"arduino" |
||||
|
], |
||||
|
"name": "Seeed Studio XIAO nRF52840", |
||||
|
"upload": { |
||||
|
"maximum_ram_size": 248832, |
||||
|
"maximum_size": 815104, |
||||
|
"protocol": "nrfutil", |
||||
|
"speed": 115200, |
||||
|
"protocols": [ |
||||
|
"jlink", |
||||
|
"nrfjprog", |
||||
|
"nrfutil", |
||||
|
"cmsis-dap", |
||||
|
"sam-ba", |
||||
|
"blackmagic" |
||||
|
], |
||||
|
"use_1200bps_touch": true, |
||||
|
"require_upload_port": true, |
||||
|
"wait_for_upload_port": true |
||||
|
}, |
||||
|
"url": "https://wiki.seeedstudio.com/meshtastic_solar_node/", |
||||
|
"vendor": "Seeed Studio" |
||||
|
} |
||||
@ -0,0 +1,81 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "SenseCapSolarBoard.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 SenseCapSolarBoard::begin() { |
||||
|
// for future use, sub-classes SHOULD call this from their begin()
|
||||
|
startup_reason = BD_STARTUP_NORMAL; |
||||
|
|
||||
|
#if defined(PIN_WIRE_SDA) && defined(PIN_WIRE_SCL) |
||||
|
Wire.setPins(PIN_WIRE_SDA, PIN_WIRE_SCL); |
||||
|
#endif |
||||
|
|
||||
|
Wire.begin(); |
||||
|
|
||||
|
#ifdef P_LORA_TX_LED |
||||
|
pinMode(P_LORA_TX_LED, OUTPUT); |
||||
|
digitalWrite(P_LORA_TX_LED, HIGH); |
||||
|
#endif |
||||
|
|
||||
|
delay(10); // give sx1262 some time to power up
|
||||
|
} |
||||
|
|
||||
|
bool SenseCapSolarBoard::startOTAUpdate(const char* id, char reply[]) { |
||||
|
// Config the peripheral connection with maximum bandwidth
|
||||
|
// more SRAM required by SoftDevice
|
||||
|
// Note: All config***() function must be called before begin()
|
||||
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); |
||||
|
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16); |
||||
|
|
||||
|
Bluefruit.begin(1, 0); |
||||
|
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||
|
Bluefruit.setTxPower(4); |
||||
|
// Set the BLE device name
|
||||
|
Bluefruit.setName("SENSECAP_SOLAR_OTA"); |
||||
|
|
||||
|
Bluefruit.Periph.setConnectCallback(connect_callback); |
||||
|
Bluefruit.Periph.setDisconnectCallback(disconnect_callback); |
||||
|
|
||||
|
// To be consistent OTA DFU should be added first if it exists
|
||||
|
bledfu.begin(); |
||||
|
|
||||
|
// Set up and start advertising
|
||||
|
// Advertising packet
|
||||
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); |
||||
|
Bluefruit.Advertising.addTxPower(); |
||||
|
Bluefruit.Advertising.addName(); |
||||
|
|
||||
|
/* Start Advertising
|
||||
|
- Enable auto advertising if disconnected |
||||
|
- Interval: fast mode = 20 ms, slow mode = 152.5 ms |
||||
|
- Timeout for fast mode is 30 seconds |
||||
|
- Start(timeout) with timeout = 0 will advertise forever (until connected) |
||||
|
|
||||
|
For recommended advertising interval |
||||
|
https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||
|
*/ |
||||
|
Bluefruit.Advertising.restartOnDisconnect(true); |
||||
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
|
|
||||
|
strcpy(reply, "OK - started"); |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <MeshCore.h> |
||||
|
#include <Arduino.h> |
||||
|
|
||||
|
class SenseCapSolarBoard : public mesh::MainBoard { |
||||
|
protected: |
||||
|
uint8_t startup_reason; |
||||
|
|
||||
|
public: |
||||
|
void begin(); |
||||
|
uint8_t getStartupReason() const override { return startup_reason; } |
||||
|
|
||||
|
#if defined(P_LORA_TX_LED) |
||||
|
void onBeforeTransmit() override { |
||||
|
digitalWrite(P_LORA_TX_LED, LOW); // turn TX LED on
|
||||
|
} |
||||
|
void onAfterTransmit() override { |
||||
|
digitalWrite(P_LORA_TX_LED, HIGH); // turn TX LED off
|
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
uint16_t getBattMilliVolts() override { |
||||
|
digitalWrite(VBAT_ENABLE, LOW); |
||||
|
int adcvalue = 0; |
||||
|
analogReadResolution(12); |
||||
|
analogReference(AR_INTERNAL_3_0); |
||||
|
delay(10); |
||||
|
adcvalue = analogRead(BATTERY_PIN); |
||||
|
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; |
||||
|
} |
||||
|
|
||||
|
const char* getManufacturerName() const override { |
||||
|
return "Seeed SenseCap Solar"; |
||||
|
} |
||||
|
|
||||
|
void reboot() override { |
||||
|
NVIC_SystemReset(); |
||||
|
} |
||||
|
|
||||
|
bool startOTAUpdate(const char* id, char reply[]) override; |
||||
|
}; |
||||
@ -0,0 +1,75 @@ |
|||||
|
[SenseCap_Solar] |
||||
|
extends = nrf52_base |
||||
|
board = seeed_sensecap_solar |
||||
|
board_build.ldscript = boards/nrf52840_s140_v7.ld |
||||
|
build_flags = ${nrf52_base.build_flags} |
||||
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include |
||||
|
-I lib/nrf52/s140_nrf52_7.3.0_API/include/nrf52 |
||||
|
-I variants/sensecap_solar |
||||
|
-I src/helpers/nrf52 |
||||
|
-D NRF52_PLATFORM=1 |
||||
|
-D RADIO_CLASS=CustomSX1262 |
||||
|
-D WRAPPER_CLASS=CustomSX1262Wrapper |
||||
|
-D P_LORA_TX_LED=12 |
||||
|
-D P_LORA_DIO_1=1 |
||||
|
-D P_LORA_RESET=2 |
||||
|
-D P_LORA_BUSY=3 |
||||
|
-D P_LORA_NSS=4 |
||||
|
-D LORA_TX_POWER=22 |
||||
|
-D SX126X_RXEN=5 |
||||
|
-D SX126X_TXEN=RADIOLIB_NC |
||||
|
-D SX126X_DIO2_AS_RF_SWITCH=1 |
||||
|
-D SX126X_DIO3_TCXO_VOLTAGE=1.8 |
||||
|
-D SX126X_CURRENT_LIMIT=140 |
||||
|
-D SX126X_RX_BOOSTED_GAIN=1 |
||||
|
-D ENV_INCLUDE_AHTX0=1 |
||||
|
-D ENV_INCLUDE_BME280=1 |
||||
|
-D ENV_INCLUDE_BMP280=1 |
||||
|
-D ENV_INCLUDE_SHTC3=1 |
||||
|
-D ENV_INCLUDE_LPS22HB=1 |
||||
|
-D ENV_INCLUDE_INA3221=1 |
||||
|
-D ENV_INCLUDE_INA219=1 |
||||
|
build_src_filter = ${nrf52_base.build_src_filter} |
||||
|
+<helpers/*.cpp> |
||||
|
+<helpers/sensors> |
||||
|
+<helpers/nrf52/SenseCapSolarBoard.cpp> |
||||
|
+<../variants/SenseCap_Solar> |
||||
|
debug_tool = jlink |
||||
|
upload_protocol = nrfutil |
||||
|
lib_deps = |
||||
|
${nrf52_base.lib_deps} |
||||
|
rweather/Crypto @ ^0.4.0 |
||||
|
adafruit/Adafruit INA3221 Library @ ^1.0.1 |
||||
|
adafruit/Adafruit INA219 @ ^1.2.3 |
||||
|
adafruit/Adafruit AHTX0 @ ^2.0.5 |
||||
|
adafruit/Adafruit BME280 Library @ ^2.3.0 |
||||
|
adafruit/Adafruit BMP280 Library @ ^2.6.8 |
||||
|
adafruit/Adafruit SHTC3 Library @ ^1.0.1 |
||||
|
arduino-libraries/Arduino_LPS22HB @ ^1.0.2 |
||||
|
|
||||
|
[env:SenseCap_Solar_repeater] |
||||
|
extends = SenseCap_Solar |
||||
|
build_flags = |
||||
|
${SenseCap_Solar.build_flags} |
||||
|
-D ADVERT_NAME='"SenseCap_Solar Repeater"' |
||||
|
-D ADVERT_LAT=0.0 |
||||
|
-D ADVERT_LON=0.0 |
||||
|
-D ADMIN_PASSWORD='"password"' |
||||
|
-D MAX_NEIGHBOURS=8 |
||||
|
; -D MESH_PACKET_LOGGING=1 |
||||
|
; -D MESH_DEBUG=1 |
||||
|
build_src_filter = ${SenseCap_Solar.build_src_filter} |
||||
|
+<../examples/simple_repeater/main.cpp> |
||||
|
|
||||
|
[env:SenseCap_Solar_room_server] |
||||
|
extends = SenseCap_Solar |
||||
|
build_flags = |
||||
|
${SenseCap_Solar.build_flags} |
||||
|
-D ADVERT_NAME='"SenseCap_Solar Room"' |
||||
|
-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 = ${SenseCap_Solar.build_src_filter} |
||||
|
+<../examples/simple_room_server/main.cpp> |
||||
@ -0,0 +1,39 @@ |
|||||
|
#include <Arduino.h> |
||||
|
#include "target.h" |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
|
||||
|
SenseCapSolarBoard 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 fallback_clock; |
||||
|
AutoDiscoverRTCClock rtc_clock(fallback_clock); |
||||
|
EnvironmentSensorManager sensors; |
||||
|
|
||||
|
bool radio_init() { |
||||
|
rtc_clock.begin(Wire); |
||||
|
|
||||
|
return radio.std_init(&SPI); |
||||
|
} |
||||
|
|
||||
|
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,21 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define RADIOLIB_STATIC_ONLY 1 |
||||
|
#include <RadioLib.h> |
||||
|
#include <helpers/RadioLibWrappers.h> |
||||
|
#include <SenseCapSolarBoard.h> |
||||
|
#include <helpers/CustomSX1262Wrapper.h> |
||||
|
#include <helpers/AutoDiscoverRTCClock.h> |
||||
|
#include <helpers/ArduinoHelpers.h> |
||||
|
#include <helpers/sensors/EnvironmentSensorManager.h> |
||||
|
|
||||
|
extern SenseCapSolarBoard board; |
||||
|
extern WRAPPER_CLASS radio_driver; |
||||
|
extern AutoDiscoverRTCClock rtc_clock; |
||||
|
extern EnvironmentSensorManager sensors; |
||||
|
|
||||
|
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(); |
||||
@ -0,0 +1,69 @@ |
|||||
|
#include "variant.h" |
||||
|
#include "wiring_constants.h" |
||||
|
#include "wiring_digital.h" |
||||
|
#include "nrf.h" |
||||
|
|
||||
|
const uint32_t g_ADigitalPinMap[] = { |
||||
|
// D0 .. D10 - Peripheral control pins
|
||||
|
2, // D0 P0.02 (A0) GNSS_WAKEUP
|
||||
|
3, // D1 P0.03 (A1) LORA_DIO1
|
||||
|
28, // D2 P0.28 (A2) LORA_RESET
|
||||
|
29, // D3 P0.29 (A3) LORA_BUSY
|
||||
|
4, // D4 P0.04 (A4/SDA) LORA_CS
|
||||
|
5, // D5 P0.05 (A5/SCL) LORA_SW
|
||||
|
43, // D6 P1.11 (UART_TX) GNSS_TX
|
||||
|
44, // D7 P1.12 (UART_RX) GNSS_RX
|
||||
|
45, // D8 P1.13 (SPI_SCK) LORA_SCK
|
||||
|
46, // D9 P1.14 (SPI_MISO) LORA_MISO
|
||||
|
47, // D10 P1.15 (SPI_MOSI) LORA_MOSI
|
||||
|
|
||||
|
// D11-D12 - LED outputs
|
||||
|
15, // D11 P0.15 User LED
|
||||
|
19, // D12 P0.19 Breathing LED
|
||||
|
|
||||
|
// D13 - User input
|
||||
|
33, // D13 P1.01 User Button
|
||||
|
|
||||
|
// D14-D15 - Grove/NFC interface
|
||||
|
9, // D14 P0.09 NFC1/GROVE_D1
|
||||
|
10, // D15 P0.10 NFC2/GROVE_D0
|
||||
|
|
||||
|
// D16 - Power management
|
||||
|
// 31, // D16 P0.31 VBAT_ADC (Battery voltage)
|
||||
|
31, // D16 P0.31 VBAT_ADC (Battery voltage)
|
||||
|
// D17 - GNSS control
|
||||
|
35, // D17 P1.03 GNSS_RESET
|
||||
|
|
||||
|
37, // D18 P1.05 GNSS_ENABLE
|
||||
|
14, // D19 P0.14 BAT_READ
|
||||
|
39, // D20 P1.07 USER_BUTTON
|
||||
|
|
||||
|
//
|
||||
|
21, // D21 P0.21 (QSPI_SCK)
|
||||
|
25, // D22 P0.25 (QSPI_CSN)
|
||||
|
20, // D23 P0.20 (QSPI_SIO_0 DI)
|
||||
|
24, // D24 P0.24 (QSPI_SIO_1 DO)
|
||||
|
22, // D25 P0.22 (QSPI_SIO_2 WP)
|
||||
|
23, // D26 P0.23 (QSPI_SIO_3 HOLD)
|
||||
|
}; |
||||
|
|
||||
|
void initVariant() { |
||||
|
pinMode(GPS_EN, OUTPUT); |
||||
|
digitalWrite(GPS_EN, LOW); |
||||
|
|
||||
|
pinMode(BATTERY_PIN, INPUT); |
||||
|
pinMode(VBAT_ENABLE, OUTPUT); |
||||
|
digitalWrite(VBAT_ENABLE, LOW); |
||||
|
|
||||
|
pinMode(PIN_QSPI_CS, OUTPUT); |
||||
|
digitalWrite(PIN_QSPI_CS, HIGH); |
||||
|
|
||||
|
pinMode(LED_GREEN, OUTPUT); |
||||
|
digitalWrite(LED_GREEN, LOW); |
||||
|
|
||||
|
pinMode(LED_BLUE, OUTPUT); |
||||
|
digitalWrite(LED_BLUE, LOW); |
||||
|
|
||||
|
pinMode(GPS_EN, OUTPUT); |
||||
|
digitalWrite(GPS_EN, HIGH); |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
#ifndef _SEEED_SENSECAP_SOLAR_H_ |
||||
|
#define _SEEED_SENSECAP_SOLAR_H_ |
||||
|
|
||||
|
/** Master clock frequency */ |
||||
|
#define VARIANT_MCK (64000000ul) |
||||
|
|
||||
|
#define USE_LFXO // Board uses 32khz crystal for LF
|
||||
|
|
||||
|
/*----------------------------------------------------------------------------
|
||||
|
* Headers |
||||
|
*----------------------------------------------------------------------------*/ |
||||
|
|
||||
|
#include "WVariant.h" |
||||
|
|
||||
|
#define PINS_COUNT (33) |
||||
|
#define NUM_DIGITAL_PINS (33) |
||||
|
#define NUM_ANALOG_INPUTS (8) |
||||
|
#define NUM_ANALOG_OUTPUTS (0) |
||||
|
|
||||
|
// LEDs
|
||||
|
#define PIN_LED (12) |
||||
|
#define LED_PWR (PINS_COUNT) |
||||
|
|
||||
|
#define LED_BUILTIN (PIN_LED) |
||||
|
|
||||
|
#define LED_RED (PINS_COUNT) |
||||
|
#define LED_GREEN (12) |
||||
|
#define LED_BLUE (11) |
||||
|
|
||||
|
#define LED_STATE_ON (1) // State when LED is litted
|
||||
|
|
||||
|
// Buttons
|
||||
|
#define PIN_BUTTON1 (13) |
||||
|
#define PIN_BUTTON2 (20) |
||||
|
|
||||
|
#define VBAT_ENABLE (19) // Output LOW to enable reading of the BAT voltage.
|
||||
|
|
||||
|
// Analog pins
|
||||
|
#define BATTERY_PIN (16) // Read the BAT voltage.
|
||||
|
#define AREF_VOLTAGE (3.0F) |
||||
|
#define ADC_MULTIPLIER (3.0F) // 1M, 512k divider bridge
|
||||
|
#define ADC_RESOLUTION (12) |
||||
|
|
||||
|
// Serial interfaces
|
||||
|
#define PIN_SERIAL1_RX (7) |
||||
|
#define PIN_SERIAL1_TX (6) |
||||
|
|
||||
|
// SPI Interfaces
|
||||
|
#define SPI_INTERFACES_COUNT (1) |
||||
|
|
||||
|
#define PIN_SPI_MISO (9) |
||||
|
#define PIN_SPI_MOSI (10) |
||||
|
#define PIN_SPI_SCK (8) |
||||
|
|
||||
|
// Lora SPI is on SPI0
|
||||
|
#define P_LORA_SCLK PIN_SPI_SCK |
||||
|
#define P_LORA_MISO PIN_SPI_MISO |
||||
|
#define P_LORA_MOSI PIN_SPI_MOSI |
||||
|
|
||||
|
// Wire Interfaces
|
||||
|
#define WIRE_INTERFACES_COUNT (1) |
||||
|
|
||||
|
#define PIN_WIRE_SDA (14) |
||||
|
#define PIN_WIRE_SCL (15) |
||||
|
|
||||
|
// GPS L76KB
|
||||
|
#define GPS_BAUDRATE 9600 |
||||
|
#define GPS_THREAD_INTERVAL 50 |
||||
|
#define PIN_GPS_TX PIN_SERIAL1_RX |
||||
|
#define PIN_GPS_RX PIN_SERIAL1_TX |
||||
|
#define PIN_GPS_STANDBY (0) |
||||
|
#define GPS_EN (18) |
||||
|
|
||||
|
// QSPI Pins
|
||||
|
#define PIN_QSPI_SCK (21) |
||||
|
#define PIN_QSPI_CS (22) |
||||
|
#define PIN_QSPI_IO0 (23) |
||||
|
#define PIN_QSPI_IO1 (24) |
||||
|
#define PIN_QSPI_IO2 (25) |
||||
|
#define PIN_QSPI_IO3 (26) |
||||
|
|
||||
|
#define EXTERNAL_FLASH_DEVICES P25Q16H |
||||
|
#define EXTERNAL_FLASH_USE_QSPI |
||||
|
|
||||
|
#endif |
||||
Loading…
Reference in new issue