Forráskód Böngészése

support building on BlueMark C3 board

Andrew Tridgell 3 éve
szülő
commit
e8b19e96ad

+ 1 - 1
.github/workflows/test_build.yml

@@ -34,7 +34,7 @@ jobs:
         id: check_files
         uses: andstor/file-existence-action@v1
         with:
-          files: "RemoteIDModule/build/esp32.esp32.esp32s3/ArduRemoteID.bin"
+          files: "RemoteIDModule/ArduRemoteID-ESP32S3_DEV.bin, RemoteIDModule/ArduRemoteID-BLUEMARK_DB200.bin, RemoteIDModule/ArduRemoteID-BLUEMARK_DB110.bin"
           allow_failure: true
 
       - name: Archive build

+ 2 - 2
RemoteIDModule/BLE_TX.cpp

@@ -95,7 +95,7 @@ bool BLE_TX::init(void)
     return true;
 }
 
-#define MIN(a,b) ((a)<(b)?(a):(b))
+#define IMIN(a,b) ((a)<(b)?(a):(b))
 
 bool BLE_TX::transmit(ODID_UAS_Data &UAS_data)
 {
@@ -116,7 +116,7 @@ bool BLE_TX::transmit(ODID_UAS_Data &UAS_data)
     char legacy_name[28] {};
     const char *UAS_ID = (const char *)UAS_data.BasicID[0].UASID;
     const uint8_t ID_len = strlen(UAS_ID);
-    const uint8_t ID_tail = MIN(4, ID_len);
+    const uint8_t ID_tail = IMIN(4, ID_len);
     snprintf(legacy_name, sizeof(legacy_name), "DroneBeacon_%s", &UAS_ID[ID_len-ID_tail]);
 
     memset(legacy_payload, 0, sizeof(legacy_payload));

+ 8 - 4
RemoteIDModule/CANDriver.cpp

@@ -2,9 +2,12 @@
   CAN driver class for ESP32
  */
 #include <Arduino.h>
+#include "options.h"
+
+#if AP_DRONECAN_ENABLED
+
 #include "CANDriver.h"
 
-#include <xtensa/hal.h>
 #include <freertos/FreeRTOS.h>
 #include "freertos/task.h"
 #include "freertos/queue.h"
@@ -12,6 +15,7 @@
 #include "esp_err.h"
 #include "esp_log.h"
 #include "driver/twai.h"
+#include "board_config.h"
 
 #define CAN1_TX_IRQ_Handler      ESP32_CAN1_TX_HANDLER
 #define CAN1_RX0_IRQ_Handler     ESP32_CAN1_RX0_HANDLER
@@ -34,9 +38,7 @@ void CANDriver::init(uint32_t bitrate)
     init_bus(bitrate);
 }
 
-#define TX_GPIO_NUM           GPIO_NUM_47
-#define RX_GPIO_NUM           GPIO_NUM_38
-static const twai_general_config_t g_config =                      {.mode = TWAI_MODE_NORMAL, .tx_io = TX_GPIO_NUM, .rx_io = RX_GPIO_NUM,        \
+static const twai_general_config_t g_config =                      {.mode = TWAI_MODE_NORMAL, .tx_io = PIN_CAN_TX, .rx_io = PIN_CAN_RX, \
                                                                     .clkout_io = TWAI_IO_UNUSED, .bus_off_io = TWAI_IO_UNUSED,      \
                                                                     .tx_queue_len = 5, .rx_queue_len = 5,                           \
                                                                     .alerts_enabled = TWAI_ALERT_NONE,  .clkout_divider = 0,        \
@@ -247,3 +249,5 @@ bool CANDriver::receive(CANFrame &out_frame)
     }
     return true;
 }
+
+#endif // AP_DRONECAN_ENABLED

+ 24 - 12
RemoteIDModule/Makefile

