From 739e5861c2e47db251725163fcd91cd822cf97b7 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Sat, 18 May 2024 10:17:03 +0200 Subject: convert from antora to asciidoctor --- .../examples/layer-by-layer/blinky-pac/src/main.rs | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 docs/examples/layer-by-layer/blinky-pac/src/main.rs (limited to 'docs/examples/layer-by-layer/blinky-pac/src') diff --git a/docs/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/examples/layer-by-layer/blinky-pac/src/main.rs new file mode 100644 index 000000000..990d46cb6 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-pac/src/main.rs @@ -0,0 +1,53 @@ +#![no_std] +#![no_main] + +use pac::gpio::vals; +use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; + +#[cortex_m_rt::entry] +fn main() -> ! { + // Enable GPIO clock + let rcc = pac::RCC; + unsafe { + rcc.ahb2enr().modify(|w| { + w.set_gpioben(true); + w.set_gpiocen(true); + }); + + rcc.ahb2rstr().modify(|w| { + w.set_gpiobrst(true); + w.set_gpiocrst(true); + w.set_gpiobrst(false); + w.set_gpiocrst(false); + }); + } + + // Setup button + let gpioc = pac::GPIOC; + const BUTTON_PIN: usize = 13; + unsafe { + gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); + gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); + gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); + } + + // Setup LED + let gpiob = pac::GPIOB; + const LED_PIN: usize = 14; + unsafe { + gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); + gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); + gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); + } + + // Main loop + loop { + unsafe { + if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW { + gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true)); + } else { + gpiob.bsrr().write(|w| w.set_br(LED_PIN, true)); + } + } + } +} -- cgit