Преглед на файлове

add CAN_TERMINATE for software driven termination

cuav-chen2 преди 1 година
родител
ревизия
da88cc20f2
променени са 4 файла, в които са добавени 20 реда и са изтрити 1 реда
  1. 10 1
      RemoteIDModule/RemoteIDModule.ino
  2. 3 0
      RemoteIDModule/board_config.h
  3. 3 0
      RemoteIDModule/parameters.cpp
  4. 4 0
      RemoteIDModule/parameters.h

+ 10 - 1
RemoteIDModule/RemoteIDModule.ino

@@ -104,9 +104,18 @@ void setup()
 #endif
 
 #if defined(PIN_CAN_TERM)
+#if !defined(CAN_TERM_EN)
+#define CAN_TERM_EN HIGH
+#endif
+
     // optional CAN termination control
     pinMode(PIN_CAN_TERM, OUTPUT);
-    digitalWrite(PIN_CAN_TERM, HIGH);
+
+    if (g.can_term == 1) {
+        digitalWrite(PIN_CAN_TERM, CAN_TERM_EN);
+    } else {
+        digitalWrite(PIN_CAN_TERM, !CAN_TERM_EN);
+    }
 #endif
 
 #if defined(BUZZER_PIN)

+ 3 - 0
RemoteIDModule/board_config.h

@@ -160,6 +160,9 @@
 
 #define WS2812_LED_PIN GPIO_NUM_48
 
+#define PIN_CAN_TERM GPIO_NUM_37
+#define CAN_TERM_EN  LOW
+
 #else
 #error "unsupported board"
 #endif

+ 3 - 0
RemoteIDModule/parameters.cpp

@@ -12,6 +12,9 @@ static nvs_handle handle;
 const Parameters::Param Parameters::params[] = {
     { "LOCK_LEVEL",        Parameters::ParamType::INT8,  (const void*)&g.lock_level,       0, -1, 2 },
     { "CAN_NODE",          Parameters::ParamType::UINT8,  (const void*)&g.can_node,         0, 0, 127 },
+#if defined(PIN_CAN_TERM)
+    { "CAN_TERMINATE",     Parameters::ParamType::UINT8,  (const void*)&g.can_term,        0, 0, 1 },
+#endif
     { "UAS_TYPE",          Parameters::ParamType::UINT8,  (const void*)&g.ua_type,          0, 0, 15 },
     { "UAS_ID_TYPE",       Parameters::ParamType::UINT8,  (const void*)&g.id_type,          0, 0, 4 },
     { "UAS_ID",            Parameters::ParamType::CHAR20, (const void*)&g.uas_id[0],        0, 0, 0 },

+ 4 - 0
RemoteIDModule/parameters.h

@@ -1,6 +1,7 @@
 #pragma once
 
 #include <stdint.h>
+#include "board_config.h"
 
 #define MAX_PUBLIC_KEYS 5
 #define PUBLIC_KEY_LEN 32
@@ -12,6 +13,9 @@
 
 class Parameters {
 public:
+#if defined(PIN_CAN_TERM)
+    uint8_t can_term = !CAN_TERM_EN;
+#endif
     int8_t lock_level;
     uint8_t can_node;
     uint8_t bcast_powerup;