2021-07-07 23:44:57 +10:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
use cortex_m_rt::entry;
|
|
|
|
use embedded_hal::PwmPin;
|
|
|
|
use panic_halt as _;
|
2021-09-02 09:37:17 +10:00
|
|
|
use rp2040_hal::{gpio::Pins, pwm::*, sio::Sio};
|
2021-07-07 23:44:57 +10:00
|
|
|
|
|
|
|
#[link_section = ".boot2"]
|
|
|
|
#[used]
|
|
|
|
pub static BOOT2: [u8; 256] = rp2040_boot2::BOOT_LOADER;
|
|
|
|
|
|
|
|
#[entry]
|
|
|
|
fn main() -> ! {
|
|
|
|
let mut pac = rp2040_pac::Peripherals::take().unwrap();
|
|
|
|
|
2021-09-02 09:37:17 +10:00
|
|
|
let sio = Sio::new(pac.SIO);
|
|
|
|
let pins = Pins::new(
|
|
|
|
pac.IO_BANK0,
|
|
|
|
pac.PADS_BANK0,
|
|
|
|
sio.gpio_bank0,
|
2021-07-07 23:50:22 +10:00
|
|
|
&mut pac.RESETS,
|
|
|
|
);
|
2021-07-07 23:44:57 +10:00
|
|
|
|
2021-09-02 09:37:17 +10:00
|
|
|
// Init PWMs
|
|
|
|
let pwm_slices = Slices::new(pac.PWM, &mut pac.RESETS);
|
2021-07-07 23:44:57 +10:00
|
|
|
|
2021-09-02 09:37:17 +10:00
|
|
|
// Configure PWM4
|
|
|
|
let mut pwm = pwm_slices.pwm4;
|
|
|
|
pwm.set_ph_correct();
|
|
|
|
pwm.enable();
|
2021-07-07 23:44:57 +10:00
|
|
|
|
2021-09-02 09:37:17 +10:00
|
|
|
// Use B channel (which outputs to GPIO 25)
|
|
|
|
let mut channel = pwm.channel_b;
|
|
|
|
channel.output_to(pins.gpio25);
|
2021-07-07 23:44:57 +10:00
|
|
|
loop {
|
2021-09-02 09:37:17 +10:00
|
|
|
channel.set_duty(15000);
|
2021-07-07 23:44:57 +10:00
|
|
|
// TODO: Replace with proper delays once we have clocks working
|
|
|
|
cortex_m::asm::delay(5_000_000);
|
2021-09-02 09:37:17 +10:00
|
|
|
channel.set_duty(30000);
|
2021-07-07 23:44:57 +10:00
|
|
|
cortex_m::asm::delay(5_000_000);
|
|
|
|
}
|
|
|
|
}
|