3.8 KiB
Plan: Computer Emulator Board Option
Add an SFML-based computer emulator as a new board configuration to enable developing and testing the bare-metal application on a desktop computer. This creates a "virtual board" that emulates the display hardware using SFML graphics, following the existing display driver architecture.
Steps
-
Create display/low_level_display_sfml.cpp and display/low_level_display_sfml.h - Implement
LowLevelDisplaySFMLclass inheriting fromLowLevelDisplay, withinit()creating an SFML window,draw_buffer()converting the 1-bit buffer to RGBA pixels (similar to lines 105-112 in the example), andrefresh()updating the SFML texture and handling window events. -
Create board_configs/board_emulator.h - Define
BOARD_NAMEas "Computer Emulator (SFML)", setDISPLAY_WIDTH/DISPLAY_HEIGHT(400x300 or configurable), defineDISPLAY_TYPE_EMULATOR_VALconstant, setDISPLAY_TYPE_SELECTEDto emulator type, setTOUCH_TYPE_SELECTEDtoTOUCH_TYPE_NONE_VALinitially, and stub out all hardware pin defines (DISPLAY_SPI_PORT, GPIO pins) as unused/invalid values. -
Update display/low_level_display_factory.cpp - Add
DISPLAY_TYPE_EMULATORto theDisplayTypeenum, add new case inLowLevelDisplay::create()switch statement to returnnew LowLevelDisplaySFML(width, height)when emulator type is selected, bypassing pin configuration struct since no hardware GPIO is needed. -
Modify CMakeLists.txt - Add conditional compilation: detect if
BOARD_EMULATORis defined, if so, find and link SFML libraries (sfml-graphics,sfml-window,sfml-system), add display/low_level_display_sfml.cpp to sources, exclude Pico SDK hardware dependencies (multicore, GPIO, SPI), and compile for native host architecture instead of ARM. -
Update board_config.h - Add
// #define BOARD_EMULATORto the board selection list with descriptive comment explaining it's for desktop testing, ensure conditional include adds#elif defined(BOARD_EMULATOR)case that includes board_configs/board_emulator.h. -
Create build_emulator.sh - Script to temporarily enable
BOARD_EMULATORdefine in board_config.h, configure CMake for host architecture (remove-DPICO_BOARD=flags), build inbuild_emulator/directory, and produce a native executablebasic1_emulatorinstead of.uf2file.
Further Considerations
-
Hardware abstraction for Pico SDK functions - The code uses
multicore_launch_core1(),gpio_init(),spi_init(), etc. Should we create stub implementations for the emulator, conditionally compile out hardware-specific code with#ifndef BOARD_EMULATOR, or refactor hardware initialization into a separate HAL layer? Recommend Option A: stub implementations that no-op for simplicity. -
Touch/mouse input support - Extend later by creating display/low_level_touch_sfml.cpp that inherits from
LowLevelTouch, capturesf::Event::MouseButtonPressedevents inrefresh(), translate mouse coordinates to touch coordinates, and updateTOUCH_TYPE_SELECTEDin board_configs/board_emulator.h to use the SFML touch driver. -
Keyboard input for hardware buttons - The example shows console keyboard input (lines 56-89). Should we map specific keys (arrow keys, space, enter) to emulate the hardware buttons like
BUTTON_KEY0_PINfound on the e-ink board, or implement a command-line interface like the example? Recommend Option A: map keys to button events for consistency with hardware boards.