Skip to content

Commit f8fd3ba

Browse files
committed
Update to Rust 2024
1 parent ca73bc8 commit f8fd3ba

10 files changed

Lines changed: 70 additions & 53 deletions

File tree

CHANGELOG.md

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

33
## [Unreleased]
44

5+
- Update package to Rust 2024.
6+
57
## [0.1.1] 2023-01-12
68

79
Fix an incorrect lifetime caught by `implied_bounds_entailment`.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ cortex-m = "0.7.2"
1616
ral-registers = "0.1"
1717

1818
[workspace.package]
19-
edition = "2021"
19+
edition = "2024"
2020
license = "MIT OR Apache-2.0"
2121
repository = "https://github.com/imxrt-rs/imxrt-dma"

src/channel.rs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
//! enabled.
99
1010
use crate::{
11-
element::Element,
12-
ral::{self, dma, dmamux, tcd::BandwidthControl, Static},
1311
Error,
12+
element::Element,
13+
ral::{self, Static, dma, dmamux, tcd::BandwidthControl},
1414
};
1515

1616
impl<const CHANNELS: usize> super::Dma<CHANNELS> {
@@ -465,10 +465,12 @@ impl Configuration {
465465
/// Caller must ensure that `hardware_source` is valid for the lifetime of the transfer,
466466
/// and valid for all subsequent transfers performed by this DMA channel with this address.
467467
pub unsafe fn set_source_hardware<E: Element>(chan: &mut Channel, hardware_source: *const E) {
468-
chan.set_source_address(hardware_source);
469-
chan.set_source_offset(0);
470-
chan.set_source_attributes::<E>(0);
471-
chan.set_source_last_address_adjustment(0);
468+
unsafe {
469+
chan.set_source_address(hardware_source);
470+
chan.set_source_offset(0);
471+
chan.set_source_attributes::<E>(0);
472+
chan.set_source_last_address_adjustment(0);
473+
}
472474
}
473475

474476
/// Set a hardware peripheral as the destination for a DMA transfer
@@ -485,10 +487,12 @@ pub unsafe fn set_destination_hardware<E: Element>(
485487
chan: &mut Channel,
486488
hardware_destination: *const E,
487489
) {
488-
chan.set_destination_address(hardware_destination);
489-
chan.set_destination_offset(0);
490-
chan.set_destination_attributes::<E>(0);
491-
chan.set_destination_last_address_adjustment(0);
490+
unsafe {
491+
chan.set_destination_address(hardware_destination);
492+
chan.set_destination_offset(0);
493+
chan.set_destination_attributes::<E>(0);
494+
chan.set_destination_last_address_adjustment(0);
495+
}
492496
}
493497

494498
/// Set a linear buffer as the source for a DMA transfer
@@ -501,10 +505,14 @@ pub unsafe fn set_destination_hardware<E: Element>(
501505
/// Caller must ensure that the source is valid for the lifetime of the transfer,
502506
/// and valid for all subsequent transfers performed by this DMA channel with this buffer.
503507
pub unsafe fn set_source_linear_buffer<E: Element>(chan: &mut Channel, source: &[E]) {
504-
chan.set_source_address(source.as_ptr());
505-
chan.set_source_offset(core::mem::size_of::<E>() as i16);
506-
chan.set_source_attributes::<E>(0);
507-
chan.set_source_last_address_adjustment((core::mem::size_of_val(source) as i32).wrapping_neg());
508+
unsafe {
509+
chan.set_source_address(source.as_ptr());
510+
chan.set_source_offset(core::mem::size_of::<E>() as i16);
511+
chan.set_source_attributes::<E>(0);
512+
chan.set_source_last_address_adjustment(
513+
(core::mem::size_of_val(source) as i32).wrapping_neg(),
514+
);
515+
}
508516
}
509517

510518
/// Set a linear buffer as the destination for a DMA transfer
@@ -517,12 +525,14 @@ pub unsafe fn set_source_linear_buffer<E: Element>(chan: &mut Channel, source: &
517525
/// Caller must ensure that the destination is valid for the lifetime of the transfer,
518526
/// and valid for all subsequent transfers performed by this DMA channel with this buffer.
519527
pub unsafe fn set_destination_linear_buffer<E: Element>(chan: &mut Channel, destination: &mut [E]) {
520-
chan.set_destination_address(destination.as_ptr());
521-
chan.set_destination_offset(core::mem::size_of::<E>() as i16);
522-
chan.set_destination_attributes::<E>(0);
523-
chan.set_destination_last_address_adjustment(
524-
(core::mem::size_of_val(destination) as i32).wrapping_neg(),
525-
);
528+
unsafe {
529+
chan.set_destination_address(destination.as_ptr());
530+
chan.set_destination_offset(core::mem::size_of::<E>() as i16);
531+
chan.set_destination_attributes::<E>(0);
532+
chan.set_destination_last_address_adjustment(
533+
(core::mem::size_of_val(destination) as i32).wrapping_neg(),
534+
);
535+
}
526536
}
527537

528538
/// Assert properties about the circular buffer
@@ -535,7 +545,7 @@ fn circular_buffer_asserts<E>(buffer: &[E]) {
535545
let start = buffer.as_ptr();
536546
let size = core::mem::size_of_val(buffer);
537547
assert!(
538-
(start as usize) % size == 0,
548+
(start as usize).is_multiple_of(size),
539549
"DMA circular buffer is not properly aligned"
540550
);
541551
}
@@ -565,10 +575,12 @@ pub unsafe fn set_source_circular_buffer<E: Element>(chan: &mut Channel, source:
565575
circular_buffer_asserts(source);
566576
let modulo = circular_buffer_modulo(source);
567577

568-
chan.set_source_address(source.as_ptr());
569-
chan.set_source_offset(core::mem::size_of::<E>() as i16);
570-
chan.set_source_attributes::<E>(modulo as u8);
571-
chan.set_source_last_address_adjustment(0);
578+
unsafe {
579+
chan.set_source_address(source.as_ptr());
580+
chan.set_source_offset(core::mem::size_of::<E>() as i16);
581+
chan.set_source_attributes::<E>(modulo as u8);
582+
chan.set_source_last_address_adjustment(0);
583+
}
572584
}
573585

574586
/// Set a circular buffer as the destination for a DMA transfer
@@ -594,8 +606,10 @@ pub unsafe fn set_destination_circular_buffer<E: Element>(
594606
circular_buffer_asserts(destination);
595607
let modulo = circular_buffer_modulo(destination);
596608

597-
chan.set_destination_address(destination.as_ptr());
598-
chan.set_destination_offset(core::mem::size_of::<E>() as i16);
599-
chan.set_destination_attributes::<E>(modulo as u8);
600-
chan.set_destination_last_address_adjustment(0);
609+
unsafe {
610+
chan.set_destination_address(destination.as_ptr());
611+
chan.set_destination_offset(core::mem::size_of::<E>() as i16);
612+
chan.set_destination_attributes::<E>(modulo as u8);
613+
chan.set_destination_last_address_adjustment(0);
614+
}
601615
}

src/error.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,22 @@ impl Debug for Error {
105105

106106
impl Display for Error {
107107
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108-
write!(f,
109-
"DMA_ES: VLD {vld} ECX {ecx} GPE {gpe} CPE {cpe} ERRCHN {errchn} SAE {sae} SOE {soe} DAE {dae} DOE {doe} NCE {nce} SGE {sge} SBE {sbe} DBE {dbe}",
110-
vld = self.is_valid() as u32,
111-
ecx = self.is_cancelled() as u32,
112-
gpe = self.is_group_priority() as u32,
113-
cpe = self.is_channel_priority() as u32,
114-
errchn = self.channel_number(),
115-
sae = self.is_source_address() as u32,
116-
soe = self.is_source_offset() as u32,
117-
dae = self.is_destination_address() as u32,
118-
doe = self.is_destination_offset() as u32,
119-
nce = self.is_loop_configuration() as u32,
120-
sge = self.is_scatter_gather() as u32,
121-
sbe = self.is_source_bus() as u32,
122-
dbe = self.is_destination_bus() as u32,
123-
)
108+
write!(
109+
f,
110+
"DMA_ES: VLD {vld} ECX {ecx} GPE {gpe} CPE {cpe} ERRCHN {errchn} SAE {sae} SOE {soe} DAE {dae} DOE {doe} NCE {nce} SGE {sge} SBE {sbe} DBE {dbe}",
111+
vld = self.is_valid() as u32,
112+
ecx = self.is_cancelled() as u32,
113+
gpe = self.is_group_priority() as u32,
114+
cpe = self.is_channel_priority() as u32,
115+
errchn = self.channel_number(),
116+
sae = self.is_source_address() as u32,
117+
soe = self.is_source_offset() as u32,
118+
dae = self.is_destination_address() as u32,
119+
doe = self.is_destination_offset() as u32,
120+
nce = self.is_loop_configuration() as u32,
121+
sge = self.is_scatter_gather() as u32,
122+
sbe = self.is_source_bus() as u32,
123+
dbe = self.is_destination_bus() as u32,
124+
)
124125
}
125126
}

src/interrupt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! DMA interrupt support
22
3-
use crate::{channel::Channel, Error};
3+
use crate::{Error, channel::Channel};
44
use core::{
55
cell::RefCell,
66
future::Future,
@@ -48,7 +48,7 @@ impl<const CHANNELS: usize> super::Dma<CHANNELS> {
4848
/// Panics if `channel` is greater than or equal to the maximum number of channels.
4949
#[inline(always)]
5050
pub unsafe fn on_interrupt(&'static self, channel: usize) {
51-
let channel = self.channel(channel);
51+
let channel = unsafe { self.channel(channel) };
5252
if channel.is_interrupt() {
5353
channel.clear_interrupt();
5454
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ impl<const CHANNELS: usize> Dma<CHANNELS> {
128128
}
129129
}
130130

131-
use interrupt::{SharedWaker, NO_WAKER};
131+
use interrupt::{NO_WAKER, SharedWaker};

src/memcpy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! DMA-powered memcpy
22
33
use crate::{
4+
Element, Error,
45
channel::{self, Channel},
56
interrupt::Transfer,
6-
Element, Error,
77
};
88

99
use core::{

src/peripheral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
//! Otherwise, you can poll the future in a loop.
99
1010
use super::{
11-
channel::{self, Channel, Configuration},
1211
Element, Error, Transfer,
12+
channel::{self, Channel, Configuration},
1313
};
1414

1515
use core::{

src/ral.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub mod dma;
1515
pub mod dmamux;
1616
pub mod tcd;
1717

18-
pub use ral_registers::{modify_reg, read_reg, write_reg};
1918
use ral_registers::{RORegister, RWRegister, WORegister};
19+
pub use ral_registers::{modify_reg, read_reg, write_reg};
2020

2121
//
2222
// Helper types for static memory

src/ral/dma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! DMA register blocks and fields
22
3-
use super::{tcd, RORegister, RWRegister, WORegister};
3+
use super::{RORegister, RWRegister, WORegister, tcd};
44

55
use core::ops::Index;
66

0 commit comments

Comments
 (0)