#hal #embedded-hal-driver #linux #driver #apu

apu_pcengines_hal

A safe wrapper around the direct memory interface of the APU2+ hardware

1 unstable release

0.1.0 Sep 22, 2020

#790 in Embedded development

41 downloads per month

MIT/Apache

14KB
263 lines

apu_pcengines_hal

A safe wrapper around the direct memory interface of the APU2+ hardware.

Installation

With cargo (or rustup) from git

sudo apt install build-essential
git clone https://gitlab.com/dns2utf8/apu_pcengines_hal.git
cargo build --release --example leds
sudo ./target/release/examples/leds

Download nightly from gitlab:

The CI builds the binary on the main branch on every commit. You can download the leds example program from https://dns2utf8.gitlab.io/apu_pcengines_hal/leds or use these commands:

wget https://dns2utf8.gitlab.io/apu_pcengines_hal/leds
sudo ./leds

lib.rs:

A safe wrapper around the direct memory interface of the APU2+ hardware.

This is a typesafe zero-cost abstraction over raw pointers. To adhere to rusts safety there are runtime checks and all pins must be returned with Mapping::free_pin

use apu_pcengines_hal::{MappingResult, APU_LED1, APU_LED2, APU_LED3};

fn main() -> MappingResult<()> {
    let mut map = apu_pcengines_hal::init()?;

    println!("init done: {:?}", map);

    let led2 = map.get_pin(APU_LED2)?;
    println!("led2: {:?}", led2);
    
    let mut led2 = led2.into_input();
    let val = led2.get();
    println!("led2: {:?} = {}", led2, val);
    
    let mut led2 = led2.into_output();
    println!("led2: {:?}", led2);
    led2.set(!val);
    
    map.free_pin(led2);
    Ok(())
}

Dependencies

~42KB