Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ bool readRegister(uint8_t reg, uint8_t *outValue) {
bool Accelerometer::begin() {
Wire.begin(PinAssignment::kI2cSda, PinAssignment::kI2cScl);

// Plain presence probe (address-only write, real stop condition)
// before attempting the repeated-start register read below. On boards
// without this part (the first production run — see
// PCB/GPIO_table.md's Accelerometer section) endTransmission(false)'s
// repeated-start check doesn't reliably report the missing ACK by
// itself — a known ESP32 I2C driver quirk — so without this,
// Wire.requestFrom() gets called against a device that was never
// there, which the Wire library logs as an alarming-looking error.
Wire.beginTransmission(kI2cAddress);
if (Wire.endTransmission() != 0) {
present_ = false;
return false;
}

uint8_t chipId = 0;
if (!readRegister(kRegChipId, &chipId)) {
present_ = false;
Expand Down
10 changes: 9 additions & 1 deletion src/calibration_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ CalibrationData CalibrationStore::load() {
CalibrationData data; // defaults if nothing has been saved yet

Preferences prefs;
if (!prefs.begin(kNamespace, /*readOnly=*/true)) {
// Not readOnly: on a device that's never saved this namespace yet
// (first boot, or after a flash-partition wipe), NVS_READONLY makes
// nvs_open() fail with ESP_ERR_NVS_NOT_FOUND, which the Preferences
// library logs as an alarming-looking error regardless of how
// gracefully the caller handles the resulting begin() == false (we
// just fall back to defaults either way). Opening read-write instead
// creates the empty namespace silently — no behavior change, no false
// "hardware is broken" errors on real hardware's first boot.
if (!prefs.begin(kNamespace, /*readOnly=*/false)) {
return data;
}

Expand Down
5 changes: 4 additions & 1 deletion src/complication_persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ constexpr const char *kNamespace = "snips_disp";

void ComplicationPersistence::load(ComplicationRegistry *registry) {
Preferences prefs;
if (!prefs.begin(kNamespace, /*readOnly=*/true)) {
// Not readOnly: avoids a misleading "nvs_open failed: NOT_FOUND" log
// on a device that's never saved this namespace yet — see
// calibration_store.cpp's load() for the full explanation.
if (!prefs.begin(kNamespace, /*readOnly=*/false)) {
return;
}

Expand Down
5 changes: 4 additions & 1 deletion src/droid_persistence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ DroidStore DroidPersistence::load() {
DroidStore store;

Preferences prefs;
if (!prefs.begin(kNamespace, /*readOnly=*/true)) {
// Not readOnly: avoids a misleading "nvs_open failed: NOT_FOUND" log
// on a device that's never saved this namespace yet — see
// calibration_store.cpp's load() for the full explanation.
if (!prefs.begin(kNamespace, /*readOnly=*/false)) {
return store;
}

Expand Down
5 changes: 4 additions & 1 deletion src/power_config_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ PowerConfig PowerConfigStore::load() {
PowerConfig config; // defaults if nothing has been saved yet

Preferences prefs;
if (!prefs.begin(kNamespace, /*readOnly=*/true)) {
// Not readOnly: avoids a misleading "nvs_open failed: NOT_FOUND" log
// on a device that's never saved this namespace yet — see
// calibration_store.cpp's load() for the full explanation.
if (!prefs.begin(kNamespace, /*readOnly=*/false)) {
return config;
}

Expand Down
Loading