From 8c23e178f3838bcdd13662a2ffefd39ec144e869 Mon Sep 17 00:00:00 2001 From: Finomnis Date: Thu, 11 Apr 2024 00:00:38 +0200 Subject: Monotonic rewrite (#874) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Rework timer_queue and monotonic architecture Goals: * make Monotonic purely internal * make Monotonic purely tick passed, no fugit involved * create a wrapper struct in the user's code via a macro that then converts the "now" from the tick based monotonic to a fugit based timestamp We need to proxy the delay functions of the timer queue anyway, so we could simply perform the conversion in those proxy functions. * Update cargo.lock * Update readme of rtic-time * CI: ESP32: Redact esp_image: Too volatile * Fixup: Changelog double entry rebase mistake --------- Co-authored-by: Henrik Tjäder --- examples/rp2040_local_i2c_init/src/main.rs | 50 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'examples/rp2040_local_i2c_init/src') diff --git a/examples/rp2040_local_i2c_init/src/main.rs b/examples/rp2040_local_i2c_init/src/main.rs index 97049dc..799376c 100644 --- a/examples/rp2040_local_i2c_init/src/main.rs +++ b/examples/rp2040_local_i2c_init/src/main.rs @@ -1,15 +1,21 @@ #![no_std] #![no_main] -#[rtic::app( - device = rp_pico::hal::pac, - dispatchers = [TIMER_IRQ_1] -)] +use rtic_monotonics::rp2040::prelude::*; + +rp2040_timer_monotonic!(Mono); + +#[rtic::app(device = rp_pico::hal::pac)] mod app { + use super::*; + use rp_pico::hal::{ - clocks, gpio, - gpio::pin::bank0::{Gpio2, Gpio25, Gpio3}, - gpio::pin::PushPullOutput, + clocks, + gpio::{ + self, + bank0::{Gpio2, Gpio25, Gpio3}, + FunctionSioOutput, PullNone, PullUp, + }, pac, sio::Sio, watchdog::Watchdog, @@ -20,15 +26,13 @@ mod app { use core::mem::MaybeUninit; use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin}; use fugit::RateExtU32; - use rtic_monotonics::rp2040::*; - use panic_probe as _; type I2CBus = I2C< pac::I2C1, ( - gpio::Pin, - gpio::Pin, + gpio::Pin, + gpio::Pin, ), >; @@ -37,7 +41,7 @@ mod app { #[local] struct Local { - led: gpio::Pin, + led: gpio::Pin, i2c: &'static mut I2CBus, } @@ -48,11 +52,8 @@ mod app { i2c_ctx: MaybeUninit = MaybeUninit::uninit() ])] fn init(mut ctx: init::Context) -> (Shared, Local) { - // Initialize the interrupt for the RP2040 timer and obtain the token - // proving that we have. - let rp2040_timer_token = rtic_monotonics::create_rp2040_monotonic_token!(); // Configure the clocks, watchdog - The default is to generate a 125 MHz system clock - Timer::start(ctx.device.TIMER, &mut ctx.device.RESETS, rp2040_timer_token); // default rp2040 clock-rate is 125MHz + Mono::start(ctx.device.TIMER, &mut ctx.device.RESETS); // default rp2040 clock-rate is 125MHz let mut watchdog = Watchdog::new(ctx.device.WATCHDOG); let clocks = clocks::init_clocks_and_plls( XOSC_CRYSTAL_FREQ, @@ -74,12 +75,21 @@ mod app { sio.gpio_bank0, &mut ctx.device.RESETS, ); - let mut led = gpioa.led.into_push_pull_output(); + let mut led = gpioa + .led + .into_pull_type::() + .into_push_pull_output(); led.set_low().unwrap(); // Init I2C pins - let sda_pin = gpioa.gpio2.into_mode::(); - let scl_pin = gpioa.gpio3.into_mode::(); + let sda_pin = gpioa + .gpio2 + .into_pull_up_disabled() + .into_function::(); + let scl_pin = gpioa + .gpio3 + .into_pull_up_disabled() + .into_function::(); // Init I2C itself, using MaybeUninit to overwrite the previously // uninitialized i2c_ctx variable without dropping its value @@ -118,7 +128,7 @@ mod app { // now to do something with it! // Delay for 1 second - Timer::delay(1000.millis()).await; + Mono::delay(1000.millis()).await; } } } -- cgit v1.2.3