Skip to content

Commit d4dbf80

Browse files
committed
Adopt new dependencies, Rust 2024
Drivers have dropped their type states, so we do the same. Without the type states, we don't need the aliases anymore. Given the LPSPI change, we have to manually configure the hardware chip select. I'm doing that directly in the example.
1 parent c339e6b commit d4dbf80

23 files changed

Lines changed: 176 additions & 272 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
## Unreleased
44

5+
**BREAKING** Adopt new imxrt-rs dependencies, including
6+
7+
- imxrt-hal 0.6
8+
- imxrt-iomuxc 0.3
9+
- imxrt-ral 0.6
10+
11+
Adoption changes the representation of drivers. See the imxrt-hal changelog for
12+
more information.
13+
14+
**BREAKING** Adopt Rust 2024 throghout all packages.
15+
516
Add USDHC1 clock configuration and expose the USDHC1 peripheral instance in
617
board resources. The BSP configures the USDHC1 root clock and publishes the
718
frequency as `USDHC1_FREQUENCY`. Pin muxing and driver initialization are left

Cargo.toml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "teensy4-bsp"
3-
version = "0.5.2"
3+
version = "0.6.0"
44
authors.workspace = true
55
edition.workspace = true
66
license.workspace = true
@@ -15,7 +15,7 @@ autoexamples = false
1515

