Skip to content

feat: (wip) add qemu for development#500

Closed
ngxson wants to merge 10 commits intocrosspoint-reader:masterfrom
ngxson:xsn/emulation
Closed

feat: (wip) add qemu for development#500
ngxson wants to merge 10 commits intocrosspoint-reader:masterfrom
ngxson:xsn/emulation

Conversation

@ngxson
Copy link
Contributor

@ngxson ngxson commented Jan 22, 2026

Summary

Important

This PR is currently on pause, see #500 (comment)

Emulation can benefit the development of functionalities that are not directly related to hardware.

Still WIP, just posting for discussion. My plan is:

  1. Add a HAL for buttons, display and sdcard
  2. Write an implementation of emulated buttons, display and sdcard that forward calls to Serial output, then have a python server to forward it to a websocket connection
  3. A web ui can be added to interact with the emulated machine via the websocket connection

For example: Display::displayBuffer() will simply turn the buffer into base64, then print it to Serial output. The python script then forward the info back into web ui.

The more complicated part will be to emulate the sdcard. Not sure yet how to do, probably emulate inside python context? (This is left open for discussion)

For now, it can already boot to home screen, but watchdog timeout is triggered randomly:

image

Note: The docker code is adapted from https://github.com/mluis/qemu-esp32


AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? Yes, but only for python/html code, here are some prompts that I used:

  • "write stub (unimplemented) from this header"
  • write python file to spawn the process and forward stdio to websocket + parent stdio
  • write minimal html, no style, to receive the websocket data and output to <div id="output">
  • decode b64 which is 1-bit bw data to canvas, rotate clockwise 90d

All C++ code is written by hand

@ngxson
Copy link
Contributor Author

ngxson commented Jan 23, 2026

Ok so my version has been able to boot into home screen. However, watchdog is triggered randomly for no reason (not even at a fixed interval, just pure random)

I suppose that esp32c3 qemu is not that stable. A simple hello world may sometimes trigger wdt timeout.

At this point, I'm not confident if this is a global issue or isolated to my host machine (docker on a macbook M3). If possible, could you give this a try on your machine? @daveallie @osteotek

(edit: you need to comment out all calls to digitalRead and analogRead, they will trigger panic immediately)

An alternative solution could be to just run this infrastructure on a real standalone esp32c3 which is significantly cheaper than buying a new xteink.

@ngxson
Copy link
Contributor Author

ngxson commented Jan 23, 2026

Last version should "just work" without further modifications to the source code. Some small things should be polished like: debouce button, add mutex to the emulation serial

But at this point, I'm quite convinced that I should get rid of qemu, it has too many problems:

  • No way to emulate GPIO or deepsleep
  • No wifi or bluetooth support (ref: docs)
  • No good way to emulate exact RAM and CPU config
  • Very unstable

Instead, I'll replace it with an option that make it flashable to a cheap esp32c3 board (4MB flash, 3.5MB usable with huge_app partition layout). With OMIT_FONTS, the compiled fw is ~2.5MB:

  • Display, sdcard and buttons will be forwarded to the emulated implementation in this PR
  • Power button will be mapped to BOOT button on the board
image

The 16MB flash version is a bit harder to find, but still cheap:

image

@ngxson
Copy link
Contributor Author

ngxson commented Jan 25, 2026

FWIW, I'm implementing it on my fork here because I think it will be too complicated upstream to crosspoint.

My forked version requires an ESP32C3 board as mentioned in the last message, but it does work very stable. Wifi can also work exactly as on the real device. On top of that, FS proxy make debugging things much easier.

I'm keeping this PR up for a bit more for anyone who wants to play with it

Image

daveallie pushed a commit that referenced this pull request Jan 27, 2026
## Summary

Extracted some changes from
#500 to make
reviewing easier

This PR adds HAL (Hardware Abstraction Layer) for display and GPIO
components, making it easier to write a stub or an emulated
implementation of the hardware.

SD card HAL will be added via another PR, because it's a bit more
tricky.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? **NO**
Jessica765 pushed a commit to Jessica765/crosspoint-reader that referenced this pull request Feb 3, 2026
## Summary

Extracted some changes from
crosspoint-reader#500 to make
reviewing easier

This PR adds HAL (Hardware Abstraction Layer) for display and GPIO
components, making it easier to write a stub or an emulated
implementation of the hardware.

SD card HAL will be added via another PR, because it's a bit more
tricky.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? **NO**
@daveallie
Copy link
Member

@ngxson given these changes aren't going ahead, are you ok for this to be closed out, just trying to do a sweep of all the PRs.

@ngxson
Copy link
Contributor Author

ngxson commented Feb 9, 2026

Yeah actually I have a habit of keeping prototype PR as draft for visibility. But it's fine to close this

@ngxson ngxson closed this Feb 9, 2026
Unintendedsideeffects pushed a commit to Unintendedsideeffects/crosspoint-reader that referenced this pull request Feb 17, 2026
## Summary

Extracted some changes from
crosspoint-reader#500 to make
reviewing easier

This PR adds HAL (Hardware Abstraction Layer) for display and GPIO
components, making it easier to write a stub or an emulated
implementation of the hardware.

SD card HAL will be added via another PR, because it's a bit more
tricky.

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? **NO**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants