Skip to content

Commit 379530d

Browse files
authored
Merge pull request #865 from jannic/fix-beta-clippy
2 parents 00785b0 + 0d79844 commit 379530d

25 files changed

+82
-82
lines changed

rp2040-hal-examples/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ static_cell = "2.1.0"
4242

4343
[target.'cfg( target_arch = "arm" )'.dependencies]
4444
embassy-executor = {version = "0.5", features = ["arch-cortex-m", "executor-thread"]}
45+
46+
[lints.clippy]
47+
too_long_first_doc_paragraph = "allow"

rp2040-hal-examples/src/bin/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn main() -> ! {
6565
use core::mem::MaybeUninit;
6666
const HEAP_SIZE: usize = 1024;
6767
static mut HEAP: [MaybeUninit<u8>; HEAP_SIZE] = [MaybeUninit::uninit(); HEAP_SIZE];
68-
unsafe { ALLOCATOR.init(HEAP.as_ptr() as usize, HEAP_SIZE) }
68+
unsafe { ALLOCATOR.init(core::ptr::addr_of_mut!(HEAP) as usize, HEAP_SIZE) }
6969
}
7070

7171
// Grab our singleton objects

rp2040-hal-examples/src/bin/gpio_irq_example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ fn main() -> ! {
149149
}
150150
}
151151

