Move the onboard radio probe into RAK3401Board::begin() so a low-voltage SYSTEMOFF at boot no longer leaves the RAK4631's onboard SX1262 in standby. Add board startup tests and run them in CI.
38 lines
1.1 KiB
C++
38 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <string.h>
|
|
|
|
namespace rak3401 {
|
|
|
|
enum class OnboardRadioState { Absent, Asleep, BusyTimeout, SleepFailed };
|
|
|
|
// Board startup only, before the primary radio starts SPI.
|
|
OnboardRadioState sleepOnboardRadio();
|
|
|
|
// IO owns the temporary SPI pin assignment; every outcome must release it.
|
|
template <typename IO>
|
|
OnboardRadioState sleepOnboardRadio(IO& io, const char* expectedVersion) {
|
|
io.begin();
|
|
io.reset();
|
|
const auto state = [&]() {
|
|
// A missing chip also times out: BUSY is pulled high until a radio drives it low.
|
|
if (!io.waitBusy(false, 20)) return OnboardRadioState::BusyTimeout;
|
|
|
|
char version[6];
|
|
io.readVersion(version);
|
|
if (memcmp(version, expectedVersion, sizeof(version)) != 0) {
|
|
return OnboardRadioState::Absent;
|
|
}
|
|
io.releaseProbePulls();
|
|
if (!io.waitBusy(false, 20)) return OnboardRadioState::BusyTimeout;
|
|
|
|
io.sleep();
|
|
// Reading over SPI here would wake the radio again. BUSY is a passive check.
|
|
return io.waitBusy(true, 20) ? OnboardRadioState::Asleep : OnboardRadioState::SleepFailed;
|
|
}();
|
|
io.end();
|
|
return state;
|
|
}
|
|
|
|
}
|