Crate embassy_agb

Crate embassy_agb 

Source
Expand description

§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;
    }
}

Re-exports§

pub use embassy_time as time;
pub use embassy_futures as futures;
pub use embassy_sync as sync;
pub use agb;
pub use config::*;

Modules§

config
Configuration types for embassy-agb
display
Async display utilities Async display operations with VBlank support
input
Async input system with configurable timer-based polling
peripherals
GBA peripheral singletons
sound
Async sound utilities Sound mixing support for Game Boy Advance
utils
Utility functions and macros Utility functions and macros for embassy-agb

Macros§

rgb15
Macro to convert hex color codes (#RRGGBB) to GBA RGB15 format

Structs§

Duration
Represents the difference between two Instants
Executor
Embassy executor with automatic Halt mode when idle
FrameEvents
Frame events returned by GbaPeripherals::wait_frame()
GbaPeripherals
High-level peripheral wrapper with automatic frame handling
InitializedGba
The initialized GBA with embassy integration
Instant
An Instant in time, based on the MCU’s clock ticks since startup.
Peripherals
GBA Peripherals struct
Spawner
Handle to spawn tasks into an executor.
Ticker
Asynchronous stream that yields every Duration, indefinitely.
Timer
A future that completes at a specified Instant.

Functions§

enable_input_polling
Enable automatic input polling with the given polling rate.
init
Initialize the embassy-agb HAL with the given configuration.

Attribute Macros§

main
Main entry point for embassy-agb async applications
task
Task macro for embassy-agb