One day I had the crazy idea to bring
I called the project Nanonyam (Nanonyam) and even came up with a logo for it (I drew for 5 minutes).
For those who think in terms of Arduino, we can say that Nanonyam is a virtual Arduino shield for controlling Windows.
In other words, Nanonyam is a virtual machine that uses firmware for the AVR microcontroller (ATMEGA2560 is recommended) as the bytecode. Inside this virtual machine is an AVR core simulator, but instead of peripherals, which are located at SRAM addresses from 0x0060 to 0x01FF, there is a special interface to virtual functions (including Windows API functions). And here it is very important to understand right away: the code for Nanonyam should not have any access to the specified memory range, so as not to accidentally call, for example, the function of deleting files or formatting a disk. The rest of the SRAM memory range from 0x0200 to 0xFFFF (this is more than in a real microcontroller) is available to the user for any purpose. I note right away that there is a special protection against accidental launch of the firmware of a real microcontroller (or firmware from another architecture): before activating "dangerous" functions, you need to call a special tricky virtual function. There are some other security features as well.
To create programs for Nanonyam, you need to use special libraries that implement all currently available virtual functions. Download the Nanonyam virtual machine and libraries for it
Nanonyam is free for home and commercial use. The Nanonyam program is provided on an "as is" basis. Source code is not provided.
The program is currently in the testing phase. Implemented about 200 virtual functions that allow you to create simple programs for Windows.
Obviously, creating something complicated in such a virtual machine will not work, since the memory for the code is only 256 kB. Data can be stored in separate files, the buffer for the graphic part is implemented externally. All functions are simplified and adapted for 8-bit architecture.
What can you do in Nanonyam? I came up with a few problems.
Development of program blocks
I once needed to design a complex menu for a 128x64 dot graphic display. I really didn't want to constantly load the firmware into a real microcontroller to see how the pixels look. And so the idea of ββNanonyam was born. The figure below shows an image from a real OLED display of one of the items on the same menu. Now I can work through it without a real device.
Nanonyam (in its final idea) is a good tool for working out program blocks for microcontrollers, as there are functions for working with graphics (you can simulate displays and indicators), with files (you can make logs, read test data), with a keyboard (you can read up to 10 buttons at the same time), with COM ports (here is a separate item).
Creating Quick Programs
For example, you need to quickly process 100500 text files. Each one needs to be opened, slightly modified according to some simple algorithm, saved and closed. If you are a Python master, then I congratulate you, you have everything. But if you are an hardened arduino (and there are many of them), then Nanonyam will help you in solving this problem. This is my second goal in Nanonyam: to add many useful functions such as text processing, taking screenshots or simulating keystrokes in the system (all of which, by the way, are already there), as well as many other functions for solving routine tasks.
Testing hardware via COM port
Nanonyam can act as a terminal that works according to your algorithm. You can draw a small menu to control the device and display the data received from the port. You can save and read data from files for analysis. A handy tool for simple debugging and calibration of hardware, as well as for creating simple virtual instrument control panels. For students and young scientists, this project can be very useful.
Programming training
However, as with the entire Arduino project, the main usefulness of Nanonyam lies in the simplification of functions, interface and bootloader. Therefore, this project should be of interest to novice programmers and those who are satisfied with the level of arduino. By the way, I myself still have not studied arduino in detail, because I always used WinAVR or AVR Studio, but started with assembler. Therefore, the example program below will be a little wrong, but quite working.
Hello Habr!
It's time to get familiar with some Nanonyam features and write a simple program. We will write in Arduino, but not in the usual way, but in the way I can now (I already said that I have not figured out this environment very well yet). First, create a new sketch and select the Mega2560 board.
Save the sketch to a file and copy next
#include <stdio.h>
#include "NanonyamnN_System_lib.c"
#include "NanonyamnN_Keyboard_lib.c"
#include "NanonyamnN_File_lib.c"
#include "NanonyamnN_Math_lib.c"
#include "NanonyamnN_Text_lib.c"
#include "NanonyamnN_Graphics_lib.c"
#include "NanonyamnN_RS232_lib.c"
It would be even more correct to make a special module βNanonyam for Arduinoβ, which can be installed directly from Arduino. As soon as I figure it out, I'll do it, but for now I'm just showing the essence of working with a virtual machine. We write the following code:
//Π‘ΡΠ°Π·Ρ ΠΏΠΎΡΠ»Π΅ Π·Π°ΠΏΡΡΠΊΠ° ΡΠΈΡΡΠ΅ΠΌ ΡΠ΅ΠΊΡΡ Π² ΠΎΠΊΠ½Π΅
void setup() {
sys_Nanonyam();//ΠΠΎΠ΄ΡΠ²Π΅ΡΠΆΠ΄Π°Π΅ΠΌ ΠΊΠΎΠ΄ Π²ΠΈΡΡΡΠ°Π»ΡΠ½ΠΎΠΉ ΠΌΠ°ΡΠΈΠ½Ρ
g_SetScreenSize(400,200);//ΠΠ°Π΄Π°ΡΠΌ ΡΠ°Π·ΠΌΠ΅Ρ Π΄ΠΈΡΠΏΠ»Π΅Ρ 400Ρ
200 ΡΠΎΡΠ΅ΠΊ
sys_WindowSetText("Example");//ΠΠ°Π³ΠΎΠ»ΠΎΠ²ΠΎΠΊ ΠΎΠΊΠ½Π°
g_ConfigExternalFont(0,60,1,0,0,0,"Arial");//ΠΠ°Π΄Π°ΡΠΌ ΡΡΠΈΡΡ Windows Π² ΡΡΠ΅ΠΉΠΊΠ΅ ΡΡΠΈΡΡΠΎΠ² 0
g_SetExternalFont(0);//ΠΡΠ±ΠΈΡΠ°Π΅ΠΌ ΡΡΠ΅ΠΉΠΊΡ ΡΡΠΈΡΡΠΎΠ² 0 Π΄Π»Ρ ΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΡΠ΅ΠΊΡΡΠ°
g_SetBackRGB(0,0,255);//Π¦Π²Π΅Ρ ΡΠΎΠ½Π° ΡΠΈΠ½ΠΈΠΉ
g_SetTextRGB(255,255,0);//Π¦Π²Π΅Ρ ΡΠ΅ΠΊΡΡΠ° ΠΆΡΠ»ΡΡΠΉ
g_ClearAll();//ΠΡΠΈΡΠ°Π΅ΠΌ ΡΠΊΡΠ°Π½ (Π·Π°Π»ΠΈΠ²ΠΊΠ° ΡΠ²Π΅ΡΠΎΠΌ ΡΠΎΠ½Π°)
g_DrawTextCenterX(0,400,70,"Hello, Habr!");//Π ΠΈΡΡΠ΅ΠΌ Π½Π°Π΄ΠΏΠΈΡΡ
g_Update();//ΠΡΠ²ΠΎΠ΄ΠΈΠΌ Π³ΡΠ°ΡΠΈΡΠ΅ΡΠΊΠΈΠΉ Π±ΡΡΠ΅Ρ Π½Π° ΡΠΊΡΠ°Π½
}
//ΠΡΠΎΡΡΠΎ ΠΆΠ΄ΡΠΌ Π·Π°ΠΊΡΡΡΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ
void loop() {
sys_Delay(100);//ΠΠ°Π΄Π΅ΡΠΆΠΊΠ° ΠΈ ΡΠ°Π·Π³ΡΡΠ·ΠΊΠ° ΠΏΡΠΎΡΠ΅ΡΡΠΎΡΠ°
}
Sketch with this program
We press the "Check" button and there should not be any errors.
Now you need to get a binary file (firmware). Select the menu "Sketch>>Export binary file (CTRL+ALT+S)Β«.
This will copy two HEX files to the sketch folder. We take only the file without the prefix "with_bootloader.mega".
There are several ways to specify a HEX file to the Nanonyam virtual machine, all of them are described
Similarly, you can create programs in other environments, such as AVR Studio or WinAVR.
This is where we finish our acquaintance with Nanonyam. The main idea should be clear.
Thank you all for your attention and good programming!
Source: habr.com