Ver Fonte

thinknode_m6: initial port

Florent há 8 meses atrás
pai
commit
14efaf6fd3

+ 72 - 0
boards/thinknode_m6.json

@@ -0,0 +1,72 @@
+{
+  "build": {
+    "arduino": {
+      "ldscript": "nrf52840_s140_v6.ld"
+    },
+    "core": "nRF5",
+    "cpu": "cortex-m4",
+    "extra_flags": "-DARDUINO_NRF52840_ELECROW_M6 -DNRF52840_XXAA",
+    "f_cpu": "64000000L",
+    "hwids": [
+      [
+        "0x239A",
+        "0x4405"
+      ],
+      [
+        "0x239A",
+        "0x0029"
+      ],
+      [
+        "0x239A",
+        "0x002A"
+      ]
+    ],
+    "usb_product": "elecrow_solar",
+    "mcu": "nrf52840",
+    "variant": "ELECROW-ThinkNode-M6",
+    "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 solar",
+  "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/Elecrow-RD",
+  "vendor": "ELECROW"
+}

+ 1 - 1
variants/thinknode_m5/platformio.ini

@@ -3,7 +3,7 @@ extends = esp32_base
 board = ESP32-S3-WROOM-1-N4
 build_flags = ${esp32_base.build_flags}
   -I variants/thinknode_m5
-  -I src/helpres/sensors
+  -I src/helpers/sensors
   -D THINKNODE_M5
   -D PIN_BUZZER=9
   -D PIN_BOARD_SCL=1

+ 95 - 0
variants/thinknode_m6/ThinkNodeM6Board.cpp

@@ -0,0 +1,95 @@
+#include "ThinkNodeM6Board.h"
+#include <Arduino.h>
+
+#ifdef THINKNODE_M6
+
+#include <Wire.h>
+#include <bluefruit.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 ThinkNodeM6Board::begin() {
+  // for future use, sub-classes SHOULD call this from their begin()
+  startup_reason = BD_STARTUP_NORMAL;
+
+  Wire.begin();
+
+#ifdef P_LORA_TX_LED
+  pinMode(P_LORA_TX_LED, OUTPUT);
+  digitalWrite(P_LORA_TX_LED, LOW);
+#endif
+
+  delay(10); // give sx1262 some time to power up
+}
+
+uint16_t ThinkNodeM6Board::getBattMilliVolts() {
+  int adcvalue = 0;
+
+  digitalWrite(PIN_ADC_CTRL, HIGH);
+  analogReference(AR_INTERNAL_3_0);
+  analogReadResolution(12);
+  delay(10);
+
+  // ADC range is 0..3000mV and resolution is 12-bit (0..4095)
+  adcvalue = analogRead(PIN_VBAT_READ);
+  digitalWrite(PIN_ADC_CTRL, LOW);
+  // Convert the raw value to compensated mv, taking the resistor-
+  // divider into account (providing the actual LIPO voltage)
+  return (uint16_t)((float)adcvalue * REAL_VBAT_MV_PER_LSB);
+}
+
+bool ThinkNodeM6Board::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("THINKNODE_M1_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;
+}
+#endif

+ 56 - 0
variants/thinknode_m6/ThinkNodeM6Board.h

@@ -0,0 +1,56 @@
+#pragma once
+
+#include <MeshCore.h>
+#include <Arduino.h>
+
+// built-ins
+#define VBAT_MV_PER_LSB   (0.73242188F)   // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
+
+#define VBAT_DIVIDER_COMP ADC_MULTIPLIER          // Compensation factor for the VBAT divider
+
+#define PIN_VBAT_READ     BATTERY_PIN
+#define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB)
+
+class ThinkNodeM6Board : public mesh::MainBoard {
+protected:
+  uint8_t startup_reason;
+
+public:
+
+  void begin();
+  uint16_t getBattMilliVolts() override;
+  bool startOTAUpdate(const char* id, char reply[]) override;
+
+  uint8_t getStartupReason() const override {
+    return startup_reason;
+  }
+
+  #if defined(P_LORA_TX_LED)
+  void onBeforeTransmit() override {
+    digitalWrite(P_LORA_TX_LED, HIGH);   // turn TX LED on
+  }
+  void onAfterTransmit() override {
+    digitalWrite(P_LORA_TX_LED, LOW);   // turn TX LED off
+  }
+  #endif
+
+  const char* getManufacturerName() const override {
+    return "Elecrow ThinkNode-M6";
+  }
+
+  void reboot() override {
+    NVIC_SystemReset();
+  }
+
+  void powerOff() override {
+
+    // turn off all leds, sd_power_system_off will not do this for us
+    #ifdef P_LORA_TX_LED
+    digitalWrite(P_LORA_TX_LED, LOW);
+    #endif
+
+    // power off board
+    sd_power_system_off();
+
+  }
+};

+ 120 - 0
variants/thinknode_m6/platformio.ini

@@ -0,0 +1,120 @@
+[ThinkNode_M6]
+extends = nrf52_base
+board = thinknode_m6
+board_build.ldscript = boards/nrf52840_s140_v6.ld
+build_flags = ${nrf52_base.build_flags}
+  ${sensor_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_m6
+  -D THINKNODE_M6=1
+  -D RADIO_CLASS=CustomSX1262
+  -D WRAPPER_CLASS=CustomSX1262Wrapper
+  -D P_LORA_DIO_1=38
+  -D P_LORA_NSS=44
+  -D P_LORA_RESET=42
+  -D P_LORA_BUSY=43
+  -D P_LORA_SCLK=45
+  -D P_LORA_MISO=47
+  -D P_LORA_MOSI=46
+  -D SX126X_DIO2_AS_RF_SWITCH=true
+  -D SX126X_DIO3_TCXO_VOLTAGE=3.3
+  -D SX126X_CURRENT_LIMIT=140
+  -D SX126X_RX_BOOSTED_GAIN=1
+  -D LORA_TX_POWER=22
+  -D P_LORA_TX_LED=PIN_LED_BLUE
+;  -D PERSISTANT_GPS=1
+;  -D ENV_SKIP_GPS_DETECT=1
+build_src_filter = ${nrf52_base.build_src_filter}
+  +<helpers/*.cpp>
+  +<helpers/sensors>
+  +<ThinkNodeM6Board.cpp>
+  +<../variants/thinknode_m6>
+lib_deps =
+  ${nrf52_base.lib_deps}
+  ${sensor_base.lib_deps}
+debug_tool = jlink
+upload_protocol = nrfutil
+
+[env:ThinkNode_M6_repeater]
+extends = ThinkNode_M6
+build_flags =
+  ${ThinkNode_M6.build_flags}
+  -D ADVERT_NAME='"ThinkNode 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
+  -D GPS_NMEA_DEBUG=1
+build_src_filter = ${ThinkNode_M6.build_src_filter}
+  +<../examples/simple_repeater/*.cpp>
+lib_deps =
+  ${ThinkNode_M6.lib_deps}
+
+[env:ThinkNode_M6_room_server]
+extends = ThinkNode_M6
+build_flags =
+  ${ThinkNode_M6.build_flags}
+  -D ADVERT_NAME='"ThinkNode 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 = ${ThinkNode_M6.build_src_filter}
+  +<../examples/simple_room_server/*.cpp>
+lib_deps =
+  ${ThinkNode_M6.lib_deps}
+
+[env:ThinkNode_M6_companion_radio_ble]
+extends = ThinkNode_M6
+board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
+board_upload.maximum_size = 712704
+build_flags =
+  ${ThinkNode_M6.build_flags}
+  -I src/helpers/ui
+  -I examples/companion_radio/ui-new
+  -D MAX_CONTACTS=350
+  -D MAX_GROUP_CHANNELS=40
+  -D BLE_PIN_CODE=123456
+  -D BLE_DEBUG_LOGGING=1
+  -D OFFLINE_QUEUE_SIZE=256
+  -D AUTO_SHUTDOWN_MILLIVOLTS=3300
+  -D QSPIFLASH=1
+;  -D MESH_PACKET_LOGGING=1
+;  -D MESH_DEBUG=1
+build_src_filter = ${ThinkNode_M6.build_src_filter}
+  +<helpers/nrf52/SerialBLEInterface.cpp>
+  +<helpers/ui/MomentaryButton.cpp>
+  +<../examples/companion_radio/*.cpp>
+  +<../examples/companion_radio/ui-new/*.cpp>
+lib_deps =
+  ${ThinkNode_M6.lib_deps}
+  densaugeo/base64 @ ~1.4.0
+  end2endzone/NonBlockingRTTTL@^1.3.0
+
+[env:ThinkNode_M6_companion_radio_usb]
+extends = ThinkNode_M6
+board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
+board_upload.maximum_size = 712704
+build_flags =
+  ${ThinkNode_M6.build_flags}
+  -I src/helpers/ui
+  -I examples/companion_radio/ui-new
+  -D MAX_CONTACTS=350
+  -D MAX_GROUP_CHANNELS=40
+  -D QSPIFLASH=1
+  -D OFFLINE_QUEUE_SIZE=256
+  -D AUTO_SHUTDOWN_MILLIVOLTS=3300
+build_src_filter = ${ThinkNode_M6.build_src_filter}
+  +<helpers/ui/buzzer.cpp>
+  +<helpers/ui/MomentaryButton.cpp>
+  +<../examples/companion_radio/*.cpp>
+  +<../examples/companion_radio/ui-new/*.cpp>
+lib_deps =
+  ${ThinkNode_M6.lib_deps}
+  densaugeo/base64 @ ~1.4.0
+  end2endzone/NonBlockingRTTTL@^1.3.0

+ 49 - 0
variants/thinknode_m6/target.cpp

@@ -0,0 +1,49 @@
+#include <Arduino.h>
+#include "target.h"
+#include <helpers/ArduinoHelpers.h>
+#include <helpers/sensors/MicroNMEALocationProvider.h>
+
+ThinkNodeM6Board 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);
+#ifdef ENV_INCLUDE_GPS
+MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
+EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
+#else
+EnvironmentSensorManager sensors = EnvironmentSensorManager();
+#endif
+
+#ifdef DISPLAY_CLASS
+  DISPLAY_CLASS display;
+  MomentaryButton user_btn(PIN_USER_BTN, 1000, true);
+#endif
+
+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
+}

+ 31 - 0
variants/thinknode_m6/target.h

@@ -0,0 +1,31 @@
+#pragma once
+
+#define RADIOLIB_STATIC_ONLY 1
+#include <RadioLib.h>
+#include <helpers/radiolib/RadioLibWrappers.h>
+#include <ThinkNodeM6Board.h>
+#include <helpers/radiolib/CustomSX1262Wrapper.h>
+#include <helpers/AutoDiscoverRTCClock.h>
+#include <helpers/SensorManager.h>
+#include <helpers/sensors/EnvironmentSensorManager.h>
+#include <helpers/sensors/LocationProvider.h>
+#ifdef DISPLAY_CLASS
+  #include <helpers/ui/GxEPDDisplay.h>
+  #include <helpers/ui/MomentaryButton.h>
+#endif
+
+extern ThinkNodeM6Board 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();

+ 35 - 0
variants/thinknode_m6/variant.cpp

@@ -0,0 +1,35 @@
+#include "variant.h"
+#include "wiring_constants.h"
+#include "wiring_digital.h"
+
+const uint32_t g_ADigitalPinMap[] = {
+  0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
+  14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+  27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
+  40, 41, 42, 43, 44, 45, 46, 47
+};
+
+void initVariant() {
+  pinMode(PIN_PWR_EN, OUTPUT);
+  digitalWrite(PIN_PWR_EN, HIGH);
+
+  pinMode(QSPI_FLASH_EN, OUTPUT);
+  digitalWrite(QSPI_FLASH_EN, HIGH);
+
+  // For now stick adc_ctrl to fixed value
+  pinMode(PIN_ADC_CTRL, OUTPUT);
+  digitalWrite(PIN_ADC_CTRL, LOW);
+
+  pinMode(PIN_LED_RED, OUTPUT);
+  pinMode(PIN_LED_BLUE, OUTPUT);
+  digitalWrite(PIN_LED_BLUE, LOW);
+  digitalWrite(PIN_LED_RED, LOW);
+
+  // gps
+  pinMode(PIN_GPS_STANDBY, OUTPUT);
+  digitalWrite(PIN_GPS_STANDBY, HIGH);
+  pinMode(PIN_GPS_EN, OUTPUT);
+  digitalWrite(PIN_GPS_EN, HIGH);
+  pinMode(PIN_GPS_RESET, OUTPUT);
+  digitalWrite(PIN_GPS_RESET, HIGH);
+}

+ 108 - 0
variants/thinknode_m6/variant.h

@@ -0,0 +1,108 @@
+/*
+ * variant.h
+ * Copyright (C) 2023 Seeed K.K.
+ * MIT License
+ */
+
+#pragma once
+
+#include "WVariant.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// Low frequency clock source
+
+#define USE_LFXO    // 32.768 kHz crystal oscillator
+#define VARIANT_MCK (64000000ul)
+
+#define WIRE_INTERFACES_COUNT   (1)
+////////////////////////////////////////////////////////////////////////////////
+// Power
+
+#define PIN_PWR_EN              (27)
+
+#define BATTERY_PIN             (28)
+#define ADC_MULTIPLIER          (1.75F)
+#define PIN_ADC_CTRL            (11)
+
+#define ADC_RESOLUTION          (12)
+#define BATTERY_SENSE_RES       (12)
+
+#define AREF_VOLTAGE            (3.0)
+
+////////////////////////////////////////////////////////////////////////////////
+// Number of pins
+
+#define PINS_COUNT              (48)
+#define NUM_DIGITAL_PINS        (48)
+#define NUM_ANALOG_INPUTS       (1)
+#define NUM_ANALOG_OUTPUTS      (0)
+
+////////////////////////////////////////////////////////////////////////////////
+// UART pin definition
+
+#define PIN_SERIAL1_RX          PIN_GPS_TX
+#define PIN_SERIAL1_TX          PIN_GPS_RX
+
+#define PIN_SERIAL2_RX          (22)
+#define PIN_SERIAL2_TX          (24)
+
+////////////////////////////////////////////////////////////////////////////////
+// I2C pin definition
+
+#define PIN_WIRE_SDA            (41)             // P1.9
+#define PIN_WIRE_SCL            (8)             // P0.8
+
+////////////////////////////////////////////////////////////////////////////////
+// SPI pin definition
+
+#define SPI_INTERFACES_COUNT    (1)
+
+#define PIN_SPI_MISO            (47)
+#define PIN_SPI_MOSI            (46)
+#define PIN_SPI_SCK             (45)
+//#define PIN_SPI_NSS             (24)
+
+////////////////////////////////////////////////////////////////////////////////
+// Builtin LEDs
+
+#define PIN_LED_RED             (12)
+#define PIN_LED_BLUE            (7)
+#define LED_BLUE                (-1)
+
+#define LED_BUILTIN             PIN_LED_BLUE
+#define PIN_LED                 LED_BUILTIN
+#define LED_PIN                 LED_BUILTIN
+#define LED_STATE_ON            HIGH
+
+////////////////////////////////////////////////////////////////////////////////
+// Builtin buttons
+
+#define PIN_BUTTON1             (17)
+#define BUTTON_PIN              PIN_BUTTON1
+#define PIN_USER_BTN            BUTTON_PIN
+
+////////////////////////////////////////////////////////////////////////////////
+// QSPI
+
+#define EXTERNAL_FLASH_DEVICES MX25R1635F
+#define EXTERNAL_FLASH_USE_QSPI
+
+#define PIN_QSPI_SCK (35)
+#define PIN_QSPI_CS  (23)
+#define PIN_QSPI_IO0 (33)  // MOSI if using two bit interface
+#define PIN_QSPI_IO1 (34)  // MISO if using two bit interface
+#define PIN_QSPI_IO2 (36)  // WP if using two bit interface (i.e. not used)
+#define PIN_QSPI_IO3 (37)  // HOLD if using two bit interface (i.e. not used)
+#define QSPI_FLASH_EN (21)
+
+////////////////////////////////////////////////////////////////////////////////
+// GPS
+
+#define GPS_L76K
+#define PIN_GPS_RX              (2)
+#define PIN_GPS_TX              (3)
+#define PIN_GPS_EN              (6)    // EN
+#define PIN_GPS_RESET           (29)
+#define PIN_GPS_STANDBY         (30)   // STANDBY
+#define PIN_GPS_PPS             (31)
+#define GPS_BAUD_RATE           9600