diff --git a/Cargo.toml b/Cargo.toml index 6d721ed..ec4ace0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,8 @@ cortex-m-rt = "0.6.5" cortex-m-semihosting = "0.3.2" panic-halt = "0.2.0" panic-semihosting = "*" -msp432p401r = { path = "../msp432p401r", features = ["rt"] } +msp432p401r = { path = "../msp432-pac", features = ["rt"] } +msp432-hal = { path = "../msp432-hal" } # Uncomment for the panic example. # panic-itm = "0.4.0" diff --git a/src/main.rs b/src/main.rs index f505828..24875d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,29 +9,22 @@ extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to c use cortex_m::{self, peripheral::syst::SystClkSource}; use cortex_m_rt::entry; -use msp432p401r; +use msp432p401r as pac; +use msp432_hal::prelude::*; use core::num::Wrapping; -const PIN0: u8 = (1u8 << 0); -const PIN1: u8 = (1u8 << 1); -const PIN2: u8 = (1u8 << 2); -//const PIN3: u8 = (1u8 << 3); -const PIN4: u8 = (1u8 << 4); -//const PIN5: u8 = (1u8 << 5); -//const PIN6: u8 = (1u8 << 6); -//const PIN7: u8 = (1u8 << 7); - const WDOG_PWORD: u8 = 0x5a; #[entry] fn main() -> ! { let cp = cortex_m::Peripherals::take().unwrap(); - let p = msp432p401r::Peripherals::take().unwrap(); + let p = pac::Peripherals::take().unwrap(); let mut syst = cp.SYST; let wdt = p.WDT_A; let dio = p.DIO; + let pins = dio.split(); // disable watchdog timer wdt.wdtctl.write(|w| unsafe { @@ -44,38 +37,59 @@ fn main() -> ! { syst.set_reload(20_000); syst.enable_counter(); - // configure digital IO pins - dio.padir.modify(|_r, w| unsafe { - w.p1dir().bits(PIN0) - .p2dir().bits(PIN0 | PIN1 | PIN2) - }); + // Set pin 1.0 to drive the single color LED + let mut led1 = pins.p1_0.into_strong_output(); + + // Set pin 2.0-2.2 to drive the RGB LED + let mut rgb_red = pins.p2_0.into_strong_output(); + let mut rgb_blue = pins.p2_1.into_strong_output(); + let mut rgb_green = pins.p2_2.into_strong_output(); // Enable pull-up on P1.4 switch - dio.paren.modify(|_r, w| unsafe { w.p1ren().bits(PIN4) }); - dio.pads.modify(|_r, w| unsafe { w.p1ds().bits(PIN4) }); + let sw2 = pins.p1_4.into_pullup(); - // Turn on LED1 on P1.0 and enable pull-up on P1.1 switch - dio.paout.write(|w| unsafe { - w.p1out().bits(PIN0 | PIN4) - .p2out().bits(0) - }); + // Turn on LED1 + led1.set_high(); let mut count: Wrapping = Wrapping(0); - let mut input: u8; + let mut input: u16; loop { while !syst.has_wrapped() {} // The button pulls the input to GND - input = (dio.pain.read().p1in().bits() & PIN4) >> 4; + input = sw2.read_pin(); count += Wrapping(1); let _led1: u8 = ((count.0 & 0x0100) >> 8) as u8; let led2: u8 = ((count.0 & 0b0000_0111_0000_0000) >> 8) as u8; - // toggle LEDs - dio.paout.write(|w| unsafe { - w.p1out().bits(input | PIN4) - .p2out().bits(led2) - }); + // toggle RGB LEDs + + if led2 & 0b001 == 1 { + rgb_red.set_high() + } else { + rgb_red.set_low() + } + + if led2 & 0b010 == 1 { + rgb_blue.set_high() + } else { + rgb_blue.set_low() + } + + if led2 & 0b100 == 1 { + rgb_green.set_high() + } else { + rgb_green.set_low() + } + + // set led1 according to sw2 + + if input != 0 { + led1.set_low() + } else { + led1.set_high() + } + } }