@@ -4,28 +4,39 @@ ARDUINO_HOME=$(HOME)/.arduino15
 ESP32_VER=2.0.3
 ESP32_TOOLS=$(ARDUINO_HOME)/packages/esp32/hardware/esp32/$(ESP32_VER)/tools
 ESPTOOL=$(ESP32_TOOLS)/esptool.py
-CHIP=esp32s3
+
+#CHIP=esp32s3
+#BOARD=ESP32S3_DEV
+
 ESP32_FQBN=esp32:esp32:$(CHIP)
-BUILD_DIR=esp32.esp32.$(CHIP)
 SERDEV := $(wildcard /dev/serial/by-id/usb-Espressif_*)
 ARDUINO_CLI=../bin/arduino-cli
 
+all: esp32s3dev bluemark-db200 bluemark-db110
 
-all: build/$(BUILD_DIR)/ArduRemoteID.bin
+esp32s3dev: CHIP=esp32s3
+esp32s3dev: ArduRemoteID-ESP32S3_DEV.bin
 
-build/$(BUILD_DIR)/ArduRemoteID.bin: build/$(BUILD_DIR)/RemoteIDModule.ino.bin
-	@echo "Merging $@"
-	@python3 $(ESPTOOL) --chip $(CHIP) merge_bin -o $@ --flash_size 4MB 0xe000 $(ESP32_TOOLS)/partitions/boot_app0.bin 0x0 build/$(BUILD_DIR)/RemoteIDModule.ino.bootloader.bin 0x10000 build/$(BUILD_DIR)/RemoteIDModule.ino.bin 0x8000 build/$(BUILD_DIR)/RemoteIDModule.ino.partitions.bin
+bluemark-db200: CHIP=esp32c3
+bluemark-db200: ArduRemoteID-BLUEMARK_DB200.bin
+
+bluemark-db110: CHIP=esp32c3
+bluemark-db110: ArduRemoteID-BLUEMARK_DB110.bin
 
 setup:
 	@echo "Installing ESP32 support"
 	$(ARDUINO_CLI) core update-index --config-file arduino-cli.yaml
 	$(ARDUINO_CLI) core install esp32:esp32@$(ESP32_VER)
 
-build/$(BUILD_DIR)/RemoteIDModule.ino.bin: *.cpp *.ino *.h
-	@echo "Building $@"
+ArduRemoteID-%.bin: *.cpp *.ino *.h
+	@echo "Building $* on $(CHIP)"
+	@BUILD_FLAGS="-DBOARD_$*"
 	@../scripts/git-version.sh
-	@$(ARDUINO_CLI) compile --export-binaries --fqbn $(ESP32_FQBN) .
+	@rm -rf build
+	@$(ARDUINO_CLI) compile -b esp32:esp32:$(CHIP) --export-binaries --build-property build.extra_flags=-DBOARD_$* .
+	@echo "Merging $*"
+	@python3 $(ESPTOOL) --chip $(CHIP) merge_bin -o ArduRemoteID-$*.bin --flash_size 4MB 0xe000 $(ESP32_TOOLS)/partitions/boot_app0.bin 0x0 build/esp32.esp32.$(CHIP)/RemoteIDModule.ino.bootloader.bin 0x10000 build/esp32.esp32.$(CHIP)/RemoteIDModule.ino.bin 0x8000 build/esp32.esp32.$(CHIP)/RemoteIDModule.ino.partitions.bin
+	@rm -rf build
 
 boards:
 	@echo "Listing boards"
@@ -34,9 +45,10 @@ boards:
 checkdev:
 	@[ "${SERDEV}" ] && echo "Using device $(SERDEV)" || ( echo "Failed to find serial device"; exit 1 )
 
-upload: checkdev build/$(BUILD_DIR)/ArduRemoteID.bin
-	@echo "Flashing"
+upload: checkdev
+	@echo "Flashing ArduRemoteID-ESP32S3_DEV.bin"
 	@$(ARDUINO_CLI) upload -p $(SERDEV) --fqbn $(ESP32_FQBN) .
 
 clean:
