From 6be52230ce10ec1ced9423348f83c595cd57bd1a Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Thu, 18 Apr 2024 20:11:33 -0400 Subject: [PATCH] chore: better docs, appease clippy --- src/bin/pin_scanner.rs | 12 +++++------- src/lib.rs | 1 + src/midi.rs | 13 ++++++++----- src/pins.rs | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/bin/pin_scanner.rs b/src/bin/pin_scanner.rs index 84bbdb8..d50d263 100644 --- a/src/bin/pin_scanner.rs +++ b/src/bin/pin_scanner.rs @@ -71,11 +71,9 @@ async fn scanner_task(mut pin_driver: pins::TransparentPins) { let mask = input ^ (((1 << pin_driver.n_total_pins) - 1) ^ (1 << gnd_pin)); for input_pin in 0..pin_driver.n_total_pins { let input_pin = input_pin as u8; - if ((1 << input_pin) & mask) != 0 { - if n_connections < MAX_CONNECTIONS { - connections[n_connections] = Some(Connection { gnd_pin, input_pin }); - n_connections += 1; - } + if ((1 << input_pin) & mask) != 0 && n_connections < MAX_CONNECTIONS { + connections[n_connections] = Some(Connection { gnd_pin, input_pin }); + n_connections += 1; } } // this should avoid overexerting the components @@ -84,8 +82,8 @@ async fn scanner_task(mut pin_driver: pins::TransparentPins) { } log::info!("SCAN RESULTS"); - for i in 0..n_connections { - match connections[i] { + for v in connections.iter().take(n_connections) { + match v { None => {} Some(con) => { log::warn!("GND {:0>2} -> INPUT {:0>2}", con.gnd_pin, con.input_pin); diff --git a/src/lib.rs b/src/lib.rs index 7102084..421b783 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![no_std] #![no_main] #![deny(rust_2018_idioms)] +#![deny(rustdoc::broken_intra_doc_links)] use embassy_time::Timer; use {defmt_rtt as _, panic_probe as _}; diff --git a/src/midi.rs b/src/midi.rs index 1ec2d5d..1405896 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -32,7 +32,7 @@ struct NoteMsg { impl NoteMsg { fn new(on: bool, note: u8, velocity: u8) -> Self { - return NoteMsg { on, note, velocity }; + NoteMsg { on, note, velocity } } } @@ -48,7 +48,7 @@ struct ControllerMsg { impl ControllerMsg { fn new(controller: Controller, value: u8) -> Self { - return ControllerMsg { controller, value }; + ControllerMsg { controller, value } } } @@ -64,10 +64,10 @@ struct MidiMsg { impl MidiMsg { fn new(msg: MsgType, channel: u8) -> Self { - return MidiMsg { + MidiMsg { msg, channel: channel & 0xf, - }; + } } } @@ -115,9 +115,10 @@ pub struct MidiChannel { impl MidiChannel { pub fn new(channel: u8) -> Self { - return MidiChannel { channel }; + MidiChannel { channel } } + /// MIDI Note-On pub async fn note_on(&self, note: u8, velocity: u8) { MIDI_QUEUE .send(MidiMsg::new( @@ -127,6 +128,7 @@ impl MidiChannel { .await; } + /// MIDI Note-Off pub async fn note_off(&self, note: u8, velocity: u8) { MIDI_QUEUE .send(MidiMsg::new( @@ -136,6 +138,7 @@ impl MidiChannel { .await; } + /// MIDI Controller (e.g. sustain pedal on/off) pub async fn controller(&self, ctrl: Controller, value: u8) { MIDI_QUEUE .send(MidiMsg::new( diff --git a/src/pins.rs b/src/pins.rs index 4495bf1..a5123ff 100644 --- a/src/pins.rs +++ b/src/pins.rs @@ -103,7 +103,7 @@ pub struct TransparentPins { usable_extended_pins: usize, } -/// Helper to define the onboard pins in TransparentPins +/// Helper to define the onboard pins in [`TransparentPins`] #[macro_export] macro_rules! pin_array { ($($pin: expr),*) => { @@ -171,7 +171,7 @@ impl TransparentPins { ) -> Result { let mut ret = TransparentPins { addrs, - pins: pins.map(|x| Flex::new(x)), + pins: pins.map(Flex::new), i2c_bus: shared_bus::BusManagerSimple::new(i2c), disable_unsafe_pins: false, usable_pins_per_extender: PINS_PER_EXTENDER,