Lilka

Struct Lilka 

Source
pub struct Lilka {
    pub peripherals: Peripherals,
    pub delay: LilkaDelay,
    pub controller: ControllerState,
    pub adc_battery: Adcbattery<'static>,
    pub display: LilkaDisplay,
    pub sd: Option<SD<Bus<SdSpi<'static>, Output<'static>, SdClock>>>,
    pub i2s_tx: I2sTx<'static>,
    pub buzzer: Buzzer,
}
Expand description

The top-level handle to all Lilka console hardware subsystems.

Created by calling Lilka::init with a LilkaConfiguration. All fields are pub so you can borrow them independently in your game loop.

§Field overview

FieldTypePurpose
peripherals[esp_hal::peripherals::Peripherals]Raw peripheral singleton (already consumed during init; kept for future use).
delayLilkaDelayembedded-hal delay implementation — Delay for blocking, embassy_time::Delay for async.
controllerControllerStateD-pad + action buttons (A/B/C/D), Select, Start.
adc_batteryAdcbatteryBattery voltage ADC on GPIO3 via ADC1.
displayLilkaDisplay240×280 ST7789 TFT display via SPI2.
sdOption<SdVolMgr>SD card volume manager; None if no card was detected.
i2s_txI2sTxI2S transmitter for audio output (default 44 100 Hz stereo).
buzzerBuzzerPWM buzzer driven by the LEDC peripheral (GPIO11).

§Example — reading a button

use lilkaoxide::prelude::*;

// Buttons use pull-up resistors: low = pressed
if lilka.controller.a.is_low() {
    defmt::info!("A pressed!");
}

§Example — reading battery voltage

use lilkaoxide::prelude::*;

let mv = lilka.adc_battery.read_voltage_mv();
defmt::info!("Battery: {} mV", mv);

Fields§

§peripherals: Peripherals§delay: LilkaDelay§controller: ControllerState§adc_battery: Adcbattery<'static>§display: LilkaDisplay§sd: Option<SD<Bus<SdSpi<'static>, Output<'static>, SdClock>>>§i2s_tx: I2sTx<'static>§buzzer: Buzzer

Implementations§

Source§

impl Lilka

Source

pub fn init(config: Configuration) -> Result<Self, InitError>

Initialises all Lilka console hardware subsystems in a fixed order.

This is the only correct entry-point to the SDK. Call it once at the beginning of main (or your embassy task) with a Configuration and receive a fully-initialised Lilka handle.

§Initialisation order
  1. esp_hal::init — set CPU clock from config.cpu_clock.
  2. RtosRuntime::start — start embassy executor (async only).
  3. init_spi_master — SPI2 at config.spi_frequency (GPIO18 SCK, GPIO17 MOSI, GPIO8 MISO).
  4. init_bus — wrap the raw SPI bus in the selected sharing wrapper (RefCell / CriticalSection / …).
  5. display::init_display — ST7789 240×280 on GPIO46 (power), GPIO15 (DC), GPIO7 (CS).
  6. sd::init_sd — SD card on GPIO16 (CS), shared SPI bus.
  7. ControllerState::init_controller — GPIO5/6/10/9/38/41/39/40/0/4 pulled-up inputs.
  8. adcbattery::init_adcbattery — ADC1, GPIO3, configured attenuation.
  9. i2s::init_i2s_tx — I2S0 DMA TX on GPIO42 (BCLK), GPIO2 (DOUT), GPIO1 (LRCK).
  10. buzzer::init_buzzer — LEDC on GPIO11.

Steps 3–5, 9, and 10 are fatal: failure returns immediately via InitError. Step 6 (SD) is non-fatal: an absent or unreadable card sets Lilka::sd to None.

§Parameters
§Returns

Ok(Lilka) with all subsystems initialised, or Err(InitError) on the first fatal failure. Regardless of the outcome the init status is printed via defmt.

§Note on async vs blocking

The function signature is async fn but the deasync proc-macro generates a synchronous wrapper when the blocking feature is active. You call Lilka::init the same way in both modes — just omit .await in blocking code.

§Examples

Blocking (features = ["blocking", "RefCellBus", "display_buffer_8192"]):

#![no_std]
#![no_main]

use lilkaoxide::prelude::*;

#[esp_hal::entry]
fn main() -> ! {
    let lilka = Lilka::init(LilkaConfiguration::default())
        .expect("hardware init failed");

    defmt::info!("Display ready, battery: {} mV",
        // Note: need mut borrow for ADC reads
        // lilka.adc_battery.read_voltage_mv()
    );
    loop {}
}

Async (features = ["async", "AsyncBus", "display_buffer_8192"]):

#![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("hardware init failed");

    assert!(lilka.rtos.is_started());
}

Auto Trait Implementations§

§

impl Freeze for Lilka

§

impl !RefUnwindSafe for Lilka

§

impl !Send for Lilka

§

impl !Sync for Lilka

§

impl Unpin for Lilka

§

impl !UnwindSafe for Lilka

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.