Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

SELF INTRODUCTION Name: Katsuhiko Kageyama X, Github ID: kishima Company: aptpod, Inc. Role: IoT edge device development, Engineering Manager Hobbies: electronics, mruby(PicoRuby)

Slide 3

Slide 3 text

AGENDA • 01 Background • 02 OS Software Design • 03 Technical Discussion • 03 Demonstration

Slide 4

Slide 4 text

01: Background

Slide 5

Slide 5 text

Why build a tiny OS •The joy of building under constraints •My childhood fascination with FAMILY BASIC •Inspired by PICO-8–style fantasy consoles •I want a real, physical ‘tiny PC’ built in Ruby picotron by Lexaloffle

Slide 6

Slide 6 text

Family mruby? • Self-contained mruby dev & runtime environment • Video output: VGA Input: PS/2 keyboard • Editor: built in C++ • Name inspired by Nintendo’s Family BASIC • First prototype built in 2019 • “Now is the time to create your own (m)Ruby computer” (RubyKaigiTakeout 2020)

Slide 7

Slide 7 text

02: OS Software Design

Slide 8

Slide 8 text

Concept ● Standalone dev & runtime environment ○ Built-in video/audio out and keyboard/mouse input ● Linux-free microcontroller as the target ○ Mostly for the romance of it ● The kind of thrill kids get from a new gadget ○ FAMILY BASIC — recreating what it gave us ● Multi-platform ○ Runs on Linux too; easy to port to other hardware later

Slide 9

Slide 9 text

Required Building Blocks • Multitasking • HW abstraction • Window manager • App lifecycle • Hardware

Slide 10

Slide 10 text

Required Building Blocks • Multitasking > FreeRTOS on ESP32 • HW abstraction > HAL(Hardware Abstraction Layer) in C • Window manager > PicoRuby code • App lifecycle > PicoRuby code • Hardware > custom board design

Slide 11

Slide 11 text

Things I Insisted On • Linux simulation • Design that doesn’t assume specific HW • Running guest languages (Lua, BASIC, MicroPython…)

Slide 12

Slide 12 text

Software architecture (real hardware)

Slide 13

Slide 13 text

Software architecture on Linux

Slide 14

Slide 14 text

Hardware(NaryaBoard) A two-ESP32 architecture Why: • ESP32S3 has no DAC • Rendering and audio are heavy; running them on the S3 would compete with PicoRuby workloads

Slide 15

Slide 15 text

Some of what I actually built ● PicoRuby-based OS features (process management, Window management, I/O management, etc.) ● PicoRuby-based GUI app framework ● UART-based 2-ESP32 inter-chip link ● Multi-platform execution (My board. M5Stack device, Linux) ● Various I/O: NTSC video out, line-level audio out, USB mouse, keyboard, gamepad input ● Multi-language support (PicoRuby / Lua / BASIC) ● Custom mini bytecode & VM ● for faster rendering. Various utilities (launcher, Shell, editor, task monitor, etc.) ● Custom board development ● And more …

Slide 16

Slide 16 text

03: Technical Discussion

Slide 17

Slide 17 text

Multi-VM Execution • FreeRTOS task ≒ thread • Runs with its own stack • Task switching at the machine-code level • Fine-grained priority management • Rich inter-task communication mechanisms • PicoRuby has its own internal task feature • mruby bytecode — task-switch granularity • Memory Partitioning • 1 VM going wild doesn’t spread to other VM / avoids leaks at shutdown Task A Task C Task B mruby VM mruby VM Lua VM Queues Task Notifications Semaphores Event Groups And so on…. Fmrb framework Fmrb framework Fmrb framework Mempool for Task A Mempool for Task B Mempool for Task C mruby- task mruby- task

Slide 18

Slide 18 text

Abstraction Layer • Hardware Abstraction Layer development • Hardware Proxy • GPIO, I2C, UART, RMT, File System APIs from ESP32 SDK — replaced with HAL APIs • Inter-core communication (UART-based link-layer implementation) • Time management • Other abstractions • FreeRTOS APIs (task management) • Memory management (memory pool allocation and TLSF memory allocation)

