Firmware of Stack-chan ● Two types of existing Stack-chan firmwares ○ Written in Arduino ■ Most famous one is AI stack-chan firmware authored by @robo8080 san ■ https://github.com/robo8080/M5Unified_StackChan_ChatGPT ○ Written in TypeScript for Moddable ■ Authored by ししかわ san (also known as the author of Stack-chan itself) ● There doesn't seem to be any firmware written in MicroPython/UI Flow. ○ If you have any information, please let me know.
Main function of Stack-chan firmware ● Shows “kawaii” face on the display of M5Stack. ○ M5Stack-Avatar (by ししかわさん) is mainly used to implement this. ○ Some variants of M5Stack-Avatar are also available. ○ Moddable firmware implements refit version of M5Stack-Avatar ● Controls servo motors forj panning and tilt. ○ ServoEasing Arduino library. ○ Moddable firmware also implements easing? (I don’t know about it) ● Wireless communications, etc…
Platforms/Languages for ESP32 (1/2) ● Official platform from Espressif is ESP-IDF ○ Mainly written in C. some part (e.g. NVS driver) is written in C++. ○ User code can be written in both C, C++. ● Arduino core for the ESP32 ○ Arduino core for ESP32 series. ○ Based heavily on ESP-IDF ○ User code: Arduino language (C++) ● MicroPython ○ Python interpreter optimized for embedded systems. ○ Based on Python 3.6 language spec + some extensions.
Platforms/Languages for ESP32 (2/2) ● Moddable ○ ECMA Script compiler for embedded systems. ○ User can use TypeScript compiler to generate ECMA Script run on Moddable. ● TinyGo ○ Go language compiler for embedded systems. ○ You can use powerful Go language multithreading feature like goroutines and channels on embedded systems. ● Rust ← New! ○ Zero cost, memory safe language, used mainly at desktop and server. ○ Can generate binaries for embedded systems.
The Rust Language ● “A language empowering everyone to build reliable and efficient software.” (https://www.rust-lang.org/) ○ Zero cost abstractions ○ Memory safety without GC ○ Powerful package manager and build system (cargo) ● Rust applications for embedded systems are increasing. ○ Linux kernel module ○ Microsoft also uses Rust for writing kernel of their OS. ● Espressif is also actively working on creating a development environment for Rust.
Rust Platforms for ESP32 ● There are 2 options available. ● Using esp-idf-sys and write application for ESP-IDF in Rust. ○ On this platform, you can use ESP-IDF functionality from Rust. ○ You can also use FreeRTOS functionality via Rust threading library. ● Using esp-hal and write bare-metal application in Rust. ← I used this. ○ No ESP-IDF dependency. ○ You can get very compact firmware and less compilation time. ○ You CANNOT use rich ESP-IDF functionality at all. ○ WiFi and BLE communications are currently experimental.
Writing Stack-chan firmware in Rust ● I've started writing Stach-chan’s firmware in Rust. ● There is a lot of functions to implement. ○ Showing “kawaii” face. ○ Controlling servo motors. ○ M5Stack Core2 platform support ← !!!!
Showing “kawaii” face with Rust ● I’ve ported M5Stack-Avatar for Rust graphics library. ○ M5Stack-Avatar uses FreeRTOS functions, which does not exist in baremetal ESP32. ○ The structure of M5Stack-Avatar works well with embedded-graphics. ■ Defining shapes, then draw to the display. ○ Around 3 days to port the minimal functionality.
Controlling servo motors ● Implementing easing function by Rust. ○ Ported from Wio Terminal-chan’s firmware. (which is also written in Rust) ● Implementing PWM output driver. ○ esp-hal crate has MCPWM peripheral driver. so all I need to do is just call it.
M5Stack Core2 platform support (1/2) ● Power management IC (AXP192) driver ○ Core2 uses AXP192 to control its power source. ○ In order to configure powers for peripherals, AXP192 must be initialized correctly. ■ Peripherals, LCD backlights, etc… ○ I have experience implementing M5StickC AXP192 driver for ESP-IDF in C++. ○ I’ve ported this driver and M5Stack official driver for Core2 to Rust.
M5Stack Core2 platform support (2/2) ● LCD (ILI9342) driver ○ Core2 uses ILI9342 LCD controller. ○ There is existing library, “ili9341” crate in crates.io, but it is a bit old and do not compatible with current embedded-hal crate. ○ I’ve ported my ILI9341 library I wrote a few years ago to latest environment.