From d784b29adf75112a5f19ea1f9e61b10100d2630c Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Tue, 21 May 2024 23:16:15 +0800 Subject: [PATCH] Compliance for Arduino NVS related handles on VM. --- examples/ili9341_example/ili9341_example.ino | 15 ++++++++++++++- examples/shell_example/shell_example.ino | 13 ++++++++++++- examples/vga_shell/vga_shell.ino | 12 +++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/examples/ili9341_example/ili9341_example.ino b/examples/ili9341_example/ili9341_example.ino index 280c1b9..afe74f4 100644 --- a/examples/ili9341_example/ili9341_example.ino +++ b/examples/ili9341_example/ili9341_example.ino @@ -21,6 +21,7 @@ * from the SD card, runs the loaded program, and resets the virtual machine. */ +#include #include #include #include @@ -42,6 +43,9 @@ fabgl::ILI9341Controller DisplayController; fabgl::Terminal Terminal; +// Non-volatile Storage class +ArduinoNvs NvsStorage; + // SPI instance for SD card SPIClass sdSpi(HSPI); @@ -62,10 +66,16 @@ void setup() { return; } + // Initialize the NVS storage + if(!NvsStorage.begin()) { + Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage."); + return; + } + // Rishka virtual machine instance RishkaVM* vm = new RishkaVM(); // Initialize Rishka VM - vm->initialize(&Terminal, &DisplayController); + vm->initialize(&Terminal, &DisplayController, &NvsStorage); if(!vm->loadFile("/sysinfo.bin")) vm->panic("Failed to \e[94mload\e[97m specified file."); @@ -74,6 +84,9 @@ void setup() { vm->run(0, NULL); // Reset VM after program execution vm->reset(); + + // Close the NVS storage + NvsStorage.close(); } void loop() { diff --git a/examples/shell_example/shell_example.ino b/examples/shell_example/shell_example.ino index 45b09c7..66b1a11 100644 --- a/examples/shell_example/shell_example.ino +++ b/examples/shell_example/shell_example.ino @@ -21,6 +21,7 @@ * file into the Rishka VM, executes it, and then waits for the next input. */ +#include #include #include #include @@ -44,6 +45,9 @@ fabgl::ILI9341Controller DisplayController; fabgl::PS2Controller PS2Controller; fabgl::Terminal Terminal; +// Non-volatile Storage class +ArduinoNvs NvsStorage; + // SPI instance for SD card SPIClass sdSpi(HSPI); @@ -131,6 +135,13 @@ void setup() { Terminal.clear(); } + // Initialize the NVS storage + if(!NvsStorage.begin()) { + Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage."); + return; + } + + // Initialize the PSRAM if(!psramInit()) { Terminal.println("\e[94mCannot\e[97m initialize PSRAM."); while(true); @@ -138,7 +149,7 @@ void setup() { // Initialize the Rishka VM instance. vm = new RishkaVM(); - vm->initialize(&Terminal, &DisplayController); + vm->initialize(&Terminal, &DisplayController, &NvsStorage); // Virtual key listener to halt program Terminal.onVirtualKeyItem = [&](VirtualKeyItem * vkItem) { diff --git a/examples/vga_shell/vga_shell.ino b/examples/vga_shell/vga_shell.ino index 0f9767b..afd8443 100644 --- a/examples/vga_shell/vga_shell.ino +++ b/examples/vga_shell/vga_shell.ino @@ -21,6 +21,7 @@ * file into the Rishka VM, executes it, and then waits for the next input. */ +#include #include #include #include @@ -37,6 +38,9 @@ fabgl::VGAController DisplayController; fabgl::PS2Controller PS2Controller; fabgl::Terminal Terminal; +// Non-volatile Storage class +ArduinoNvs NvsStorage; + // SPI instance for SD card SPIClass sdSpi(HSPI); @@ -120,6 +124,12 @@ void setup() { Terminal.clear(); } + // Initialize the NVS storage + if(!NvsStorage.begin()) { + Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage."); + return; + } + // Initialize PSRAM if(!psramInit()) { Terminal.println("\e[94mCannot\e[97m initialize PSRAM."); @@ -128,7 +138,7 @@ void setup() { // Initialize the Rishka VM instance. vm = new RishkaVM(); - vm->initialize(&Terminal, &DisplayController); + vm->initialize(&Terminal, &DisplayController, &NvsStorage); // Virtual key listener to halt program Terminal.onVirtualKeyItem = [&](VirtualKeyItem * vkItem) {