mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-10 22:33:54 +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:
@@ -62,13 +62,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)]
|
||||
@@ -80,7 +80,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] = [
|
||||
|
||||
@@ -193,6 +193,16 @@ fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize {
|
||||
n
|
||||
}
|
||||
|
||||
/// Format zero into `buf`, returning 1 if the buffer is non-empty, else 0.
|
||||
fn format_zero(buf: &mut [u8]) -> usize {
|
||||
if !buf.is_empty() {
|
||||
buf[0] = b'0';
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/// Format a `u32` as decimal ASCII into `buf`.
|
||||
///
|
||||
/// # Arguments
|
||||
@@ -205,11 +215,7 @@ fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize {
|
||||
/// Number of bytes written.
|
||||
pub fn format_u32(buf: &mut [u8], value: u32) -> usize {
|
||||
if value == 0 {
|
||||
if !buf.is_empty() {
|
||||
buf[0] = b'0';
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return format_zero(buf);
|
||||
}
|
||||
let mut tmp = [0u8; 10];
|
||||
let n = u32_to_digits_reversed(&mut tmp, value);
|
||||
@@ -241,6 +247,7 @@ mod tests {
|
||||
// Import all parent module items
|
||||
use super::*;
|
||||
|
||||
/// New state is disabled.
|
||||
#[test]
|
||||
fn new_state_is_disabled() {
|
||||
let state = WatchdogDriverState::new();
|
||||
@@ -249,6 +256,7 @@ mod tests {
|
||||
assert_eq!(state.feed_count(), 0);
|
||||
}
|
||||
|
||||
/// Enable activates watchdog.
|
||||
#[test]
|
||||
fn enable_activates_watchdog() {
|
||||
let mut state = WatchdogDriverState::new();
|
||||
@@ -258,6 +266,7 @@ mod tests {
|
||||
assert_eq!(state.feed_count(), 0);
|
||||
}
|
||||
|
||||
/// Feed increments count.
|
||||
#[test]
|
||||
fn feed_increments_count() {
|
||||
let mut state = WatchdogDriverState::new();
|
||||
@@ -268,6 +277,7 @@ mod tests {
|
||||
assert_eq!(state.feed_count(), 2);
|
||||
}
|
||||
|
||||
/// Feed returns false when disabled.
|
||||
#[test]
|
||||
fn feed_returns_false_when_disabled() {
|
||||
let mut state = WatchdogDriverState::new();
|
||||
@@ -275,6 +285,7 @@ mod tests {
|
||||
assert_eq!(state.feed_count(), 0);
|
||||
}
|
||||
|
||||
/// Enable resets feed count.
|
||||
#[test]
|
||||
fn enable_resets_feed_count() {
|
||||
let mut state = WatchdogDriverState::new();
|
||||
@@ -287,21 +298,25 @@ mod tests {
|
||||
assert_eq!(state.timeout_ms(), 5000);
|
||||
}
|
||||
|
||||
/// Default timeout matches c demo.
|
||||
#[test]
|
||||
fn default_timeout_matches_c_demo() {
|
||||
assert_eq!(DEFAULT_TIMEOUT_MS, 3000);
|
||||
}
|
||||
|
||||
/// Feed interval matches c demo.
|
||||
#[test]
|
||||
fn feed_interval_matches_c_demo() {
|
||||
assert_eq!(FEED_INTERVAL_MS, 1000);
|
||||
}
|
||||
|
||||
/// Max timeout is 8388.
|
||||
#[test]
|
||||
fn max_timeout_is_8388() {
|
||||
assert_eq!(MAX_TIMEOUT_MS, 8388);
|
||||
}
|
||||
|
||||
/// Format fed matches c output.
|
||||
#[test]
|
||||
fn format_fed_matches_c_output() {
|
||||
let mut buf = [0u8; 32];
|
||||
@@ -309,6 +324,7 @@ mod tests {
|
||||
assert_eq!(&buf[..n], b"Watchdog fed\r\n");
|
||||
}
|
||||
|
||||
/// Format reset reason watchdog.
|
||||
#[test]
|
||||
fn format_reset_reason_watchdog() {
|
||||
let mut buf = [0u8; 64];
|
||||
@@ -316,6 +332,7 @@ mod tests {
|
||||
assert_eq!(&buf[..n], b"System rebooted by watchdog timeout\r\n");
|
||||
}
|
||||
|
||||
/// Format reset reason normal.
|
||||
#[test]
|
||||
fn format_reset_reason_normal() {
|
||||
let mut buf = [0u8; 64];
|
||||
@@ -323,6 +340,7 @@ mod tests {
|
||||
assert_eq!(&buf[..n], b"Normal power-on reset\r\n");
|
||||
}
|
||||
|
||||
/// Format enabled 3s.
|
||||
#[test]
|
||||
fn format_enabled_3s() {
|
||||
let mut buf = [0u8; 64];
|
||||
@@ -333,6 +351,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Format enabled 5s.
|
||||
#[test]
|
||||
fn format_enabled_5s() {
|
||||
let mut buf = [0u8; 64];
|
||||
@@ -343,6 +362,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Format u32 zero.
|
||||
#[test]
|
||||
fn format_u32_zero() {
|
||||
let mut buf = [0u8; 16];
|
||||
@@ -350,6 +370,7 @@ mod tests {
|
||||
assert_eq!(&buf[..n], b"0");
|
||||
}
|
||||
|
||||
/// Format u32 large value.
|
||||
#[test]
|
||||
fn format_u32_large_value() {
|
||||
let mut buf = [0u8; 16];
|
||||
|
||||
Reference in New Issue
Block a user