Przeglądaj źródła

variants: Thinknode M3/M6: Use common Nrf52Board class

Signed-off-by: Frieder Schrempf <frieder@fris.de>
Frieder Schrempf 7 miesięcy temu
rodzic
commit
578d55b28a

+ 2 - 68
variants/thinknode_m3/ThinknodeM3Board.cpp

@@ -5,76 +5,10 @@
 #include <bluefruit.h>
 
 void ThinknodeM3Board::begin() {
-  // for future use, sub-classes SHOULD call this from their begin()
-  startup_reason = BD_STARTUP_NORMAL;
+  Nrf52BoardDCDC::begin();
   btn_prev_state = HIGH;
 
-  sd_power_mode_set(NRF_POWER_MODE_LOWPWR);
-
-  // Enable DC/DC converter for improved power efficiency
-  NRF_POWER->DCDCEN = 1;
-
   Wire.begin();
 
   delay(10);   // give sx1262 some time to power up
-}
-
-#if 0
-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");
-}
-
-
-bool TrackerThinknodeM3Board::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("T1000E_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
+}

+ 8 - 18
variants/thinknode_m3/ThinknodeM3Board.h

@@ -1,13 +1,13 @@
 #pragma once
 
-#include <MeshCore.h>
 #include <Arduino.h>
+#include <MeshCore.h>
+#include <helpers/NRF52Board.h>
 
 #define ADC_FACTOR ((1000.0*ADC_MULTIPLIER*AREF_VOLTAGE)/ADC_MAX)
 
-class ThinknodeM3Board : public mesh::MainBoard {
+class ThinknodeM3Board : public Nrf52BoardDCDC {
 protected:
-  uint8_t startup_reason;
   uint8_t btn_prev_state;
 
 public:
@@ -27,12 +27,10 @@ public:
     return (uint16_t)((float)adcvalue * ADC_FACTOR);
   }
 
-  uint8_t getStartupReason() const override { return startup_reason; }
-
-  #if defined(P_LORA_TX_LED)
-  #if !defined(P_LORA_TX_LED_ON)
-    #define P_LORA_TX_LED_ON HIGH
-  #endif
+#if defined(P_LORA_TX_LED)
+#if !defined(P_LORA_TX_LED_ON)
+#define P_LORA_TX_LED_ON HIGH
+#endif
   void onBeforeTransmit() override {
     digitalWrite(P_LORA_TX_LED, P_LORA_TX_LED_ON);   // turn TX LED on
   }
@@ -56,13 +54,5 @@ public:
     return 0;
   }
 
-  void powerOff() override {
-    sd_power_system_off();
-  }
-
-  void reboot() override {
-    NVIC_SystemReset();
-  }
-
-//  bool startOTAUpdate(const char* id, char reply[]) override;
+  void powerOff() override { sd_power_system_off(); }
 };

+ 1 - 60
variants/thinknode_m6/ThinkNodeM6Board.cpp

@@ -4,25 +4,9 @@
 #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;
+  NRF52Board::begin();
 
   Wire.begin();
 
@@ -49,47 +33,4 @@ uint16_t ThinkNodeM6Board::getBattMilliVolts() {
   // 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

+ 5 - 17
variants/thinknode_m6/ThinkNodeM6Board.h

@@ -1,7 +1,8 @@
 #pragma once
 
-#include <MeshCore.h>
 #include <Arduino.h>
+#include <MeshCore.h>
+#include <helpers/NRF52Board.h>
 
 // built-ins
 #define VBAT_MV_PER_LSB   (0.73242188F)   // 3.0V ADC range and 12-bit ADC resolution = 3000mV/4096
@@ -11,21 +12,13 @@
 #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;
-
+class ThinkNodeM6Board : public Nrf52BoardOTA {
 public:
-
+  ThinkNodeM6Board() : NRF52BoardOTA("THINKNODE_M1_OTA") {}
   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)
+#if defined(P_LORA_TX_LED)
   void onBeforeTransmit() override {
     digitalWrite(P_LORA_TX_LED, HIGH);   // turn TX LED on
   }
@@ -38,10 +31,6 @@ public:
     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
@@ -51,6 +40,5 @@ public:
 
     // power off board
     sd_power_system_off();
-
   }
 };