Add BHI260AP sensor hub with deferred init

BHI260AP firmware upload (~260KB at 1MHz I2C) takes ~10 seconds and
blocks the main loop. Moved init from setup() to a deferred check in
the main loop that runs once after 5 seconds when hw_ready is true.
This allows the radio and serial to come up immediately while the
sensor firmware uploads in the background.

Also restores XL9555 DRV_EN and DISP_EN enables at boot (lost during
earlier git checkout/stash operations).
This commit is contained in:
GlassOnTin 2026-03-27 18:03:33 +00:00
commit 84c7b886c4

View file

@ -21,6 +21,13 @@
#include "XL9555.h"
#include "CO5300.h"
#include "DRV2605.h"
// BHI260AP sensor hub — IMU + GPIO expansion
#include <SensorBHI260AP.hpp>
#define BOSCH_BHI260_GPIO
#include <BoschFirmware.h>
SensorBHI260AP *bhi260 = NULL;
bool bhi260_ready = false;
#endif
#define CHANNEL_FIFO_SIZE (CONFIG_UART_BUFFER_SIZE / NUM_CHANNELS)
@ -281,6 +288,10 @@ void setup() {
drv2605_init();
if (drv2605_ready) drv2605_play(HAPTIC_SHARP_CLICK); // Boot feedback
// BHI260AP init deferred — firmware upload takes ~10s at 1MHz I2C
// and blocks serial communication during boot. Will be initialized
// lazily from the main loop after radio is up.
// Beacon timer wakeup: if we woke from deep sleep via timer,
// take the fast path — init GPS/LoRa only, transmit, sleep again.
// esp_reset_reason() reliably distinguishes deep sleep from cold boot.
@ -1986,6 +1997,23 @@ void loop() {
input_read();
#endif
// Deferred BHI260AP init — runs once after boot is complete
// Firmware upload takes ~10s and blocks, so we do it after radio is up
#if BOARD_MODEL == BOARD_TWATCH_ULT
if (!bhi260_ready && bhi260 == NULL && hw_ready && millis() > 5000) {
Wire.setClock(1000000UL);
bhi260 = new SensorBHI260AP();
bhi260->setPins(-1);
bhi260->setFirmware(bosch_firmware_image, bosch_firmware_size, false);
bhi260->setBootFromFlash(false);
if (bhi260->begin(Wire, 0x28, I2C_SDA, I2C_SCL)) {
bhi260_ready = true;
pinMode(SENSOR_INT, INPUT);
}
Wire.setClock(400000UL);
}
#endif
if (memory_low) {
#if PLATFORM == PLATFORM_ESP32
if (esp_get_free_heap_size() < 8192) {