Mousefood Brings Terminal UI to Embedded Displays with Ratatui Backend
#Hardware

Mousefood Brings Terminal UI to Embedded Displays with Ratatui Backend

AI & ML Reporter
4 min read

Mousefood provides a no-std embedded-graphics backend for Ratatui, enabling terminal-style interfaces on embedded displays with support for special characters, bold/italic fonts, and color themes.

The embedded-graphics ecosystem has gained a powerful new tool with the release of Mousefood, a no-std backend that brings Ratatui's terminal UI capabilities to embedded displays. This innovative library bridges the gap between sophisticated terminal interfaces and resource-constrained embedded systems, opening up new possibilities for device interfaces.

What Mousefood Enables

At its core, Mousefood allows developers to use Ratatui's rich widget system on embedded displays. Ratatui, known for its terminal interface capabilities, provides a wide array of widgets including blocks, paragraphs, lists, and more. With Mousefood, these same widgets can now be rendered on physical displays like ILI9341, ST7735, SSD1306, and various e-ink displays.

Featured image

The library handles the complex task of translating Ratatui's terminal-oriented drawing commands into pixel-based rendering suitable for embedded displays. This means developers can design interfaces using familiar terminal UI patterns while targeting hardware displays.

Special Character Support

One of Mousefood's standout features is its handling of special characters. Embedded-graphics typically uses bitmap fonts with limited character sets to conserve space, which poses a problem for Ratatui's interface elements that rely heavily on box-drawing glyphs, Braille characters, and other special symbols.

Mousefood addresses this by defaulting to embedded-graphics-unicodefonts, which provides fonts with a much larger character set. This ensures that Ratatui's widgets render correctly with all their intended visual elements intact.

For developers concerned about memory usage, Mousefood offers flexibility. The fonts feature can be disabled to save space, with ibm437 as an alternative that includes some drawing characters though with a smaller character set than the Unicode fonts.

Font Styling and Color Themes

Mousefood supports bold and italic font modifiers through the EmbeddedBackendConfig. Developers can provide separate fonts for regular, bold, and italic styles, with regular fonts serving as fallbacks when specific styles aren't available. All fonts must be the same size, ensuring consistent rendering.

Color customization is equally flexible. The color_theme option in EmbeddedBackendConfig allows complete remapping of the ANSI palette. While the default uses standard ANSI colors, developers can define custom themes to match their application's aesthetic or improve visibility on specific display types.

Mousefood includes several built-in themes, including the standard ANSI palette and the popular Tokyo Night theme with its distinctive blue and purple tones.

Development and Testing Tools

For development and testing, Mousefood integrates with the embedded-graphics-simulator crate. This allows developers to run and test their interfaces on a computer before deploying to actual hardware. The simulator example in the repository demonstrates this capability, making iterative development much more convenient.

E-Paper Display Support

The library includes specialized support for e-paper displays (EPDs) from both WeAct Studio and Waveshare Electronics. These displays present unique challenges due to their refresh characteristics and often require specific configuration patterns. Mousefood provides examples and guidance for setting up these displays, including the necessary flush callback patterns for proper operation.

Performance Considerations

Developers should be aware of several performance and memory considerations when using Mousefood. Flash memory on embedded devices is typically very limited, and the fonts feature can significantly increase binary size. For optimal frame rates, the library recommends using opt-level = 3 during compilation, though this further increases the binary size.

The library is designed to be hardware-agnostic and has been successfully tested on various platforms including ESP32 (Xtensa architecture), ESP32-C6 (RISC-V), STM32, RP2040, and RP2350.

Getting Started

Setting up Mousefood is straightforward. Developers add it as a dependency via Cargo and create an EmbeddedBackend instance with their display driver. The library provides a mock display for testing and includes comprehensive documentation on docs.rs.

Real-World Applications

Several projects are already leveraging Mousefood's capabilities. Tuitar provides a portable guitar training tool with a graphical interface, Mnyaoo32 offers an eccentric way to consume IRC messages using ESP32, and Phone-OS represents a modern phone operating system for ESP32 CYD. These examples demonstrate the library's versatility across different application domains.

Conclusion

Mousefood represents a significant advancement in embedded UI development by bringing sophisticated terminal interface capabilities to resource-constrained devices. Its thoughtful handling of special characters, flexible font and color options, and support for various display types make it a valuable tool for developers building interfaces for embedded systems.

With its dual licensing under Apache 2.0 and MIT terms, Mousefood is positioned to become a go-to solution for embedded UI development, enabling richer, more user-friendly interfaces on devices where such capabilities were previously difficult or impossible to achieve.

Comments

Loading comments...