#![no_std]
#![no_main]
use cortex_m::singleton;
use cortex_m_rt::entry;
use embedded_hal::digital::OutputPin;
use hal::dma::{single_buffer, DMAExt};
use hal::pac;
use panic_halt as _;
use rp2040_hal as hal;
use rp2040_hal::clocks::Clock;
#[link_section = ".boot2"]
#[used]
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER_GENERIC_03H;
const XTAL_FREQ_HZ: u32 = 12_000_000u32;
#[entry]
fn main() -> ! {
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
let mut watchdog = hal::watchdog::Watchdog::new(pac.WATCHDOG);
let clocks = hal::clocks::init_clocks_and_plls(
XTAL_FREQ_HZ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.unwrap();
let sio = hal::sio::Sio::new(pac.SIO);
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let dma = pac.DMA.split(&mut pac.RESETS);
let mut led_pin = pins.gpio25.into_push_pull_output();
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
let tx_buf = singleton!(: [u8; 16] = [0x42; 16]).unwrap();
let rx_buf = singleton!(: [u8; 16] = [0; 16]).unwrap();
let transfer = single_buffer::Config::new(dma.ch0, tx_buf, rx_buf).start();
let (_ch, tx_buf, rx_buf) = transfer.wait();
let delay_ms = if tx_buf == rx_buf { 1000 } else { 100 };
loop {
led_pin.set_high().unwrap();
delay.delay_ms(delay_ms);
led_pin.set_low().unwrap();
delay.delay_ms(delay_ms);
}
}