Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update examples to RTIC v2
Browse files Browse the repository at this point in the history
The new framework has support for async tasks. It might be helpful for
demonstrating async drivers, or for users who are comparing RTIC's
latest documentation against our examples.

This is a minimal migration, and it's not trying to change any example's
behavior. Let me know if you notice something different.

Tested on a 1010EVK using the `_pit`, `_defmt_rtt`, and `_logging`
examples.  Also tested `_rtic_controller` on an 1170EVK, and
`_rtic_device` on a 1010EVK.
mciantyre committed May 27, 2024
1 parent d443eb1 commit 33e4eb2
Showing 17 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ codegen-units = 256
cortex-m = "0.7"
imxrt-rt = { workspace = true }
menu = "0.3.2"
cortex-m-rtic = "1.0"
rtic = { version = "2.0", features = ["thumbv7-backend"] }
log = "0.4"
defmt = "0.3"
pin-utils = "0.1"
5 changes: 3 additions & 2 deletions examples/rtic_defmt_rtt.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ mod app {
struct Shared {}

#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(cx: init::Context) -> (Shared, Local) {
let mut cortex_m = cx.core;
let (
board::Common {
@@ -50,7 +50,7 @@ mod app {
make_log.set_interrupt_enable(true);
make_log.enable();

(Shared {}, Local { led, make_log }, init::Monotonics())
(Shared {}, Local { led, make_log })
}

#[task(binds = BOARD_PIT, local = [led, make_log, counter: u32 = 0], priority = 1)]
@@ -59,6 +59,7 @@ mod app {
make_log,
led,
counter,
..
} = cx.local;

// Is it time for us to send a new log message?
4 changes: 2 additions & 2 deletions examples/rtic_dma_uart.rs
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ mod app {
}

#[init(local = [buf: [u8; 32] = [0; 32]])]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(cx: init::Context) -> (Shared, Local) {
let (
board::Common { mut dma, .. },
board::Specifics {
@@ -58,7 +58,6 @@ mod app {
buffer: cx.local.buf,
state: State::Receiving,
},
init::Monotonics(),
)
}

@@ -70,6 +69,7 @@ mod app {
state,
buffer,
console,
..
} = cx.local;

while channel.is_interrupt() {
4 changes: 2 additions & 2 deletions examples/rtic_gpio_input.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ mod app {
}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (_, _, pit, _),
@@ -40,7 +40,7 @@ mod app {
let delay = BlockingPit::from_pit(pit);
let button_port = ports.button_mut();
button_port.set_interrupt(&button, Some(Trigger::FallingEdge));
(Shared {}, Local { led, button, delay }, init::Monotonics())
(Shared {}, Local { led, button, delay })
}

#[task(binds = BOARD_BUTTON, local = [led, delay, button])]
4 changes: 2 additions & 2 deletions examples/rtic_gpt.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ mod app {
}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
board::Common {
mut gpt1, mut gpt2, ..
@@ -44,7 +44,7 @@ mod app {
init_gpt(&mut gpt2, GPT2_DELAY_MS);

gpt1.enable();
(Shared { led, gpt1, gpt2 }, Local {}, init::Monotonics())
(Shared { led, gpt1, gpt2 }, Local {})
}

#[task(binds = BOARD_GPT1, shared = [led, gpt1, gpt2])]
6 changes: 3 additions & 3 deletions examples/rtic_logging.rs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ mod app {
}

#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(cx: init::Context) -> (Shared, Local) {
let mut cortex_m = cx.core;
let (
board::Common {
@@ -112,7 +112,6 @@ mod app {
poll_log,
make_log,
},
init::Monotonics(),
)
}

@@ -141,7 +140,7 @@ mod app {

/// Actually performs the poll call.
#[task(shared = [poller], priority = 2)]
fn poll_logger(mut cx: poll_logger::Context) {
async fn poll_logger(mut cx: poll_logger::Context) {
cx.shared.poller.lock(|poller| poller.poll());
}

@@ -152,6 +151,7 @@ mod app {
make_log,
led,
counter,
..
} = cx.local;

// Is it time for us to poll the logger?
4 changes: 2 additions & 2 deletions examples/rtic_pit.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ mod app {
}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (_, _, mut pit, _),
@@ -30,7 +30,7 @@ mod app {
pit.set_interrupt_enable(true);
pit.set_load_timer_value(PIT_DELAY_MS);
pit.enable();
(Shared {}, Local { led, pit }, init::Monotonics())
(Shared {}, Local { led, pit })
}

#[task(binds = BOARD_PIT, local = [led, pit])]
4 changes: 2 additions & 2 deletions examples/rtic_pwm.rs
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ mod app {
}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
_,
board::Specifics {
@@ -54,7 +54,7 @@ mod app {
submodule.set_load_ok(&mut module);
submodule.set_running(&mut module, true);

(Shared {}, Local { led, submodule }, init::Monotonics())
(Shared {}, Local { led, submodule })
}

#[task(binds = BOARD_PWM, local = [led, submodule, counter: u32 = 0])]
6 changes: 3 additions & 3 deletions examples/rtic_spi.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ mod app {
struct Shared {}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (_, board::Specifics { mut spi, .. }) = board::new();
// Trigger when the TX FIFO is empty.
spi.set_watermark(Direction::Tx, 0);
@@ -32,12 +32,12 @@ mod app {
// Starts the I/O as soon as we're done initializing, since
// the TX FIFO is empty.
spi.set_interrupts(Interrupts::TRANSMIT_DATA);
(Shared {}, Local { spi }, init::Monotonics())
(Shared {}, Local { spi })
}

#[task(binds = BOARD_SPI, local = [spi])]
fn spi_interrupt(cx: spi_interrupt::Context) {
let spi_interrupt::LocalResources { spi } = cx.local;
let spi_interrupt::LocalResources { spi, .. } = cx.local;

let status = spi.status();
spi.clear_status(Status::TRANSMIT_DATA | Status::RECEIVE_DATA);
4 changes: 2 additions & 2 deletions examples/rtic_spi_blocking.rs
Original file line number Diff line number Diff line change
@@ -26,15 +26,15 @@ mod app {
struct Shared {}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (_, _, pit, _),
..
},
board::Specifics { spi, .. },
) = board::new();
(Shared {}, Local { spi, pit }, init::Monotonics())
(Shared {}, Local { spi, pit })
}

#[idle(local = [spi, pit])]
4 changes: 1 addition & 3 deletions examples/rtic_spi_controller.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ mod app {
}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (_, _, mut pit, _),
@@ -51,13 +51,11 @@ mod app {
pit.enable();

spi.set_bit_order(BIT_ORDER);

(
Shared {
errors: AtomicU32::new(0),
},
Local { spi, pit },
init::Monotonics(),
)
}

4 changes: 2 additions & 2 deletions examples/rtic_spi_device.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ mod app {
const BIT_ORDER: BitOrder = BitOrder::Msb;

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (_, board::Specifics { mut spi, .. }) = board::new();

spi.disabled(|spi| spi.set_device_enable(true));
@@ -48,7 +48,7 @@ mod app {
spi.set_watermark(Direction::Rx, 1);
spi.set_interrupts(Interrupts::RECEIVE_DATA);

(Shared {}, Local { spi }, init::Monotonics())
(Shared {}, Local { spi })
}

#[task(binds=BOARD_SPI, local = [spi])]
4 changes: 2 additions & 2 deletions examples/rtic_uart.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ mod app {
struct Shared {}

#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(_: init::Context) -> (Shared, Local) {
let (
_,
board::Specifics {
@@ -53,7 +53,7 @@ mod app {
// Interrupt when we receive a byte.
console.set_interrupts(lpuart::Interrupts::RECEIVE_FULL);
});
(Shared {}, Local { led, console }, init::Monotonics())
(Shared {}, Local { led, console })
}

#[task(binds = BOARD_CONSOLE, local = [led, console])]
4 changes: 2 additions & 2 deletions examples/rtic_usb_keypress.rs
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ mod app {
struct Shared {}

#[init(local = [bus: Option<UsbBusAllocator<Bus>> = None])]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(ctx: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (mut timer, _, _, _),
@@ -123,7 +123,6 @@ mod app {
timer,
message: MESSAGE.iter().cycle(),
},
init::Monotonics(),
)
}

@@ -144,6 +143,7 @@ mod app {
led,
configured,
message,
..
} = ctx.local;

device.poll(&mut [class]);
4 changes: 2 additions & 2 deletions examples/rtic_usb_mouse.rs
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ mod app {
struct Shared {}

#[init(local = [bus: Option<UsbBusAllocator<Bus>> = None])]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(ctx: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (mut timer, _, _, _),
@@ -117,7 +117,6 @@ mod app {
poller,
timer,
},
init::Monotonics(),
)
}

@@ -137,6 +136,7 @@ mod app {
device,
led,
configured,
..
} = ctx.local;

device.poll(&mut [class]);
4 changes: 2 additions & 2 deletions examples/rtic_usb_serial.rs
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ mod app {
struct Shared {}

#[init(local = [bus: Option<UsbBusAllocator<Bus>> = None])]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(ctx: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (mut timer, _, _, _),
@@ -119,7 +119,6 @@ mod app {
poller,
timer,
},
init::Monotonics(),
)
}

@@ -139,6 +138,7 @@ mod app {
device,
configured,
led,
..
} = ctx.local;

if device.poll(&mut [class]) {
4 changes: 2 additions & 2 deletions examples/rtic_usb_test_class.rs
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ mod app {
struct Shared {}

#[init(local = [bus: Option<UsbBusAllocator<Bus>> = None])]
fn init(ctx: init::Context) -> (Shared, Local, init::Monotonics) {
fn init(ctx: init::Context) -> (Shared, Local) {
let (
board::Common {
pit: (mut timer, _, _, _),
@@ -107,7 +107,6 @@ mod app {
poller,
timer,
},
init::Monotonics(),
)
}

@@ -126,6 +125,7 @@ mod app {
class,
device,
configured,
..
} = ctx.local;

if device.poll(&mut [class]) {

0 comments on commit 33e4eb2

Please sign in to comment.