Skip to content

Commit a338016

Browse files
Fix examples clippy warnings
1 parent 5022441 commit a338016

11 files changed

+96
-91
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ littlefs2 = { version = "0.5", optional = true }
3838
[dev-dependencies]
3939
aes = "0.7"
4040
cortex-m-rt = "0.6"
41-
# cortex-m-rtic = "0.5"
42-
lpc55-rtic = "0.5"
41+
rtic = { package = "cortex-m-rtic", version = "1" }
4342
cortex-m-semihosting = "0.3"
4443
heapless = "0.7"
4544
panic-halt = "0.2"

examples/adc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,5 +143,7 @@ fn main() -> ! {
143143
}
144144

145145
heprintln!("looping").unwrap();
146-
loop {}
146+
loop {
147+
heprintln!("looping").unwrap();
148+
}
147149
}

examples/aes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ fn main() -> ! {
3636
//
3737
// via software
3838
//
39-
let mut sw_block = block.clone();
40-
let cipher = aes::Aes256::new(&key);
39+
let mut sw_block = block;
40+
let cipher = aes::Aes256::new(key);
4141

4242
let (sw_cyc_enc, _) = hal::count_cycles(|| {
4343
cipher.encrypt_block(&mut sw_block);
@@ -57,7 +57,7 @@ fn main() -> ! {
5757
//
5858
// via hardware
5959
//
60-
let mut hw_block = block.clone();
60+
let mut hw_block = block;
6161
let cipher = hashcrypt.aes256(&raw_key);
6262

6363
cipher.prime_for_encryption();

examples/late.rs

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! examples/late.rs
22
3-
#![deny(unsafe_code)]
43
// something something about:
54
//
65
// error: use of deprecated item
@@ -11,34 +10,44 @@
1110
#![no_main]
1211
#![no_std]
1312

14-
use cortex_m_semihosting::hprintln;
15-
use hal::raw::Interrupt;
16-
use heapless::spsc::{Consumer, Producer, Queue};
17-
use lpc55_hal as hal;
1813
use panic_semihosting as _;
1914

20-
#[rtic::app(device = hal::raw)]
21-
const APP: () = {
22-
// Late resources
23-
struct Resources {
15+
#[rtic::app(device = lpc55_hal::raw)]
16+
mod app {
17+
use core::ptr::addr_of_mut;
18+
19+
use cortex_m_semihosting::hprintln;
20+
use hal::raw::Interrupt;
21+
use heapless::spsc::{Consumer, Producer, Queue};
22+
use lpc55_hal as hal;
23+
24+
#[shared]
25+
struct SharedResources {}
26+
27+
#[local]
28+
struct LocalResources {
2429
p: Producer<'static, u32, 4>,
2530
c: Consumer<'static, u32, 4>,
2631
}
2732

2833
#[init]
29-
fn init(_: init::Context) -> init::LateResources {
34+
fn init(_ctx: init::Context) -> (SharedResources, LocalResources, init::Monotonics) {
3035
static mut Q: Queue<u32, 4> = Queue::new();
3136

32-
let (p, c) = Q.split();
37+
let (p, c) = unsafe { (*addr_of_mut!(Q)).split() };
3338

3439
// Initialization of late resources
35-
init::LateResources { p, c }
40+
(
41+
SharedResources {},
42+
LocalResources { p, c },
43+
init::Monotonics(),
44+
)
3645
}
3746

38-
#[idle(resources = [c])]
39-
fn idle(c: idle::Context) -> ! {
47+
#[idle(local = [c])]
48+
fn idle(ctx: idle::Context) -> ! {
4049
loop {
41-
if let Some(byte) = c.resources.c.dequeue() {
50+
if let Some(byte) = ctx.local.c.dequeue() {
4251
hprintln!("received message: {}", byte).unwrap();
4352
// cortex_m::asm::wfi();
4453
} else {
@@ -47,8 +56,8 @@ const APP: () = {
4756
}
4857
}
4958

50-
#[task(binds = ADC0, resources = [p])]
51-
fn adc0(c: adc0::Context) {
52-
c.resources.p.enqueue(42).unwrap();
59+
#[task(binds = ADC0, local = [p])]
60+
fn adc0(ctx: adc0::Context) {
61+
ctx.local.p.enqueue(42).unwrap();
5362
}
54-
};
63+
}

examples/prince.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ fn main() -> ! {
3939
let flash = hal.flash.enabled(&mut syscon);
4040
let mut flash = hal::FlashGordon::new(flash);
4141

42-
let mut rng = hal.rng.enabled(&mut syscon);
42+
let rng = hal.rng.enabled(&mut syscon);
4343

44-
let mut prince = hal.prince.enabled(&mut rng);
44+
let mut prince = hal.prince.enabled(&rng);
4545

4646
prince.enable_all_region_2();
4747

4848
hprintln!("writing AA's to flash data.").ok();
4949

50-
flash.erase_page((DATA_ADDR / 512)).unwrap();
50+
flash.erase_page(DATA_ADDR / 512).unwrap();
5151
flash.erase_page((DATA_ADDR / 512) + 1).unwrap();
5252

5353
prince.write_encrypted(|_prince| {
@@ -58,6 +58,7 @@ fn main() -> ! {
5858
hprintln!("Read bytes PRINCE ON:").ok();
5959
let mut buf = [0u8; 1024];
6060

61+
#[allow(clippy::needless_range_loop)]
6162
for i in 0..buf.len() {
6263
let ptr = DATA_ADDR as *const u8;
6364
buf[i] = unsafe { *ptr.add(i) };
@@ -68,6 +69,7 @@ fn main() -> ! {
6869
// Turn off PRINCE.
6970
prince.disable_all_region_2();
7071

72+
#[allow(clippy::needless_range_loop)]
7173
for i in 0..buf.len() {
7274
let ptr = DATA_ADDR as *const u8;
7375
buf[i] = unsafe { *ptr.add(i) };

examples/puf.rs

+11-20
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn main() -> ! {
9494
// write first 512-byte chunk
9595
write_buf[0..4].copy_from_slice(&(State::Enrolled as u32).to_ne_bytes());
9696
write_buf[16..].copy_from_slice(&ac[..496]);
97-
flash.write(PUF_STATE_FLASH + 0, &write_buf).unwrap();
97+
flash.write(PUF_STATE_FLASH, &write_buf).unwrap();
9898

9999
// // write 2nd chunk
100100
write_buf.copy_from_slice(&ac[496..1008]);
@@ -117,10 +117,10 @@ fn main() -> ! {
117117
}
118118

119119
for i in 0..kc1.len() {
120-
assert!(kc1[i] == check_buf[1192 + 52 * 0 + i])
120+
assert!(kc1[i] == check_buf[1192 + i])
121121
}
122122
for i in 0..kc2.len() {
123-
assert!(kc2[i] == check_buf[1192 + 52 * 1 + i])
123+
assert!(kc2[i] == check_buf[1192 + 52 + i])
124124
}
125125
for i in 0..kc3.len() {
126126
assert!(kc3[i] == check_buf[1192 + 52 * 2 + i])
@@ -133,23 +133,12 @@ fn main() -> ! {
133133
} else {
134134
dbg!("The device is already enrolled.");
135135
flash.read(PUF_STATE_FLASH + 16, &mut check_buf);
136-
for i in 0..1192 {
137-
ac[i] = check_buf[i];
138-
}
139-
140-
for i in 0..kc1.len() {
141-
kc1[i] = check_buf[1192 + 52 * 0 + i];
142-
}
143-
for i in 0..kc2.len() {
144-
kc2[i] = check_buf[1192 + 52 * 1 + i];
145-
}
146-
for i in 0..kc3.len() {
147-
kc3[i] = check_buf[1192 + 52 * 2 + i];
148-
}
149-
for i in 0..kc4.len() {
150-
kc4[i] = check_buf[1192 + 52 * 3 + i];
151-
}
136+
ac.copy_from_slice(&check_buf[..1192]);
152137

138+
kc1.copy_from_slice(&check_buf[1192..][..52]);
139+
kc2.copy_from_slice(&check_buf[1192 + 52..][..52]);
140+
kc3.copy_from_slice(&check_buf[1192 + 52 * 2..][..52]);
141+
kc4.copy_from_slice(&check_buf[1192 + 52 * 3..][..52]);
153142
dump_hex!(ac[..16], 16);
154143
dump_hex!(ac[1192 - 16..], 16);
155144

@@ -203,5 +192,7 @@ fn main() -> ! {
203192
}
204193

205194
dbg!("Looping");
206-
loop {}
195+
loop {
196+
dbg!("Loop");
197+
}
207198
}

examples/pwm.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ extern crate panic_semihosting; // 4004 bytes
77
#[macro_use(block)]
88
extern crate nb;
99

10+
use core::f32;
11+
1012
use cortex_m_rt::entry;
1113

1214
use hal::drivers::{Pins, Pwm, Timer};
@@ -95,8 +97,9 @@ fn main() -> ! {
9597
}
9698
}
9799

100+
#[allow(clippy::needless_range_loop)]
98101
for i in 0..3 {
99-
let duty = (sin(duties[i] * 3.141_592_7_f32 / 180f32) * 255f32) as u16;
102+
let duty = (sin(duties[i] * f32::consts::PI / 180f32) * 255f32) as u16;
100103
match i {
101104
0 => {
102105
// need to tune down red some

examples/rtic_led.rs

+25-18
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@
33

44
extern crate panic_semihosting;
55
// extern crate panic_halt;
6-
use cortex_m_semihosting::dbg;
76

8-
use hal::{drivers::pins, drivers::pins::Level, prelude::*, typestates::pin};
9-
use lpc55_hal as hal;
7+
#[rtic::app(device = lpc55_hal::raw, peripherals = true)]
8+
mod app {
9+
use cortex_m_semihosting::dbg;
1010

11-
type RedLed = hal::Pin<pins::Pio1_6, pin::state::Gpio<pin::gpio::direction::Output>>;
11+
use hal::{drivers::pins, drivers::pins::Level, prelude::*, typestates::pin};
12+
use lpc55_hal as hal;
1213

13-
#[rtic::app(device = crate::hal::raw, peripherals = true)]
14-
const APP: () = {
15-
struct Resources {
14+
type RedLed = hal::Pin<pins::Pio1_6, pin::state::Gpio<pin::gpio::direction::Output>>;
15+
#[shared]
16+
struct SharedResources {}
17+
18+
#[local]
19+
struct LocalResources {
1620
led: RedLed,
1721
// delay: hal::clock::Ticks<'static, hal::syscon::Fro1MhzUtickClock<states::init_state::Enabled>>,
1822
// sleep: hal::sleep::Busy<'static, 'static>,
1923
}
2024

2125
#[init]
22-
fn init(c: init::Context) -> init::LateResources {
26+
fn init(c: init::Context) -> (SharedResources, LocalResources, init::Monotonics) {
2327
// dbg!("init");
2428
let _cp = c.core;
2529
let dp = c.device;
@@ -48,18 +52,21 @@ const APP: () = {
4852
// let mut utick = hal::utick::wrap(dp.UTICK).enabled(&mut syscon, &clock);
4953
// // let mut sleep = hal::sleep::Busy::prepare(&mut utick);
5054
// let mut sleep = hal::sleep::Busy::wrap(&mut utick);
51-
52-
init::LateResources {
53-
led: red_led,
54-
// delay,
55-
// sleep,
56-
}
55+
(
56+
SharedResources {},
57+
LocalResources {
58+
led: red_led,
59+
// delay,
60+
// sleep,
61+
},
62+
init::Monotonics(),
63+
)
5764
}
5865

5966
// #[idle(resources = [led, delay, sleep])]
60-
#[idle(resources = [led])]
61-
fn idle(c: idle::Context) -> ! {
62-
let led = c.resources.led;
67+
#[idle(local = [led])]
68+
fn idle(ctx: idle::Context) -> ! {
69+
let led = ctx.local.led;
6370
loop {
6471
dbg!("low");
6572
led.set_low().unwrap();
@@ -70,4 +77,4 @@ const APP: () = {
7077
// c.resources.sleep.sleep(c.resources.delay);
7178
}
7279
}
73-
};
80+
}

examples/semihosting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fn main() -> ! {
2727
const UUID: *mut u32 = 0x0009_FC70 as *mut u32;
2828
// dbg!(UUID);
2929
let mut uuid: [u32; 4] = [0; 4];
30+
#[allow(clippy::needless_range_loop)]
3031
for i in 0..4 {
3132
uuid[i] = unsafe { dbg!(UUID.add(i).read_volatile()) };
3233
}

examples/touch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn main() -> ! {
8484
let mut touch_sensor = touch_sensor.enabled(&mut dma, touch_token);
8585

8686
// Used to get tunning information for capacitive touch
87-
if 1 == 1 {
87+
{
8888
let mut counts = [0u32; 3];
8989
let mut times = [0u32; 128];
9090
let mut results = [0u32; 128];

examples/usb.rs

+14-23
Original file line numberDiff line numberDiff line change
@@ -96,39 +96,30 @@ fn main() -> ! {
9696
}
9797

9898
if !(buf_in_use || need_zlp) {
99-
match cdc_acm.read_packet(&mut buf) {
100-
Ok(count) => {
101-
size = count;
102-
buf_in_use = true;
103-
// dbg!(&buf[..count]);
104-
// if count > 1 {
105-
// dbg!(count);
106-
// }
107-
}
108-
_ => {}
99+
if let Ok(count) = cdc_acm.read_packet(&mut buf) {
100+
size = count;
101+
buf_in_use = true;
102+
// dbg!(&buf[..count]);
103+
// if count > 1 {
104+
// dbg!(count);
105+
// }
109106
}
110107
}
111108

112109
if buf_in_use {
113110
red_led.set_low().ok(); // Turn on
114-
match cdc_acm.write_packet(&buf[..size]) {
115-
Ok(count) => {
116-
assert!(count == size);
117-
buf_in_use = false;
118-
need_zlp = size == 8;
119-
}
120-
_ => {}
111+
if let Ok(count) = cdc_acm.write_packet(&buf[..size]) {
112+
assert!(count == size);
113+
buf_in_use = false;
114+
need_zlp = size == 8;
121115
}
122116
red_led.set_high().ok(); // Turn off
123117
}
124118

125119
if need_zlp {
126-
match cdc_acm.write_packet(&[]) {
127-
Ok(count) => {
128-
assert!(count == 0);
129-
need_zlp = false;
130-
}
131-
_ => {}
120+
if let Ok(count) = cdc_acm.write_packet(&[]) {
121+
assert!(count == 0);
122+
need_zlp = false;
132123
}
133124
}
134125

0 commit comments

Comments
 (0)