The SX1262's NSS, RESET, BUSY and DIO1 sit on the TCA9535 (P0.0..P0.3) while SCK/MISO/MOSI are real GPIOs. IndicatorRadioHal derives from ArduinoHal, keeps hardware FSPI at 4 MHz and maps the virtual pins 0x40..0x43 onto expander transfers; every other pin goes straight to the Arduino pin and interrupt functions, as ArduinoHal does. The meshcomod core is used as is: CustomSX1262 and its wrapper run unchanged on top of the HAL. DIO1 has no GPIO edge. The expander's open-drain /INT on GPIO42 has an IRAM ISR that only notifies a dispatch task, because the read needs I2C and the bus mutex. That task reads both input bytes under the bus lock: the TCA9535 releases /INT only when the port that changed is read, and several port-1 inputs float, so a port-0-only read could leave GPIO42 low for good. Every port-0 byte feeds a small edge detector (Dio1Edge) through the expander's port-0 observer, which calls the callback RadioLib attached to DIO1 once per rise. That callback is the core's setFlag, so TX-done and RX-done reach the core exactly as they would from a DIO1 interrupt. A BUSY poll is a port-0 read as well, and it clears /INT. Sampling DIO1 in those reads means a rise that lands while RadioLib waits on BUSY fires the callback from that read instead of being lost; the dispatch task's next read sees the level already high and does not fire again. The task also re-reads every 50 ms, so a rise whose /INT was missed still fires the callback, at most 50 ms late. MESH_RADIO_DIO1_POLLED is not set: polling the IRQ register would add an SPI transfer, and with it expander writes for NSS, on every pass of the receive path. Floating port-1 inputs can keep /INT toggling, each toggle an I2C read at high priority. The task counts ISR wakes and timeouts and logs them for each of the first six 10 s windows, then only above 500 wakes/s and at most once a minute, so the idle wake rate is visible at bring-up without flooding the console later. TCXO or crystal comes from the radio strap read at boot: the env's SX126X_DIO3_TCXO_VOLTAGE calls indicatorTcxoVoltage(), which returns 2.4 V for the TCXO radio and 0 for the crystal one. radio_init() starts the radio with the strap's setting and, if that fails, with the other one, because std_init only falls back from TCXO to 0 V and a TCXO board whose strap misread as crystal would never start otherwise. main.cpp's one retry runs both again. The log says which voltage was requested and which one the radio came up with. The board reports GPIO42 (indicator::kExpanderIntGpio, shared with the HAL) as its IRQ line and never light-sleeps: the inherited ESP32Board versions would treat the virtual DIO1 pin as a GPIO, and /INT is active low while the light-sleep wake source is high-level. test_indicator_dio1 covers the virtual-pin routing and the once-per-rise rule across dispatch and BUSY reads; run-host-tests.sh gets its include path. Signed-off-by: Confituurke <9595028+Confituurke@users.noreply.github.com>
89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
// Host test for the SenseCAP Indicator DIO1 edge detector (IndicatorDio1.h): the
|
|
// virtual-pin routing and the rule that every read of expander port 0 -- the
|
|
// dispatch task's and the BUSY polls' alike -- fires the radio callback exactly
|
|
// once per DIO1 rise.
|
|
//
|
|
// c++ -std=c++17 -Wall -Wextra -I src -I variants/sensecap_indicator test/test_indicator_dio1.cpp -o /tmp/ind_dio1 && /tmp/ind_dio1
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
|
|
#include "IndicatorDio1.h"
|
|
|
|
using namespace indicator;
|
|
|
|
static int s_calls = 0;
|
|
static void onDio1() { ++s_calls; }
|
|
|
|
static void virtual_pin_routing() {
|
|
static_assert(kExpanderPinFlag == 0x40, "virtual pin flag");
|
|
assert(isExpanderPin(0x43));
|
|
assert(isExpanderPin(0x40));
|
|
assert(!isExpanderPin(41));
|
|
assert(!isExpanderPin(0));
|
|
assert(expanderBit(0x43) == 3);
|
|
assert(expanderBit(0x40) == pins::kLoraNss);
|
|
}
|
|
|
|
static void rising_edge_fires_once() {
|
|
s_calls = 0;
|
|
Dio1Edge edge;
|
|
edge.arm(onDio1);
|
|
assert(edge.armed());
|
|
assert(!edge.onPort0(0x00));
|
|
assert(edge.onPort0(0x08));
|
|
assert(s_calls == 1);
|
|
assert(!edge.onPort0(0x08));
|
|
assert(s_calls == 1);
|
|
}
|
|
|
|
static void edge_seen_in_busy_read_fires_once() {
|
|
s_calls = 0;
|
|
Dio1Edge edge;
|
|
edge.arm(onDio1);
|
|
assert(!edge.onPort0(0x04)); // BUSY high, DIO1 low
|
|
assert(edge.onPort0(0x08)); // the HAL's BUSY poll sees DIO1 rise
|
|
assert(!edge.onPort0(0x08)); // the dispatch task's read that follows
|
|
assert(s_calls == 1);
|
|
}
|
|
|
|
static void level_high_without_edge_does_not_refire() {
|
|
s_calls = 0;
|
|
Dio1Edge edge;
|
|
edge.arm(onDio1);
|
|
assert(edge.onPort0(0x08));
|
|
assert(!edge.onPort0(0x48)); // touch INT changed, DIO1 still high
|
|
assert(!edge.onPort0(0x4C)); // BUSY toggles too
|
|
assert(s_calls == 1);
|
|
}
|
|
|
|
static void no_callback_while_disarmed() {
|
|
s_calls = 0;
|
|
Dio1Edge edge;
|
|
edge.disarm();
|
|
assert(!edge.armed());
|
|
assert(!edge.onPort0(0x00));
|
|
assert(!edge.onPort0(0x08));
|
|
assert(s_calls == 0);
|
|
|
|
edge.arm(onDio1); // DIO1 is high now: no phantom edge on re-arm
|
|
assert(!edge.onPort0(0x08));
|
|
assert(s_calls == 0);
|
|
|
|
assert(!edge.onPort0(0x00));
|
|
assert(edge.onPort0(0x08));
|
|
assert(s_calls == 1);
|
|
}
|
|
|
|
int main() {
|
|
virtual_pin_routing();
|
|
rising_edge_fires_once();
|
|
edge_seen_in_busy_read_fires_once();
|
|
level_high_without_edge_does_not_refire();
|
|
no_callback_while_disarmed();
|
|
printf("all indicator dio1 tests passed\n");
|
|
return 0;
|
|
}
|