Expand description
§lilkaoxide — Rust HAL SDK for the Lilka game console
no_std HAL built on top of [esp-hal] and [embedded-hal].
Supports both blocking and async (embassy) execution models via feature flags.
- Lilka console — https://docs.lilka.dev/
- LilkaOxide docs — https://rust.lilka.dev/
- Source code — https://gitlab.com/imbiruss/lilkaoxide
- crates.io — https://crates.io/crates/lilkaoxide
§Hardware (Lilka v2 — ESP32-S3-WROOM-N16R8)
| Peripheral | Controller / Interface | GPIOs |
|---|---|---|
| IPS TFT display 240×280 | ST7789 via SPI2 | SCK=18, MOSI=17, MISO=8, DC=15, CS=7, PWR=46 |
| SD card | SPI2 (shared) | CS=16 |
| Buttons (10) | GPIO pull-up, active-low | 0, 4, 5, 6, 9, 10, 38, 39, 40, 41 |
| Battery ADC | ADC1 CH2 | GPIO3 (100 kΩ / 33 kΩ divider) |
| Audio DAC (I2S) | I2S0 + DMA | BCLK=42, DOUT=2, LRCK=1 |
| Piezo buzzer | LEDC PWM | GPIO11 |
| Wi-Fi / BT | ESP32-S3 built-in | (feature radio) |
§Quick start
# Cargo.toml
[dependencies]
lilkaoxide = { version = "0.1", features = ["blocking", "RefCellBus", "display_buffer_8192"] }Blocking:
#![no_std]
#![no_main]
use lilkaoxide::prelude::*;
#[esp_hal::entry]
fn main() -> ! {
let mut lilka = Lilka::init(LilkaConfiguration::default())
.expect("init failed");
loop {
if lilka.controller.a.is_low() {
defmt::info!("Button A pressed");
}
let mv = lilka.adc_battery.read_voltage_mv();
if mv < 3_300 {
defmt::warn!("Low battery: {} mV", mv);
}
}
}Async (embassy):
#![no_std]
#![no_main]
use lilkaoxide::prelude::*;
#[embassy_executor::main]
async fn main(_spawner: embassy_executor::Spawner) {
let lilka = Lilka::init(LilkaConfiguration::default())
.await
.expect("init failed");
assert!(lilka.rtos.is_started());
}§Feature flags
| Feature | Description |
|---|---|
blocking | Blocking drivers. Mutually exclusive with async. |
async | Async drivers (embassy). Mutually exclusive with blocking. |
RefCellBus | Share SPI via RefCell. Single-core, no ISRs. blocking only. |
CriticalSectionBus | Share SPI via critical section. ISR-safe. blocking only. |
AtomicBus | Share SPI via atomic cell. blocking only. |
AsyncBus | Share SPI via async Mutex. Required with async. |
alloc | Global allocator (esp-alloc). |
radio | Wi-Fi / BLE (requires alloc). |
display_buffer_512 | SPI display DMA buffer: 512 B. |
display_buffer_1024 | SPI display DMA buffer: 1 024 B. |
display_buffer_8192 | SPI display DMA buffer: 8 192 B (default). |
Incompatible feature combinations are caught at compile time via [
compile_error!].
§Memory and lifetime rules
- Peripherals are single-owner resources — move each pin/peripheral exactly once into its driver.
- The shared SPI bus lives in a [
static_cell::StaticCell] — all bus references are'static. - DMA descriptors and buffers come from static storage (
dma_buffers!) — sizes must beconst. - Keep long-lived drivers (display, SD, I2S TX) inside
Lilkato preserve ownership and lifetimes. - In
asyncbuilds, never hold a borrowed stack reference across.await— keep data owned or'static. - Feature pairs are mutually exclusive:
blocking↔async,RefCellBus↔CriticalSectionBus↔AtomicBus↔AsyncBus.
Re-exports§
pub use defmt;pub use esp_hal as hal;pub use mipidsi;
Modules§
Structs§
- AdcCfg
- ADC channel configuration for the battery-monitoring pin (GPIO3 / ADC1).
- Adcbattery
- Battery voltage monitor using the ESP32-S3 ADC1 peripheral.
- Buzzer
- PWM buzzer driver backed by the ESP32-S3 LEDC peripheral.
- Buzzer
Config - Configuration for the on-board PWM buzzer (LEDC peripheral, GPIO11).
- Controller
State - State of all physical input buttons on the Lilka game console.
- I2sTx
Config - Configuration for the I2S0 transmitter.
- Lilka
- The top-level handle to all Lilka console hardware subsystems.
- Lilka
Configuration - Top-level configuration passed to
crate::Lilka::init.
Enums§
- Buzzer
Init Error - Error returned when the LEDC buzzer fails to initialise.
- Display
Init Error - Error returned when the ST7789 display fails to initialise.
- I2sInit
Error - Error returned when the I2S0 peripheral fails to initialise.
- Init
Error - Error returned by
Lilka::initif any subsystem fails to initialise. - SdInit
Error - Error returned when the SD card fails to initialise.
- SpiInit
Error - Error returned by SPI bus or device initialisation functions.
Functions§
- init_
bus - Places the raw SPI bus into a
'staticshared wrapper and returns a'staticreference to it. - init_
spi_ master - Initialises the ESP32-S3 SPI2 master bus at the requested frequency.
Type Aliases§
- I2sTx
- Alias for the I2S transmitter handle, parameterised by the blocking/async drive mode.
- Lilka
Delay - The delay type used by the SPI bus sharing wrappers.
- Lilka
Display - Type alias for the Lilka display handle.
- Lilka
SpiBus - The raw SPI2 master bus type. Lifetime is
'staticbecause it lives in a [StaticCell] afterinit_busis called. - SdVol
Mgr - Type alias for the SD volume manager (same as [
SDC]). - SpiBus
Wrapper - Shared SPI bus wrapper type, selected by the active bus-sharing feature.
- SpiDev
- A virtual SPI device (chip-select + delay) created from a shared
SpiBusWrapper.