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:
Kevin Thomas
2026-04-06 08:32:55 -04:00
parent d9fe6c314e
commit 3604b3c921
9896 changed files with 3106 additions and 312146 deletions
@@ -6,7 +6,7 @@
*
* Entry point after reset. Performs stack initialization, XOSC
* setup, subsystem reset release, UART initialization,
* coprocessor enable, and branches to main().
* and branches to main().
*
******************************************************************************
* @attention
+10
View File
@@ -22,6 +22,11 @@
#include "rp2350_delay.h"
/**
* @brief Delay for the specified number of milliseconds.
* @param ms number of milliseconds to delay
* @retval None
*/
void delay_ms(uint32_t ms)
{
if (ms == 0)
@@ -38,6 +43,11 @@ void delay_ms(uint32_t ms)
);
}
/**
* @brief Delay for the specified number of microseconds.
* @param us number of microseconds to delay
* @retval None
*/
void delay_us(uint32_t us)
{
if (us == 0)
@@ -22,6 +22,10 @@
#include "rp2350_reset.h"
/**
* @brief Release IO_BANK0 from reset and wait until ready.
* @retval None
*/
void reset_init_subsystem(void)
{
uint32_t value;
@@ -40,6 +40,10 @@ void _late_init(void)
timer_tick_init();
}
/**
* @brief Reset handler entry point (naked, noreturn).
* @retval None
*/
void __attribute__((naked, noreturn)) Reset_Handler(void)
{
__asm__ volatile (
@@ -21,6 +21,10 @@
#include "rp2350_stack.h"
/**
* @brief Initialize MSP, PSP, MSPLIM, and PSPLIM stack pointers.
* @retval None
*/
void stack_init(void)
{
__asm__ volatile (
+14
View File
@@ -102,18 +102,32 @@ static void _timer_arm_alarm(void)
TIMER0->ALARM0 = target;
}
/**
* @brief Release TIMER0 from reset and wait until ready.
* @retval None
*/
void timer_release_reset(void)
{
_timer_clear_reset_bit();
_timer_wait_reset_done();
}
/**
* @brief Start the TIMER0 tick generator at 1 us resolution.
* @retval None
*/
void timer_tick_init(void)
{
_timer_set_tick_cycles();
_timer_enable_tick();
}
/**
* @brief Start a repeating alarm that fires every period_ms milliseconds.
* @param period_ms interval in milliseconds between callbacks
* @param cb function to call on each alarm
* @retval None
*/
void timer_alarm_start(uint32_t period_ms, timer_callback_t cb)
{
_user_callback = cb;
+31
View File
@@ -79,12 +79,20 @@ static void _uart_enable(void)
UART_BASE[UART_CR_OFFSET] = UART_CR_ENABLE;
}
/**
* @brief Release UART0 from reset and wait until ready.
* @retval None
*/
void uart_release_reset(void)
{
_uart_clear_reset_bit();
_uart_wait_reset_done();
}
/**
* @brief Initialize UART0 pins, baud rate, line control, and enable.
* @retval None
*/
void uart_init(void)
{
_uart_configure_pins();
@@ -92,11 +100,19 @@ void uart_init(void)
_uart_enable();
}
/**
* @brief Check whether a received byte is waiting in the UART FIFO.
* @retval bool true if at least one byte is available
*/
bool uart_is_readable(void)
{
return (UART_BASE[UART_FR_OFFSET] & UART_FR_RXFE_MASK) == 0;
}
/**
* @brief Read one character from UART0 (blocking).
* @retval char the received character
*/
char uart_getchar(void)
{
while (UART_BASE[UART_FR_OFFSET] & UART_FR_RXFE_MASK) {
@@ -104,6 +120,11 @@ char uart_getchar(void)
return (char)(UART_BASE[UART_DR_OFFSET] & 0xFF);
}
/**
* @brief Transmit one character over UART0 (blocking).
* @param c character to transmit
* @retval None
*/
void uart_putchar(char c)
{
while (UART_BASE[UART_FR_OFFSET] & UART_FR_TXFF_MASK) {
@@ -111,6 +132,11 @@ void uart_putchar(char c)
UART_BASE[UART_DR_OFFSET] = (uint32_t)c;
}
/**
* @brief Transmit a null-terminated string over UART0.
* @param str pointer to the string to send
* @retval None
*/
void uart_puts(const char *str)
{
while (*str) {
@@ -118,6 +144,11 @@ void uart_puts(const char *str)
}
}
/**
* @brief Convert a lowercase ASCII character to uppercase.
* @param c input character
* @retval char uppercase equivalent or original character
*/
char uart_to_upper(char c)
{
if (c >= 'a' && c <= 'z')
+12
View File
@@ -22,6 +22,10 @@
#include "rp2350_xosc.h"
/**
* @brief Initialize the external crystal oscillator and wait until stable.
* @retval None
*/
void xosc_init(void)
{
XOSC->STARTUP = 0x00C4U;
@@ -30,6 +34,10 @@ void xosc_init(void)
}
}
/**
* @brief Enable the XOSC peripheral clock via CLK_PERI_CTRL.
* @retval None
*/
void xosc_enable_peri_clk(void)
{
uint32_t value;
@@ -40,6 +48,10 @@ void xosc_enable_peri_clk(void)
CLOCKS->CLK_PERI_CTRL = value;
}
/**
* @brief Switch CLK_REF source to XOSC for a stable 12 MHz clk_sys.
* @retval None
*/
void xosc_set_clk_ref(void)
{
CLOCKS->CLK_REF_CTRL = CLK_REF_CTRL_SRC_XOSC;