152+
#[allow(static_mut_refs)] // See https://github.com/rust-embedded/cortex-m/pull/561
152153
#[interrupt]
153154
fn IO_IRQ_BANK0() {
154155
// The `#[interrupt]` attribute covertly converts this to `&'static mut Option<LedAndButton>`

rp2040-hal-examples/src/bin/multicore_fifo_blink.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ fn main() -> ! {
115115
let mut mc = Multicore::new(&mut pac.PSM, &mut pac.PPB, &mut sio.fifo);
116116
let cores = mc.cores();
117117
let core1 = &mut cores[1];
118+
#[allow(static_mut_refs)]
118119
let _test = core1.spawn(unsafe { &mut CORE1_STACK.mem }, move || {
119120
core1_task(sys_freq)
120121
});

rp2040-hal-examples/src/bin/multicore_polyblink.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ fn main() -> ! {
105105
let mut mc = Multicore::new(&mut pac.PSM, &mut pac.PPB, &mut sio.fifo);
106106
let cores = mc.cores();
107107
let core1 = &mut cores[1];
108+
#[allow(static_mut_refs)]
108109
core1
109110
.spawn(unsafe { &mut CORE1_STACK.mem }, move || {
110111
// Get the second core's copy of the `CorePeripherals`, which are per-core.

rp2040-hal-examples/src/bin/pwm_irq_input.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;
4747

4848
/// 50 Hz PWM servo signals have a pulse width between 1000 us and 2000 us with
4949
/// 1500 us as the centre point. us is the abbreviation for micro seconds.
50-
50+
///
5151
/// The PWM threshold value for turning off the LED in us
5252
const LOW_US: u16 = 1475;
5353

@@ -60,7 +60,7 @@ const XTAL_FREQ_HZ: u32 = 12_000_000u32;
6060

6161
/// Pin types quickly become very long!
6262
/// We'll create some type aliases using `type` to help with that
63-
63+
///
6464
/// This pin will be our output - it will drive an LED if you run this on a Pico
6565
type LedPin = gpio::Pin<gpio::bank0::Gpio25, gpio::FunctionSio<gpio::SioOutput>, gpio::PullNone>;
6666

@@ -164,6 +164,7 @@ fn main() -> ! {
164164
}
165165
}
166166

167+
#[allow(static_mut_refs)] // See https://github.com/rust-embedded/cortex-m/pull/561
167168
#[interrupt]
168169
fn IO_IRQ_BANK0() {
169170
// The `#[interrupt]` attribute covertly converts this to `&'static mut Option<LedAndInput>`

rp2040-hal-examples/src/bin/rtc_irq_example.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn main() -> ! {
144144
}
145145

146146
#[allow(non_snake_case)]
147+
#[allow(static_mut_refs)] // See https://github.com/rust-embedded/cortex-m/pull/561
147148
#[interrupt]
148149
fn RTC_IRQ() {
149150
// The `#[interrupt]` attribute covertly converts this to `&'static mut Option<LedAndRtc>`

rp2040-hal-examples/src/bin/vector_table.rs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rp2040_hal as hal;
1717

1818
// A shorter alias for the Peripheral Access Crate
1919
use hal::pac;
20+
use static_cell::ConstStaticCell;
2021

2122
// Some traits we need
2223
use core::cell::RefCell;
@@ -29,7 +30,7 @@ use rp2040_hal::timer::Alarm;
2930
use rp2040_hal::vector_table::VectorTable;
3031

3132
// Memory that will hold our vector table in RAM
32-
static mut RAM_VTABLE: VectorTable = VectorTable::new();
33+
static RAM_VTABLE: ConstStaticCell<VectorTable> = ConstStaticCell::new(VectorTable::new());
3334

3435
// Give our LED and Alarm a type alias to make it easier to refer to them
3536
type LedAndAlarm = (
@@ -38,7 +39,7 @@ type LedAndAlarm = (
3839
);
3940

4041
// Place our LED and Alarm type in a static variable, so we can access it from interrupts
41-
static mut LED_AND_ALARM: Mutex<RefCell<Option<LedAndAlarm>>> = Mutex::new(RefCell::new(None));
42+
static LED_AND_ALARM: Mutex<RefCell<Option<LedAndAlarm>>> = Mutex::new(RefCell::new(None));
4243

4344
// Period that each of the alarms will be set for - 1 second and 300ms respectively
4445
const SLOW_BLINK_INTERVAL_US: MicrosDurationU32 = MicrosDurationU32::secs(1);
@@ -76,12 +77,12 @@ fn main() -> ! {
7677

7778
// Need to make a reference to the Peripheral Base at this scope to avoid confusing the borrow checker
7879
let ppb = &mut pac.PPB;
79-
unsafe {
80-
// Copy the vector table that cortex_m_rt produced into the RAM vector table
81-
RAM_VTABLE.init(ppb);
82-
// Replace the function that is called on Alarm0 interrupts with a new one
83-
RAM_VTABLE.register_handler(pac::Interrupt::TIMER_IRQ_0 as usize, timer_irq0_replacement);
84-
}
80+
81+
let ram_vtable = RAM_VTABLE.take();
82+
// Copy the vector table that cortex_m_rt produced into the RAM vector table
83+
ram_vtable.init(ppb);
84+
// Replace the function that is called on Alarm0 interrupts with a new one
85+
ram_vtable.register_handler(pac::Interrupt::TIMER_IRQ_0 as usize, timer_irq0_replacement);
8586

8687
// Configure the clocks
8788
let clocks = hal::clocks::init_clocks_and_plls(
@@ -117,9 +118,7 @@ fn main() -> ! {
117118
// Enable generating an interrupt on alarm
118119
alarm.enable_interrupt();
119120
// Move alarm into ALARM, so that it can be accessed from interrupts
120-
unsafe {
121-
LED_AND_ALARM.borrow(cs).replace(Some((led_pin, alarm)));
122-
}
121+
LED_AND_ALARM.borrow(cs).replace(Some((led_pin, alarm)));
123122
});
124123
// Unmask the timer0 IRQ so that it will generate an interrupt
125124
unsafe {
@@ -130,7 +129,7 @@ fn main() -> ! {
130129
delay.delay_ms(5000);
131130
unsafe {
132131
critical_section::with(|_| {
133-
RAM_VTABLE.activate(ppb);
132+
ram_vtable.activate(ppb);
134133
});
135134
}
136135

@@ -146,7 +145,7 @@ fn main() -> ! {
146145
fn TIMER_IRQ_0() {
147146
critical_section::with(|cs| {
148147
// Temporarily take our LED_AND_ALARM
149-
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
148+
let ledalarm = LED_AND_ALARM.borrow(cs).take();
150149
if let Some((mut led, mut alarm)) = ledalarm {
151150
// Clear the alarm interrupt or this interrupt service routine will keep firing
152151
alarm.clear_interrupt();
@@ -155,31 +154,27 @@ fn TIMER_IRQ_0() {
155154
// Blink the LED so we know we hit this interrupt
156155
led.toggle().unwrap();
157156
// Return LED_AND_ALARM into our static variable
158-
unsafe {
159-
LED_AND_ALARM
160-
.borrow(cs)
161-
.replace_with(|_| Some((led, alarm)));
162-
}
157+
LED_AND_ALARM
158+
.borrow(cs)
159+
.replace_with(|_| Some((led, alarm)));
163160
}
164161
});
165162
}
166163

167164
// This is the function we will use to replace TIMER_IRQ_0 in our RAM Vector Table
168165
extern "C" fn timer_irq0_replacement() {
169166
critical_section::with(|cs| {
170-
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
167+
let ledalarm = LED_AND_ALARM.borrow(cs).take();
171168
if let Some((mut led, mut alarm)) = ledalarm {
172169
// Clear the alarm interrupt or this interrupt service routine will keep firing
173170
alarm.clear_interrupt();
174171
// Schedule a new alarm after FAST_BLINK_INTERVAL_US have passed (300 milliseconds)
175172
let _ = alarm.schedule(FAST_BLINK_INTERVAL_US);
176173
led.toggle().unwrap();
177174
// Return LED_AND_ALARM into our static variable
178-
unsafe {
179-
LED_AND_ALARM
180-
.borrow(cs)
181-
.replace_with(|_| Some((led, alarm)));
182-
}
175+
LED_AND_ALARM
176+
.borrow(cs)
177+
.replace_with(|_| Some((led, alarm)));
183178
}
184179
});
185180
}

rp2040-hal/src/adc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,14 @@ impl<'a, Word> AdcFifo<'a, Word> {
813813
}
814814
}
815815

816-
impl<'a> AdcFifo<'a, u16> {
816+
impl AdcFifo<'_, u16> {
817817
/// Read a single value from the fifo (u16 version, not shifted)
818818
pub fn read(&mut self) -> u16 {
819819
self.read_from_fifo()
820820
}
821821
}
822822

823-
impl<'a> AdcFifo<'a, u8> {
823+
impl AdcFifo<'_, u8> {
824824
/// Read a single value from the fifo (u8 version, shifted)
825825
///
826826
/// Also see [`AdcFifoBuilder::shift_8bit`].

rp2040-hal/src/async_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ where
128128
r
129129
}
130130
}
131-
impl<'periph, Periph, PFn, EnIrqFn, CancelFn, OutputTy> Drop
132-
for CancellablePollFn<'periph, Periph, PFn, EnIrqFn, CancelFn, OutputTy>
131+
impl<Periph, PFn, EnIrqFn, CancelFn, OutputTy> Drop
132+
for CancellablePollFn<'_, Periph, PFn, EnIrqFn, CancelFn, OutputTy>
133133
where
134134
Periph: sealed::Wakeable,
135135
CancelFn: FnMut(&mut Periph),

0 commit comments

Comments
 (0)