Expand description
Portable display and touch interfaces for Cheap Yellow Display (CYD) applications.
The Cyd trait represents a ready-to-use device with a display and
calibrated touch input. Hardware, browser, and in-memory devices all provide
the same Cyd, CydDisplay, CydTouch, and
CydFrame interfaces.
§Portable CYD abstraction
CydEsp / CydRp / CydWasm / CydMemory
│ implement
▼
Cyd
┌───────┴───────┐
parts().0 parts().1
CydDisplay CydTouch
│ │
frame_mut() try_read()
▼ ▼
CydFrame TouchEvent
borrowed frame calibrated + orientedCyd::parts borrows the display and touch components together.
CydDisplay::frame_mut returns a temporary borrowed frame for a display
region, while CydTouch::try_read returns already calibrated and oriented
events. A full-screen frame is the special case where the borrowed region is
the complete display.
Touch-event coordinates and drawing coordinates use the same logical orientation. Do not rotate touch points again.
§See CYD in action
Linkage Blaze demonstrates animated clocks, mechanisms, and figures built with Device Envoy’s portable CYD display APIs. Explore the examples in the interactive Linkage Blaze gallery.
§Application example
Startup code constructs the appropriate CYD device. Application code can then read calibrated touch input and draw without naming a platform-specific type:
use device_envoy_core::cyd::{
Cyd, CydDisplay, CydTouch,
display::{CydFrame, DrawItem},
touch::TouchEvent,
};
use embedded_graphics::pixelcolor::{Rgb888, RgbColor};
async fn draw_once<C: Cyd>(cyd: &mut C) -> Result<(), C::Error> {
let (display, touch) = cyd.parts();
let touch_event = touch.try_read()?;
let mut frame = display.full_frame_mut();
frame.write_text("Hello CYD");
if let Some(TouchEvent::Down { point } | TouchEvent::Move { point }) =
touch_event
{
DrawItem::Circle {
center: (point.x as f32, point.y as f32),
pixel_radius: 24.0,
color: Rgb888::RED,
}
.draw(&mut frame);
}
frame.flush().await
}An application would normally call draw_once repeatedly as part of its event
or frame loop.
§Choose a drawing strategy
The example uses a full-screen buffered frame, the simplest and most flexible
option but also the one that requires the most memory. Start with
CydDisplay::full_frame_mut when a full-screen buffer is practical.
CydDisplay supports four general drawing strategies:
- Full-screen buffering: Use
CydDisplay::full_frame_mutto draw the complete display into one buffer before flushing it. This is the simplest and most flexible approach, but it requires one RGB565 value for every screen pixel. - Regional buffering: Use
CydDisplay::frame_mutto draw graphics or text into a smaller rectangular buffer and flush it to any chosen region of the screen. Successive calls can reuse the same storage with different positions, widths, and heights, provided each rectangle fits the buffer’s pixel capacity. - Tiled drawing: Use
CydDisplay::for_each_tileto redraw the scene one small tile at a time when a larger buffer would use too much memory. This requires only one tile-sized buffer. - Contiguous streaming: Use
CydDisplay::fill_contiguousorCydDisplay::fill_contiguous_fullto generate or supply row-major RGB565 pixels as the display consumes them. This needs no reusable pixel frame buffer and is useful whenever each pixel can be computed quickly from its screen coordinates, including simple geometric shapes, procedural graphics, and existing bitmap data.
Small heterogeneous scenes can instead be streamed with
CydDisplay::draw_items, which also needs no reusable pixel frame buffer. See
the CydDisplay documentation for the compact storage table,
immediate-drawing capacity rule, and coordinate conventions.
§Implementations
Modules§
- display
- Display-only data, asset, and drawing plumbing for the CYD’s
cyddevice abstraction. - touch
- Touch-side support types for the CYD’s
cyddevice abstraction.
Constants§
- SCREEN_
PIXELS - Total panel pixel count (
SCREEN_WIDTH * SCREEN_HEIGHT= 320 * 240 = 76,800).
Traits§
- Cyd
- A ready-to-use CYD device with display and calibrated touch components.
- CydDisplay
- A CYD display.
- CydTouch
- A CYD touch source that returns calibrated, oriented touch events in logical display coordinates.