Add BLE host transport selectable via DIP8 alongside UART.

Master can speak the same framed protobuf protocol over NimBLE or UART; goTool gains -ble, ble-rtt, and ble-stream timing checks for ESP-NOW coexistence.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-23 16:11:10 +02:00
co-authored by Cursor
parent d7441cb85f
commit 92a13d7fd0
28 changed files with 2306 additions and 250 deletions
+28 -7
View File
@@ -32,8 +32,10 @@
#include "led_ring.h"
#include "pod_settings.h"
#include "uart.h"
#include "ble_host.h"
#include "battery_uv.h"
#include <stdint.h>
#include <string.h>
enum MASTER_STATES {
MSTATE_INIT,
@@ -94,7 +96,8 @@ void app_main(void) {
gpio_reset_pin(DIP_MASTER);
gpio_set_direction(DIP_MASTER, GPIO_MODE_INPUT);
uint8_t master = gpio_get_level(DIP_MASTER) ? 0 : 1;
uint8_t network = 0;
uint8_t network = 1;
bool host_ble = false;
esp_err_t err;
@@ -137,12 +140,20 @@ void app_main(void) {
-1);
if (err != ESP_OK) {
ESP_LOGI(TAG, "Could not read IO Expander input %d", err);
} else {
/* High nibble physically reversed on PCB; DIP1..8 after reverse+invert. */
uint8_t bits = (uint8_t)(~reverse_high_nibble_lut(read_val));
/* DIP8 (bit7) = host transport: 1 = BLE, 0 = UART */
host_ble = (bits & 0x80u) != 0;
uint8_t net_bits = (uint8_t)(bits & 0x7Fu);
if (net_bits == 0 || (net_bits & (net_bits - 1u)) != 0) {
ESP_LOGW(TAG, "invalid network DIP one-hot=0x%02x; fallback network=1",
net_bits);
network = 1;
} else {
network = (uint8_t)(__builtin_ctz(net_bits) + 1); /* 1..7 */
}
}
// Build NetworkNumber because Pin 5-8 are reversed
network = reverse_high_nibble_lut(read_val);
network = ~network; // reverse bits
network = __builtin_ctz(network) +
1; // map network to 0-8, 0 is not a valid network
}
if (bus_handle != NULL) {
@@ -167,6 +178,7 @@ void app_main(void) {
app_config.master = (master != 0);
app_config.network = network;
app_config.host_ble = host_ble;
if (running != NULL) {
memcpy(app_config.running_partition, running->label,
sizeof(app_config.running_partition));
@@ -177,6 +189,8 @@ void app_main(void) {
ESP_LOGI(TAG, "RUNNING CONFIG:");
ESP_LOGI(TAG, "Master: %d", app_config.master);
ESP_LOGI(TAG, "Network: %d", app_config.network);
ESP_LOGI(TAG, "Host: %s (DIP8; reboot to switch)",
app_config.host_ble ? "BLE" : "UART");
ESP_LOGI(TAG, "Running Partition: %s (OTA slot %d)",
app_config.running_partition, ota_slot);
@@ -193,7 +207,14 @@ void app_main(void) {
if (app_config.master) {
cmd_queue = xQueueCreate(64, sizeof(generic_msg_t));
init_cmdHandler(cmd_queue);
init_uart(cmd_queue);
if (app_config.host_ble) {
err = init_ble_host(cmd_queue);
if (err != ESP_OK) {
ESP_LOGE(TAG, "BLE host init failed: %s", esp_err_to_name(err));
}
} else {
init_uart(cmd_queue);
}
cmd_version_register();
cmd_client_info_register();
cmd_accel_deadzone_register();