Skip to content
Snippets Groups Projects
Commit 42c94647 authored by Samuel Tardieu's avatar Samuel Tardieu
Browse files

Make Clippy happy

parent 4b50504c
No related branches found
No related tags found
No related merge requests found
...@@ -16,3 +16,6 @@ embassy-time = { git = "https://github.com/embassy-rs/embassy", features = ["def ...@@ -16,3 +16,6 @@ embassy-time = { git = "https://github.com/embassy-rs/embassy", features = ["def
heapless = "0.8.0" heapless = "0.8.0"
i2c2-target = { path = "../i2c2-target" } i2c2-target = { path = "../i2c2-target" }
panic-probe = { version = "0.3.1", features = ["print-defmt"] } panic-probe = { version = "0.3.1", features = ["print-defmt"] }
[lints.clippy]
pedantic = "deny"
...@@ -66,6 +66,7 @@ impl Encoders<'_> { ...@@ -66,6 +66,7 @@ impl Encoders<'_> {
} }
} }
#[allow(clippy::cast_possible_wrap)]
fn ticks_since(old: &mut u16, new: u16) -> i16 { fn ticks_since(old: &mut u16, new: u16) -> i16 {
let diff = (new - *old) as i16; let diff = (new - *old) as i16;
*old = new; *old = new;
......
...@@ -31,6 +31,7 @@ impl State { ...@@ -31,6 +31,7 @@ impl State {
} }
} }
#[allow(clippy::cast_possible_wrap)]
fn set_motor_speed(&mut self, ms: [u8; 2]) { fn set_motor_speed(&mut self, ms: [u8; 2]) {
let (max_pwm, mmp) = ( let (max_pwm, mmp) = (
self.motors.max_pwm() as i32, self.motors.max_pwm() as i32,
...@@ -86,6 +87,12 @@ static mut STATE: Option<State> = None; ...@@ -86,6 +87,12 @@ static mut STATE: Option<State> = None;
/// to be able to be checked outside any critical section. /// to be able to be checked outside any critical section.
static WATCHDOG_EXPIRATION: AtomicU32 = AtomicU32::new(0); static WATCHDOG_EXPIRATION: AtomicU32 = AtomicU32::new(0);
/// Number of milliseconds since boot
#[allow(clippy::cast_possible_truncation)]
fn current_millis() -> u32 {
Instant::now().as_millis() as u32
}
#[embassy_executor::task] #[embassy_executor::task]
pub async fn start_i2c_target( pub async fn start_i2c_target(
i2c2: I2C2, i2c2: I2C2,
...@@ -99,11 +106,10 @@ pub async fn start_i2c_target( ...@@ -99,11 +106,10 @@ pub async fn start_i2c_target(
} }
loop { loop {
Timer::after_millis(100).await; Timer::after_millis(100).await;
if Instant::now().as_millis() as u32 >= WATCHDOG_EXPIRATION.load(Ordering::Relaxed) { if current_millis() >= WATCHDOG_EXPIRATION.load(Ordering::Relaxed) {
State::with_critical_section(|state| { State::with_critical_section(|state| {
if state.is_moving() if state.is_moving()
&& Instant::now().as_millis() as u32 && current_millis() >= WATCHDOG_EXPIRATION.load(Ordering::Relaxed)
>= WATCHDOG_EXPIRATION.load(Ordering::Relaxed)
{ {
state.standby(); state.standby();
} }
...@@ -117,7 +123,7 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) { ...@@ -117,7 +123,7 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
let state = unsafe { STATE.as_mut().unwrap() }; let state = unsafe { STATE.as_mut().unwrap() };
if process_command(state, command, response) { if process_command(state, command, response) {
WATCHDOG_EXPIRATION.store( WATCHDOG_EXPIRATION.store(
Instant::now().as_millis() as u32 + 100 * state.watchdog_ticks as u32, current_millis() + 100 * u32::from(state.watchdog_ticks),
Ordering::Relaxed, Ordering::Relaxed,
); );
} else { } else {
...@@ -180,7 +186,7 @@ fn process_command( ...@@ -180,7 +186,7 @@ fn process_command(
response.push_back(right[1]).unwrap(); response.push_back(right[1]).unwrap();
} }
[STATUS] => { [STATUS] => {
response.push_back(state.is_moving() as u8).unwrap(); response.push_back(u8::from(state.is_moving())).unwrap();
} }
_ => { _ => {
defmt::warn!("unknown command or args {:#04x}", command); defmt::warn!("unknown command or args {:#04x}", command);
......
...@@ -5,6 +5,7 @@ use embassy_stm32::{ ...@@ -5,6 +5,7 @@ use embassy_stm32::{
peripherals::{PA10, PA11, PA4, PA5, PB5, PB6, PB8, TIM1}, peripherals::{PA10, PA11, PA4, PA5, PB5, PB6, PB8, TIM1},
time::Hertz, time::Hertz,
timer::{ timer::{
low_level::CountingMode,
simple_pwm::{PwmPin, SimplePwm}, simple_pwm::{PwmPin, SimplePwm},
Channel, Channel,
}, },
...@@ -40,7 +41,7 @@ impl Neg for Movement { ...@@ -40,7 +41,7 @@ impl Neg for Movement {
} }
impl Tb6612fng<'_> { impl Tb6612fng<'_> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::similar_names, clippy::too_many_arguments)]
pub fn new( pub fn new(
pa4: PA4, pa4: PA4,
pa5: PA5, pa5: PA5,
...@@ -66,7 +67,7 @@ impl Tb6612fng<'_> { ...@@ -66,7 +67,7 @@ impl Tb6612fng<'_> {
Some(ch3), Some(ch3),
Some(ch4), Some(ch4),
freq, freq,
Default::default(), CountingMode::default(),
); );
pwm.enable(Channel::Ch3); pwm.enable(Channel::Ch3);
pwm.enable(Channel::Ch4); pwm.enable(Channel::Ch4);
...@@ -112,6 +113,7 @@ impl Tb6612fng<'_> { ...@@ -112,6 +113,7 @@ impl Tb6612fng<'_> {
self.move_right(right); self.move_right(right);
} }
#[allow(clippy::cast_sign_loss)]
fn make_command(&self, movement: Movement) -> (Level, Level, u32) { fn make_command(&self, movement: Movement) -> (Level, Level, u32) {
let max_duty = self.max_pwm(); let max_duty = self.max_pwm();
match movement { match movement {
......
...@@ -8,3 +8,8 @@ edition = "2021" ...@@ -8,3 +8,8 @@ edition = "2021"
defmt = "0.3.5" defmt = "0.3.5"
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["defmt", "stm32f103c8", "unstable-pac", "time-driver-tim4"] } embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["defmt", "stm32f103c8", "unstable-pac", "time-driver-tim4"] }
heapless = "0.8.0" heapless = "0.8.0"
[lints.clippy]
pedantic = "deny"
missing_panics_doc = "allow"
must_use_candidate = "allow"
...@@ -176,7 +176,7 @@ unsafe fn I2C2_EV() { ...@@ -176,7 +176,7 @@ unsafe fn I2C2_EV() {
let state = unsafe { STATE.as_mut().unwrap() }; let state = unsafe { STATE.as_mut().unwrap() };
if sr1.rxne() { if sr1.rxne() {
defmt::trace!("I2C2_EV RXNE"); defmt::trace!("I2C2_EV RXNE");
let b = pac::I2C2.dr().read().0 as u8; let b = pac::I2C2.dr().read().dr();
defmt::trace!( defmt::trace!(
"received byte {:#04x} - sr1 is now {:#06x}", "received byte {:#04x} - sr1 is now {:#06x}",
&b, &b,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment