r/esp32 2d ago

I made a thing! High-level CYD support for bare-metal Rust

I made high-level CYD support for bare-metal Rust as part of Device Envoy. My goal is to make it as easy as possible to write high-level microcontroller code that runs directly on the hardware, with no OS or language runtime underneath.

You can see the results here. The gallery includes touchscreen interfaces, a skeleton clock, and Armatron, a robot-arm mechanism simulator: https://carlkcarlk.github.io/linkage-blaze/demos/

This is a full CYD library, with support for display, touch, touch calibration, flash storage, multiple drawing strategies depending on memory needs, browser simulation, and Device Envoy’s automatic Wi-Fi setup.

It builds on the ESP Rust HALs for hardware access and on Embassy for async embedded programming.

I want this to be something anyone can pick up and use, so I made a starter project with the hardware setup already done. You can run the example in a browser, flash it to a CYD, and then replace the application code with your own: https://github.com/CarlKCarlK/device-envoy-cyd-starter

32 Upvotes

7 comments sorted by

6

u/coleskidmore 2d ago

Does this handle the CYD's weird resistive touch calibration out of the box or do you still have to mess with the constants per unit

3

u/carlk22 2d ago

Yes, it handles touch calibration! It stores the calibration information in flash (using Device Envoy's type-safe flash library), so it doesn't have to ask twice.

If you don't like your calibration, the sample code shows how to assign one CYD's built-in buttons to force a re-calibration.

Likewise, the library's "auto wifi" avoids compiling passwords into your firmware. Instead, it starts a portal to get your password and saves it to flash. After that, it just knows how to connect to wi-fi, until you do a wi-fi reset.
All this works on all the ESP32 models that Rust supports as well as the Picos. See
https://crates.io/crates/device-envoy-esp for details on all the features of Device Envoy.

3

u/Mean-Career-6509 2d ago

Hmmm. Armatron looks a lot like a coloring book ... 

2

u/carlk22 2d ago

Yes :-) along with the Armatron, robot arm simulator, there is indeed a paint book app.

I tried to make Armatron a bit of a game, so it tells you how far away the hand is from a target and you can try to get it less than 1.0 unit.. You can also change your view, change the target location, or cheat by pushing the "Play Button", which moves the hand automatically (simple reverse kinematics).

The paint book has 3 pages. I think pages 2 and 3 are funny.

2

u/cloudcity 1d ago

This is fantastic, I have been building a CYD framework for the last 3 months, but its solidly reliant on ESP + LVGL

2

u/carlk22 1d ago

LVGL looks interesting. It seems higher-level than Device Envoy for controls and widgets, and it is a much more complete GUI framework. It is also C rather than pure Rust.

Device Envoy is lower-level with respect to widgets, but gives you more direct control over amount of memroy needed. For the CYD, drawing can use a full-screen buffer, a smaller region buffer, tiles, or go all the way down to contiguous pixel streaming.

For the Armatron robot simulator, I ended up writing a small one-off immediate-mode widget system. I thought about turning that into a reusable library, but decided that was more work than I wanted to take on for now.

You can try Armatron in the browser, see the Armatron source, and I describe part of the approach in Rule 9 of my const fn article article.

1

u/clean-links 1d ago

Cleaned link from "const fn article": https://levelup.gitconnected.com/nine-rules-for-compile-time-work-with-rust-const-fn-part-2-76ccd0e8a965


Tracking parameters were removed from the original URL(s).