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
heapless = "0.8.0"
i2c2-target = { path = "../i2c2-target" }
panic-probe = { version = "0.3.1", features = ["print-defmt"] }
[lints.clippy]
pedantic = "deny"
......@@ -66,6 +66,7 @@ impl Encoders<'_> {
}
}
#[allow(clippy::cast_possible_wrap)]
fn ticks_since(old: &mut u16, new: u16) -> i16 {
let diff = (new - *old) as i16;
*old = new;
......
......@@ -31,6 +31,7 @@ impl State {
}
}
#[allow(clippy::cast_possible_wrap)]
fn set_motor_speed(&mut self, ms: [u8; 2]) {
let (max_pwm, mmp) = (
self.motors.max_pwm() as i32,
......@@ -86,6 +87,12 @@ static mut STATE: Option<State> = None;
/// to be able to be checked outside any critical section.
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]
pub async fn start_i2c_target(
i2c2: I2C2,
......@@ -99,11 +106,10 @@ pub async fn start_i2c_target(
}
loop {
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| {
if state.is_moving()
&& Instant::now().as_millis() as u32
>= WATCHDOG_EXPIRATION.load(Ordering::Relaxed)
&& current_millis() >= WATCHDOG_EXPIRATION.load(Ordering::Relaxed)
{
state.standby();
}
......@@ -117,7 +123,7 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
let state = unsafe { STATE.as_mut().unwrap() };
if process_command(state, command, response) {
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,
);
} else {
......@@ -180,7 +186,7 @@ fn process_command(
response.push_back(right[1]).unwrap();
}
[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);
......
......@@ -5,6 +5,7 @@ use embassy_stm32::{
peripherals::{PA10, PA11, PA4, PA5, PB5, PB6, PB8, TIM1},
time::Hertz,
timer::{
low_level::CountingMode,
simple_pwm::{PwmPin, SimplePwm},
Channel,
},
......@@ -40,7 +41,7 @@ impl Neg for Movement {
}
impl Tb6612fng<'_> {
#[allow(clippy::too_many_arguments)]
#[allow(clippy::similar_names, clippy::too_many_arguments)]
pub fn new(
pa4: PA4,
pa5: PA5,
......@@ -66,7 +67,7 @@ impl Tb6612fng<'_> {
Some(ch3),
Some(ch4),
freq,
Default::default(),
CountingMode::default(),
);
pwm.enable(Channel::Ch3);
pwm.enable(Channel::Ch4);
......@@ -112,6 +113,7 @@ impl Tb6612fng<'_> {
self.move_right(right);
}
#[allow(clippy::cast_sign_loss)]
fn make_command(&self, movement: Movement) -> (Level, Level, u32) {
let max_duty = self.max_pwm();
match movement {
......
......@@ -8,3 +8,8 @@ edition = "2021"
defmt = "0.3.5"
embassy-stm32 = { git = "https://github.com/embassy-rs/embassy", features = ["defmt", "stm32f103c8", "unstable-pac", "time-driver-tim4"] }
heapless = "0.8.0"
[lints.clippy]
pedantic = "deny"
missing_panics_doc = "allow"
must_use_candidate = "allow"
......@@ -176,7 +176,7 @@ unsafe fn I2C2_EV() {
let state = unsafe { STATE.as_mut().unwrap() };
if sr1.rxne() {
defmt::trace!("I2C2_EV RXNE");
let b = pac::I2C2.dr().read().0 as u8;
let b = pac::I2C2.dr().read().dr();
defmt::trace!(
"received byte {:#04x} - sr1 is now {:#06x}",
&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