embassy-agb 0.1.0

Embassy async support for Game Boy Advance development with agb
Documentation

Embassy async support for agb

This crate provides async/await support for Game Boy Advance development using the embassy executor. It integrates with the existing agb library to provide async APIs for display, input, sound, and timing.

Features

  • Async display operations (VBlank waiting, DMA transfers)
  • Async input handling (button press events) with automatic polling
  • Async sound mixing
  • Embassy time integration with GBA timers
  • Task spawning and management
  • Automatic power management via Halt mode

Example

#![no_std]
#![no_main]

use embassy_agb::Spawner;
use embassy_agb::agb::sound::mixer::Frequency;
use agb::include_wav;

static JUMP: agb::sound::mixer::SoundData = include_wav!("jump.wav");

#[embassy_agb::main]
async fn main(_spawner: Spawner) -> ! {
    let mut gba = embassy_agb::init(Default::default());
    
    // Get peripherals with convenient frame handling
    let mut peripherals = gba.peripherals(Frequency::Hz10512);
    
    loop {
        // wait_frame() returns events that occurred during the frame
        let events = peripherals.wait_frame().await;
        
        // Check button events from the frame context
        if events.is_pressed(agb::input::Button::A) {
            peripherals.play_sound(&JUMP);
        }
        
        // Or access peripherals directly for continuous state
        if peripherals.input.is_pressed(agb::input::Button::LEFT) {
            // Move left...
        }
        
        // Use frame counter for animations
        let animation_frame = (events.frame_count / 8) as usize;
    }
}