1616
[workspace.package]
1717
authors = ["Ian McIntyre <ianpmcintyre@gmail.com>"]
18-
edition = "2021"
18+
edition = "2024"
1919
license = "MIT OR Apache-2.0"
2020
repository = "https://github.com/mciantyre/teensy4-rs"
2121
categories = [
@@ -35,7 +35,7 @@ features = ["critical-section-single-core"]
3535

3636
[dependencies.teensy4-fcb]
3737
path = "teensy4-fcb"
38-
version = "0.4"
38+
version = "0.5"
3939

4040
[dependencies.imxrt-ral]
4141
workspace = true
@@ -52,7 +52,7 @@ workspace = true
5252
optional = true
5353

5454
[dependencies.teensy4-pins]
55-
version = "0.3.1"
55+
version = "0.4"
5656
path = "teensy4-pins"
5757

5858
[workspace]
@@ -64,11 +64,11 @@ members = [
6464
]
6565

6666
[workspace.dependencies]
67-
imxrt-boot-gen = { version = "0.3.0", features = ["imxrt1060"] }
68-
imxrt-hal = { version = "0.5.3", features = ["imxrt1060"] }
69-
imxrt-iomuxc = { version = "0.2.0", features = ["imxrt1060"] }
70-
imxrt-log = { version = "0.1" }
71-
imxrt-ral = { version = "0.5", features = ["imxrt1062"] }
67+
imxrt-boot-gen = { version = "0.4.0" }
68+
imxrt-hal = { version = "0.6.0", features = ["imxrt1060"] }
69+
imxrt-iomuxc = { version = "0.3.0", features = ["imxrt1060"] }
70+
imxrt-log = { version = "0.2.0", default-features = false }
71+
imxrt-ral = { version = "0.6.0", features = ["imxrt1062"] }
7272
imxrt-rt = { version = "0.1.4", features = ["device"] }
7373

7474
[features]
@@ -88,21 +88,21 @@ rustdoc-args = ["--cfg", "docsrs"]
8888
default-target = "thumbv7em-none-eabihf"
8989

9090
[dev-dependencies.teensy4-panic]
91-
version = "0.2"
91+
version = "0.3"
9292
path = "teensy4-panic"
9393
features = ["log"]
9494

9595
[dev-dependencies]
96-
defmt = "0.3"
96+
defmt = "1.0"
9797
defmt-bbq = "0.1"
9898
embedded-hal = "0.2"
99-
imxrt-log = { workspace = true, default-features = false, features = ["usbd", "log"] }
99+
imxrt-log = { workspace = true, features = ["usbd", "log"] }
100100
log = "0.4"
101101
nb = "1"
102102
rtic = { version = "2", features = ["thumbv7-backend"] }
103103
rtic-monotonics = { version = "1", default-features = false, features = ["cortex-m-systick"] }
104-
usb-device = "0.2"
105-
usbd-serial = "0.1"
104+
usb-device = "0.3"
105+
usbd-serial = "0.2"
106106

107107
[[example]]
108108
name = "blocking_gpt"
@@ -151,3 +151,9 @@ required-features = ["rt"]
151151
[[example]]
152152
name = "rtic_usb_log"
153153
required-features = ["rt"]
154+
155+
[patch.crates-io.imxrt-hal]
156+
git = "https://github.com/mciantyre/imxrt-hal"
157+
158+
[patch.crates-io.imxrt-log]
159+
git = "https://github.com/mciantyre/imxrt-hal"

examples/blocking_gpt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const GPT_DIVIDER: u32 = 8;
2222
/// ...the GPT frequency is
2323
const GPT_FREQUENCY: u32 = board::PERCLK_FREQUENCY / GPT_DIVIDER;
2424

25-
fn init_gpt<const N: u8>(gpt: &mut gpt::Gpt<N>) {
25+
fn init_gpt(gpt: &mut gpt::Gpt) {
2626
gpt.set_clock_source(GPT_CLOCK_SOURCE);
2727
gpt.set_divider(GPT_DIVIDER);
2828
}

examples/blocking_pit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ fn main() -> ! {
2121
..
2222
} = board::t40(board::instances());
2323
let led = board::led(&mut gpio2, pins.p13);
24-
let mut delay = Blocking::<_, { board::PERCLK_FREQUENCY }>::from_pit(pit.0);
24+
let mut delay =
25+
Blocking::<_, { board::PERCLK_FREQUENCY }>::from_pit(pit, bsp::hal::pit::Channel::Chan0);
2526
loop {
2627
delay.block_ms(500);
2728
led.toggle();

examples/blocking_uart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn main() -> ! {
3030
} = board::t40(board::instances());
3131
let led = board::led(&mut gpio2, pins.p13);
3232

33-
let mut lpuart2: board::Lpuart2 = board::lpuart(lpuart2, pins.p14, pins.p15, 115200);
33+
let mut lpuart2: board::Lpuart = board::lpuart(lpuart2, pins.p14, pins.p15, 115200);
3434
loop {
3535
led.toggle();
3636
let byte = nb::block!(lpuart2.read()).unwrap();

examples/rtic_configure_pin.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,10 @@ use teensy4_panic as _;
1010
#[rtic::app(device = teensy4_bsp, peripherals = true)]
1111
mod app {
1212
use bsp::board;
13-
use bsp::{
14-
hal::{gpio, iomuxc},
15-
pins,
16-
};
13+
use bsp::hal::{gpio, iomuxc};
1714
use teensy4_bsp as bsp;
1815

19-
type Input = gpio::Input<pins::t40::P7>;
16+
type Input = gpio::Input;
2017

2118
const PIN_CONFIG: iomuxc::Config =
2219
iomuxc::Config::zero().set_pull_keeper(Some(iomuxc::PullKeeper::Pulldown100k));
@@ -40,7 +37,7 @@ mod app {
4037
let led = board::led(&mut gpio2, pins.p13);
4138

4239
iomuxc::configure(&mut pins.p7, PIN_CONFIG);
43-
let input = gpio2.input(pins.p7);
40+
let input = gpio2.input(pins.p7).expect("P7 is a GPIO2 pin");
4441

4542
(Shared {}, Local { led, input })
4643
}

examples/rtic_defmt_usb_log.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,16 @@ mod app {
4949
use bsp::{
5050
board,
5151
hal::usbd::{
52-
gpt::{Instance::Gpt0, Mode},
5352
BusAdapter, EndpointMemory, EndpointState, Speed,
53+
gpt::{Instance::Gpt0, Mode},
5454
},
5555
};
5656
use teensy4_bsp as bsp;
5757

5858
use usb_device::{
59+
LangID,
5960
bus::UsbBusAllocator,
60-
device::{UsbDevice, UsbDeviceBuilder, UsbDeviceState, UsbVidPid},
61+
device::{StringDescriptors, UsbDevice, UsbDeviceBuilder, UsbDeviceState, UsbVidPid},
6162
};
6263
use usbd_serial::SerialPort;
6364

@@ -131,7 +132,8 @@ mod app {
131132
let usb_bus = cx.local.usb_bus.insert(UsbBusAllocator::new(bus_adapter));
132133
let usb_class = SerialPort::new(usb_bus);
133134
let usb_device = UsbDeviceBuilder::new(usb_bus, VID_PID)
134-
.product(PRODUCT)
135+
.strings(&[StringDescriptors::new(LangID::EN_US).product(PRODUCT)])
136+
.expect("Failed to set string descriptors")
135137
.device_class(usbd_serial::USB_CLASS_CDC)
136138
.build();
137139

examples/rtic_gpt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ mod app {
2727
#[shared]
2828
struct Shared {
2929
led: board::Led,
30-
gpt1: hal::gpt::Gpt1,
31-
gpt2: hal::gpt::Gpt2,
30+
gpt1: hal::gpt::Gpt,
31+
gpt2: hal::gpt::Gpt,
3232
}
3333

34-
fn init_gpt<const N: u8>(gpt: &mut hal::gpt::Gpt<N>) {
34+
fn init_gpt(gpt: &mut hal::gpt::Gpt) {
3535
gpt.set_clock_source(GPT_CLOCK_SOURCE);
3636
gpt.set_divider(GPT_DIVIDER);
3737
gpt.set_output_compare_count(OCR, GPT_DELAY_MS);

examples/rtic_lpspi.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use teensy4_panic as _;
2222
#[rtic::app(device = teensy4_bsp, peripherals = true, dispatchers = [KPP])]
2323
mod app {
2424
use bsp::board;
25+
use bsp::hal::iomuxc;
2526
use teensy4_bsp as bsp;
2627

2728
use imxrt_log as logging;
@@ -35,10 +36,10 @@ mod app {
3536
/// These resources are local to individual tasks.
3637
#[local]
3738
struct Local {
38-
lpspi3: board::Lpspi3<teensy4_bsp::pins::common::P1, teensy4_bsp::pins::common::P0>,
39+
lpspi3: board::Lpspi,
3940

4041
/// Note: lpspi4 SCK is on pin 13 which collides with the Teensy 4/4.1 LED
41-
lpspi4: board::Lpspi4,
42+
lpspi4: board::Lpspi,
4243

4344
/// A poller to control USB logging.
4445
poller: logging::Poller,
@@ -49,7 +50,7 @@ mod app {
4950
// Specify 't40', 't41', or 'tmm' (for MicroMod) depending on
5051
// which board you're using.
5152
let board::Resources {
52-
pins,
53+
mut pins,
5354
usb,
5455
lpspi3,
5556
lpspi4,
@@ -58,13 +59,15 @@ mod app {
5859

5960
let poller = logging::log::usbd(usb, logging::Interrupts::Enabled).unwrap();
6061

62+
// Prepare the hardware chip select until the
63+
// HAL can help us out.
64+
iomuxc::lpspi::prepare(&mut pins.p0);
6165
let mut lpspi3 = board::lpspi(
6266
lpspi3,
6367
board::LpspiPins {
6468
sdo: pins.p26,
6569
sdi: pins.p1,
6670
sck: pins.p27,
67-
pcs0: pins.p0,
6871
},
6972
1_000_000,
7073
);
@@ -73,13 +76,14 @@ mod app {
7376
spi.set_peripheral_enable(true);
7477
});
7578

76-
let lpspi4: board::Lpspi4 = board::lpspi(
79+
// See note above about preparing chip selects.
80+
iomuxc::lpspi::prepare(&mut pins.p10);
81+
let lpspi4: board::Lpspi = board::lpspi(
7782
lpspi4,
7883
board::LpspiPins {
7984
sdo: pins.p11,
8085
sdi: pins.p12,
8186
sck: pins.p13,
82-
pcs0: pins.p10,
8387
},
8488
1_000_000,
8589
);

examples/rtic_pit.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ mod app {
1818
#[local]
1919
struct Local {
2020
led: board::Led,
21-
pit: bsp::hal::pit::Pit<2>,
21+
pit: bsp::hal::pit::Pit,
2222
}
2323

2424
#[init]
2525
fn init(cx: init::Context) -> (Shared, Local) {
2626
let board::Resources {
2727
pins,
28-
pit: (_, _, mut pit, _),
28+
mut pit,
2929
mut gpio2,
3030
..
3131
} = board::t40(cx.device);
3232
let led = board::led(&mut gpio2, pins.p13);
33-
pit.set_interrupt_enable(true);
34-
pit.set_load_timer_value(PIT_DELAY_MS);
35-
pit.enable();
33+
use bsp::hal::pit::Channel;
34+
pit.set_interrupt_enable(Channel::Chan2, true);
35+
pit.set_load_timer_value(Channel::Chan2, PIT_DELAY_MS);
36+
pit.enable(Channel::Chan2);
3637
(Shared {}, Local { led, pit })
3738
}
3839

@@ -48,9 +49,10 @@ mod app {
4849
let pit = cx.local.pit;
4950
let led = cx.local.led;
5051

52+
use bsp::hal::pit::Channel;
5153
led.toggle();
52-
while pit.is_elapsed() {
53-
pit.clear_elapsed();
54+
while pit.is_elapsed(Channel::Chan2) {
55+
pit.clear_elapsed(Channel::Chan2);
5456
}
5557
}
5658
}

0 commit comments

Comments
 (0)