mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-06-10 16:23:55 +02:00
refactor: enforce max 8 code lines, add docstrings, fix warnings across all Rust and C SDK projects
Rust (all 15 projects):
- Refactored overlength functions: format_counter, format_u8, format_f32_1,
format_u32_minimal, gpio_drive, read_sensor, poll_sensor, format_round_trip,
format_u32, prepare_write_buf, write_min_digits, write_temp, UartDriver::init,
init_spi, angle_to_pulse_us, compute_servo_level
- Added 200+ docstrings to test functions, mock structs, impl blocks
- Fixed pub static comments (//) to doc comments (///) in all main.rs files
- Fixed helper function ordering (helpers above callers)
- Fixed Fn(u32) -> FnMut(u32) bound in button poll_button
- Moved OneShot trait import from main.rs to board.rs in adc project
- Added unsafe {} blocks in flash unsafe fn bodies (Rust 2024 edition)
- Removed unused hal::Clock imports from pwm/servo main.rs
- All 15 projects build with zero errors and zero warnings
C Pico SDK (all 15 projects):
- Added docstrings to all public functions, macros, and static variables
- All 15 projects rebuilt with zero errors
Cleanup:
- Removed build/ and target/ directories from git tracking
- Added target/ to .gitignore
- Deleted temporary fix_rust_docs.py script
This commit is contained in:
@@ -103,50 +103,62 @@ mod tests {
|
||||
// Error type trait for mock pin implementations
|
||||
use embedded_hal::digital::ErrorType;
|
||||
|
||||
/// Mock GPIO pin for testing.
|
||||
struct MockPin {
|
||||
state: bool,
|
||||
}
|
||||
|
||||
impl MockPin {
|
||||
/// New.
|
||||
fn new() -> Self {
|
||||
Self { state: false }
|
||||
}
|
||||
}
|
||||
|
||||
/// ErrorType implementation for MockPin.
|
||||
impl ErrorType for MockPin {
|
||||
type Error = Infallible;
|
||||
}
|
||||
|
||||
/// OutputPin implementation for MockPin.
|
||||
impl OutputPin for MockPin {
|
||||
/// Set low.
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
self.state = false;
|
||||
Ok(())
|
||||
}
|
||||
/// Set high.
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
self.state = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// StatefulOutputPin implementation for MockPin.
|
||||
impl StatefulOutputPin for MockPin {
|
||||
/// Is set high.
|
||||
fn is_set_high(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(self.state)
|
||||
}
|
||||
/// Is set low.
|
||||
fn is_set_low(&mut self) -> Result<bool, Self::Error> {
|
||||
Ok(!self.state)
|
||||
}
|
||||
/// Toggle.
|
||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||
self.state = !self.state;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Init starts low.
|
||||
#[test]
|
||||
fn init_starts_low() {
|
||||
let drv = BlinkDriver::init(MockPin::new());
|
||||
assert!(!drv.pin.state);
|
||||
}
|
||||
|
||||
/// On sets high.
|
||||
#[test]
|
||||
fn on_sets_high() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -154,6 +166,7 @@ mod tests {
|
||||
assert!(drv.pin.state);
|
||||
}
|
||||
|
||||
/// Off sets low.
|
||||
#[test]
|
||||
fn off_sets_low() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -162,6 +175,7 @@ mod tests {
|
||||
assert!(!drv.pin.state);
|
||||
}
|
||||
|
||||
/// Toggle from low goes high.
|
||||
#[test]
|
||||
fn toggle_from_low_goes_high() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -169,6 +183,7 @@ mod tests {
|
||||
assert!(drv.pin.state);
|
||||
}
|
||||
|
||||
/// Toggle from high goes low.
|
||||
#[test]
|
||||
fn toggle_from_high_goes_low() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -177,6 +192,7 @@ mod tests {
|
||||
assert!(!drv.pin.state);
|
||||
}
|
||||
|
||||
/// Get state reflects on.
|
||||
#[test]
|
||||
fn get_state_reflects_on() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -184,6 +200,7 @@ mod tests {
|
||||
assert!(drv.get_state());
|
||||
}
|
||||
|
||||
/// Get state reflects off.
|
||||
#[test]
|
||||
fn get_state_reflects_off() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
@@ -192,6 +209,7 @@ mod tests {
|
||||
assert!(!drv.get_state());
|
||||
}
|
||||
|
||||
/// Double toggle returns to original.
|
||||
#[test]
|
||||
fn double_toggle_returns_to_original() {
|
||||
let mut drv = BlinkDriver::init(MockPin::new());
|
||||
|
||||
@@ -61,13 +61,13 @@ use rp235x_hal as hal;
|
||||
#[cfg(rp2040)]
|
||||
use rp2040_hal as hal;
|
||||
|
||||
// Second-stage boot loader for RP2040
|
||||
/// Second-stage boot loader for RP2040
|
||||
#[unsafe(link_section = ".boot2")]
|
||||
#[used]
|
||||
#[cfg(rp2040)]
|
||||
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080;
|
||||
|
||||
// Boot metadata for the RP2350 Boot ROM
|
||||
/// Boot metadata for the RP2350 Boot ROM
|
||||
#[unsafe(link_section = ".start_block")]
|
||||
#[used]
|
||||
#[cfg(rp2350)]
|
||||
@@ -79,7 +79,7 @@ fn main() -> ! {
|
||||
board::run(hal::pac::Peripherals::take().unwrap())
|
||||
}
|
||||
|
||||
// Picotool binary info metadata
|
||||
/// Picotool binary info metadata
|
||||
#[unsafe(link_section = ".bi_entries")]
|
||||
#[used]
|
||||
pub static PICOTOOL_ENTRIES: [hal::binary_info::EntryAddr; 5] = [
|
||||
|
||||
Reference in New Issue
Block a user