GUI
Author: Konrad Armbrecht 2025
The GUI adds a user-friendly interface to the PicoNut simulator. While previously only the output of text via the UART interface was possible, the GUI now also allows the display of graphics and the output of audio signals. To achieve this, the GUI reads directly from the peripheral registers and converts the information into a Qt-compatible format in order to output it.
Thanks to its modular architecture, further functions can be added to the GUI, for example, to capture user input. In the long term, this opens up the possibility of running interactive applications such as computer games directly on the PicoNut.
Fig. 32 GUI window that displays the running graphics_fancy_random_squares program.
GUI class
-
class gui
This module provides a Qt-based GUI that is available to the piconut simulator. Currently implemented are functions for the image output of the graphics peripheral. The simulator terminates when the GUI window is closed.
- Author
Konrad Armbrecht
Functions
Call sequence and data flow of a new image frame
Every write access to the framebuffer triggers a flush operation. This means that the flush_to_gui callback function in the graphics class is called automatically upon each write.
This initiates a chain of function calls:
top_tb::flush_framebuffer -> gui::set_image -> mainwindow::image_to_gui -> framebuffer_to_image::output_image.
The class framebuffer_to_image is responsible for converting the framebuffer data into a Qt-compatible image format. For this purpose, the color information of each pixel is read from the framebuffer in hex format and converted into the QRgb format. The converted values are stored in a two-dimensional QVector<QVector<QRgb>>, which enables efficient processing and subsequent image assembly. The pixel values are then assembled into a QImage, which is returned after the output_image method is executed.
The output image, returned by the framebuffer_to_image class, is converted by the mainwindow class to a QPixmap and sent to the label that is part of the GUI and displays the graphics framebuffer content for the user.
Framebuffer to image class
-
class framebuffer_to_image
A class for converting framebuffer data into a Qt-compatible QImage.
This class is responsible for converting the frame buffer content into a Qt displayable format. The class can be used in the simulation environment.
- Author
Konrad Armbrecht
Within that class an empty QVector “qrgb_array” is created that will be filled with Qt readable pixel information. To fill the QVector, the framebuffer content is read address by address. The containing hex values are converted to QRgb values and copied into the QVector. The QRgb values are then used to assemble the output image, which is finally being returned.
Functions
-
QImage framebuffer_to_image::output_image()
Converts the raw framebuffer data into QRgb format and creates a QImage from it.
- Returns:
QImage containing the processed framebuffer data.
Mainwindow class
-
class mainwindow
This class provides a Qt-based GUI window that displays the assembled output image. It is responsible for filling the QLabel with the output image.
- Author
Konrad Armbrecht
The GUI adapts dynamically to changes in window size while preserving the correct aspect ratio. Additionally, it allows for simulation control, as the simulator is terminated when the main window is closed.
Functions
-
MainWindow::MainWindow(QWidget *parent = nullptr)
Constructor.
Initializes the UI components and sets up the image display area.
- Parameters:
parent – The parent widget (default: nullptr).
-
void MainWindow::image_to_gui(uint32_t *framebuffer, uint32_t framebuffer_size)
Updates the GUI with the latest framebuffer content.
Converts the framebuffer content into a
QPixmapand displays it in the GUI. The image adapts to the QLabel size dynamically.- Parameters:
framebuffer – Pointer to the framebuffer data.
framebuffer_size – Size of the framebuffer in pixel.
-
bool MainWindow::is_mainwindow_open() const
Check if the main window is open.
- Returns:
True if the main window is open, otherwise false.
Audio playback
TODO