Skip to content

Commit

Permalink
Compliance for Arduino NVS related handles on VM.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed May 21, 2024
1 parent 664c000 commit d784b29
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
15 changes: 14 additions & 1 deletion examples/ili9341_example/ili9341_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* from the SD card, runs the loaded program, and resets the virtual machine.
*/

#include <ArduinoNvs.h>
#include <fabgl.h>
#include <rishka.h>
#include <SD.h>
Expand All @@ -42,6 +43,9 @@
fabgl::ILI9341Controller DisplayController;
fabgl::Terminal Terminal;

// Non-volatile Storage class
ArduinoNvs NvsStorage;

// SPI instance for SD card
SPIClass sdSpi(HSPI);

Expand All @@ -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.");
Expand All @@ -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() {
Expand Down
13 changes: 12 additions & 1 deletion examples/shell_example/shell_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* file into the Rishka VM, executes it, and then waits for the next input.
*/

#include <ArduinoNvs.h>
#include <fabgl.h>
#include <rishka.h>
#include <SD.h>
Expand All @@ -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);

Expand Down Expand Up @@ -131,14 +135,21 @@ 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);
}

// 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) {
Expand Down
12 changes: 11 additions & 1 deletion examples/vga_shell/vga_shell.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* file into the Rishka VM, executes it, and then waits for the next input.
*/

#include <ArduinoNvs.h>
#include <fabgl.h>
#include <rishka.h>
#include <SD.h>
Expand All @@ -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);

Expand Down Expand Up @@ -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.");
Expand All @@ -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) {
Expand Down

0 comments on commit d784b29

Please sign in to comment.