aboutsummaryrefslogtreecommitdiff
path: root/examples/rp2040_local_i2c_init/src
diff options
context:
space:
mode:
authorFinomnis <Finomnis@users.noreply.github.com>2024-04-11 00:00:38 +0200
committerGitHub <noreply@github.com>2024-04-10 22:00:38 +0000
commit8c23e178f3838bcdd13662a2ffefd39ec144e869 (patch)
treef2d2cefcd6bb2876e74ee6035b5489a4a2d9590f /examples/rp2040_local_i2c_init/src
parente4cc5fd17b8a2df332af0ee25c8bd7092e66afb0 (diff)
Monotonic rewrite (#874)
* 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 <henrik@tjaders.com>
Diffstat (limited to 'examples/rp2040_local_i2c_init/src')
-rw-r--r--examples/rp2040_local_i2c_init/src/main.rs50
1 files changed, 30 insertions, 20 deletions
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<Gpio2, gpio::FunctionI2C>,
- gpio::Pin<Gpio3, gpio::FunctionI2C>,
+ gpio::Pin<Gpio2, gpio::FunctionI2C, PullUp>,
+ gpio::Pin<Gpio3, gpio::FunctionI2C, PullUp>,
),
>;
@@ -37,7 +41,7 @@ mod app {
#[local]
struct Local {
- led: gpio::Pin<Gpio25, PushPullOutput>,
+ led: gpio::Pin<Gpio25, FunctionSioOutput, PullNone>,
i2c: &'static mut I2CBus,
}
@@ -48,11 +52,8 @@ mod app {
i2c_ctx: MaybeUninit<I2CBus> = 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::<PullNone>()
+ .into_push_pull_output();
led.set_low().unwrap();
// Init I2C pins
- let sda_pin = gpioa.gpio2.into_mode::<gpio::FunctionI2C>();
- let scl_pin = gpioa.gpio3.into_mode::<gpio::FunctionI2C>();
+ let sda_pin = gpioa
+ .gpio2
+ .into_pull_up_disabled()
+ .into_function::<gpio::FunctionI2C>();
+ let scl_pin = gpioa
+ .gpio3
+ .into_pull_up_disabled()
+ .into_function::<gpio::FunctionI2C>();
// 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;
}
}
}