mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-08-18 00:47:20 +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:
@@ -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
|
||||
|
||||
@@ -38,12 +38,23 @@ static bool _debounce_confirm(uint32_t pin)
|
||||
return !gpio_get(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize a GPIO pin as an active-low button input with pull-up.
|
||||
* @param pin GPIO pin number to configure as a button input
|
||||
* @param debounce_ms debounce settling time in milliseconds
|
||||
* @retval None
|
||||
*/
|
||||
void button_init(uint32_t pin, uint32_t debounce_ms)
|
||||
{
|
||||
debounce_delay_ms = debounce_ms;
|
||||
gpio_config_input_pullup(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the debounced state of the button.
|
||||
* @param pin GPIO pin number previously initialized with button_init()
|
||||
* @retval bool true if the button is firmly pressed, false if released
|
||||
*/
|
||||
bool button_is_pressed(uint32_t pin)
|
||||
{
|
||||
if (!gpio_get(pin))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -78,6 +78,11 @@ static void _gpio_enable_output(uint32_t gpio_num)
|
||||
SIO[SIO_GPIO_OE_SET_OFFSET] = (1U << gpio_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure a GPIO pin as SIO output.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval None
|
||||
*/
|
||||
void gpio_config(uint32_t gpio_num)
|
||||
{
|
||||
_gpio_config_pad(gpio_num);
|
||||
@@ -85,26 +90,51 @@ void gpio_config(uint32_t gpio_num)
|
||||
_gpio_enable_output(gpio_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Drive a GPIO output high.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval None
|
||||
*/
|
||||
void gpio_set(uint32_t gpio_num)
|
||||
{
|
||||
SIO[SIO_GPIO_OUT_SET_OFFSET] = (1U << gpio_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Drive a GPIO output low.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval None
|
||||
*/
|
||||
void gpio_clear(uint32_t gpio_num)
|
||||
{
|
||||
SIO[SIO_GPIO_OUT_CLR_OFFSET] = (1U << gpio_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle a GPIO output.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval None
|
||||
*/
|
||||
void gpio_toggle(uint32_t gpio_num)
|
||||
{
|
||||
SIO[SIO_GPIO_OUT_XOR_OFFSET] = (1U << gpio_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the current input level of a GPIO pin.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval bool true if pin is high, false if low
|
||||
*/
|
||||
bool gpio_get(uint32_t gpio_num)
|
||||
{
|
||||
return (SIO[SIO_GPIO_IN_OFFSET] & (1U << gpio_num)) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure a GPIO pin as SIO input with internal pull-up.
|
||||
* @param gpio_num GPIO pin number (0-29)
|
||||
* @retval None
|
||||
*/
|
||||
void gpio_config_input_pullup(uint32_t gpio_num)
|
||||
{
|
||||
_gpio_config_pad_input_pullup(gpio_num);
|
||||
|
||||
@@ -22,27 +22,52 @@
|
||||
#include "rp2350_led.h"
|
||||
#include "rp2350_gpio.h"
|
||||
|
||||
/**
|
||||
* @brief Initialize a GPIO pin as a push-pull digital output.
|
||||
* @param pin GPIO pin number to configure
|
||||
* @retval None
|
||||
*/
|
||||
void led_init(uint32_t pin)
|
||||
{
|
||||
gpio_config(pin);
|
||||
gpio_clear(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Drive the output pin high (LED on).
|
||||
* @param pin GPIO pin number
|
||||
* @retval None
|
||||
*/
|
||||
void led_on(uint32_t pin)
|
||||
{
|
||||
gpio_set(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Drive the output pin low (LED off).
|
||||
* @param pin GPIO pin number
|
||||
* @retval None
|
||||
*/
|
||||
void led_off(uint32_t pin)
|
||||
{
|
||||
gpio_clear(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggle the current state of the output pin.
|
||||
* @param pin GPIO pin number
|
||||
* @retval None
|
||||
*/
|
||||
void led_toggle(uint32_t pin)
|
||||
{
|
||||
gpio_toggle(pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Query the current drive state of the output pin.
|
||||
* @param pin GPIO pin number
|
||||
* @retval bool true if the pin is driven high, false if low
|
||||
*/
|
||||
bool led_get_state(uint32_t pin)
|
||||
{
|
||||
return gpio_get(pin);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -29,6 +29,10 @@
|
||||
|
||||
extern int main(void);
|
||||
|
||||
/**
|
||||
* @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 (
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user