Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example without Embassy dependency #4

Open
murraytodd opened this issue Jun 7, 2024 · 6 comments
Open

Example without Embassy dependency #4

murraytodd opened this issue Jun 7, 2024 · 6 comments

Comments

@murraytodd
Copy link

Hi, I'm trying to follow the example to use the driver, but the initialization depends on the embassy_time's definition of a Delay trait. It would be nice to see how to do it with the lower-level embedded-hal API.

@JadKHaddad
Copy link
Owner

JadKHaddad commented Jun 7, 2024

Hi, I am going to assume that you are talking about the blue-pill example since it showcases the blocking functionality of the driver and uses embassy.

The driver relies on the HAL's specific implementation of the embedded-hal-1.0.0 Traits (DelayNs and I2c). In this case, stm32. At the time of creating the examples, cortex-m did not support embedded-hal-1.0.0 but only embedded-hal-0.2.*. embassy_stm32, on the other hand, did support embedded-hal-1.0.0, and that's why I included it in the examples.

Nonetheless, I'm going to check again if cortex-m has implemented support for embedded-hal-1.0.0 and update the examples accordingly.

issue

@murraytodd
Copy link
Author

It's both of the examples. Essentially, I'm writing a fairly simple rp2040-hal example to start with (using the rp-pico BSP) and I'm trying to follow your example for instantiating the driver via the UninitBMP180 builder. I'm good with creating and passing the i2c device, but for the Delay timer I don't know what to create and pass through.

@JadKHaddad
Copy link
Owner

have you tried?

#![no_std]
#![no_main]

use panic_halt as _;
use rp2040_hal::pac;

#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;

const XTAL_FREQ_HZ: u32 = 12_000_000u32;

#[rp2040_hal::entry]
fn main() -> ! {
    let mut pac = pac::Peripherals::take().unwrap();
    let mut watchdog = rp2040_hal::Watchdog::new(pac.WATCHDOG);
    let clocks = rp2040_hal::clocks::init_clocks_and_plls(
        XTAL_FREQ_HZ,
        pac.XOSC,
        pac.CLOCKS,
        pac.PLL_SYS,
        pac.PLL_USB,
        &mut pac.RESETS,
        &mut watchdog,
    )
    .unwrap();

    let timer = rp2040_hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);

    loop {}
}

@murraytodd
Copy link
Author

Thanks for your help. I see now, it's a matter that rp2040-hal actually hasn't completed its implementation. In their timer.rs code, there's a comment "There is no Embedded HAL 1.0 equivalent at this time. If all you need is a delay, Timer does implement embedded_hal::delay::DelayNs."

Thanks. I really appreciate your taking the time to help give me some more breadcrumbs to follow.

@murraytodd
Copy link
Author

I got it figured out. Your advice was correct, but I had included the async::UninitBMP180Builder instead of the blocking::UninitBMP180Builder. Since rp2040-hal did implement the embedded_hal::delay::DelayNs trait, it was indeed sufficient for our needs. Thanks again for the help.

@JadKHaddad
Copy link
Owner

Glad to hear that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants