From abaf98de01c7e9201ae6f934ef7f856c4c40887d Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Fri, 4 Jun 2021 12:45:09 +0200 Subject: [PATCH] Exchange hal with own svd2rust generated hal --- Cargo.toml | 3 +-- src/main.rs | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e88e805..03f1793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,8 +13,7 @@ cortex-m-semihosting = "0.3.7" panic-semihosting = "0.5.6" -nrf52832-hal = { features = ["rt"], path = "/home/tkl/nrf-hal/nrf52832-hal" } - +nrf52-hal = { git = "https://git.blackfinn.de/rust/nrf52-hal.git" } [dependencies.embedded-hal] version = "0.2.3" diff --git a/src/main.rs b/src/main.rs index a4b4a08..977154d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,7 @@ use cortex_m::peripheral::{syst, Peripherals}; use cortex_m_rt::{entry, exception}; use cortex_m_semihosting::hprintln; -use embedded_hal::digital::v2::OutputPin; -use nrf52832_hal as hal; -use nrf52832_hal::gpio::Level; +use nrf52_hal as hal; use panic_semihosting as _; @@ -26,10 +24,17 @@ fn main() -> ! { systick.enable_interrupt(); systick.enable_counter(); - let p = hal::pac::Peripherals::take().unwrap(); - let port0 = hal::gpio::p0::Parts::new(p.P0); - let mut led = port0.p0_17.into_push_pull_output(Level::Low); - led.set_low().unwrap(); + let nrf_peripherals = hal::Peripherals::take().unwrap(); + let p0 = nrf_peripherals.P0; + + unsafe { + p0.outset.write(|w| w.bits(1 << 17)); + p0.pin_cnf[17].write(|w| { + w.input().disconnect(); + w.dir().output(); + w + }); + } let mut state:bool = false; loop { @@ -38,11 +43,11 @@ fn main() -> ! { FIRE_1S = false; if state { hprintln!("off").unwrap(); - led.set_low().unwrap(); + p0.outclr.write(|w| w.bits(1 << 17)); state = false; } else { hprintln!("on").unwrap(); - led.set_high().unwrap(); + p0.outset.write(|w| w.bits(1 << 17)); state = true; } }