-	rm -rf ..esp32* *.bin build
+	rm -rf ..esp32* *.bin build*
+

+ 5 - 10
RemoteIDModule/RemoteIDModule.ino

@@ -11,7 +11,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <opendroneid.h>
-
+#include "board_config.h"
 #include "options.h"
 #include "mavlink.h"
 #include "DroneCAN.h"
@@ -37,11 +37,6 @@ static BLE_TX ble;
 
 #define OUTPUT_RATE_HZ 5
 
-/*
-  assume ESP32-s3 for now, using pins 17 and 18 for uart
- */
-#define RX_PIN 17
-#define TX_PIN 18
 #define DEBUG_BAUDRATE 57600
 #define MAVLINK_BAUDRATE 57600
 
@@ -61,7 +56,7 @@ void setup()
                   FW_VERSION_MAJOR, FW_VERSION_MINOR, GIT_VERSION);
 
     // Serial1 for MAVLink
-    Serial1.begin(MAVLINK_BAUDRATE, SERIAL_8N1, RX_PIN, TX_PIN);
+    Serial1.begin(MAVLINK_BAUDRATE, SERIAL_8N1, PIN_UART_RX, PIN_UART_TX);
 
     // set all fields to invalid/initial values
     odid_initUasData(&UAS_data);
@@ -81,8 +76,8 @@ void setup()
 #endif
 }
 
-#define MIN(x,y) ((x)<(y)?(x):(y))
-#define ODID_COPY_STR(to, from) strncpy(to, (const char*)from, MIN(sizeof(to), sizeof(from)))
+#define IMIN(x,y) ((x)<(y)?(x):(y))
+#define ODID_COPY_STR(to, from) strncpy(to, (const char*)from, IMIN(sizeof(to), sizeof(from)))
 
 /*
   check parsing of UAS_data, this checks ranges of values to ensure we
@@ -196,7 +191,7 @@ static void set_data_mavlink(MAVLinkSerial &m)
 }
 
 #undef ODID_COPY_STR
-#define ODID_COPY_STR(to, from) memcpy(to, from.data, MIN(from.len, sizeof(to)))
+#define ODID_COPY_STR(to, from) memcpy(to, from.data, IMIN(from.len, sizeof(to)))
 
 #if AP_DRONECAN_ENABLED
 static void set_data_dronecan(void)

+ 27 - 0
RemoteIDModule/board_config.h

@@ -0,0 +1,27 @@
+/*
+  board configuration file
+ */
+
+#pragma once
+
+#ifdef BOARD_ESP32S3_DEV
+#define PIN_CAN_TX GPIO_NUM_47
+#define PIN_CAN_RX GPIO_NUM_38
+
+#define PIN_UART_TX 18
+#define PIN_UART_RX 17
+
+#elif defined(BOARD_BLUEMARK_DB200)
+#define PIN_CAN_TX GPIO_NUM_4
+#define PIN_CAN_RX GPIO_NUM_18
+
+#define PIN_UART_TX 15
+#define PIN_UART_RX 16
+
+#elif defined(BOARD_BLUEMARK_DB110)
+#define PIN_UART_TX 5
+#define PIN_UART_RX 4
+
+#else
+#error "unsupported board"
+#endif

+ 4 - 1
RemoteIDModule/options.h

@@ -1,6 +1,9 @@
 /*
   control optional behaviour in the firmware at build time
  */
+#pragma once
+
+#include "board_config.h"
 
 // enable WiFi NAN support
 #define AP_WIFI_NAN_ENABLED 1
@@ -13,7 +16,7 @@
 #define AP_BROADCAST_ON_POWER_UP 1
 
 // do we support DroneCAN connnection to flight controller?
-#define AP_DRONECAN_ENABLED 1
+#define AP_DRONECAN_ENABLED defined(PIN_CAN_TX) && defined(PIN_CAN_RX)
 
 // do we support MAVLink connnection to flight controller?
 #define AP_MAVLINK_ENABLED 1