diff options
Diffstat (limited to 'docs/examples')
| -rw-r--r-- | docs/examples/basic/.cargo/config.toml | 9 | ||||
| -rw-r--r-- | docs/examples/basic/Cargo.toml | 18 | ||||
| -rw-r--r-- | docs/examples/basic/build.rs | 35 | ||||
| -rw-r--r-- | docs/examples/basic/memory.x | 7 | ||||
| -rw-r--r-- | docs/examples/basic/src/main.rs | 26 | ||||
| l--------- | docs/examples/examples | 1 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/.cargo/config.toml | 14 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/Cargo.toml | 21 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-async/Cargo.toml | 15 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-async/src/main.rs | 23 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-hal/Cargo.toml | 14 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-hal/src/main.rs | 21 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-irq/Cargo.toml | 14 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-irq/src/main.rs | 93 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/Cargo.toml | 14 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/src/main.rs | 53 |
16 files changed, 378 insertions, 0 deletions
diff --git a/docs/examples/basic/.cargo/config.toml b/docs/examples/basic/.cargo/config.toml new file mode 100644 index 000000000..8ca28df39 --- /dev/null +++ b/docs/examples/basic/.cargo/config.toml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip nRF52840_xxAA" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_LOG = "trace" | ||
diff --git a/docs/examples/basic/Cargo.toml b/docs/examples/basic/Cargo.toml new file mode 100644 index 000000000..2c282145d --- /dev/null +++ b/docs/examples/basic/Cargo.toml | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-basic-example" | ||
| 5 | version = "0.1.0" | ||
| 6 | license = "MIT OR Apache-2.0" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | embassy-executor = { version = "0.5.0", path = "../../../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] } | ||
| 10 | embassy-time = { version = "0.3.0", path = "../../../../../embassy-time", features = ["defmt"] } | ||
| 11 | embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } | ||
| 12 | |||
| 13 | defmt = "0.3" | ||
| 14 | defmt-rtt = "0.3" | ||
| 15 | |||
| 16 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | ||
| 17 | cortex-m-rt = "0.7.0" | ||
| 18 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
diff --git a/docs/examples/basic/build.rs b/docs/examples/basic/build.rs new file mode 100644 index 000000000..30691aa97 --- /dev/null +++ b/docs/examples/basic/build.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | //! This build script copies the `memory.x` file from the crate root into | ||
| 2 | //! a directory where the linker can always find it at build time. | ||
| 3 | //! For many projects this is optional, as the linker always searches the | ||
| 4 | //! project root directory -- wherever `Cargo.toml` is. However, if you | ||
| 5 | //! are using a workspace or have a more complicated build setup, this | ||
| 6 | //! build script becomes required. Additionally, by requesting that | ||
| 7 | //! Cargo re-run the build script whenever `memory.x` is changed, | ||
| 8 | //! updating `memory.x` ensures a rebuild of the application with the | ||
| 9 | //! new memory settings. | ||
| 10 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | // Put `memory.x` in our output directory and ensure it's | ||
| 18 | // on the linker search path. | ||
| 19 | let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| 20 | File::create(out.join("memory.x")) | ||
| 21 | .unwrap() | ||
| 22 | .write_all(include_bytes!("memory.x")) | ||
| 23 | .unwrap(); | ||
| 24 | println!("cargo:rustc-link-search={}", out.display()); | ||
| 25 | |||
| 26 | // By default, Cargo will re-run a build script whenever | ||
| 27 | // any file in the project changes. By specifying `memory.x` | ||
| 28 | // here, we ensure the build script is only re-run when | ||
| 29 | // `memory.x` is changed. | ||
| 30 | println!("cargo:rerun-if-changed=memory.x"); | ||
| 31 | |||
| 32 | println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
| 33 | println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
| 34 | println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
| 35 | } | ||
diff --git a/docs/examples/basic/memory.x b/docs/examples/basic/memory.x new file mode 100644 index 000000000..9b04edec0 --- /dev/null +++ b/docs/examples/basic/memory.x | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 4 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 5 | FLASH : ORIGIN = 0x00000000, LENGTH = 1024K | ||
| 6 | RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
| 7 | } | ||
diff --git a/docs/examples/basic/src/main.rs b/docs/examples/basic/src/main.rs new file mode 100644 index 000000000..4412712c8 --- /dev/null +++ b/docs/examples/basic/src/main.rs | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | ||
| 7 | use embassy_time::{Duration, Timer}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; // global logger | ||
| 9 | |||
| 10 | #[embassy_executor::task] | ||
| 11 | async fn blinker(mut led: Output<'static>, interval: Duration) { | ||
| 12 | loop { | ||
| 13 | led.set_high(); | ||
| 14 | Timer::after(interval).await; | ||
| 15 | led.set_low(); | ||
| 16 | Timer::after(interval).await; | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | #[embassy_executor::main] | ||
| 21 | async fn main(spawner: Spawner) { | ||
| 22 | let p = embassy_nrf::init(Default::default()); | ||
| 23 | |||
| 24 | let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | ||
| 25 | unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300)))); | ||
| 26 | } | ||
diff --git a/docs/examples/examples b/docs/examples/examples new file mode 120000 index 000000000..d15735c1d --- /dev/null +++ b/docs/examples/examples | |||
| @@ -0,0 +1 @@ | |||
| ../../examples \ No newline at end of file | |||
diff --git a/docs/examples/layer-by-layer/.cargo/config.toml b/docs/examples/layer-by-layer/.cargo/config.toml new file mode 100644 index 000000000..3012f05dc --- /dev/null +++ b/docs/examples/layer-by-layer/.cargo/config.toml | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | runner = "probe-run --chip STM32L475VG" | ||
| 3 | |||
| 4 | rustflags = [ | ||
| 5 | "-C", "link-arg=--nmagic", | ||
| 6 | "-C", "link-arg=-Tlink.x", | ||
| 7 | "-C", "link-arg=-Tdefmt.x", | ||
| 8 | ] | ||
| 9 | |||
| 10 | [build] | ||
| 11 | target = "thumbv7em-none-eabihf" | ||
| 12 | |||
| 13 | [env] | ||
| 14 | DEFMT_LOG = "trace" | ||
diff --git a/docs/examples/layer-by-layer/Cargo.toml b/docs/examples/layer-by-layer/Cargo.toml new file mode 100644 index 000000000..943249a17 --- /dev/null +++ b/docs/examples/layer-by-layer/Cargo.toml | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | [workspace] | ||
| 2 | resolver = "2" | ||
| 3 | members = [ | ||
| 4 | "blinky-pac", | ||
| 5 | "blinky-hal", | ||
| 6 | "blinky-irq", | ||
| 7 | "blinky-async", | ||
| 8 | ] | ||
| 9 | |||
| 10 | [patch.crates-io] | ||
| 11 | embassy-executor = { path = "../../../../../embassy-executor" } | ||
| 12 | embassy-stm32 = { path = "../../../../../embassy-stm32" } | ||
| 13 | |||
| 14 | [profile.release] | ||
| 15 | codegen-units = 1 | ||
| 16 | debug = 2 | ||
| 17 | debug-assertions = false | ||
| 18 | incremental = false | ||
| 19 | lto = "fat" | ||
| 20 | opt-level = 's' | ||
| 21 | overflow-checks = false | ||
diff --git a/docs/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/examples/layer-by-layer/blinky-async/Cargo.toml new file mode 100644 index 000000000..64f7e8403 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-async/Cargo.toml | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | [package] | ||
| 2 | name = "blinky-async" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = "0.7" | ||
| 9 | cortex-m-rt = "0.7" | ||
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } | ||
| 11 | embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread"] } | ||
| 12 | |||
| 13 | defmt = "0.3.0" | ||
| 14 | defmt-rtt = "0.3.0" | ||
| 15 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
diff --git a/docs/examples/layer-by-layer/blinky-async/src/main.rs b/docs/examples/layer-by-layer/blinky-async/src/main.rs new file mode 100644 index 000000000..004602816 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-async/src/main.rs | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use embassy_executor::Spawner; | ||
| 5 | use embassy_stm32::exti::ExtiInput; | ||
| 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; | ||
| 7 | use {defmt_rtt as _, panic_probe as _}; | ||
| 8 | |||
| 9 | #[embassy_executor::main] | ||
| 10 | async fn main(_spawner: Spawner) { | ||
| 11 | let p = embassy_stm32::init(Default::default()); | ||
| 12 | let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); | ||
| 13 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); | ||
| 14 | |||
| 15 | loop { | ||
| 16 | button.wait_for_any_edge().await; | ||
| 17 | if button.is_low() { | ||
| 18 | led.set_high(); | ||
| 19 | } else { | ||
| 20 | led.set_low(); | ||
| 21 | } | ||
| 22 | } | ||
| 23 | } | ||
diff --git a/docs/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml new file mode 100644 index 000000000..c15de2db2 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | [package] | ||
| 2 | name = "blinky-hal" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = "0.7" | ||
| 9 | cortex-m-rt = "0.7" | ||
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] } | ||
| 11 | |||
| 12 | defmt = "0.3.0" | ||
| 13 | defmt-rtt = "0.3.0" | ||
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
diff --git a/docs/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/examples/layer-by-layer/blinky-hal/src/main.rs new file mode 100644 index 000000000..d0c9f4907 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-hal/src/main.rs | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use cortex_m_rt::entry; | ||
| 5 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 6 | use {defmt_rtt as _, panic_probe as _}; | ||
| 7 | |||
| 8 | #[entry] | ||
| 9 | fn main() -> ! { | ||
| 10 | let p = embassy_stm32::init(Default::default()); | ||
| 11 | let mut led = Output::new(p.PB14, Level::High, Speed::VeryHigh); | ||
| 12 | let button = Input::new(p.PC13, Pull::Up); | ||
| 13 | |||
| 14 | loop { | ||
| 15 | if button.is_low() { | ||
| 16 | led.set_high(); | ||
| 17 | } else { | ||
| 18 | led.set_low(); | ||
| 19 | } | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/docs/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml new file mode 100644 index 000000000..9733658b6 --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | [package] | ||
| 2 | name = "blinky-irq" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = "0.7" | ||
| 9 | cortex-m-rt = { version = "0.7" } | ||
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "unstable-pac"] } | ||
| 11 | |||
| 12 | defmt = "0.3.0" | ||
| 13 | defmt-rtt = "0.3.0" | ||
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
diff --git a/docs/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/examples/layer-by-layer/blinky-irq/src/main.rs new file mode 100644 index 000000000..743c9d99b --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-irq/src/main.rs | |||
| @@ -0,0 +1,93 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use core::cell::RefCell; | ||
| 5 | |||
| 6 | use cortex_m::interrupt::Mutex; | ||
| 7 | use cortex_m::peripheral::NVIC; | ||
| 8 | use cortex_m_rt::entry; | ||
| 9 | use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; | ||
| 10 | use embassy_stm32::{interrupt, pac}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | static BUTTON: Mutex<RefCell<Option<Input<'static>>>> = Mutex::new(RefCell::new(None)); | ||
| 14 | static LED: Mutex<RefCell<Option<Output<'static>>>> = Mutex::new(RefCell::new(None)); | ||
| 15 | |||
| 16 | #[entry] | ||
| 17 | fn main() -> ! { | ||
| 18 | let p = embassy_stm32::init(Default::default()); | ||
| 19 | let led = Output::new(p.PB14, Level::Low, Speed::Low); | ||
| 20 | let mut button = Input::new(p.PC13, Pull::Up); | ||
| 21 | |||
| 22 | cortex_m::interrupt::free(|cs| { | ||
| 23 | enable_interrupt(&mut button); | ||
| 24 | |||
| 25 | LED.borrow(cs).borrow_mut().replace(led); | ||
| 26 | BUTTON.borrow(cs).borrow_mut().replace(button); | ||
| 27 | |||
| 28 | unsafe { NVIC::unmask(pac::Interrupt::EXTI15_10) }; | ||
| 29 | }); | ||
| 30 | |||
| 31 | loop { | ||
| 32 | cortex_m::asm::wfe(); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | #[interrupt] | ||
| 37 | fn EXTI15_10() { | ||
| 38 | cortex_m::interrupt::free(|cs| { | ||
| 39 | let mut button = BUTTON.borrow(cs).borrow_mut(); | ||
| 40 | let button = button.as_mut().unwrap(); | ||
| 41 | |||
| 42 | let mut led = LED.borrow(cs).borrow_mut(); | ||
| 43 | let led = led.as_mut().unwrap(); | ||
| 44 | if check_interrupt(button) { | ||
| 45 | if button.is_low() { | ||
| 46 | led.set_high(); | ||
| 47 | } else { | ||
| 48 | led.set_low(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | clear_interrupt(button); | ||
| 52 | }); | ||
| 53 | } | ||
| 54 | // | ||
| 55 | // | ||
| 56 | // | ||
| 57 | // | ||
| 58 | // | ||
| 59 | // | ||
| 60 | // "Hidden" HAL-like methods for doing interrupts with embassy. Hardcode pin just to give audience an idea of what it looks like | ||
| 61 | |||
| 62 | const PORT: u8 = 2; | ||
| 63 | const PIN: usize = 13; | ||
| 64 | fn check_interrupt(_pin: &mut Input<'static>) -> bool { | ||
| 65 | let exti = pac::EXTI; | ||
| 66 | let pin = PIN; | ||
| 67 | let lines = exti.pr(0).read(); | ||
| 68 | lines.line(pin) | ||
| 69 | } | ||
| 70 | |||
| 71 | fn clear_interrupt(_pin: &mut Input<'static>) { | ||
| 72 | let exti = pac::EXTI; | ||
| 73 | let pin = PIN; | ||
| 74 | let mut lines = exti.pr(0).read(); | ||
| 75 | lines.set_line(pin, true); | ||
| 76 | exti.pr(0).write_value(lines); | ||
| 77 | } | ||
| 78 | |||
| 79 | fn enable_interrupt(_pin: &mut Input<'static>) { | ||
| 80 | cortex_m::interrupt::free(|_| { | ||
| 81 | let rcc = pac::RCC; | ||
| 82 | rcc.apb2enr().modify(|w| w.set_syscfgen(true)); | ||
| 83 | |||
| 84 | let port = PORT; | ||
| 85 | let pin = PIN; | ||
| 86 | let syscfg = pac::SYSCFG; | ||
| 87 | let exti = pac::EXTI; | ||
| 88 | syscfg.exticr(pin / 4).modify(|w| w.set_exti(pin % 4, port)); | ||
| 89 | exti.imr(0).modify(|w| w.set_line(pin, true)); | ||
| 90 | exti.rtsr(0).modify(|w| w.set_line(pin, true)); | ||
| 91 | exti.ftsr(0).modify(|w| w.set_line(pin, true)); | ||
| 92 | }); | ||
| 93 | } | ||
diff --git a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml new file mode 100644 index 000000000..f872b94cb --- /dev/null +++ b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | [package] | ||
| 2 | name = "blinky-pac" | ||
| 3 | version = "0.1.0" | ||
| 4 | edition = "2021" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | cortex-m = "0.7" | ||
| 9 | cortex-m-rt = "0.7" | ||
| 10 | stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] } | ||
| 11 | |||
| 12 | defmt = "0.3.0" | ||
| 13 | defmt-rtt = "0.3.0" | ||
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | ||
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 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use pac::gpio::vals; | ||
| 5 | use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; | ||
| 6 | |||
| 7 | #[cortex_m_rt::entry] | ||
| 8 | fn main() -> ! { | ||
| 9 | // Enable GPIO clock | ||
| 10 | let rcc = pac::RCC; | ||
| 11 | unsafe { | ||
| 12 | rcc.ahb2enr().modify(|w| { | ||
| 13 | w.set_gpioben(true); | ||
| 14 | w.set_gpiocen(true); | ||
| 15 | }); | ||
| 16 | |||
| 17 | rcc.ahb2rstr().modify(|w| { | ||
| 18 | w.set_gpiobrst(true); | ||
| 19 | w.set_gpiocrst(true); | ||
| 20 | w.set_gpiobrst(false); | ||
| 21 | w.set_gpiocrst(false); | ||
| 22 | }); | ||
| 23 | } | ||
| 24 | |||
| 25 | // Setup button | ||
| 26 | let gpioc = pac::GPIOC; | ||
| 27 | const BUTTON_PIN: usize = 13; | ||
| 28 | unsafe { | ||
| 29 | gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); | ||
| 30 | gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); | ||
| 31 | gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); | ||
| 32 | } | ||
| 33 | |||
| 34 | // Setup LED | ||
| 35 | let gpiob = pac::GPIOB; | ||
| 36 | const LED_PIN: usize = 14; | ||
| 37 | unsafe { | ||
| 38 | gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); | ||
| 39 | gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); | ||
| 40 | gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); | ||
| 41 | } | ||
| 42 | |||
| 43 | // Main loop | ||
| 44 | loop { | ||
| 45 | unsafe { | ||
| 46 | if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW { | ||
| 47 | gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true)); | ||
| 48 | } else { | ||
| 49 | gpiob.bsrr().write(|w| w.set_br(LED_PIN, true)); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | } | ||
| 53 | } | ||