Slide 19

Slide 19 text

PicoRuby porting •mrbgem swaps • Machine • HAL — modified to use HAL; Tick management changed too • io, dir, filesystem • Stdio-related path fixes; Filesystem switched to LittleFS •Patches • Prism, compiler, env, require, sandbox, mruby-task etc.

Slide 20

Slide 20 text

Ruby GUI Application Framework • Event-driven framework • RTOS APIs let tasks wait on events without polling • Important for snappy key-press response • But it doesn’t play well with Task Tick processing — still debugging • Defined an FmrbGfx class for screen drawing — hides comms with the rendering ESP32

Slide 21

Slide 21 text

Inter VM communication • FreeRTOS queue + callbacks pass events between VMs •Keyboard, mouse, lifecycle control, etc. • Packed in a language-agnostic format with MessagePack (Proc can’t cross) • Cross-language between VMs (mruby Lua) communicates the same way

Slide 22

Slide 22 text

HID event flow ① ② ③ ④

Slide 23

Slide 23 text

Drawing command flow ① ② ④ ③

Slide 24

Slide 24 text

Drawing DSL and mini-VM • Most inter-core commands are drawing instructions • Built a drawing DSL, simple bytecode converter, and a mini VM for rendering • Window title bars, game object drawing, etc. all run the same logic each time, so they can be batched

Slide 25

Slide 25 text

Drawing DSL and mini-VM • Communication overhead drastically reduced

Slide 26

Slide 26 text

PC Simulation environment • Running on PC is essential for dev productivity • The same source code (almost untouched) builds and runs on Linux • Docker containers make it easy to try • Tech stack • ESP-IDF Linux build + SDL2 + LovyanGFX • 3-container Docker setup (ESP32S3 + ESP32 + SDL2)

Slide 27

Slide 27 text

04: Demonstration

Slide 28

Slide 28 text

Demo movie https://www.youtube.com/watch?v=9vkRaOoxJJI

Slide 29

Slide 29 text

DEMO on Linux simulator 1. Docker compose develop environment 2. One Docker container via noVNC

Slide 30

Slide 30 text

Demo Scenario 1: Dev Experience [ Simulator DEMO ] • Shell • Editor • HelloWorld

Slide 31

Slide 31 text

Demo Scenario 2: Multi-language VM [ Simulator demo ] • Launch an app written in Lua • Launch an app written in BASIC

Slide 32

Slide 32 text

On the board I built [ LIVE DEMO ] Narya board’s NTSC output to HDMI — converted and shown on screen

Slide 33

Slide 33 text

Demo Scenario 3: Sound [ LIVE DEMO ] • Open the piano app and play notes from the keyboard • Open NSF Player

Slide 34

Slide 34 text

Demo Scenario 4: Game [ LIVE DEMO ] •Run a Flappy Bird- style game •Run 3D game

Slide 35

Slide 35 text

Demo Scenario 5: Electronics [ Video ] • Open the mini keyboard app — input shows up in the GUI • Open the LED app — the LEDs wired to the computer light up in sync with the screen • Now touch the mini keyboard and the LEDs display the typed characters

Slide 36

Slide 36 text

Demo Scenario 5: How it works • VM communication used • I2C KBD app publish key event • LED Matrix app subscribe the event • RGB-LED driven by RMT Task A Task B I2C KBD app LED Matrix app Key Event (MessagePack) I2C Keyboad LED Matrix Read I2C Control LED RMT

Slide 37

Slide 37 text

Summary ● Built my own dev-anywhere device — OS and all — on top of PicoRuby ● Achieved performance usable on a microcontroller ● SW and HW are both open source — you’re free to hack on it ● https://github.com/family-mruby/family-mruby ● There are still many bugs and performance issues. ● I’ll be selling a small batch of the hardware on BOOTH — if you’re interested, scan the QR code on screen or check my X / blog ● Day 2 Afternoon break : I wiil perform demo in Ruby Showcase郭,

Slide 38

Slide 38 text

THANK YOU! https://silentworlds.booth.pm/