Skip to content

Commit d784b29

Browse files
committed
Compliance for Arduino NVS related handles on VM.
1 parent 664c000 commit d784b29

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

examples/ili9341_example/ili9341_example.ino

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* from the SD card, runs the loaded program, and resets the virtual machine.
2222
*/
2323

24+
#include <ArduinoNvs.h>
2425
#include <fabgl.h>
2526
#include <rishka.h>
2627
#include <SD.h>
@@ -42,6 +43,9 @@
4243
fabgl::ILI9341Controller DisplayController;
4344
fabgl::Terminal Terminal;
4445

46+
// Non-volatile Storage class
47+
ArduinoNvs NvsStorage;
48+
4549
// SPI instance for SD card
4650
SPIClass sdSpi(HSPI);
4751

@@ -62,10 +66,16 @@ void setup() {
6266
return;
6367
}
6468

69+
// Initialize the NVS storage
70+
if(!NvsStorage.begin()) {
71+
Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage.");
72+
return;
73+
}
74+
6575
// Rishka virtual machine instance
6676
RishkaVM* vm = new RishkaVM();
6777
// Initialize Rishka VM
68-
vm->initialize(&Terminal, &DisplayController);
78+
vm->initialize(&Terminal, &DisplayController, &NvsStorage);
6979

7080
if(!vm->loadFile("/sysinfo.bin"))
7181
vm->panic("Failed to \e[94mload\e[97m specified file.");
@@ -74,6 +84,9 @@ void setup() {
7484
vm->run(0, NULL);
7585
// Reset VM after program execution
7686
vm->reset();
87+
88+
// Close the NVS storage
89+
NvsStorage.close();
7790
}
7891

7992
void loop() {

examples/shell_example/shell_example.ino

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* file into the Rishka VM, executes it, and then waits for the next input.
2222
*/
2323

24+
#include <ArduinoNvs.h>
2425
#include <fabgl.h>
2526
#include <rishka.h>
2627
#include <SD.h>
@@ -44,6 +45,9 @@ fabgl::ILI9341Controller DisplayController;
4445
fabgl::PS2Controller PS2Controller;
4546
fabgl::Terminal Terminal;
4647

48+
// Non-volatile Storage class
49+
ArduinoNvs NvsStorage;
50+
4751
// SPI instance for SD card
4852
SPIClass sdSpi(HSPI);
4953

@@ -131,14 +135,21 @@ void setup() {
131135
Terminal.clear();
132136
}
133137

138+
// Initialize the NVS storage
139+
if(!NvsStorage.begin()) {
140+
Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage.");
141+
return;
142+
}
143+
144+
// Initialize the PSRAM
134145
if(!psramInit()) {
135146
Terminal.println("\e[94mCannot\e[97m initialize PSRAM.");
136147
while(true);
137148
}
138149

139150
// Initialize the Rishka VM instance.
140151
vm = new RishkaVM();
141-
vm->initialize(&Terminal, &DisplayController);
152+
vm->initialize(&Terminal, &DisplayController, &NvsStorage);
142153

143154
// Virtual key listener to halt program
144155
Terminal.onVirtualKeyItem = [&](VirtualKeyItem * vkItem) {

examples/vga_shell/vga_shell.ino

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* file into the Rishka VM, executes it, and then waits for the next input.
2222
*/
2323

24+
#include <ArduinoNvs.h>
2425
#include <fabgl.h>
2526
#include <rishka.h>
2627
#include <SD.h>
@@ -37,6 +38,9 @@ fabgl::VGAController DisplayController;
3738
fabgl::PS2Controller PS2Controller;
3839
fabgl::Terminal Terminal;
3940

41+
// Non-volatile Storage class
42+
ArduinoNvs NvsStorage;
43+
4044
// SPI instance for SD card
4145
SPIClass sdSpi(HSPI);
4246

@@ -120,6 +124,12 @@ void setup() {
120124
Terminal.clear();
121125
}
122126

127+
// Initialize the NVS storage
128+
if(!NvsStorage.begin()) {
129+
Terminal.println("Unable to \e[94initialize\e[97m non-volatile storage.");
130+
return;
131+
}
132+
123133
// Initialize PSRAM
124134
if(!psramInit()) {
125135
Terminal.println("\e[94mCannot\e[97m initialize PSRAM.");
@@ -128,7 +138,7 @@ void setup() {
128138

129139
// Initialize the Rishka VM instance.
130140
vm = new RishkaVM();
131-
vm->initialize(&Terminal, &DisplayController);
141+
vm->initialize(&Terminal, &DisplayController, &NvsStorage);
132142

133143
// Virtual key listener to halt program
134144
Terminal.onVirtualKeyItem = [&](VirtualKeyItem * vkItem) {

0 commit comments

Comments
 (0)