diff --git a/drivers/0x01_uart_rust/src/board.rs b/drivers/0x01_uart_rust/src/board.rs index 10926bb..80be89a 100644 --- a/drivers/0x01_uart_rust/src/board.rs +++ b/drivers/0x01_uart_rust/src/board.rs @@ -31,6 +31,9 @@ use rp235x_hal as hal; #[cfg(rp2040)] use rp2040_hal as hal; +// UART driver for echo demo +use crate::uart; + /// External crystal frequency in Hz (12 MHz). pub(crate) const XTAL_FREQ_HZ: u32 = 12_000_000u32; @@ -91,4 +94,33 @@ pub(crate) fn init_pins( hal::gpio::Pins::new(io_bank0, pads_bank0, sio.gpio_bank0, resets) } +/// Initialise all peripherals and run the UART echo demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let mut drv = uart::UartDriver::init(pac.UART0, pins.gpio0, pins.gpio1, UART_BAUD, &mut pac.RESETS, &clocks); + drv.puts(b"UART driver ready (115200 8N1)\r\n"); + drv.puts(b"Type characters to echo them back in UPPERCASE:\r\n"); + echo_loop(&mut drv) +} + +/// Run the uppercase echo loop forever. +/// +/// # Arguments +/// +/// * `drv` - Mutable reference to the UART driver. +fn echo_loop(drv: &mut uart::UartDriver) -> ! { + loop { + if drv.is_readable() { + let c = drv.getchar(); + drv.putchar(uart::UartDriver::to_upper(c)); + } + } +} + // End of file diff --git a/drivers/0x01_uart_rust/src/main.rs b/drivers/0x01_uart_rust/src/main.rs index 2ccb850..1b86fb7 100644 --- a/drivers/0x01_uart_rust/src/main.rs +++ b/drivers/0x01_uart_rust/src/main.rs @@ -76,33 +76,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the UART uppercase echo demo. -/// -/// Initializes UART0 and enters an infinite loop that reads incoming -/// characters, converts them to uppercase, and echoes them back. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut watchdog, - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let mut drv = uart::UartDriver::init( - pac.UART0, pins.gpio0, pins.gpio1, board::UART_BAUD, &mut pac.RESETS, &clocks, - ); - drv.puts(b"UART driver ready (115200 8N1)\r\n"); - drv.puts(b"Type characters to echo them back in UPPERCASE:\r\n"); - loop { - if drv.is_readable() { - let c = drv.getchar(); - let upper = uart::UartDriver::to_upper(c); - drv.putchar(upper); - } - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x02_blink_rust/src/board.rs b/drivers/0x02_blink_rust/src/board.rs index ddb5bb9..301c5f3 100644 --- a/drivers/0x02_blink_rust/src/board.rs +++ b/drivers/0x02_blink_rust/src/board.rs @@ -30,7 +30,7 @@ use fugit::RateExtU32; // Clock trait for accessing system clock frequency use hal::Clock; // GPIO pin types and function selectors -use hal::gpio::{FunctionNull, FunctionUart, Pin, PullDown, PullNone}; +use hal::gpio::{FunctionNull, FunctionSioOutput, FunctionUart, Pin, PullDown, PullNone}; // UART configuration and peripheral types use hal::uart::{DataBits, Enabled, StopBits, UartConfig, UartPeripheral}; @@ -170,4 +170,43 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()) } +/// Type alias for the onboard LED pin configured as push-pull output. +type LedPin = Pin; + +/// Initialise all peripherals and run the blink demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let mut led = crate::blink::BlinkDriver::init(pins.gpio25.into_push_pull_output()); + uart.write_full_blocking(b"Blink driver initialized on GPIO 25\r\n"); + blink_loop(&uart, &mut delay, &mut led) +} + +/// Toggle LED, report state, and delay in a loop forever. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `delay` - Mutable reference to the blocking delay provider. +/// * `led` - Mutable reference to the blink driver. +fn blink_loop( + uart: &EnabledUart, + delay: &mut cortex_m::delay::Delay, + led: &mut crate::blink::BlinkDriver, +) -> ! { + loop { + led.toggle(); + let msg = if led.get_state() { b"LED: ON\r\n" as &[u8] } else { b"LED: OFF\r\n" }; + uart.write_full_blocking(msg); + delay.delay_ms(BLINK_DELAY_MS); + } +} + // End of file diff --git a/drivers/0x02_blink_rust/src/main.rs b/drivers/0x02_blink_rust/src/main.rs index 2654dba..13396cf 100644 --- a/drivers/0x02_blink_rust/src/main.rs +++ b/drivers/0x02_blink_rust/src/main.rs @@ -74,34 +74,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the LED blink demo. -/// -/// Initializes the onboard LED and enters an infinite loop that -/// toggles the LED state every BLINK_DELAY_MS milliseconds. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let mut led = blink::BlinkDriver::init(pins.gpio25.into_push_pull_output()); - uart.write_full_blocking(b"Blink driver initialized on GPIO 25\r\n"); - loop { - led.toggle(); - if led.get_state() { - uart.write_full_blocking(b"LED: ON\r\n"); - } else { - uart.write_full_blocking(b"LED: OFF\r\n"); - } - delay.delay_ms(board::BLINK_DELAY_MS); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x03_button_rust/src/board.rs b/drivers/0x03_button_rust/src/board.rs index 73261a6..67aeb0c 100644 --- a/drivers/0x03_button_rust/src/board.rs +++ b/drivers/0x03_button_rust/src/board.rs @@ -25,12 +25,14 @@ //! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //! SOFTWARE. +// Interior mutability for shared delay access +use core::cell::RefCell; // Rate extension trait for .Hz() baud rate construction use fugit::RateExtU32; // Clock trait for accessing system clock frequency use hal::Clock; // GPIO pin types and function selectors -use hal::gpio::{FunctionNull, FunctionUart, Pin, PullDown, PullNone}; +use hal::gpio::{FunctionNull, FunctionSioInput, FunctionSioOutput, FunctionUart, Pin, PullDown, PullNone, PullUp}; // UART configuration and peripheral types use hal::uart::{DataBits, Enabled, StopBits, UartConfig, UartPeripheral}; @@ -173,4 +175,80 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()) } +/// Type alias for the button input pin (GPIO 15, pull-up). +type BtnPin = Pin; + +/// Type alias for the LED output pin (GPIO 25, push-pull). +type LedPin = Pin; + +/// Initialise all peripherals and run the button debounce demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let delay = RefCell::new(init_delay(&clocks)); + uart.write_full_blocking(b"Button driver initialized: button=GPIO15 led=GPIO25\r\n"); + button_demo(&uart, pins.gpio15, pins.gpio25, &delay) +} + +/// Create button and LED drivers, then run the polling loop. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `btn_pin` - Default GPIO 15 pin for the button input. +/// * `led_pin` - Default GPIO 25 pin for the LED output. +/// * `delay` - Shared reference to the delay provider. +fn button_demo( + uart: &EnabledUart, + btn_pin: Pin, + led_pin: Pin, + delay: &RefCell, +) -> ! { + let mut btn = crate::button::ButtonDriver::init( + btn_pin.into_pull_up_input(), DEBOUNCE_MS, |ms| delay.borrow_mut().delay_ms(ms), + ); + let mut led = crate::button::ButtonLed::init(led_pin.into_push_pull_output()); + let mut last = false; + loop { poll_button(uart, &mut btn, &mut led, &mut last, delay); } +} + +/// Poll button state, update LED, and report edge transitions. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `btn` - Mutable reference to the button driver. +/// * `led` - Mutable reference to the LED driver. +/// * `last` - Mutable reference to the previous button state. +/// * `delay` - Shared reference to the delay provider. +fn poll_button( + uart: &EnabledUart, + btn: &mut crate::button::ButtonDriver, + led: &mut crate::button::ButtonLed, + last: &mut bool, + delay: &RefCell, +) { + let pressed = btn.is_pressed(); + led.set(pressed); + if pressed != *last { report_edge(uart, pressed); *last = pressed; } + delay.borrow_mut().delay_ms(POLL_MS); +} + +/// Print button press/release message over UART. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `pressed` - `true` if the button is pressed, `false` if released. +fn report_edge(uart: &EnabledUart, pressed: bool) { + let msg = if pressed { b"Button: PRESSED\r\n" as &[u8] } else { b"Button: RELEASED\r\n" }; + uart.write_full_blocking(msg); +} + // End of file diff --git a/drivers/0x03_button_rust/src/main.rs b/drivers/0x03_button_rust/src/main.rs index aa54628..209cf35 100644 --- a/drivers/0x03_button_rust/src/main.rs +++ b/drivers/0x03_button_rust/src/main.rs @@ -54,8 +54,6 @@ use panic_halt as _; #[cfg(target_arch = "arm")] use panic_probe as _; -// Interior mutability for shared peripheral access -use core::cell::RefCell; // HAL entry-point macro use hal::entry; @@ -78,44 +76,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the button debounce demo. -/// -/// Initializes button and LED, then continuously polls button state -/// and mirrors it to the LED with UART reporting on edge transitions. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let delay = RefCell::new(board::init_delay(&clocks)); - let btn_pin = pins.gpio15.into_pull_up_input(); - let led_pin = pins.gpio25.into_push_pull_output(); - let mut btn = button::ButtonDriver::init(btn_pin, board::DEBOUNCE_MS, |ms| { - delay.borrow_mut().delay_ms(ms); - }); - let mut led = button::ButtonLed::init(led_pin); - uart.write_full_blocking(b"Button driver initialized: button=GPIO15 led=GPIO25\r\n"); - let mut last_state = false; - loop { - let pressed = btn.is_pressed(); - led.set(pressed); - if pressed != last_state { - if pressed { - uart.write_full_blocking(b"Button: PRESSED\r\n"); - } else { - uart.write_full_blocking(b"Button: RELEASED\r\n"); - } - last_state = pressed; - } - delay.borrow_mut().delay_ms(board::POLL_MS); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x04_pwm_rust/src/board.rs b/drivers/0x04_pwm_rust/src/board.rs index 157e221..a540039 100644 --- a/drivers/0x04_pwm_rust/src/board.rs +++ b/drivers/0x04_pwm_rust/src/board.rs @@ -186,28 +186,27 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay /// /// Number of bytes written into the buffer. pub(crate) fn format_duty(buf: &mut [u8], duty: u8) -> usize { - let prefix = b"Duty: "; - buf[..6].copy_from_slice(prefix); + buf[..6].copy_from_slice(b"Duty: "); let mut pos = 6; - if duty >= 100 { - buf[pos] = b'1'; pos += 1; - buf[pos] = b'0'; pos += 1; - buf[pos] = b'0'; pos += 1; - } else if duty >= 10 { - buf[pos] = b' '; pos += 1; - buf[pos] = b'0' + duty / 10; pos += 1; - buf[pos] = b'0' + duty % 10; pos += 1; - } else { - buf[pos] = b' '; pos += 1; - buf[pos] = b' '; pos += 1; - buf[pos] = b'0' + duty; pos += 1; - } + pos += write_duty_digits(&mut buf[pos..], duty); buf[pos] = b'%'; pos += 1; buf[pos] = b'\r'; pos += 1; buf[pos] = b'\n'; pos += 1; pos } +/// Write the 3-character right-justified duty digits into `buf`. +fn write_duty_digits(buf: &mut [u8], duty: u8) -> usize { + if duty >= 100 { + buf[0] = b'1'; buf[1] = b'0'; buf[2] = b'0'; + } else if duty >= 10 { + buf[0] = b' '; buf[1] = b'0' + duty / 10; buf[2] = b'0' + duty % 10; + } else { + buf[0] = b' '; buf[1] = b' '; buf[2] = b'0' + duty; + } + 3 +} + /// Sweep the PWM duty cycle from 0% to 100% in steps of 5. /// /// # Arguments @@ -224,11 +223,7 @@ pub(crate) fn sweep_up( ) { let mut duty: u8 = 0; while duty <= 100 { - let level = crate::pwm::duty_to_level(duty, PWM_WRAP) as u16; - channel.set_duty_cycle(level).ok(); - let n = format_duty(buf, duty); - uart.write_full_blocking(&buf[..n]); - delay.delay_ms(50u32); + apply_duty(uart, channel, delay, buf, duty); duty += 5; } } @@ -249,13 +244,99 @@ pub(crate) fn sweep_down( ) { let mut duty: i8 = 100; while duty >= 0 { - let level = crate::pwm::duty_to_level(duty as u8, PWM_WRAP) as u16; - channel.set_duty_cycle(level).ok(); - let n = format_duty(buf, duty as u8); - uart.write_full_blocking(&buf[..n]); - delay.delay_ms(50u32); + apply_duty(uart, channel, delay, buf, duty as u8); duty -= 5; } } +/// Apply a single duty step: set PWM level, format, print, and delay. +fn apply_duty( + uart: &EnabledUart, + channel: &mut impl SetDutyCycle, + delay: &mut cortex_m::delay::Delay, + buf: &mut [u8; 16], + duty: u8, +) { + let level = crate::pwm::duty_to_level(duty, PWM_WRAP) as u16; + channel.set_duty_cycle(level).ok(); + let n = format_duty(buf, duty); + uart.write_full_blocking(&buf[..n]); + delay.delay_ms(50u32); +} + +/// Type alias for PWM slice 4 (onboard LED, GPIO 25). +type PwmSlice4 = hal::pwm::Slice; + +/// Initialise all peripherals and run the PWM breathing demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let mut pwm = init_pwm(pac.PWM, &mut pac.RESETS, &clocks, pins.gpio25); + uart.write_full_blocking(b"PWM initialized: GPIO25 @ 1000 Hz\r\n"); + pwm_loop(&uart, &mut pwm, &mut delay) +} + +/// Configure PWM slice 4 for 1 kHz output on channel B (GPIO 25). +/// +/// # Arguments +/// +/// * `pwm_pac` - PAC PWM peripheral singleton. +/// * `resets` - Mutable reference to the RESETS peripheral. +/// * `clocks` - Reference to the initialised clock configuration. +/// * `led_pin` - Default GPIO 25 pin to bind to PWM channel B. +/// +/// # Returns +/// +/// Configured PWM slice 4 in free-running mode. +fn init_pwm( + pwm_pac: hal::pac::PWM, + resets: &mut hal::pac::RESETS, + clocks: &hal::clocks::ClocksManager, + led_pin: Pin, +) -> PwmSlice4 { + let slices = hal::pwm::Slices::new(pwm_pac, resets); + let mut slice = slices.pwm4; + configure_pwm_div(&mut slice, clocks); + slice.set_top(PWM_WRAP as u16); + slice.enable(); + slice.channel_b.output_to(led_pin); + slice +} + +/// Set the clock divider for a PWM slice based on the system clock. +/// +/// # Arguments +/// +/// * `slice` - Mutable reference to the PWM slice to configure. +/// * `clocks` - Reference to the initialised clock configuration. +fn configure_pwm_div(slice: &mut PwmSlice4, clocks: &hal::clocks::ClocksManager) { + let sys_hz = clocks.system_clock.freq().to_Hz(); + let div = crate::pwm::calc_clk_div(sys_hz, PWM_FREQ_HZ, PWM_WRAP); + let div_int = div as u8; + slice.set_div_int(div_int); + slice.set_div_frac((((div - div_int as f32) * 16.0) as u8).min(15)); +} + +/// Run the PWM duty-cycle sweep loop forever. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `pwm` - Mutable reference to the configured PWM slice. +/// * `delay` - Mutable reference to the blocking delay provider. +fn pwm_loop(uart: &EnabledUart, pwm: &mut PwmSlice4, delay: &mut cortex_m::delay::Delay) -> ! { + let mut buf = [0u8; 16]; + loop { + sweep_up(uart, &mut pwm.channel_b, delay, &mut buf); + sweep_down(uart, &mut pwm.channel_b, delay, &mut buf); + } +} + // End of file diff --git a/drivers/0x04_pwm_rust/src/main.rs b/drivers/0x04_pwm_rust/src/main.rs index c0ccc5d..5d4580f 100644 --- a/drivers/0x04_pwm_rust/src/main.rs +++ b/drivers/0x04_pwm_rust/src/main.rs @@ -79,40 +79,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the PWM LED breathing demo. -/// -/// Initializes PWM at 1 kHz on the onboard LED and enters an infinite -/// loop that sweeps the duty cycle up and down to produce a smooth -/// breathing effect, reporting each step over UART. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - uart.write_full_blocking(b"PWM initialized: GPIO25 @ 1000 Hz\r\n"); - let pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); - let mut pwm_slice = pwm_slices.pwm4; - let sys_hz = clocks.system_clock.freq().to_Hz(); - let div = pwm::calc_clk_div(sys_hz, board::PWM_FREQ_HZ, board::PWM_WRAP); - let div_int = div as u8; - pwm_slice.set_div_int(div_int); - pwm_slice.set_div_frac((((div - div_int as f32) * 16.0) as u8).min(15)); - pwm_slice.set_top(board::PWM_WRAP as u16); - pwm_slice.enable(); - pwm_slice.channel_b.output_to(pins.gpio25); - let mut buf = [0u8; 16]; - loop { - board::sweep_up(&uart, &mut pwm_slice.channel_b, &mut delay, &mut buf); - board::sweep_down(&uart, &mut pwm_slice.channel_b, &mut delay, &mut buf); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x05_servo_rust/src/board.rs b/drivers/0x05_servo_rust/src/board.rs index b4b833e..a527401 100644 --- a/drivers/0x05_servo_rust/src/board.rs +++ b/drivers/0x05_servo_rust/src/board.rs @@ -186,28 +186,28 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay /// /// Number of bytes written into the buffer. pub(crate) fn format_angle(buf: &mut [u8], angle: i32) -> usize { - let prefix = b"Angle: "; - buf[..7].copy_from_slice(prefix); + buf[..7].copy_from_slice(b"Angle: "); let mut pos = 7; let a = if angle < 0 { 0 } else { angle as u32 }; - if a >= 100 { - buf[pos] = b'0' + (a / 100) as u8; pos += 1; - buf[pos] = b'0' + ((a / 10) % 10) as u8; pos += 1; - buf[pos] = b'0' + (a % 10) as u8; pos += 1; - } else if a >= 10 { - buf[pos] = b' '; pos += 1; - buf[pos] = b'0' + (a / 10) as u8; pos += 1; - buf[pos] = b'0' + (a % 10) as u8; pos += 1; - } else { - buf[pos] = b' '; pos += 1; - buf[pos] = b' '; pos += 1; - buf[pos] = b'0' + a as u8; pos += 1; - } - let suffix = b" deg\r\n"; - buf[pos..pos + 6].copy_from_slice(suffix); + pos += write_angle_digits(&mut buf[pos..], a); + buf[pos..pos + 6].copy_from_slice(b" deg\r\n"); pos + 6 } +/// Write 3-character right-justified angle digits into `buf`. +fn write_angle_digits(buf: &mut [u8], a: u32) -> usize { + if a >= 100 { + buf[0] = b'0' + (a / 100) as u8; + buf[1] = b'0' + ((a / 10) % 10) as u8; + buf[2] = b'0' + (a % 10) as u8; + } else if a >= 10 { + buf[0] = b' '; buf[1] = b'0' + (a / 10) as u8; buf[2] = b'0' + (a % 10) as u8; + } else { + buf[0] = b' '; buf[1] = b' '; buf[2] = b'0' + a as u8; + } + 3 +} + /// Sweep the servo angle upward from 0 to 180 in STEP_DEGREES increments. /// /// # Arguments @@ -224,12 +224,7 @@ pub(crate) fn sweep_angle_up( ) { let mut angle: i32 = 0; while angle <= 180 { - let pulse = crate::servo::angle_to_pulse_us(angle as f32, crate::servo::SERVO_DEFAULT_MIN_US, crate::servo::SERVO_DEFAULT_MAX_US); - let level = crate::servo::pulse_us_to_level(pulse as u32, crate::servo::SERVO_WRAP, crate::servo::SERVO_HZ) as u16; - channel.set_duty_cycle(level).ok(); - let n = format_angle(buf, angle); - uart.write_full_blocking(&buf[..n]); - delay.delay_ms(STEP_DELAY_MS); + apply_angle(uart, channel, delay, buf, angle); angle += STEP_DEGREES; } } @@ -250,14 +245,115 @@ pub(crate) fn sweep_angle_down( ) { let mut angle: i32 = 180; while angle >= 0 { - let pulse = crate::servo::angle_to_pulse_us(angle as f32, crate::servo::SERVO_DEFAULT_MIN_US, crate::servo::SERVO_DEFAULT_MAX_US); - let level = crate::servo::pulse_us_to_level(pulse as u32, crate::servo::SERVO_WRAP, crate::servo::SERVO_HZ) as u16; - channel.set_duty_cycle(level).ok(); - let n = format_angle(buf, angle); - uart.write_full_blocking(&buf[..n]); - delay.delay_ms(STEP_DELAY_MS); + apply_angle(uart, channel, delay, buf, angle); angle -= STEP_DEGREES; } } +/// Apply a single angle step: compute pulse, set PWM, format, print, delay. +fn apply_angle( + uart: &EnabledUart, + channel: &mut impl SetDutyCycle, + delay: &mut cortex_m::delay::Delay, + buf: &mut [u8; 20], + angle: i32, +) { + let level = compute_servo_level(angle) as u16; + channel.set_duty_cycle(level).ok(); + let n = format_angle(buf, angle); + uart.write_full_blocking(&buf[..n]); + delay.delay_ms(STEP_DELAY_MS); +} + +/// Compute the PWM level for a given angle using servo constants. +fn compute_servo_level(angle: i32) -> u32 { + let pulse = crate::servo::angle_to_pulse_us(angle as f32, crate::servo::SERVO_DEFAULT_MIN_US, crate::servo::SERVO_DEFAULT_MAX_US); + crate::servo::pulse_us_to_level(pulse as u32, crate::servo::SERVO_WRAP, crate::servo::SERVO_HZ) +} + +/// Type alias for PWM slice 3 (servo on GPIO 6, channel A). +type PwmSlice3 = hal::pwm::Slice; + +/// Initialise all peripherals and run the servo sweep demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let mut pwm = init_servo_pwm(pac.PWM, &mut pac.RESETS, &clocks, pins.gpio6); + announce_servo(&uart); + servo_loop(&uart, &mut pwm, &mut delay) +} + +/// Configure PWM slice 3 for 50 Hz servo output on channel A (GPIO 6). +/// +/// # Arguments +/// +/// * `pwm_pac` - PAC PWM peripheral singleton. +/// * `resets` - Mutable reference to the RESETS peripheral. +/// * `clocks` - Reference to the initialised clock configuration. +/// * `servo_pin` - Default GPIO 6 pin to bind to PWM channel A. +/// +/// # Returns +/// +/// Configured PWM slice 3 in free-running mode. +fn init_servo_pwm( + pwm_pac: hal::pac::PWM, + resets: &mut hal::pac::RESETS, + clocks: &hal::clocks::ClocksManager, + servo_pin: Pin, +) -> PwmSlice3 { + let slices = hal::pwm::Slices::new(pwm_pac, resets); + let mut slice = slices.pwm3; + configure_servo_div(&mut slice, clocks); + slice.enable(); + slice.channel_a.output_to(servo_pin); + slice +} + +/// Set the clock divider and wrap for a servo PWM slice. +/// +/// # Arguments +/// +/// * `slice` - Mutable reference to the PWM slice to configure. +/// * `clocks` - Reference to the initialised clock configuration. +fn configure_servo_div(slice: &mut PwmSlice3, clocks: &hal::clocks::ClocksManager) { + let sys_hz = clocks.system_clock.freq().to_Hz(); + let div = crate::servo::calc_clk_div(sys_hz, crate::servo::SERVO_HZ, crate::servo::SERVO_WRAP); + let div_int = div as u8; + slice.set_div_int(div_int); + slice.set_div_frac((((div - div_int as f32) * 16.0) as u8).min(15)); + slice.set_top(crate::servo::SERVO_WRAP as u16); +} + +/// Print the servo initialisation banner over UART. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +fn announce_servo(uart: &EnabledUart) { + uart.write_full_blocking(b"Servo driver initialized on GPIO 6\r\n"); + uart.write_full_blocking(b"Sweeping 0 -> 180 -> 0 degrees in 10-degree steps\r\n"); +} + +/// Run the servo angle sweep loop forever. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `pwm` - Mutable reference to the configured PWM slice. +/// * `delay` - Mutable reference to the blocking delay provider. +fn servo_loop(uart: &EnabledUart, pwm: &mut PwmSlice3, delay: &mut cortex_m::delay::Delay) -> ! { + let mut buf = [0u8; 20]; + loop { + sweep_angle_up(uart, &mut pwm.channel_a, delay, &mut buf); + sweep_angle_down(uart, &mut pwm.channel_a, delay, &mut buf); + } +} + // End of file diff --git a/drivers/0x05_servo_rust/src/main.rs b/drivers/0x05_servo_rust/src/main.rs index d0e1955..300b4ff 100644 --- a/drivers/0x05_servo_rust/src/main.rs +++ b/drivers/0x05_servo_rust/src/main.rs @@ -78,40 +78,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the servo sweep demo. -/// -/// Initializes the servo on GPIO 6 and continuously sweeps 0-180-0 -/// degrees in 10-degree increments, reporting each angle over UART. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let pwm_slices = hal::pwm::Slices::new(pac.PWM, &mut pac.RESETS); - let mut pwm = pwm_slices.pwm3; - let sys_hz = clocks.system_clock.freq().to_Hz(); - let div = servo::calc_clk_div(sys_hz, servo::SERVO_HZ, servo::SERVO_WRAP); - let div_int = div as u8; - pwm.set_div_int(div_int); - pwm.set_div_frac((((div - div_int as f32) * 16.0) as u8).min(15)); - pwm.set_top(servo::SERVO_WRAP as u16); - pwm.enable(); - pwm.channel_a.output_to(pins.gpio6); - uart.write_full_blocking(b"Servo driver initialized on GPIO 6\r\n"); - uart.write_full_blocking(b"Sweeping 0 -> 180 -> 0 degrees in 10-degree steps\r\n"); - let mut buf = [0u8; 20]; - loop { - board::sweep_angle_up(&uart, &mut pwm.channel_a, &mut delay, &mut buf); - board::sweep_angle_down(&uart, &mut pwm.channel_a, &mut delay, &mut buf); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x06_adc_rust/src/board.rs b/drivers/0x06_adc_rust/src/board.rs index 678bc95..093c7fb 100644 --- a/drivers/0x06_adc_rust/src/board.rs +++ b/drivers/0x06_adc_rust/src/board.rs @@ -183,37 +183,133 @@ pub(crate) fn init_delay(clocks: &hal::clocks::ClocksManager) -> cortex_m::delay /// /// Number of bytes written into the buffer. pub(crate) fn format_adc_line(buf: &mut [u8], mv: u32, temp_int: i32, temp_frac: u8) -> usize { - let prefix = b"ADC0: "; - buf[..6].copy_from_slice(prefix); + buf[..6].copy_from_slice(b"ADC0: "); let mut pos = 6; - let thousands = ((mv / 1000) % 10) as u8; - let hundreds = ((mv / 100) % 10) as u8; - let tens = ((mv / 10) % 10) as u8; - let ones = (mv % 10) as u8; - buf[pos] = b'0' + thousands; pos += 1; - buf[pos] = b'0' + hundreds; pos += 1; - buf[pos] = b'0' + tens; pos += 1; - buf[pos] = b'0' + ones; pos += 1; - let mid = b" mV | Chip temp: "; - buf[pos..pos + 19].copy_from_slice(mid); + pos += write_mv_digits(&mut buf[pos..], mv); + buf[pos..pos + 19].copy_from_slice(b" mV | Chip temp: "); pos += 19; - let abs_temp = if temp_int < 0 { -temp_int } else { temp_int } as u32; - if temp_int < 0 { - buf[pos] = b'-'; pos += 1; - } - if abs_temp >= 100 { - buf[pos] = b'0' + ((abs_temp / 100) % 10) as u8; pos += 1; - } - if abs_temp >= 10 { - buf[pos] = b'0' + ((abs_temp / 10) % 10) as u8; pos += 1; - } - buf[pos] = b'0' + (abs_temp % 10) as u8; pos += 1; + pos += write_temp(&mut buf[pos..], temp_int, temp_frac); + buf[pos..pos + 4].copy_from_slice(b" C\r\n"); + pos + 4 +} + +/// Write 4-digit millivolt value into `buf`. +fn write_mv_digits(buf: &mut [u8], mv: u32) -> usize { + buf[0] = b'0' + ((mv / 1000) % 10) as u8; + buf[1] = b'0' + ((mv / 100) % 10) as u8; + buf[2] = b'0' + ((mv / 10) % 10) as u8; + buf[3] = b'0' + (mv % 10) as u8; + 4 +} + +/// Write temperature as "[-]NN.F" into `buf`. +fn write_temp(buf: &mut [u8], temp_int: i32, temp_frac: u8) -> usize { + let mut pos = 0; + let abs_temp = if temp_int < 0 { buf[pos] = b'-'; pos += 1; -temp_int } else { temp_int } as u32; + pos += write_min_digits(&mut buf[pos..], abs_temp); buf[pos] = b'.'; pos += 1; buf[pos] = b'0' + temp_frac; pos += 1; - let suffix = b" C\r\n"; - buf[pos..pos + 4].copy_from_slice(suffix); - pos += 4; pos } +/// Write a u32 with minimum digits (no leading zeros). +fn write_min_digits(buf: &mut [u8], val: u32) -> usize { + let mut pos = 0; + if val >= 100 { buf[pos] = b'0' + ((val / 100) % 10) as u8; pos += 1; } + if val >= 10 { buf[pos] = b'0' + ((val / 10) % 10) as u8; pos += 1; } + buf[pos] = b'0' + (val % 10) as u8; + pos + 1 +} + +/// Type alias for the ADC input pin on GPIO 26. +type Gpio26Adc = hal::adc::AdcPin>; + +/// Initialise all peripherals and run the ADC demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let (mut adc, mut adc_pin, mut temp) = init_adc(pac.ADC, pins.gpio26, &mut pac.RESETS); + uart.write_full_blocking(b"ADC driver initialized: GPIO26 (channel 0)\r\n"); + adc_loop(&uart, &mut adc, &mut adc_pin, &mut temp, &mut delay) +} + +/// Create the ADC peripheral, GPIO 26 input channel, and temperature sensor. +/// +/// # Arguments +/// +/// * `adc_pac` - PAC ADC peripheral singleton. +/// * `gpio26` - Default GPIO 26 pin to use as ADC input. +/// * `resets` - Mutable reference to the RESETS peripheral. +/// +/// # Returns +/// +/// Tuple of (ADC driver, ADC pin channel, temperature sensor channel). +fn init_adc( + adc_pac: hal::pac::ADC, + gpio26: Pin, + resets: &mut hal::pac::RESETS, +) -> (hal::Adc, Gpio26Adc, hal::adc::TempSense) { + let mut adc = hal::Adc::new(adc_pac, resets); + let pin = hal::adc::AdcPin::new(gpio26).unwrap(); + let temp = adc.take_temp_sensor().unwrap(); + (adc, pin, temp) +} + +/// Sample voltage and temperature, format, and print in a loop. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `adc` - Mutable reference to the ADC driver. +/// * `adc_pin` - Mutable reference to the GPIO 26 ADC channel. +/// * `temp` - Mutable reference to the temperature sensor channel. +/// * `delay` - Mutable reference to the blocking delay provider. +fn adc_loop( + uart: &EnabledUart, + adc: &mut hal::Adc, + adc_pin: &mut Gpio26Adc, + temp: &mut hal::adc::TempSense, + delay: &mut cortex_m::delay::Delay, +) -> ! { + let mut buf = [0u8; 48]; + loop { + let (mv, temp_int, temp_frac) = read_adc(adc, adc_pin, temp); + let n = format_adc_line(&mut buf, mv, temp_int, temp_frac); + uart.write_full_blocking(&buf[..n]); + delay.delay_ms(POLL_MS); + } +} + +/// Read voltage and temperature from the ADC. +/// +/// # Arguments +/// +/// * `adc` - Mutable reference to the ADC driver. +/// * `adc_pin` - Mutable reference to the GPIO 26 ADC channel. +/// * `temp` - Mutable reference to the temperature sensor channel. +/// +/// # Returns +/// +/// Tuple of (millivolts, integer temperature, fractional temperature digit). +fn read_adc( + adc: &mut hal::Adc, + adc_pin: &mut Gpio26Adc, + temp: &mut hal::adc::TempSense, +) -> (u32, i32, u8) { + let raw_v: u16 = adc.read(adc_pin).unwrap(); + let mv = crate::adc::raw_to_mv(raw_v); + let raw_t: u16 = adc.read(temp).unwrap(); + let celsius = crate::adc::raw_to_celsius(raw_t); + let temp_int = celsius as i32; + let temp_frac = (((celsius - temp_int as f32) * 10.0) as u8).min(9); + (mv, temp_int, temp_frac) +} + // End of file diff --git a/drivers/0x06_adc_rust/src/main.rs b/drivers/0x06_adc_rust/src/main.rs index 92b55a4..c94f569 100644 --- a/drivers/0x06_adc_rust/src/main.rs +++ b/drivers/0x06_adc_rust/src/main.rs @@ -78,39 +78,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the ADC voltage and temperature demo. -/// -/// Initializes the ADC on GPIO26 channel 0 and prints readings -/// every 500 ms over UART. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let mut adc_hw = hal::Adc::new(pac.ADC, &mut pac.RESETS); - let mut adc_pin = hal::adc::AdcPin::new(pins.gpio26).unwrap(); - let mut temp_sensor = adc_hw.take_temp_sensor().unwrap(); - uart.write_full_blocking(b"ADC driver initialized: GPIO26 (channel 0)\r\n"); - let mut buf = [0u8; 48]; - loop { - let raw_v: u16 = adc_hw.read(&mut adc_pin).unwrap(); - let mv = adc::raw_to_mv(raw_v); - let raw_t: u16 = adc_hw.read(&mut temp_sensor).unwrap(); - let temp = adc::raw_to_celsius(raw_t); - let temp_int = temp as i32; - let temp_frac = (((temp - temp_int as f32) * 10.0) as u8).min(9); - let n = board::format_adc_line(&mut buf, mv, temp_int, temp_frac); - uart.write_full_blocking(&buf[..n]); - delay.delay_ms(board::POLL_MS); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x07_i2c_rust/src/board.rs b/drivers/0x07_i2c_rust/src/board.rs index 551bb63..7e1972e 100644 --- a/drivers/0x07_i2c_rust/src/board.rs +++ b/drivers/0x07_i2c_rust/src/board.rs @@ -32,7 +32,7 @@ use fugit::RateExtU32; // Clock trait for accessing system clock frequency use hal::Clock; // GPIO pin types and function selectors -use hal::gpio::{FunctionNull, FunctionUart, Pin, PullDown, PullNone}; +use hal::gpio::{FunctionI2C, FunctionNull, FunctionUart, Pin, PullDown, PullNone, PullUp}; // UART configuration and peripheral types use hal::uart::{DataBits, Enabled, StopBits, UartConfig, UartPeripheral}; @@ -190,4 +190,77 @@ pub(crate) fn probe_addr(i2c: &mut impl I2c, addr: u8) -> bool { i2c.read(addr, &mut dummy).is_ok() } +/// Initialise all peripherals and run the I2C bus scanner demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let mut i2c = init_i2c(pac.I2C1, pins.gpio2, pins.gpio3, &mut pac.RESETS, &clocks); + uart.write_full_blocking(b"I2C driver initialized: I2C1 @ 100000 Hz SDA=GPIO2 SCL=GPIO3\r\n"); + scan_loop(&uart, &mut i2c, &mut delay) +} + +/// Initialise I2C1 on SDA=GPIO2 / SCL=GPIO3. +/// +/// # Arguments +/// +/// * `i2c1` - PAC I2C1 peripheral singleton. +/// * `sda` - Default GPIO 2 pin (will be reconfigured for I2C). +/// * `scl` - Default GPIO 3 pin (will be reconfigured for I2C). +/// * `resets` - Mutable reference to the RESETS peripheral. +/// * `clocks` - Reference to the initialised clock configuration. +/// +/// # Returns +/// +/// Configured I2C1 bus controller. +fn init_i2c( + i2c1: hal::pac::I2C1, + sda: Pin, + scl: Pin, + resets: &mut hal::pac::RESETS, + clocks: &hal::clocks::ClocksManager, +) -> impl I2c { + let sda = sda.reconfigure::(); + let scl = scl.reconfigure::(); + hal::I2C::i2c1(i2c1, sda, scl, I2C_BAUD.Hz(), resets, clocks.system_clock.freq()) +} + +/// Run the I2C address scan loop forever. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `i2c` - Mutable reference to the I2C bus controller. +/// * `delay` - Mutable reference to the blocking delay provider. +fn scan_loop(uart: &EnabledUart, i2c: &mut impl I2c, delay: &mut cortex_m::delay::Delay) -> ! { + let mut buf = [0u8; 80]; + loop { + let n = crate::i2c::format_scan_header(&mut buf); + uart.write_full_blocking(&buf[..n]); + scan_addresses(uart, i2c, &mut buf); + delay.delay_ms(SCAN_DELAY_MS); + } +} + +/// Scan all 128 addresses and print the formatted result. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `i2c` - Mutable reference to the I2C bus controller. +/// * `buf` - Scratch buffer for formatting output. +fn scan_addresses(uart: &EnabledUart, i2c: &mut impl I2c, buf: &mut [u8; 80]) { + for addr in 0u8..128 { + let found = !crate::i2c::is_reserved(addr) && probe_addr(i2c, addr); + let n = crate::i2c::format_scan_entry(buf, addr, found); + uart.write_full_blocking(&buf[..n]); + } +} + // End of file diff --git a/drivers/0x07_i2c_rust/src/i2c.rs b/drivers/0x07_i2c_rust/src/i2c.rs index 8e41be5..1e1a174 100644 --- a/drivers/0x07_i2c_rust/src/i2c.rs +++ b/drivers/0x07_i2c_rust/src/i2c.rs @@ -87,33 +87,36 @@ pub fn format_scan_header(buf: &mut [u8]) -> usize { /// /// Number of bytes written into the buffer. pub fn format_scan_entry(buf: &mut [u8], addr: u8, found: bool) -> usize { - let mut pos = 0; - if addr % 16 == 0 { - buf[pos] = hex_digit((addr >> 4) & 0x0F); pos += 1; - buf[pos] = hex_digit(addr & 0x0F); pos += 1; - buf[pos] = b':'; pos += 1; - buf[pos] = b' '; pos += 1; - } - if is_reserved(addr) { - buf[pos] = b' '; pos += 1; - buf[pos] = b' '; pos += 1; - buf[pos] = b' '; pos += 1; - } else if found { - buf[pos] = hex_digit((addr >> 4) & 0x0F); pos += 1; - buf[pos] = hex_digit(addr & 0x0F); pos += 1; - buf[pos] = b' '; pos += 1; - } else { - buf[pos] = b'-'; pos += 1; - buf[pos] = b'-'; pos += 1; - buf[pos] = b' '; pos += 1; - } - if addr % 16 == 15 { - buf[pos] = b'\r'; pos += 1; - buf[pos] = b'\n'; pos += 1; - } + let mut pos = format_row_prefix(buf, addr); + pos += format_cell(&mut buf[pos..], addr, found); + if addr % 16 == 15 { buf[pos] = b'\r'; pos += 1; buf[pos] = b'\n'; pos += 1; } pos } +/// Write the row prefix ("XX: ") if addr is at a 16-byte boundary. +fn format_row_prefix(buf: &mut [u8], addr: u8) -> usize { + if addr % 16 != 0 { return 0; } + buf[0] = hex_digit((addr >> 4) & 0x0F); + buf[1] = hex_digit(addr & 0x0F); + buf[2] = b':'; + buf[3] = b' '; + 4 +} + +/// Write a single cell: "XX " if found, "-- " if not, " " if reserved. +fn format_cell(buf: &mut [u8], addr: u8, found: bool) -> usize { + let cell = cell_bytes(addr, found); + buf[..3].copy_from_slice(&cell); + 3 +} + +/// Return the 3-byte cell content for an I2C scan address. +fn cell_bytes(addr: u8, found: bool) -> [u8; 3] { + if is_reserved(addr) { return [b' ', b' ', b' ']; } + if found { [hex_digit((addr >> 4) & 0x0F), hex_digit(addr & 0x0F), b' '] } + else { [b'-', b'-', b' '] } +} + #[cfg(test)] mod tests { // Import all parent module items diff --git a/drivers/0x07_i2c_rust/src/main.rs b/drivers/0x07_i2c_rust/src/main.rs index aa9dfb9..f42d5ab 100644 --- a/drivers/0x07_i2c_rust/src/main.rs +++ b/drivers/0x07_i2c_rust/src/main.rs @@ -56,14 +56,8 @@ use panic_halt as _; #[cfg(target_arch = "arm")] use panic_probe as _; -// Rate extension trait for .Hz() baud rate construction -use fugit::RateExtU32; -// Clock trait for accessing system clock frequency -use hal::Clock; // HAL entry-point macro use hal::entry; -// GPIO traits for I2C pin reconfiguration -use hal::gpio::{FunctionI2C, PullUp}; // Alias our HAL crate #[cfg(rp2350)] @@ -84,42 +78,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the I2C bus scanner demo. -/// -/// Initializes I2C1 at 100 kHz on SDA=GPIO2 / SCL=GPIO3 and prints -/// a formatted hex table of all responding device addresses over UART, -/// repeating every 5 seconds. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let sda_pin = pins.gpio2.reconfigure::(); - let scl_pin = pins.gpio3.reconfigure::(); - let mut i2c = hal::I2C::i2c1( - pac.I2C1, sda_pin, scl_pin, board::I2C_BAUD.Hz(), - &mut pac.RESETS, clocks.system_clock.freq(), - ); - uart.write_full_blocking(b"I2C driver initialized: I2C1 @ 100000 Hz SDA=GPIO2 SCL=GPIO3\r\n"); - let mut buf = [0u8; 80]; - loop { - let n = i2c::format_scan_header(&mut buf); - uart.write_full_blocking(&buf[..n]); - for addr in 0u8..128 { - let found = !i2c::is_reserved(addr) && board::probe_addr(&mut i2c, addr); - let n = i2c::format_scan_entry(&mut buf, addr, found); - uart.write_full_blocking(&buf[..n]); - } - delay.delay_ms(board::SCAN_DELAY_MS); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x08_lcd1602_rust/src/board.rs b/drivers/0x08_lcd1602_rust/src/board.rs index 64cd246..1bd6c44 100644 --- a/drivers/0x08_lcd1602_rust/src/board.rs +++ b/drivers/0x08_lcd1602_rust/src/board.rs @@ -32,7 +32,7 @@ use fugit::RateExtU32; // Clock trait for accessing system clock frequency use hal::Clock; // GPIO pin types and function selectors -use hal::gpio::{FunctionNull, FunctionUart, Pin, PullDown, PullNone}; +use hal::gpio::{FunctionI2C, FunctionNull, FunctionUart, Pin, PullDown, PullNone, PullUp}; // UART configuration and peripheral types use hal::uart::{DataBits, Enabled, StopBits, UartConfig, UartPeripheral}; @@ -246,14 +246,19 @@ fn lcd_send(i2c: &mut impl I2c, addr: u8, value: u8, mode: u8, delay: &mut corte /// * `addr` - 7-bit I2C address of the PCF8574. /// * `delay` - Delay provider for timing. fn lcd_hd44780_reset(i2c: &mut impl I2c, addr: u8, delay: &mut cortex_m::delay::Delay) { + lcd_reset_pulse_3x(i2c, addr, delay); + lcd_write4(i2c, addr, 0x02, 0, delay); + delay.delay_us(150); +} + +/// Send three 0x03 nibbles with required power-on delays. +fn lcd_reset_pulse_3x(i2c: &mut impl I2c, addr: u8, delay: &mut cortex_m::delay::Delay) { lcd_write4(i2c, addr, 0x03, 0, delay); delay.delay_ms(5); lcd_write4(i2c, addr, 0x03, 0, delay); delay.delay_us(150); lcd_write4(i2c, addr, 0x03, 0, delay); delay.delay_us(150); - lcd_write4(i2c, addr, 0x02, 0, delay); - delay.delay_us(150); } /// Send post-reset configuration commands to the HD44780. @@ -312,9 +317,14 @@ pub(crate) fn setup_display( ) { lcd_hd44780_reset(i2c, LCD_I2C_ADDR, delay); lcd_hd44780_configure(i2c, LCD_I2C_ADDR, delay); + lcd_show_title(i2c, delay); + uart.write_full_blocking(b"LCD 1602 driver initialized at I2C addr 0x27\r\n"); +} + +/// Write the title text on LCD row 0. +fn lcd_show_title(i2c: &mut impl I2c, delay: &mut cortex_m::delay::Delay) { lcd_set_cursor(i2c, LCD_I2C_ADDR, 0, 0, delay); lcd_puts(i2c, LCD_I2C_ADDR, b"Reverse Eng.", delay); - uart.write_full_blocking(b"LCD 1602 driver initialized at I2C addr 0x27\r\n"); } /// Format and display the next counter value on LCD line 1. @@ -334,11 +344,78 @@ pub(crate) fn update_counter( let mut buf = [0u8; 16]; let n = crate::lcd1602::format_counter(&mut buf, *count); *count += 1; - lcd_set_cursor(i2c, LCD_I2C_ADDR, 1, 0, delay); - lcd_puts(i2c, LCD_I2C_ADDR, &buf[..n], delay); - uart.write_full_blocking(&buf[..n]); - uart.write_full_blocking(b"\r\n"); + lcd_display_counter(i2c, delay, &buf[..n]); + uart_log_counter(uart, &buf[..n]); delay.delay_ms(COUNTER_DELAY_MS); } +/// Write counter text to LCD line 1. +fn lcd_display_counter(i2c: &mut impl I2c, delay: &mut cortex_m::delay::Delay, text: &[u8]) { + lcd_set_cursor(i2c, LCD_I2C_ADDR, 1, 0, delay); + lcd_puts(i2c, LCD_I2C_ADDR, text, delay); +} + +/// Log counter text over UART with trailing CRLF. +fn uart_log_counter(uart: &EnabledUart, text: &[u8]) { + uart.write_full_blocking(text); + uart.write_full_blocking(b"\r\n"); +} + +/// Initialise all peripherals and run the LCD 1602 counter demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let mut i2c = init_i2c(pac.I2C1, pins.gpio2, pins.gpio3, &mut pac.RESETS, &clocks); + setup_display(&mut i2c, &uart, &mut delay); + counter_loop(&mut i2c, &uart, &mut delay) +} + +/// Initialise I2C1 on SDA=GPIO2 / SCL=GPIO3. +/// +/// # Arguments +/// +/// * `i2c1` - PAC I2C1 peripheral singleton. +/// * `sda` - Default GPIO 2 pin (will be reconfigured for I2C). +/// * `scl` - Default GPIO 3 pin (will be reconfigured for I2C). +/// * `resets` - Mutable reference to the RESETS peripheral. +/// * `clocks` - Reference to the initialised clock configuration. +/// +/// # Returns +/// +/// Configured I2C1 bus controller. +fn init_i2c( + i2c1: hal::pac::I2C1, + sda: Pin, + scl: Pin, + resets: &mut hal::pac::RESETS, + clocks: &hal::clocks::ClocksManager, +) -> impl I2c { + let sda = sda.reconfigure::(); + let scl = scl.reconfigure::(); + hal::I2C::i2c1(i2c1, sda, scl, I2C_BAUD.Hz(), resets, clocks.system_clock.freq()) +} + +/// Run the counter display loop forever. +/// +/// # Arguments +/// +/// * `i2c` - Mutable reference to the I2C bus controller. +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `delay` - Mutable reference to the blocking delay provider. +fn counter_loop( + i2c: &mut impl I2c, + uart: &EnabledUart, + delay: &mut cortex_m::delay::Delay, +) -> ! { + let mut count: u32 = 0; + loop { update_counter(i2c, uart, delay, &mut count); } +} + // End of file diff --git a/drivers/0x08_lcd1602_rust/src/main.rs b/drivers/0x08_lcd1602_rust/src/main.rs index 0c815a0..1906bbb 100644 --- a/drivers/0x08_lcd1602_rust/src/main.rs +++ b/drivers/0x08_lcd1602_rust/src/main.rs @@ -56,14 +56,8 @@ use panic_halt as _; #[cfg(target_arch = "arm")] use panic_probe as _; -// Rate extension trait for .Hz() baud rate construction -use fugit::RateExtU32; -// Clock trait for accessing system clock frequency -use hal::Clock; // HAL entry-point macro use hal::entry; -// GPIO traits for I2C pin reconfiguration -use hal::gpio::{FunctionI2C, PullUp}; // Alias our HAL crate #[cfg(rp2350)] @@ -84,34 +78,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the LCD 1602 counter demo. -/// -/// Initializes the LCD over I2C with a static title on line 0 and -/// continuously increments a counter on line 1 every second. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let sda_pin = pins.gpio2.reconfigure::(); - let scl_pin = pins.gpio3.reconfigure::(); - let mut i2c = hal::I2C::i2c1( - pac.I2C1, sda_pin, scl_pin, board::I2C_BAUD.Hz(), - &mut pac.RESETS, clocks.system_clock.freq(), - ); - board::setup_display(&mut i2c, &uart, &mut delay); - let mut count: u32 = 0; - loop { - board::update_counter(&mut i2c, &uart, &mut delay, &mut count); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x09_dht11_rust/src/board.rs b/drivers/0x09_dht11_rust/src/board.rs index 9ae9d11..ca66226 100644 --- a/drivers/0x09_dht11_rust/src/board.rs +++ b/drivers/0x09_dht11_rust/src/board.rs @@ -382,4 +382,24 @@ pub(crate) fn poll_sensor( delay.delay_ms(POLL_MS); } +/// Initialise all peripherals and run the DHT11 sensor demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + #[cfg(rp2350)] + let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); + #[cfg(rp2040)] + let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); + let _ = pins.gpio4.into_pull_up_input(); + uart.write_full_blocking(b"DHT11 driver initialized on GPIO 4\r\n"); + loop { poll_sensor(&uart, &timer, &mut delay); } +} + // End of file diff --git a/drivers/0x09_dht11_rust/src/dht11.rs b/drivers/0x09_dht11_rust/src/dht11.rs index b05727f..60c6c43 100644 --- a/drivers/0x09_dht11_rust/src/dht11.rs +++ b/drivers/0x09_dht11_rust/src/dht11.rs @@ -111,21 +111,20 @@ pub fn parse_temperature(data: &[u8; 5]) -> f32 { /// /// Number of bytes written into the buffer. pub fn format_reading(buf: &mut [u8], humidity: f32, temperature: f32) -> usize { - let mut pos = 0; - let prefix = b"Humidity: "; - buf[pos..pos + prefix.len()].copy_from_slice(prefix); - pos += prefix.len(); + let mut pos = copy_slice(buf, 0, b"Humidity: "); pos += format_f32_1(&mut buf[pos..], humidity); - let mid = b"% Temperature: "; - buf[pos..pos + mid.len()].copy_from_slice(mid); - pos += mid.len(); + pos += copy_slice(buf, pos, b"% Temperature: "); pos += format_f32_1(&mut buf[pos..], temperature); - let suffix = b" C"; - buf[pos..pos + suffix.len()].copy_from_slice(suffix); - pos += suffix.len(); + pos += copy_slice(buf, pos, b" C"); pos } +/// Copy a byte slice into `buf` at the given offset, returning bytes written. +fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize { + buf[offset..offset + src.len()].copy_from_slice(src); + src.len() +} + /// Format a failed-read error message. /// /// # Arguments @@ -185,17 +184,7 @@ fn format_f32_1(buf: &mut [u8], val: f32) -> usize { let scaled = (val * 10.0) as u32; let integer = scaled / 10; let frac = (scaled % 10) as u8; - let mut pos = 0; - if integer >= 100 { - buf[pos] = b'0' + (integer / 100) as u8; - pos += 1; - } - if integer >= 10 { - buf[pos] = b'0' + ((integer / 10) % 10) as u8; - pos += 1; - } - buf[pos] = b'0' + (integer % 10) as u8; - pos += 1; + let mut pos = format_u32_minimal(buf, integer); buf[pos] = b'.'; pos += 1; buf[pos] = b'0' + frac; @@ -203,6 +192,21 @@ fn format_f32_1(buf: &mut [u8], val: f32) -> usize { pos } +/// Format a u32 as minimal decimal digits (no leading zeros). +fn format_u32_minimal(buf: &mut [u8], value: u32) -> usize { + let mut pos = 0; + if value >= 100 { + buf[pos] = b'0' + (value / 100) as u8; + pos += 1; + } + if value >= 10 { + buf[pos] = b'0' + ((value / 10) % 10) as u8; + pos += 1; + } + buf[pos] = b'0' + (value % 10) as u8; + pos + 1 +} + #[cfg(test)] mod tests { // Import all parent module items diff --git a/drivers/0x09_dht11_rust/src/main.rs b/drivers/0x09_dht11_rust/src/main.rs index 6fd964e..fe9df96 100644 --- a/drivers/0x09_dht11_rust/src/main.rs +++ b/drivers/0x09_dht11_rust/src/main.rs @@ -78,32 +78,9 @@ pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_W25Q080; pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the DHT11 sensor demo. -/// -/// Initializes the DHT11 on GPIO4 and continuously reads temperature -/// and humidity, printing results over UART every 2 seconds. -/// -/// # Returns -/// -/// Does not return. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - #[cfg(rp2350)] - let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); - #[cfg(rp2040)] - let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); - let _dht_pin = pins.gpio4.into_pull_up_input(); - uart.write_full_blocking(b"DHT11 driver initialized on GPIO 4\r\n"); - loop { - board::poll_sensor(&uart, &timer, &mut delay); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0a_ir_rust/src/board.rs b/drivers/0x0a_ir_rust/src/board.rs index 27546c4..669c3ef 100644 --- a/drivers/0x0a_ir_rust/src/board.rs +++ b/drivers/0x0a_ir_rust/src/board.rs @@ -216,4 +216,36 @@ pub(crate) fn poll_receiver( uart.write_full_blocking(&buf[..len]); } delay.delay_ms(POLL_MS); -} \ No newline at end of file +} + +/// Initialise all peripherals and run the NEC IR receiver demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + #[cfg(rp2350)] + let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); + #[cfg(rp2040)] + let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); + let _ = pins.gpio5.into_pull_up_input(); + announce_ir(&uart); + loop { poll_receiver(&uart, &timer, &mut delay); } +} + +/// Print the IR driver initialisation banner over UART. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +fn announce_ir(uart: &EnabledUart) { + uart.write_full_blocking(b"NEC IR driver initialized on GPIO 5\r\n"); + uart.write_full_blocking(b"Press a button on your NEC remote...\r\n"); +} + +// End of file \ No newline at end of file diff --git a/drivers/0x0a_ir_rust/src/ir.rs b/drivers/0x0a_ir_rust/src/ir.rs index 70f2337..ea37aba 100644 --- a/drivers/0x0a_ir_rust/src/ir.rs +++ b/drivers/0x0a_ir_rust/src/ir.rs @@ -98,39 +98,38 @@ pub fn validate_nec_frame(data: &[u8; 4]) -> Option { /// Format the decoded command as hexadecimal and decimal followed by CRLF. pub fn format_command(buf: &mut [u8], command: u8) -> usize { - let mut pos = 0; let prefix = b"NEC command: 0x"; - buf[pos..pos + prefix.len()].copy_from_slice(prefix); - pos += prefix.len(); + let mut pos = copy_slice(buf, 0, prefix); pos += format_hex_u8(buf, pos, command); - let middle = b" ("; - buf[pos..pos + middle.len()].copy_from_slice(middle); - pos += middle.len(); + pos += copy_slice(buf, pos, b" ("); pos += format_u8(buf, pos, command); - buf[pos] = b')'; - pos += 1; - buf[pos] = b'\r'; - pos += 1; - buf[pos] = b'\n'; - pos += 1; + pos += copy_slice(buf, pos, b")\r\n"); pos } +/// Copy a byte slice into `buf` at the given offset, returning bytes written. +fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize { + buf[offset..offset + src.len()].copy_from_slice(src); + src.len() +} + /// Format an unsigned 8-bit integer at the given buffer offset. fn format_u8(buf: &mut [u8], pos: usize, value: u8) -> usize { - if value >= 100 { - buf[pos] = b'0' + value / 100; - buf[pos + 1] = b'0' + (value / 10) % 10; - buf[pos + 2] = b'0' + value % 10; - 3 - } else if value >= 10 { - buf[pos] = b'0' + value / 10; - buf[pos + 1] = b'0' + value % 10; - 2 - } else { - buf[pos] = b'0' + value; - 1 - } + let n = u8_digit_count(value); + write_u8_digits(buf, pos, value, n); + n +} + +/// Return the number of decimal digits in a u8. +fn u8_digit_count(value: u8) -> usize { + if value >= 100 { 3 } else if value >= 10 { 2 } else { 1 } +} + +/// Write the decimal digits of a u8 into `buf` at `pos`. +fn write_u8_digits(buf: &mut [u8], pos: usize, value: u8, n: usize) { + if n >= 3 { buf[pos] = b'0' + value / 100; } + if n >= 2 { buf[pos + n - 2] = b'0' + (value / 10) % 10; } + buf[pos + n - 1] = b'0' + value % 10; } /// Format an unsigned 8-bit integer as two uppercase hexadecimal digits. diff --git a/drivers/0x0a_ir_rust/src/main.rs b/drivers/0x0a_ir_rust/src/main.rs index b3bf891..b5338a8 100644 --- a/drivers/0x0a_ir_rust/src/main.rs +++ b/drivers/0x0a_ir_rust/src/main.rs @@ -79,24 +79,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the NEC IR receiver demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - #[cfg(rp2350)] - let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); - #[cfg(rp2040)] - let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); - let _ir_pin = pins.gpio5.into_pull_up_input(); - uart.write_full_blocking(b"NEC IR driver initialized on GPIO 5\r\n"); - uart.write_full_blocking(b"Press a button on your NEC remote...\r\n"); - loop { - board::poll_receiver(&uart, &timer, &mut delay); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0a_ir_rust/target/debug/.fingerprint/ir-84fc5ce82174c7a1/dep-build-script-build-script-build b/drivers/0x0a_ir_rust/target/debug/.fingerprint/ir-84fc5ce82174c7a1/dep-build-script-build-script-build index 3e996bc..50d3354 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/.fingerprint/ir-84fc5ce82174c7a1/dep-build-script-build-script-build and b/drivers/0x0a_ir_rust/target/debug/.fingerprint/ir-84fc5ce82174c7a1/dep-build-script-build-script-build differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index ae55471..3c2e06a 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index 799e5e1..074a038 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index 22d23e7..b4c7013 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index 9390640..c4bfaf7 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index 43427f4..5593e2c 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index 3b2316e..988c59c 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index 0976323..2475b39 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0a_ir_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index 8000b45..707cda5 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index 633a079..9c1e6e1 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index ad15370..904d55f 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index 70250e5..a9f7236 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index 245b936..58fa153 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0a_ir_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin similarity index 99% rename from drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin rename to drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin index 5a72929..8747dd9 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin and b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/dep-graph.bin differ diff --git a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin similarity index 87% rename from drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin rename to drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin index 8e61482..80ec066 100644 Binary files a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin and b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/query-cache.bin differ diff --git a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/work-products.bin b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/work-products.bin similarity index 100% rename from drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq-dkki1ud3c61y7xezfw7wh0g35/work-products.bin rename to drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl-dkki1ud3c61y7xezfw7wh0g35/work-products.bin diff --git a/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq.lock b/drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl.lock similarity index 100% rename from drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh072qtjmo-0uf08uq.lock rename to drivers/0x0a_ir_rust/target/debug/incremental/build_script_build-0shzm4iu000x5/s-hh8hs4cnca-1rtvfsl.lock diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/ir-4fcd623141f865ef/dep-test-lib-ir_lib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/ir-4fcd623141f865ef/dep-test-lib-ir_lib index 1198714..a01de6e 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/ir-4fcd623141f865ef/dep-test-lib-ir_lib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/ir-4fcd623141f865ef/dep-test-lib-ir_lib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index 4a30d4e..3541d4e 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index e732864..cfbe5cd 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index 2d8f284..6c39231 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index 1045c0f..2736de2 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index 3ab2d73..acabbc9 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index 0e57b9b..9d2d3c9 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index 09e64e0..ede453a 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index 77c89c0..c23eaef 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index 09960a5..f57f75e 100644 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/dep-graph.bin b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/dep-graph.bin deleted file mode 100644 index 0a0b18e..0000000 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/query-cache.bin b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/query-cache.bin deleted file mode 100644 index 991b1a0..0000000 Binary files a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/query-cache.bin and /dev/null differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/dep-graph.bin b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/dep-graph.bin new file mode 100644 index 0000000..72d5cbc Binary files /dev/null and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/dep-graph.bin differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/query-cache.bin b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/query-cache.bin new file mode 100644 index 0000000..5e17785 Binary files /dev/null and b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/query-cache.bin differ diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/work-products.bin b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/work-products.bin similarity index 100% rename from drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8-bxcop442im5czbhcocpffv4jq/work-products.bin rename to drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm-7yqa7zuampsbel70cbovcmri9/work-products.bin diff --git a/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8.lock b/drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm.lock similarity index 100% rename from drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh072rtzj8-0hpaxo8.lock rename to drivers/0x0a_ir_rust/target/x86_64-pc-windows-msvc/debug/incremental/ir_lib-3nn42q02bqrwm/s-hh8hs506n3-1cyg6zm.lock diff --git a/drivers/0x0b_spi_rust/src/board.rs b/drivers/0x0b_spi_rust/src/board.rs index 4cc2288..5c43a4b 100644 --- a/drivers/0x0b_spi_rust/src/board.rs +++ b/drivers/0x0b_spi_rust/src/board.rs @@ -196,4 +196,24 @@ pub(crate) fn loopback_transfer( uart.write_full_blocking(&line_buf[..rx_len]); spi::clear_rx_buffer(&mut rx); delay.delay_ms(POLL_MS); -} \ No newline at end of file +} + +/// Initialise all peripherals and run the SPI loopback demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + let (mut spi, mut cs) = init_spi( + pac.SPI0, pins.gpio16, pins.gpio17, pins.gpio18, pins.gpio19, &mut pac.RESETS, &clocks, + ); + uart.write_full_blocking(b"SPI driver initialized on SPI0 at 1000000 Hz\r\n"); + loop { loopback_transfer(&mut spi, &mut cs, &uart, &mut delay); } +} + +// End of file \ No newline at end of file diff --git a/drivers/0x0b_spi_rust/src/main.rs b/drivers/0x0b_spi_rust/src/main.rs index d10f43c..626f5ea 100644 --- a/drivers/0x0b_spi_rust/src/main.rs +++ b/drivers/0x0b_spi_rust/src/main.rs @@ -78,27 +78,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the SPI loopback demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let (mut spi_dev, mut cs) = board::init_spi( - pac.SPI0, - pins.gpio16, - pins.gpio17, - pins.gpio18, - pins.gpio19, - &mut pac.RESETS, - &clocks, - ); - uart.write_full_blocking(b"SPI driver initialized on SPI0 at 1000000 Hz\r\n"); - loop { - board::loopback_transfer(&mut spi_dev, &mut cs, &uart, &mut delay); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0b_spi_rust/src/spi.rs b/drivers/0x0b_spi_rust/src/spi.rs index e7b19ac..67918ce 100644 --- a/drivers/0x0b_spi_rust/src/spi.rs +++ b/drivers/0x0b_spi_rust/src/spi.rs @@ -77,22 +77,25 @@ fn format_line(buf: &mut [u8], prefix: &[u8], text: &[u8], extra_blank_line: boo let mut pos = 0; buf[pos..pos + prefix.len()].copy_from_slice(prefix); pos += prefix.len(); - let text_len = c_string_len(text); - buf[pos..pos + text_len].copy_from_slice(&text[..text_len]); - pos += text_len; - buf[pos] = b'\r'; - pos += 1; - buf[pos] = b'\n'; - pos += 1; - if extra_blank_line { - buf[pos] = b'\r'; - pos += 1; - buf[pos] = b'\n'; - pos += 1; - } + pos += copy_c_string(&mut buf[pos..], text); + pos += append_crlf(&mut buf[pos..], extra_blank_line); pos } +/// Copy bytes from `text` up to the first NUL into `buf`. +fn copy_c_string(buf: &mut [u8], text: &[u8]) -> usize { + let len = c_string_len(text); + buf[..len].copy_from_slice(&text[..len]); + len +} + +/// Append CRLF (and optionally a second blank CRLF) to `buf`. +fn append_crlf(buf: &mut [u8], extra: bool) -> usize { + buf[0] = b'\r'; + buf[1] = b'\n'; + if extra { buf[2] = b'\r'; buf[3] = b'\n'; 4 } else { 2 } +} + /// Return the length up to the first NUL byte or full slice length. fn c_string_len(text: &[u8]) -> usize { let mut len = 0usize; diff --git a/drivers/0x0b_spi_rust/target/debug/.fingerprint/spi-c5f700521a1a0090/dep-build-script-build-script-build b/drivers/0x0b_spi_rust/target/debug/.fingerprint/spi-c5f700521a1a0090/dep-build-script-build-script-build index 01d04c0..23adc53 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/.fingerprint/spi-c5f700521a1a0090/dep-build-script-build-script-build and b/drivers/0x0b_spi_rust/target/debug/.fingerprint/spi-c5f700521a1a0090/dep-build-script-build-script-build differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index 04645fe..c2c7bb3 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index b6dc791..b37c211 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index b351294..7bae581 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index e5f2478..ff78d1a 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index 12cd0ea..533efce 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index d777dd3..810163a 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index 09a68f4..0a1b47b 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0b_spi_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index b6baf39..a8957b3 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index 07901a8..17cc21e 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index 36681ed..45d00b0 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index ee611b8..4bc2a28 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index 6aab621..a5b8b3c 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0b_spi_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/dep-graph.bin b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/dep-graph.bin deleted file mode 100644 index 44d7741..0000000 Binary files a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/dep-graph.bin b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/dep-graph.bin new file mode 100644 index 0000000..28ebb02 Binary files /dev/null and b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/dep-graph.bin differ diff --git a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/query-cache.bin b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/query-cache.bin similarity index 80% rename from drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/query-cache.bin rename to drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/query-cache.bin index 2e7c3b5..2fbc3dc 100644 Binary files a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/query-cache.bin and b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/query-cache.bin differ diff --git a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/work-products.bin b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/work-products.bin similarity index 100% rename from drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u-10564qjo92hk7mphsyxk1euec/work-products.bin rename to drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7-56v4uheo5n1ih97iqfvx7ydmf/work-products.bin diff --git a/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u.lock b/drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7.lock similarity index 100% rename from drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh069u8mwt-0w3nq0u.lock rename to drivers/0x0b_spi_rust/target/debug/incremental/build_script_build-3egk0k4hhrki9/s-hh8hp4pviz-0hfh3x7.lock diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index d71f2e1..a0c01f2 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index 2158628..00f8903 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index da76d2a..9857394 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index 3e8c3b2..7261850 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index c2b3d6e..db067d1 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index c88e10c..05b01c3 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index b775d18..8d96035 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index 6f4c54e..bfdbd0b 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index 01d3815..d1ba402 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/dep-graph.bin b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/dep-graph.bin deleted file mode 100644 index bba1bef..0000000 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/dep-graph.bin b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/dep-graph.bin new file mode 100644 index 0000000..77b98c9 Binary files /dev/null and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/dep-graph.bin differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/query-cache.bin b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/query-cache.bin similarity index 61% rename from drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/query-cache.bin rename to drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/query-cache.bin index e9e8962..43f19b6 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/query-cache.bin and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/query-cache.bin differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/work-products.bin b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/work-products.bin similarity index 59% rename from drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/work-products.bin rename to drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/work-products.bin index f1961b0..59d7e63 100644 Binary files a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih-5up2rbvdnqasbk4rl4hlf54gw/work-products.bin and b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr-c1zbtps8xl7kahr1ju4wx6wet/work-products.bin differ diff --git a/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih.lock b/drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr.lock similarity index 100% rename from drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh069uyaoa-1xe6eih.lock rename to drivers/0x0b_spi_rust/target/x86_64-pc-windows-msvc/debug/incremental/spi_lib-0mvicxlxmwnhl/s-hh8hp7h2xk-0agqchr.lock diff --git a/drivers/0x0c_multicore_rust/src/board.rs b/drivers/0x0c_multicore_rust/src/board.rs index a9f3688..5b0131a 100644 --- a/drivers/0x0c_multicore_rust/src/board.rs +++ b/drivers/0x0c_multicore_rust/src/board.rs @@ -165,3 +165,21 @@ pub(crate) fn send_and_print( *counter = counter.wrapping_add(1); delay.delay_ms(POLL_MS); } + +/// Initialise all peripherals and run the multicore FIFO demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let (pins, mut fifo) = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + spawn_core1(&mut pac.PSM, &mut pac.PPB, &mut fifo); + let mut counter = 0u32; + loop { send_and_print(&mut fifo, &uart, &mut counter, &mut delay); } +} + +// End of file diff --git a/drivers/0x0c_multicore_rust/src/main.rs b/drivers/0x0c_multicore_rust/src/main.rs index 65d5e9b..697cb6e 100644 --- a/drivers/0x0c_multicore_rust/src/main.rs +++ b/drivers/0x0c_multicore_rust/src/main.rs @@ -76,21 +76,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the multicore FIFO demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let (pins, mut fifo) = board::init_pins( - pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS, - ); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - board::spawn_core1(&mut pac.PSM, &mut pac.PPB, &mut fifo); - let mut counter = 0u32; - loop { - board::send_and_print(&mut fifo, &uart, &mut counter, &mut delay); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0c_multicore_rust/src/multicore.rs b/drivers/0x0c_multicore_rust/src/multicore.rs index 3ff1733..74e2752 100644 --- a/drivers/0x0c_multicore_rust/src/multicore.rs +++ b/drivers/0x0c_multicore_rust/src/multicore.rs @@ -37,17 +37,27 @@ fn format_u32(buf: &mut [u8], value: u32) -> usize { return 1; } let mut tmp = [0u8; 10]; - let mut pos = 0usize; - let mut v = value; - while v > 0 { - tmp[pos] = b'0' + (v % 10) as u8; - v /= 10; - pos += 1; + let n = u32_to_digits_reversed(&mut tmp, value); + reverse_copy(buf, &tmp, n); + n +} + +/// Convert a u32 to reversed decimal digits in a temporary buffer. +fn u32_to_digits_reversed(tmp: &mut [u8; 10], mut value: u32) -> usize { + let mut n = 0usize; + while value > 0 { + tmp[n] = b'0' + (value % 10) as u8; + value /= 10; + n += 1; } - for i in 0..pos { - buf[i] = tmp[pos - 1 - i]; + n +} + +/// Copy digits from a reversed temporary buffer into the output buffer. +fn reverse_copy(buf: &mut [u8], tmp: &[u8], n: usize) { + for i in 0..n { + buf[i] = tmp[n - 1 - i]; } - pos } /// Format the round-trip message for UART output. diff --git a/drivers/0x0c_multicore_rust/target/debug/.fingerprint/multicore-7014d98f2ea9de7a/dep-build-script-build-script-build b/drivers/0x0c_multicore_rust/target/debug/.fingerprint/multicore-7014d98f2ea9de7a/dep-build-script-build-script-build index 28e8386..8dcfbf9 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/.fingerprint/multicore-7014d98f2ea9de7a/dep-build-script-build-script-build and b/drivers/0x0c_multicore_rust/target/debug/.fingerprint/multicore-7014d98f2ea9de7a/dep-build-script-build-script-build differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index a496648..b288032 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index b2ea79e..d83fc08 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index e25dc1c..cbaa397 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index 1f153bd..464ceb9 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index 72a6db5..4a4ed9c 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index dd6f5b0..3ee3cfa 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index 4ca4bab..7544b75 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index ac1e9c5..c369683 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index 37fd700..002d33f 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index 1e25da3..9409fef 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index 8684a95..4884b6c 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index ef1e3ac..0c1789c 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0c_multicore_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/dep-graph.bin b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/dep-graph.bin deleted file mode 100644 index 6644686..0000000 Binary files a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/dep-graph.bin b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/dep-graph.bin new file mode 100644 index 0000000..4d6cc3a Binary files /dev/null and b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/dep-graph.bin differ diff --git a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/query-cache.bin b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/query-cache.bin similarity index 80% rename from drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/query-cache.bin rename to drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/query-cache.bin index 80a3bbb..12e0a14 100644 Binary files a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/query-cache.bin and b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/query-cache.bin differ diff --git a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/work-products.bin b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/work-products.bin similarity index 100% rename from drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s-1aeerfb4pk4hqkqylfrrav0ep/work-products.bin rename to drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly-ci1u36gns3won7c9fcwm11wif/work-products.bin diff --git a/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s.lock b/drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly.lock similarity index 100% rename from drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh06afx9yl-1p38m6s.lock rename to drivers/0x0c_multicore_rust/target/debug/incremental/build_script_build-0gqaoml0g1qsz/s-hh8hpbb7fd-122baly.lock diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index bdc6cf6..be1e0d1 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index e6afbe5..cfd9715 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index 3971e7e..0b22b6f 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index e5acd88..39ca850 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index b0e31a6..f5009ad 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index 4686f22..30a9a19 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index d5da6d3..a5c876d 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index 5c2df9f..3b9ab0e 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index 603d352..30933f5 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/dep-graph.bin b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/dep-graph.bin deleted file mode 100644 index 9059a5f..0000000 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/dep-graph.bin b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/dep-graph.bin new file mode 100644 index 0000000..757eb2d Binary files /dev/null and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/dep-graph.bin differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/query-cache.bin b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/query-cache.bin similarity index 58% rename from drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/query-cache.bin rename to drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/query-cache.bin index 03cc1b0..72097dc 100644 Binary files a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/query-cache.bin and b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/query-cache.bin differ diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/work-products.bin b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/work-products.bin similarity index 100% rename from drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb-el5o6133nhmr9d82n3c2vr3ob/work-products.bin rename to drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2-5uc2lmjcl2ykj3m227xk48egw/work-products.bin diff --git a/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb.lock b/drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2.lock similarity index 100% rename from drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh06ah17jl-1hm7mzb.lock rename to drivers/0x0c_multicore_rust/target/x86_64-pc-windows-msvc/debug/incremental/multicore_lib-1c9dfjtnu9sxs/s-hh8hpec4cu-13csza2.lock diff --git a/drivers/0x0d_timer_rust/src/board.rs b/drivers/0x0d_timer_rust/src/board.rs index 00bd84d..d27c1d0 100644 --- a/drivers/0x0d_timer_rust/src/board.rs +++ b/drivers/0x0d_timer_rust/src/board.rs @@ -26,7 +26,7 @@ //! SOFTWARE. // Timer driver pure-logic functions and constants -use crate::timer_driver; +use crate::timer; // Rate extension trait for .Hz() baud rate construction use fugit::RateExtU32; // Clock trait for accessing system clock frequency @@ -193,23 +193,67 @@ pub(crate) fn heartbeat_loop( uart: &EnabledUart, timer: &HalTimer, delay: &mut cortex_m::delay::Delay, - state: &mut timer_driver::TimerDriverState, + state: &mut timer::TimerDriverState, ) -> ! { let mut last_us = timer.get_counter().ticks() as u32; let period_us = state.period_ms() as u64 * 1_000; loop { - let now_us = timer.get_counter().ticks() as u32; - let elapsed = now_us.wrapping_sub(last_us) as u64; - if elapsed >= period_us { - last_us = now_us; - if state.on_fire() { - let mut buf = [0u8; 32]; - let n = timer_driver::format_heartbeat(&mut buf); - uart.write_full_blocking(&buf[..n]); - } - } + let (now, elapsed) = tick_elapsed(timer, last_us); + if elapsed >= period_us { last_us = now; fire_heartbeat(uart, state); } delay.delay_us(100); } } +/// Compute elapsed microseconds since last checkpoint. +fn tick_elapsed(timer: &HalTimer, last_us: u32) -> (u32, u64) { + let now_us = timer.get_counter().ticks() as u32; + (now_us, now_us.wrapping_sub(last_us) as u64) +} + +/// Fire the heartbeat callback and print the message over UART. +fn fire_heartbeat(uart: &EnabledUart, state: &mut timer::TimerDriverState) { + if state.on_fire() { + let mut buf = [0u8; 32]; + let n = timer::format_heartbeat(&mut buf); + uart.write_full_blocking(&buf[..n]); + } +} + +/// Initialise all peripherals and run the repeating timer demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + #[cfg(rp2350)] + let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); + #[cfg(rp2040)] + let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); + let mut state = start_timer(&uart); + heartbeat_loop(&uart, &timer, &mut delay, &mut state) +} + +/// Create the timer driver state, start it, and report over UART. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// +/// # Returns +/// +/// Initialised timer driver state. +fn start_timer(uart: &EnabledUart) -> timer::TimerDriverState { + let mut state = timer::TimerDriverState::new(); + state.start(timer::DEFAULT_PERIOD_MS); + let mut buf = [0u8; 64]; + let n = timer::format_started(&mut buf, timer::DEFAULT_PERIOD_MS); + uart.write_full_blocking(&buf[..n]); + state +} + // End of file diff --git a/drivers/0x0d_timer_rust/src/lib.rs b/drivers/0x0d_timer_rust/src/lib.rs index 2224a8b..454ffce 100644 --- a/drivers/0x0d_timer_rust/src/lib.rs +++ b/drivers/0x0d_timer_rust/src/lib.rs @@ -6,4 +6,4 @@ #![no_std] // Timer driver module -pub mod timer_driver; +pub mod timer; diff --git a/drivers/0x0d_timer_rust/src/main.rs b/drivers/0x0d_timer_rust/src/main.rs index 842020f..2e7bc4f 100644 --- a/drivers/0x0d_timer_rust/src/main.rs +++ b/drivers/0x0d_timer_rust/src/main.rs @@ -1,5 +1,5 @@ //! @file main.rs -//! @brief Repeating timer demo using timer_driver.rs +//! @brief Repeating timer demo using timer.rs //! @author Kevin Thomas //! @date 2025 //! @@ -28,7 +28,7 @@ //! ----------------------------------------------------------------------------- //! //! Demonstrates repeating timer callbacks using the timer driver -//! (timer_driver.rs). A one-second heartbeat timer prints a message +//! (timer.rs). A one-second heartbeat timer prints a message //! over UART to confirm the timer is firing. //! //! Wiring: @@ -41,7 +41,7 @@ mod board; // Timer driver module — suppress warnings for unused public API functions #[allow(dead_code)] -mod timer_driver; +mod timer; // Debugging output over RTT use defmt_rtt as _; @@ -76,24 +76,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the repeating timer demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - #[cfg(rp2350)] - let timer = hal::Timer::new_timer0(pac.TIMER0, &mut pac.RESETS, &clocks); - #[cfg(rp2040)] - let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS); - let mut state = timer_driver::TimerDriverState::new(); - state.start(timer_driver::DEFAULT_PERIOD_MS); - let mut buf = [0u8; 64]; - let n = timer_driver::format_started(&mut buf, timer_driver::DEFAULT_PERIOD_MS); - uart.write_full_blocking(&buf[..n]); - board::heartbeat_loop(&uart, &timer, &mut delay, &mut state); + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0d_timer_rust/src/timer_driver.rs b/drivers/0x0d_timer_rust/src/timer.rs similarity index 94% rename from drivers/0x0d_timer_rust/src/timer_driver.rs rename to drivers/0x0d_timer_rust/src/timer.rs index d494c6c..869e715 100644 --- a/drivers/0x0d_timer_rust/src/timer_driver.rs +++ b/drivers/0x0d_timer_rust/src/timer.rs @@ -1,4 +1,4 @@ -//! @file timer_driver.rs +//! @file timer.rs //! @brief Implementation of the repeating timer driver //! @author Kevin Thomas //! @date 2025 @@ -184,17 +184,27 @@ fn format_u32(buf: &mut [u8], value: u32) -> usize { return 1; } let mut tmp = [0u8; 10]; + let n = u32_to_digits_reversed(&mut tmp, value); + reverse_copy(buf, &tmp, n); + n +} + +/// Convert a u32 to reversed decimal digits in a temporary buffer. +fn u32_to_digits_reversed(tmp: &mut [u8; 10], mut value: u32) -> usize { let mut n = 0usize; - let mut v = value; - while v > 0 { - tmp[n] = b'0' + (v % 10) as u8; - v /= 10; + while value > 0 { + tmp[n] = b'0' + (value % 10) as u8; + value /= 10; n += 1; } + n +} + +/// Copy digits from a reversed temporary buffer into the output buffer. +fn reverse_copy(buf: &mut [u8], tmp: &[u8], n: usize) { for i in 0..n { buf[i] = tmp[n - 1 - i]; } - n } #[cfg(test)] diff --git a/drivers/0x0d_timer_rust/target/.rustc_info.json b/drivers/0x0d_timer_rust/target/.rustc_info.json index d0c9241..32619c0 100644 --- a/drivers/0x0d_timer_rust/target/.rustc_info.json +++ b/drivers/0x0d_timer_rust/target/.rustc_info.json @@ -1 +1 @@ -{"rustc_fingerprint":3018370877978686052,"outputs":{"692057488268926967":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\assem.KEVINTHOMAS\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"5409910182631311548":{"success":true,"status":"","code":0,"stdout":"rustc 1.91.1 (ed61e7d7e 2025-11-07)\nbinary: rustc\ncommit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb\ncommit-date: 2025-11-07\nhost: x86_64-pc-windows-msvc\nrelease: 1.91.1\nLLVM version: 21.1.2\n","stderr":""},"7671865365644980443":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.a\nC:\\Users\\assem.KEVINTHOMAS\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\noff\n___\ndebug_assertions\npanic=\"abort\"\nproc_macro\ntarget_abi=\"eabihf\"\ntarget_arch=\"arm\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"none\"\ntarget_pointer_width=\"32\"\ntarget_vendor=\"unknown\"\n","stderr":"warning: dropping unsupported crate type `dylib` for target `thumbv8m.main-none-eabihf`\n\nwarning: dropping unsupported crate type `cdylib` for target `thumbv8m.main-none-eabihf`\n\nwarning: dropping unsupported crate type `proc-macro` for target `thumbv8m.main-none-eabihf`\n\nwarning: 3 warnings emitted\n\n"}},"successes":{}} \ No newline at end of file +{"rustc_fingerprint":3018370877978686052,"outputs":{"6257262133114560740":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\assem.KEVINTHOMAS\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"5409910182631311548":{"success":true,"status":"","code":0,"stdout":"rustc 1.91.1 (ed61e7d7e 2025-11-07)\nbinary: rustc\ncommit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb\ncommit-date: 2025-11-07\nhost: x86_64-pc-windows-msvc\nrelease: 1.91.1\nLLVM version: 21.1.2\n","stderr":""},"692057488268926967":{"success":true,"status":"","code":0,"stdout":"___.exe\nlib___.rlib\n___.dll\n___.dll\n___.lib\n___.dll\nC:\\Users\\assem.KEVINTHOMAS\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\npacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"msvc\"\ntarget_family=\"windows\"\ntarget_feature=\"cmpxchg16b\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"windows\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"pc\"\nwindows\n","stderr":""},"7671865365644980443":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.a\nC:\\Users\\assem.KEVINTHOMAS\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\noff\n___\ndebug_assertions\npanic=\"abort\"\nproc_macro\ntarget_abi=\"eabihf\"\ntarget_arch=\"arm\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"none\"\ntarget_pointer_width=\"32\"\ntarget_vendor=\"unknown\"\n","stderr":"warning: dropping unsupported crate type `dylib` for target `thumbv8m.main-none-eabihf`\n\nwarning: dropping unsupported crate type `cdylib` for target `thumbv8m.main-none-eabihf`\n\nwarning: dropping unsupported crate type `proc-macro` for target `thumbv8m.main-none-eabihf`\n\nwarning: 3 warnings emitted\n\n"}},"successes":{}} \ No newline at end of file diff --git a/drivers/0x0d_timer_rust/target/debug/.fingerprint/timer-17e9b2117fa5601f/dep-build-script-build-script-build b/drivers/0x0d_timer_rust/target/debug/.fingerprint/timer-17e9b2117fa5601f/dep-build-script-build-script-build index 59bf8ea..88f45de 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/.fingerprint/timer-17e9b2117fa5601f/dep-build-script-build-script-build and b/drivers/0x0d_timer_rust/target/debug/.fingerprint/timer-17e9b2117fa5601f/dep-build-script-build-script-build differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index d8bcab0..32052d3 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index 81a1e2c..ad634ed 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index 4b80bea..8e428cb 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index 96cc7bf..4501e7a 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index b4461a0..8dc3ee4 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index 77121e4..8dd5730 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index bf82c24..9ea990e 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0d_timer_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index 6cef4ec..9c7620b 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index b3c75a1..f5e33eb 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index 760cde3..261632b 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index 3a37aae..9a3a693 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index 4a048c9..09f1d1b 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0d_timer_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/dep-graph.bin b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/dep-graph.bin deleted file mode 100644 index 5fa5231..0000000 Binary files a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/dep-graph.bin b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/dep-graph.bin new file mode 100644 index 0000000..1ccaf12 Binary files /dev/null and b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/dep-graph.bin differ diff --git a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/query-cache.bin b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/query-cache.bin similarity index 79% rename from drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/query-cache.bin rename to drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/query-cache.bin index bcf07fe..afa63a0 100644 Binary files a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/query-cache.bin and b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/query-cache.bin differ diff --git a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/work-products.bin b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/work-products.bin similarity index 100% rename from drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n-1ov6w35mnllk99yov8ctso63x/work-products.bin rename to drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x-2qq7qfvhxx779glwekz4p1un8/work-products.bin diff --git a/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n.lock b/drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x.lock similarity index 100% rename from drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh0p99nn1t-13an63n.lock rename to drivers/0x0d_timer_rust/target/debug/incremental/build_script_build-10pxabieoxnyj/s-hh8hpi5sn7-0ekht9x.lock diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/timer-3a23861b59824fbe/dep-test-lib-timer_lib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/timer-3a23861b59824fbe/dep-test-lib-timer_lib index 949bb0c..e55c85f 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/timer-3a23861b59824fbe/dep-test-lib-timer_lib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/timer-3a23861b59824fbe/dep-test-lib-timer_lib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index c34ad73..f9b763d 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index ebdbe02..326aa14 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index 19518b3..ba18c49 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index e97621f..33dbcd8 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index b591b4b..ef7fd2c 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index be915c0..9a6e901 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index 97a62f9..bc871fd 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index a883bde..bd50647 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index baaa85f..5c8c7f8 100644 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/dep-graph.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/dep-graph.bin deleted file mode 100644 index 87da2b6..0000000 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/query-cache.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/query-cache.bin deleted file mode 100644 index d0dcfbd..0000000 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/query-cache.bin and /dev/null differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/work-products.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/work-products.bin deleted file mode 100644 index 0ed9726..0000000 Binary files a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36-av3w930ff5v4r74de245mc16i/work-products.bin and /dev/null differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/dep-graph.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/dep-graph.bin new file mode 100644 index 0000000..d200b4c Binary files /dev/null and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/dep-graph.bin differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/query-cache.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/query-cache.bin new file mode 100644 index 0000000..20e12ac Binary files /dev/null and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/query-cache.bin differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/work-products.bin b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/work-products.bin new file mode 100644 index 0000000..b4da934 Binary files /dev/null and b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4-earx8edb9bhtftt4p9omggaqn/work-products.bin differ diff --git a/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36.lock b/drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4.lock similarity index 100% rename from drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh0p3di1xb-0t76u36.lock rename to drivers/0x0d_timer_rust/target/x86_64-pc-windows-msvc/debug/incremental/timer_lib-1uqhcid1314c3/s-hh8hpkyl6h-1dorzw4.lock diff --git a/drivers/0x0e_watchdog_rust/src/board.rs b/drivers/0x0e_watchdog_rust/src/board.rs index 48309f2..2a54b97 100644 --- a/drivers/0x0e_watchdog_rust/src/board.rs +++ b/drivers/0x0e_watchdog_rust/src/board.rs @@ -26,7 +26,7 @@ //! SOFTWARE. // Watchdog driver pure-logic functions and constants -use crate::watchdog_driver; +use crate::watchdog; // Microsecond duration type for watchdog timeout use fugit::ExtU32; // Rate extension trait for .Hz() baud rate construction @@ -227,16 +227,64 @@ pub(crate) fn feed_loop( uart: &EnabledUart, watchdog: &hal::Watchdog, delay: &mut cortex_m::delay::Delay, - state: &mut watchdog_driver::WatchdogDriverState, + state: &mut watchdog::WatchdogDriverState, ) -> ! { loop { watchdog_feed(watchdog); state.feed(); let mut buf = [0u8; 32]; - let n = watchdog_driver::format_fed(&mut buf); + let n = watchdog::format_fed(&mut buf); uart.write_full_blocking(&buf[..n]); - delay.delay_ms(watchdog_driver::FEED_INTERVAL_MS); + delay.delay_ms(watchdog::FEED_INTERVAL_MS); } } +/// Initialise all peripherals and run the watchdog feed demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + let mut delay = init_delay(&clocks); + report_reset_reason(&uart); + let mut state = start_watchdog(&uart, &mut wd); + feed_loop(&uart, &wd, &mut delay, &mut state) +} + +/// Print whether the last reset was caused by the watchdog. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +fn report_reset_reason(uart: &EnabledUart) { + let mut buf = [0u8; 64]; + let caused = watchdog_caused_reboot(); + let n = watchdog::format_reset_reason(&mut buf, caused); + uart.write_full_blocking(&buf[..n]); +} + +/// Create the driver state, enable the hardware watchdog, and report. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `wd` - Mutable reference to the HAL watchdog. +/// +/// # Returns +/// +/// Initialised watchdog driver state. +fn start_watchdog(uart: &EnabledUart, wd: &mut hal::Watchdog) -> watchdog::WatchdogDriverState { + let mut state = watchdog::WatchdogDriverState::new(); + state.enable(watchdog::DEFAULT_TIMEOUT_MS); + watchdog_enable(wd, watchdog::DEFAULT_TIMEOUT_MS); + let mut buf = [0u8; 64]; + let n = watchdog::format_enabled(&mut buf, watchdog::DEFAULT_TIMEOUT_MS); + uart.write_full_blocking(&buf[..n]); + state +} + // End of file diff --git a/drivers/0x0e_watchdog_rust/src/lib.rs b/drivers/0x0e_watchdog_rust/src/lib.rs index 4728a4d..a3f7eee 100644 --- a/drivers/0x0e_watchdog_rust/src/lib.rs +++ b/drivers/0x0e_watchdog_rust/src/lib.rs @@ -6,4 +6,4 @@ #![no_std] // Watchdog driver module -pub mod watchdog_driver; +pub mod watchdog; diff --git a/drivers/0x0e_watchdog_rust/src/main.rs b/drivers/0x0e_watchdog_rust/src/main.rs index 60122e7..7b33df2 100644 --- a/drivers/0x0e_watchdog_rust/src/main.rs +++ b/drivers/0x0e_watchdog_rust/src/main.rs @@ -1,5 +1,5 @@ //! @file main.rs -//! @brief Watchdog feed demo using watchdog_driver.rs +//! @brief Watchdog feed demo using watchdog.rs //! @author Kevin Thomas //! @date 2025 //! @@ -28,7 +28,7 @@ //! ----------------------------------------------------------------------------- //! //! Demonstrates the hardware watchdog using the watchdog driver -//! (watchdog_driver.rs). The watchdog is enabled with a 3-second +//! (watchdog.rs). The watchdog is enabled with a 3-second //! timeout and fed every second. If the feed loop were removed, the //! chip would automatically reboot after 3 seconds. //! @@ -42,7 +42,7 @@ mod board; // Watchdog driver module — suppress warnings for unused public API functions #[allow(dead_code)] -mod watchdog_driver; +mod watchdog; // Debugging output over RTT use defmt_rtt as _; @@ -77,25 +77,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the watchdog demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let mut watchdog = hal::Watchdog::new(pac.WATCHDOG); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut watchdog, - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut delay = board::init_delay(&clocks); - let mut buf = [0u8; 64]; - let caused = board::watchdog_caused_reboot(); - let n = watchdog_driver::format_reset_reason(&mut buf, caused); - uart.write_full_blocking(&buf[..n]); - let mut state = watchdog_driver::WatchdogDriverState::new(); - state.enable(watchdog_driver::DEFAULT_TIMEOUT_MS); - board::watchdog_enable(&mut watchdog, watchdog_driver::DEFAULT_TIMEOUT_MS); - let n = watchdog_driver::format_enabled(&mut buf, watchdog_driver::DEFAULT_TIMEOUT_MS); - uart.write_full_blocking(&buf[..n]); - board::feed_loop(&uart, &watchdog, &mut delay, &mut state); + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0e_watchdog_rust/src/watchdog_driver.rs b/drivers/0x0e_watchdog_rust/src/watchdog.rs similarity index 90% rename from drivers/0x0e_watchdog_rust/src/watchdog_driver.rs rename to drivers/0x0e_watchdog_rust/src/watchdog.rs index 2299758..a7fa9fe 100644 --- a/drivers/0x0e_watchdog_rust/src/watchdog_driver.rs +++ b/drivers/0x0e_watchdog_rust/src/watchdog.rs @@ -1,4 +1,4 @@ -//! @file watchdog_driver.rs +//! @file watchdog.rs //! @brief Pure-logic watchdog timer driver (host-testable, no HAL) //! @author Kevin Thomas //! @date 2025 @@ -180,22 +180,19 @@ pub fn format_reset_reason(buf: &mut [u8], caused_reboot: bool) -> usize { pub fn format_enabled(buf: &mut [u8], timeout_ms: u32) -> usize { let prefix = b"Watchdog enabled ("; let suffix = b"s timeout). Feeding every 1s...\r\n"; - let mut pos = 0usize; - // Write prefix - let n = prefix.len().min(buf.len()); - buf[..n].copy_from_slice(&prefix[..n]); - pos += n; - // Write timeout in seconds (integer division matches C printf) - let secs = timeout_ms / 1000; - let written = format_u32(&mut buf[pos..], secs); - pos += written; - // Write suffix - let n = suffix.len().min(buf.len().saturating_sub(pos)); - buf[pos..pos + n].copy_from_slice(&suffix[..n]); - pos += n; + let mut pos = copy_slice(buf, 0, prefix); + pos += format_u32(&mut buf[pos..], timeout_ms / 1000); + pos += copy_slice(buf, pos, suffix); pos } +/// Copy a byte slice into `buf` at the given offset, returning bytes written. +fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize { + let n = src.len().min(buf.len().saturating_sub(offset)); + buf[offset..offset + n].copy_from_slice(&src[..n]); + n +} + /// Format a `u32` as decimal ASCII into `buf`. /// /// # Arguments @@ -215,18 +212,28 @@ pub fn format_u32(buf: &mut [u8], value: u32) -> usize { return 0; } let mut tmp = [0u8; 10]; + let n = u32_to_digits_reversed(&mut tmp, value); + reverse_copy(buf, &tmp, n); + n +} + +/// Convert a u32 to reversed decimal digits in a temporary buffer. +fn u32_to_digits_reversed(tmp: &mut [u8; 10], mut value: u32) -> usize { let mut i = 0usize; - let mut v = value; - while v > 0 { - tmp[i] = b'0' + (v % 10) as u8; - v /= 10; + while value > 0 { + tmp[i] = b'0' + (value % 10) as u8; + value /= 10; i += 1; } - let n = i.min(buf.len()); - for j in 0..n { - buf[j] = tmp[i - 1 - j]; + i +} + +/// Copy digits from a reversed temporary buffer into the output buffer. +fn reverse_copy(buf: &mut [u8], tmp: &[u8], n: usize) { + let count = n.min(buf.len()); + for j in 0..count { + buf[j] = tmp[n - 1 - j]; } - n } #[cfg(test)] diff --git a/drivers/0x0e_watchdog_rust/target/debug/.fingerprint/watchdog-fc8a973e94837d1c/dep-build-script-build-script-build b/drivers/0x0e_watchdog_rust/target/debug/.fingerprint/watchdog-fc8a973e94837d1c/dep-build-script-build-script-build index dac03bd..712a9d6 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/.fingerprint/watchdog-fc8a973e94837d1c/dep-build-script-build-script-build and b/drivers/0x0e_watchdog_rust/target/debug/.fingerprint/watchdog-fc8a973e94837d1c/dep-build-script-build-script-build differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index 311dc93..14872fe 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index 2a65628..fa5c017 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index 14cb305..e3ab5cf 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index 53ffb52..4d6baf8 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index 8cb1ad8..6f91840 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index fdfe390..f68c504 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index 9f9b056..616d256 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index a5ab6e8..1387eb0 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index 4139a1c..bc112d3 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index e4322e9..24705ce 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index 856758b..2e03ad9 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index 6f958f4..16d9859 100644 Binary files a/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0e_watchdog_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/dep-graph.bin b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/dep-graph.bin deleted file mode 100644 index 8ece843..0000000 Binary files a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/query-cache.bin b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/query-cache.bin deleted file mode 100644 index 4662f71..0000000 Binary files a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/query-cache.bin and /dev/null differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/dep-graph.bin b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/dep-graph.bin new file mode 100644 index 0000000..994ef45 Binary files /dev/null and b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/dep-graph.bin differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/query-cache.bin b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/query-cache.bin new file mode 100644 index 0000000..7d8e671 Binary files /dev/null and b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/query-cache.bin differ diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/work-products.bin b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/work-products.bin similarity index 100% rename from drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9-7ruxhp9i80ctrj1otjzmwh5dt/work-products.bin rename to drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y-b04q10i26v4ftexuq8uy7edo8/work-products.bin diff --git a/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9.lock b/drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y.lock similarity index 100% rename from drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh0waek16v-1nnlyg9.lock rename to drivers/0x0e_watchdog_rust/target/debug/incremental/build_script_build-3ocbqu5l2hxdu/s-hh8hpooiqe-08ezm3y.lock diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/watchdog-bd181a0f6618b946/dep-test-lib-watchdog_lib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/watchdog-bd181a0f6618b946/dep-test-lib-watchdog_lib index 7cc00ed..fbf2a29 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/watchdog-bd181a0f6618b946/dep-test-lib-watchdog_lib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/watchdog-bd181a0f6618b946/dep-test-lib-watchdog_lib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index 26f5f5f..dfb72d5 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index 417e406..3f4d1c2 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index b0ab1c9..34e623d 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index 0a4f645..37e6aec 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index 40e1006..0784fe5 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index a1a447e..f2e53f0 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index 98d1898..73f3799 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index 2e4ef8a..21369d5 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index 5c0f714..078616b 100644 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/dep-graph.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/dep-graph.bin deleted file mode 100644 index 2c150a0..0000000 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/query-cache.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/query-cache.bin deleted file mode 100644 index a7e6e46..0000000 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/query-cache.bin and /dev/null differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/work-products.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/work-products.bin deleted file mode 100644 index cdd6ab3..0000000 Binary files a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel-78uwiolb5027zesl3270jpumb/work-products.bin and /dev/null differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/dep-graph.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/dep-graph.bin new file mode 100644 index 0000000..13019f2 Binary files /dev/null and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/dep-graph.bin differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/query-cache.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/query-cache.bin new file mode 100644 index 0000000..438619a Binary files /dev/null and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/query-cache.bin differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/work-products.bin b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/work-products.bin new file mode 100644 index 0000000..97a6ca3 Binary files /dev/null and b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf-458lnvbl5nys4y5e6i5vpb5z1/work-products.bin differ diff --git a/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel.lock b/drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf.lock similarity index 100% rename from drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh0wahotgh-1ikboel.lock rename to drivers/0x0e_watchdog_rust/target/x86_64-pc-windows-msvc/debug/incremental/watchdog_lib-3ltukezch7seo/s-hh8hpril9d-1u3sewf.lock diff --git a/drivers/0x0f_flash_rust/src/board.rs b/drivers/0x0f_flash_rust/src/board.rs index c2b696e..a166018 100644 --- a/drivers/0x0f_flash_rust/src/board.rs +++ b/drivers/0x0f_flash_rust/src/board.rs @@ -26,7 +26,7 @@ //! SOFTWARE. // Flash driver pure-logic functions and constants -use crate::flash_driver; +use crate::flash; // Rate extension trait for .Hz() baud rate construction use fugit::RateExtU32; // Clock trait for accessing system clock frequency @@ -176,8 +176,8 @@ pub(crate) fn flash_write(flash_offset: u32, data: &[u8]) { rom_data::flash_exit_xip(); rom_data::flash_range_erase( flash_offset, - flash_driver::FLASH_SECTOR_SIZE as usize, - flash_driver::FLASH_SECTOR_SIZE, + flash::FLASH_SECTOR_SIZE as usize, + flash::FLASH_SECTOR_SIZE, 0x20, ); rom_data::flash_range_program(flash_offset, data.as_ptr(), len); @@ -198,10 +198,50 @@ pub(crate) fn flash_write(flash_offset: u32, data: &[u8]) { /// * `flash_offset` - Byte offset from the start of flash. /// * `out` - Destination buffer. pub(crate) fn flash_read(flash_offset: u32, out: &mut [u8]) { - let addr = (flash_driver::XIP_BASE + flash_offset) as *const u8; + let addr = (flash::XIP_BASE + flash_offset) as *const u8; for (i, byte) in out.iter_mut().enumerate() { *byte = unsafe { core::ptr::read_volatile(addr.add(i)) }; } } +/// Initialise all peripherals and run the flash demo. +/// +/// # Arguments +/// +/// * `pac` - PAC Peripherals singleton (consumed). +pub(crate) fn run(mut pac: hal::pac::Peripherals) -> ! { + let mut wd = hal::Watchdog::new(pac.WATCHDOG); + let clocks = init_clocks(pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut wd); + let pins = init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); + let uart = init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); + flash_demo(&uart); + loop { cortex_m::asm::wfe(); } +} + +/// Execute the flash write / read-back / report sequence. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +fn flash_demo(uart: &EnabledUart) { + let mut write_buf = [0u8; flash::FLASH_WRITE_LEN]; + flash::prepare_write_buf(&mut write_buf); + flash_write(flash::FLASH_TARGET_OFFSET, &write_buf); + let mut read_buf = [0u8; flash::FLASH_WRITE_LEN]; + flash_read(flash::FLASH_TARGET_OFFSET, &mut read_buf); + report_readback(uart, &read_buf); +} + +/// Format and print the flash read-back result over UART. +/// +/// # Arguments +/// +/// * `uart` - Reference to the enabled UART peripheral for serial output. +/// * `read_buf` - Buffer containing the data read back from flash. +fn report_readback(uart: &EnabledUart, read_buf: &[u8]) { + let mut out = [0u8; 128]; + let n = flash::format_readback(&mut out, read_buf); + uart.write_full_blocking(&out[..n]); +} + // End of file diff --git a/drivers/0x0f_flash_rust/src/flash_driver.rs b/drivers/0x0f_flash_rust/src/flash.rs similarity index 89% rename from drivers/0x0f_flash_rust/src/flash_driver.rs rename to drivers/0x0f_flash_rust/src/flash.rs index 256faf6..ea42d79 100644 --- a/drivers/0x0f_flash_rust/src/flash_driver.rs +++ b/drivers/0x0f_flash_rust/src/flash.rs @@ -1,4 +1,4 @@ -//! @file flash_driver.rs +//! @file flash.rs //! @brief Pure-logic flash driver (host-testable, no HAL) //! @author Kevin Thomas //! @date 2025 @@ -89,23 +89,27 @@ pub fn prepare_write_buf(buf: &mut [u8]) -> usize { pub fn format_readback(buf: &mut [u8], read_data: &[u8]) -> usize { let prefix = b"Flash readback: "; let suffix = b"\r\n"; - let mut pos = 0usize; - // Write prefix - let n = prefix.len().min(buf.len()); - buf[..n].copy_from_slice(&prefix[..n]); - pos += n; - // Find NUL terminator in read_data - let str_len = read_data.iter().position(|&b| b == 0).unwrap_or(read_data.len()); - let copy_len = str_len.min(buf.len().saturating_sub(pos)); - buf[pos..pos + copy_len].copy_from_slice(&read_data[..copy_len]); - pos += copy_len; - // Write suffix - let n = suffix.len().min(buf.len().saturating_sub(pos)); - buf[pos..pos + n].copy_from_slice(&suffix[..n]); - pos += n; + let mut pos = copy_slice(buf, 0, prefix); + pos += copy_c_string(&mut buf[pos..], read_data); + pos += copy_slice(buf, pos, suffix); pos } +/// Copy a byte slice into `buf` at the given offset, returning bytes written. +fn copy_slice(buf: &mut [u8], offset: usize, src: &[u8]) -> usize { + let n = src.len().min(buf.len().saturating_sub(offset)); + buf[offset..offset + n].copy_from_slice(&src[..n]); + n +} + +/// Copy bytes from `data` up to the first NUL into `buf`. +fn copy_c_string(buf: &mut [u8], data: &[u8]) -> usize { + let str_len = data.iter().position(|&b| b == 0).unwrap_or(data.len()); + let n = str_len.min(buf.len()); + buf[..n].copy_from_slice(&data[..n]); + n +} + #[cfg(test)] mod tests { // Import all parent module items diff --git a/drivers/0x0f_flash_rust/src/lib.rs b/drivers/0x0f_flash_rust/src/lib.rs index cc1869e..c5e1da6 100644 --- a/drivers/0x0f_flash_rust/src/lib.rs +++ b/drivers/0x0f_flash_rust/src/lib.rs @@ -6,4 +6,4 @@ #![no_std] // Flash driver module -pub mod flash_driver; +pub mod flash; diff --git a/drivers/0x0f_flash_rust/src/main.rs b/drivers/0x0f_flash_rust/src/main.rs index c7bea5a..a1edf90 100644 --- a/drivers/0x0f_flash_rust/src/main.rs +++ b/drivers/0x0f_flash_rust/src/main.rs @@ -1,5 +1,5 @@ //! @file main.rs -//! @brief On-chip flash write/read demo using flash_driver.rs +//! @brief On-chip flash write/read demo using flash.rs //! @author Kevin Thomas //! @date 2025 //! @@ -28,7 +28,7 @@ //! ----------------------------------------------------------------------------- //! //! Demonstrates on-chip flash read/write using the flash driver -//! (flash_driver.rs). A string is written to the last sector of flash +//! (flash.rs). A string is written to the last sector of flash //! and then read back to verify. The result is printed over UART. //! //! Wiring: @@ -41,7 +41,7 @@ mod board; // Flash driver module — suppress warnings for unused public API functions #[allow(dead_code)] -mod flash_driver; +mod flash; // Debugging output over RTT use defmt_rtt as _; @@ -76,24 +76,7 @@ pub static IMAGE_DEF: hal::block::ImageDef = hal::block::ImageDef::secure_exe(); /// Application entry point for the on-chip flash demo. #[entry] fn main() -> ! { - let mut pac = hal::pac::Peripherals::take().unwrap(); - let clocks = board::init_clocks( - pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, - &mut hal::Watchdog::new(pac.WATCHDOG), - ); - let pins = board::init_pins(pac.IO_BANK0, pac.PADS_BANK0, pac.SIO, &mut pac.RESETS); - let uart = board::init_uart(pac.UART0, pins.gpio0, pins.gpio1, &mut pac.RESETS, &clocks); - let mut write_buf = [0u8; flash_driver::FLASH_WRITE_LEN]; - flash_driver::prepare_write_buf(&mut write_buf); - board::flash_write(flash_driver::FLASH_TARGET_OFFSET, &write_buf); - let mut read_buf = [0u8; flash_driver::FLASH_WRITE_LEN]; - board::flash_read(flash_driver::FLASH_TARGET_OFFSET, &mut read_buf); - let mut out = [0u8; 128]; - let n = flash_driver::format_readback(&mut out, &read_buf); - uart.write_full_blocking(&out[..n]); - loop { - cortex_m::asm::wfe(); - } + board::run(hal::pac::Peripherals::take().unwrap()) } // Picotool binary info metadata diff --git a/drivers/0x0f_flash_rust/target/debug/.fingerprint/flash-218e15dedd4b5a51/dep-build-script-build-script-build b/drivers/0x0f_flash_rust/target/debug/.fingerprint/flash-218e15dedd4b5a51/dep-build-script-build-script-build index 4a69ffa..cf03435 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/.fingerprint/flash-218e15dedd4b5a51/dep-build-script-build-script-build and b/drivers/0x0f_flash_rust/target/debug/.fingerprint/flash-218e15dedd4b5a51/dep-build-script-build-script-build differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib index 43ccc1f..55d387d 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libaho_corasick-1aaa353ec7c4e140.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib index c3b3ed7..9e25abf 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libdefmt_parser-81b32bd6fbfa32bb.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib index 4738659..2697cbb 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro2-46513bb3b182cce7.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib index 1ab5137..a07624d 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libproc_macro_error2-89ac44b6df5e6ba6.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib index aeed414..1ea4064 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libquote-6f69cd1a9ff0a213.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib index 88d1838..f859d54 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libregex-8a91533eb98f4d5b.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib index 4fc8158..a6a78a4 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libregex_automata-fc1728f9436b246a.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib b/drivers/0x0f_flash_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib index dc1142c..7a4c1d6 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/librustc_version-8e5c430a4a79f41c.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib index 72ccc00..d54cd64 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libsemver-e9945ff4a6c4487d.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libsyn-17816738f598d97a.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libsyn-17816738f598d97a.rlib index 00ddeb4..2570165 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libsyn-17816738f598d97a.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libsyn-17816738f598d97a.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib b/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib index eb01904..d4433b6 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib and b/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rlib differ diff --git a/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta b/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta index 2fe4c26..5551eca 100644 Binary files a/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta and b/drivers/0x0f_flash_rust/target/debug/deps/libthiserror-5e1f850ae7470021.rmeta differ diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/dep-graph.bin b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/dep-graph.bin deleted file mode 100644 index c08cae5..0000000 Binary files a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/query-cache.bin b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/query-cache.bin deleted file mode 100644 index d24d15a..0000000 Binary files a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/query-cache.bin and /dev/null differ diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/dep-graph.bin b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/dep-graph.bin new file mode 100644 index 0000000..13fafbb Binary files /dev/null and b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/dep-graph.bin differ diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/query-cache.bin b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/query-cache.bin new file mode 100644 index 0000000..9041b87 Binary files /dev/null and b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/query-cache.bin differ diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/work-products.bin b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/work-products.bin similarity index 100% rename from drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh-cuv6hx26qtzqlk4cxq2a8pygc/work-products.bin rename to drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur-emtrnb7t0bq7osn5p7qsz0v3o/work-products.bin diff --git a/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh.lock b/drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur.lock similarity index 100% rename from drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh1akevbr8-0vlijqh.lock rename to drivers/0x0f_flash_rust/target/debug/incremental/build_script_build-34a511vnqd67x/s-hh8hpv9fnl-0x414ur.lock diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/flash-af1d1390f572a00c/dep-test-lib-flash_lib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/flash-af1d1390f572a00c/dep-test-lib-flash_lib index a7218ec..3ba9f79 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/flash-af1d1390f572a00c/dep-test-lib-flash_lib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/.fingerprint/flash-af1d1390f572a00c/dep-test-lib-flash_lib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib index 9670fc9..52023f2 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libbare_metal-145a5d0b259a961f.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib index 4300873..027735a 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m-2a73fdb527afce78.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib index a39cb8d..257788a 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libcortex_m_rt-1983f3d2358748be.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib index eccac4a..a8e2f04 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt-2c114c35910f6ff9.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib index 9d5afc0..038d61d 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta index cd85a17..ced5835 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libdefmt_rtt-763f7cb4cba4722e.rmeta differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib index ff10ee3..30ecea8 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libembedded_hal-2f8737b8fe724068.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib index c8dd100..1e29d59 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libfugit-2449898f4b817f7f.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib index 9df28a2..b1803ab 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/deps/libnb-1bbc00152754770b.rlib differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/dep-graph.bin b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/dep-graph.bin deleted file mode 100644 index 1e96c01..0000000 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/dep-graph.bin and /dev/null differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/query-cache.bin b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/query-cache.bin deleted file mode 100644 index 497ac45..0000000 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/query-cache.bin and /dev/null differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/dep-graph.bin b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/dep-graph.bin new file mode 100644 index 0000000..f4d9441 Binary files /dev/null and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/dep-graph.bin differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/query-cache.bin b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/query-cache.bin new file mode 100644 index 0000000..b77ab2f Binary files /dev/null and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/query-cache.bin differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/work-products.bin b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/work-products.bin similarity index 65% rename from drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/work-products.bin rename to drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/work-products.bin index 36247ea..fd88d06 100644 Binary files a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb-a74xqegaffutanxj877zkhm8v/work-products.bin and b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr-75gkcylzlnlmdrqo45ztnk1u5/work-products.bin differ diff --git a/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb.lock b/drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr.lock similarity index 100% rename from drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh1aki6jxs-0uryqsb.lock rename to drivers/0x0f_flash_rust/target/x86_64-pc-windows-msvc/debug/incremental/flash_lib-023vjv9akcgxp/s-hh8hpy6qix-1istyqr.lock