bouffalolab / bl-pac

Embedded Rust Peripheral Access Crate for Bouffalo chips
Mulan Permissive Software License, Version 2
43 stars 4 forks source link

doesn't satisfy `Peripherals: Iterator` #4

Open wsndshx opened 1 year ago

wsndshx commented 1 year ago

在尝试获取外设的时候提示错误

`Peripherals` is not an iterator
the following trait bounds were not satisfied:
`Peripherals: Iterator`
which is required by `&mut Peripherals: Iterator`

下面是我使用的代码

#![no_std]
#![no_main]

use panic_halt as _;
use bl616_pac::Peripherals;

use riscv_rt::entry;

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take().unwrap();

    loop {

    }
}
wsndshx commented 1 year ago

虽然不知是否为正确用法,但目前使用以下的方式获取外设

#![no_std]
#![no_main]

use panic_halt as _;
use bl616_pac::Peripherals;

use riscv_rt::entry;

// get_peripherals 获取外设
fn get_peripherals() -> Peripherals {
    unsafe {
        Peripherals::steal()
    }
}

#[entry]
fn main() -> ! {
    let peripherals = get_peripherals();
    loop {
    }
}