mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-06-06 22:33:57 +02:00
Fixed Rust drivers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user