{"id":50509716,"url":"https://github.com/dmatking/display-sim","last_synced_at":"2026-06-02T19:01:12.868Z","repository":{"id":359417122,"uuid":"1244854795","full_name":"dmatking/display-sim","owner":"dmatking","description":"Native desktop simulator for embedded display projects (LCD/OLED/e-ink) — preview, screenshot, and interactively edit your UI layout without flashing hardware.","archived":false,"fork":false,"pushed_at":"2026-05-21T20:14:31.000Z","size":409,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-22T04:21:20.878Z","etag":null,"topics":["display","embedded","firmware","sdl2","simulator"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dmatking.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-20T17:01:35.000Z","updated_at":"2026-05-21T20:14:35.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/dmatking/display-sim","commit_stats":null,"previous_names":["dmatking/esp32-screencap"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/dmatking/display-sim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatking%2Fdisplay-sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatking%2Fdisplay-sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatking%2Fdisplay-sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatking%2Fdisplay-sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmatking","download_url":"https://codeload.github.com/dmatking/display-sim/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmatking%2Fdisplay-sim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33833277,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-02T02:00:07.132Z","response_time":109,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["display","embedded","firmware","sdl2","simulator"],"created_at":"2026-06-02T19:01:11.571Z","updated_at":"2026-06-02T19:01:12.862Z","avatar_url":"https://github.com/dmatking.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# display-sim\n\nNative Linux/Windows desktop simulator for embedded display projects. Preview your firmware's UI in a live SDL2 window, save PNG screenshots, and interactively drag elements around to tune the layout — all without flashing hardware.\n\nWorks with any project that owns a framebuffer in memory: LCD, OLED, e-ink, monochrome, color, doesn't matter. ESP-IDF stubs are bundled because that's where it started, but they're optional and the same approach works for any embedded toolchain (STM32, RP2040, Zephyr, bare-metal) as long as you provide the equivalent shim headers.\n\n\u003cimg src=\"assets/cyd_repo.png\" alt=\"CYD 320x240 dashboard screenshot\" width=\"320\" hspace=\"8\"\u003e\u0026nbsp;\u003cimg src=\"assets/p4_repo.png\" alt=\"Waveshare P4 720x720 dashboard screenshot\" width=\"320\" hspace=\"8\"\u003e\n\n*Rendered from the sim, not the device — same renderer either way. From [esp32-gh-dashboard](https://github.com/dmatking/esp32-gh-dashboard), a project using display-sim for both desktop preview and layout editing.*\n\nAnimation works too. Both bundled examples run at ~30 fps headless and were sampled out to the GIFs below:\n\n\u003cimg src=\"assets/mono_demo.gif\" alt=\"SH1107 128x128 OLED bouncing ball at 30 fps\" width=\"256\" hspace=\"8\"\u003e\u0026nbsp;\u003cimg src=\"assets/color_demo.gif\" alt=\"240x240 RGB565 bouncing squares over a rainbow gradient\" width=\"240\" hspace=\"8\"\u003e\n\n## How it works\n\nYour project's display driver has two implementations:\n\n| File | Used when |\n|---|---|\n| `display_hw.c` (or whatever you call it) | Building for the target — talks to real hardware |\n| `display_sim.c` | Building for desktop — calls into display-sim |\n\nThe desktop build is a native CMake project that:\n1. (Optionally) includes the bundled stub headers to shadow ESP-IDF / driver / FreeRTOS includes\n2. Links SDL2 for the live preview window\n3. Uses `stb_image_write` (vendored, header-only) for PNG output\n\nThe project's framebuffer is pointed to directly — no copy, no protocol change.\n\n## Supported display formats\n\n| `screencap_format_t` | Description | Common hardware |\n|---|---|---|\n| `SCREENCAP_MONO_PAGES` | 1-bpp, 8-rows-per-page | SH1107, SSD1306, SSD1309 |\n| `SCREENCAP_RGB565` | 16-bpp packed, row-major | ST7789, ILI9341, ST7796, ST7703 |\n| `SCREENCAP_RGB888` | 24-bpp, row-major | generic RGB framebuffer |\n\n\u003e **Note:** the C API uses a `screencap_` prefix throughout — that's the legacy name from when this repo was called `esp32-screencap`. Functionally the library is now `display-sim`, but the symbol prefix stays for API stability. A future major version may rename it.\n\n## Dependencies\n\n```\nsudo apt install libsdl2-dev\n```\n\nNo other runtime dependencies. PNG output uses vendored `stb_image_write.h`.\n\n## Quick start\n\nClone as a submodule in your project:\n\n```bash\ngit submodule add https://github.com/dmatking/display-sim.git sim/display-sim\n```\n\nCreate `sim/CMakeLists.txt`:\n\n```cmake\ncmake_minimum_required(VERSION 3.16)\nproject(myproject_sim C)\n\ninclude(display-sim/cmake/screencap.cmake)\n\nscreencap_add_sim(myproject_sim\n    SOURCES\n        main_sim.c          # your sim entry point\n        display_sim.c       # calls screencap_init / screencap_flush\n        ../main/game.c      # your existing app code (unchanged)\n        ../main/render.c\n    INCLUDES\n        ../main             # your project's headers\n)\n```\n\nBuild:\n\n```bash\nmkdir sim/build \u0026\u0026 cd sim/build\ncmake ..\nmake\n./myproject_sim\n```\n\n## Keyboard shortcuts (SDL window)\n\n| Key | Action |\n|---|---|\n| `P` | Save `screenshot_NNNN.png` (auto-increments) |\n| `G` | Toggle a 10/50 px minor/major grid overlay (alignment aid) |\n| `E` | Toggle layout edit mode (only if the project registered an editor — see below) |\n| Click | Print board-space coords to stdout (or select an editor element if edit mode is on) |\n| `Esc` / close | Quit |\n\n## Layout editor (optional)\n\nProjects with hand-positioned UI elements can register an editor session and drag elements around the live window. display-sim handles all the UI (selection, drag math, arrow-key nudge, save callback); the project owns the underlying coordinates.\n\n```c\nstatic screencap_elem_t elems[] = {\n    { .id = \"title\",  .x = 4,  .y = 4,  .w = 256, .h = 16 },\n    { .id = \"score\",  .x = 4,  .y = 28, .w = 64,  .h = 16 },\n    /* … */\n};\n\nstatic void save_layout(const screencap_elem_t *e, int n, void *ctx)\n{\n    /* Write your positions back to source / a generated header. */\n}\n\nscreencap_editor_register(elems, sizeof(elems)/sizeof(elems[0]),\n                          save_layout, NULL /* reload */, NULL /* ctx */);\n```\n\nOnce registered, the editor responds to:\n\n| Key | Action |\n|---|---|\n| `E` | Toggle edit mode (highlights all rects, enables selection) |\n| Click | Select the topmost element under the cursor |\n| Drag | Move the selected element |\n| Arrows | Nudge selected element by 1 px (Shift = 10 px) |\n| `S` | Invoke the save callback |\n| `R` | Invoke the reload callback |\n\nElement rects are in **board-space pixels** (same coords as the framebuffer); display-sim handles the window-scale conversion. It writes the new x/y back into the array the project passes — call `screencap_editor_active()` if you need to know whether edit mode is on.\n\n## Headless / CI mode\n\n```bash\n./myproject_sim --screenshot output.png\n./myproject_sim --screenshot output.png --frames 60   # run 60 ticks first\n./myproject_sim --screenshot output.png --grid        # bake grid overlay into the PNG\n```\n\nReturns exit code 0 on success. Can be run in a CI job with a virtual framebuffer (`Xvfb`) or headless SDL (`SDL_VIDEODRIVER=offscreen`).\n\n## Writing a display_sim.c\n\n```c\n#include \"display.h\"\n#include \"screencap.h\"\n\n/* argc/argv forwarded from main_sim.c */\nextern int   sim_argc;\nextern char **sim_argv;\n\nint display_init(display_t *dev)\n{\n    screencap_cfg_t cfg = {\n        .width    = DISP_WIDTH,\n        .height   = DISP_HEIGHT,\n        .format   = SCREENCAP_RGB565,\n        .scale    = 2,             /* window zoom factor */\n        .title    = \"My Project\",\n        .framebuf = dev-\u003eframebuf, /* point at your existing buffer */\n    };\n    return screencap_init(\u0026cfg, sim_argc, sim_argv);\n}\n\nvoid display_flush(display_t *dev)\n{\n    (void)dev;\n    screencap_flush();\n}\n```\n\nThen in your sim main loop:\n\n```c\nwhile (screencap_poll()) {\n    app_tick();          /* your existing logic */\n    display_flush(\u0026lcd);\n    SDL_Delay(33);       /* ~30 fps */\n}\nscreencap_destroy();\n```\n\n## ESP-IDF stub headers (optional)\n\nIf your project is built with ESP-IDF, bundled stub headers let you compile the firmware sources unchanged on desktop. Pass the include path to `screencap_add_sim` (the cmake helper does it automatically) and ESP-IDF code finds the right symbols:\n\n| Header | What it stubs |\n|---|---|\n| `esp_err.h` | `esp_err_t`, `ESP_OK`, `ESP_FAIL` |\n| `esp_log.h` | `ESP_LOGI/W/E/D/V` → `printf` |\n| `esp_random.h` | `esp_random()` → `rand()` |\n| `esp_timer.h` | `esp_timer_get_time()` → `clock_gettime` |\n| `driver/i2c_master.h` | handle typedefs |\n| `driver/spi_master.h` | handle typedefs, `SPI2_HOST`/`SPI3_HOST` |\n| `driver/gpio.h` | `gpio_num_t` |\n| `freertos/FreeRTOS.h` | `TickType_t`, `pdTRUE`, `pdMS_TO_TICKS` |\n| `freertos/task.h` | `vTaskDelay()` → `usleep` |\n\nFor anything not listed (or for other toolchains entirely — STM32 HAL, Pico SDK, Zephyr, etc.), add a stub header to your project's `sim/` directory and include it before the `display-sim/` path — it will shadow the missing header.\n\n## Examples\n\n### Real project\n\n**[esp32-gh-dashboard](https://github.com/dmatking/esp32-gh-dashboard)** is a complete GitHub traffic dashboard for five ESP32-family display boards (CYD 2.8\", CYD-S3, CYD 3.5\", Waveshare 2.0\", Waveshare P4) that uses display-sim end-to-end:\n\n- Desktop preview during firmware development (no flash cycle for layout iteration)\n- PNG screenshots for the README, scripted out of the headless mode\n- Grid overlay + click-for-coords during initial layout work\n- The drag editor wired up to two layout structs (`layout_cyd_repo_t`, `layout_p4_repo_t`) — drag elements around in the sim, hit `S`, regenerated C source lands in the firmware on the next build\n- GitHub Actions builds the firmware for all five boards on push to main\n\nBrowse [`sim/main_sim.c`](https://github.com/dmatking/esp32-gh-dashboard/blob/main/sim/main_sim.c), [`sim/layout_editor.c`](https://github.com/dmatking/esp32-gh-dashboard/blob/main/sim/layout_editor.c), and [`sim/CMakeLists.txt`](https://github.com/dmatking/esp32-gh-dashboard/blob/main/sim/CMakeLists.txt) for a full integration.\n\n### Standalone demos\n\n| Example | Display | What it shows |\n|---|---|---|\n| [`examples/mono_sh1107/`](examples/mono_sh1107/) | SH1107 128×128 OLED | Bouncing ball, frame counter |\n| [`examples/color_rgb565/`](examples/color_rgb565/) | Generic 240×240 RGB565 | Rainbow gradient, bouncing colored squares |\n\nBuild an example:\n\n```bash\ncd examples/mono_sh1107\nmkdir build \u0026\u0026 cd build\ncmake ..\nmake\n./mono_sh1107_sim\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmatking%2Fdisplay-sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmatking%2Fdisplay-sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmatking%2Fdisplay-sim/lists"}