Arduino off-ramp: raw NVS settings reads + millis/delay shim - #127
Draft
zjwhitehead wants to merge 5 commits into
Draft
zjwhitehead wants to merge 5 commits into
zjwhitehead wants to merge 5 commits into
Conversation
Drop Arduino Preferences from the load and factory-reset paths so reads use the same nvs_* keys and types as the existing single-commit write path. Field devices stay byte-compatible (u8/u16/i32, 4-byte float blob). Co-authored-by: Zach Whitehead <zjwhitehead@users.noreply.github.com>
Add timeMillis() (esp_timer_get_time()/1000) and timeDelay() (vTaskDelay + pdMS_TO_TICKS) and switch production firmware call sites. Native and screenshot tests keep compiling via the header's non-ESP path. Co-authored-by: Zach Whitehead <zjwhitehead@users.noreply.github.com>
Arduino 2.0.17 delay() is vTaskDelay(ms / portTICK_PERIOD_MS) with no busy-wait remainder. Drop the delay(0) early-return so timeDelay(0) still yields, matching that implementation. Co-authored-by: Zach Whitehead <zjwhitehead@users.noreply.github.com>
ESP32 treats uint32_t and unsigned long as distinct for -Wformat, so %lu prints of timeMillis() failed the firmware build. Keep the Arduino millis() return type so existing format strings stay valid. Co-authored-by: Zach Whitehead <zjwhitehead@users.noreply.github.com>
Load sites call nvs_get_* directly with the same keys, u8 0/1 bools, 4-byte float blob, and miss defaults. Factory reset inlines erase_all so nvsEraseNamespace is no longer needed. Co-authored-by: Zach Whitehead <zjwhitehead@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two scoped Arduino off-ramp steps. Does not bump espressif32 / ESP-IDF, does not drop
framework = arduino, espidf, and does not migrate GPIO, ADC, LEDC, Wire/SPI, Adafruit, or NimBLE.1) Finish NVS for device settings (drop Preferences reads)
writeDeviceData()already used raw ESP-IDFnvs_*with a singlenvs_commit().refreshDeviceData()and factory reset still went through ArduinoPreferences.This PR ports the read/load and reset paths to the same raw NVS API and key layout, then removes
#include <Preferences.h>and thePreferencesinstance fromdevice_settings.cpp. Load sites callnvs_get_*/nvs_erase_alldirectly (no typed getter wrappers).Field compatibility
Verified against Arduino-ESP32 2.0.17
Preferences.cpp(espressif32@6.13.0) and the existing write-path comments. Keys and NVS types are unchanged, so devices already in the field keep their stored values:ver_major,ver_minor,scr_rot,perf_mode,theme,revisionu8getUChar→nvs_get_u8metric_tmp,metric_altu80/1getBoolisgetUChar == 1sea_presgetFloat/putFloataregetBytes/putBytes→nvs_*_blobarmed_timeu16getUShort→nvs_get_u16tz_offseti32getInt→nvs_get_i32Namespace remains
openppg. Missing keys still fall back to the same defaults. Factory reset still wipes the namespace (nvs_erase_all+ commit, equivalent toPreferences.clear()) and writes defaults. USBSerial / WebSerial strings and command behavior are unchanged.2) Time shim: replace Arduino
millis()/delay()Added
inc/sp140/time_utils.h:timeMillis()→esp_timer_get_time() / 1000ULL, returnsunsigned long(same as Arduinomillis())timeDelay(ms)→vTaskDelay(pdMS_TO_TICKS(ms))(same as Arduino-ESP32 2.0.17delay(), which isvTaskDelay(ms / portTICK_PERIOD_MS)with no busy-wait remainder)On this firmware
CONFIG_FREERTOS_HZ=1000, so one tick is 1 ms. Productionsrc/call sites now use the shim, including BLE files that only needed a clock (NimBLE itself is untouched).Arduino.hincludes that are still needed for other APIs are left in place.Native / screenshot tests keep compiling: the header’s non-
ESP_PLATFORMpath delegates to the existing Arduino stubmillis()/delay()so screenshot timestamps stay on the same clock.How to test
platformio test -e native-test platformio run -e OpenPPG-CESP32S3-CAN-SP140Optional (CI also runs this):
./test/test_screenshots/build_and_run.shValidation so far
platformio test -e native-test: 60/60 passed (local)cpplintoninc/andsrc/: clean (local)pio-buildfailed on-Werror=format(%luvsuint32_t). Fixed by returningunsigned longfromtimeMillis().openppg/SINE-ESC-CAN; CIpio-buildis the equivalent check.Intentionally left
src/sp140/diagnostics.cppstill uses ArduinoPreferences— boot-diag history lives in a different namespace and is out of scope.writeDeviceData().millis()/delay()intest/native_stubsandtest/screenshot_stubs— native clock for unit/screenshot tests.millis()intest/test_screenshots— test harness, not firmware.delay().Arduino.hincludes still required for Serial, GPIO, and other Arduino APIs.Do not merge until reviewed.