Compare commits

..

No commits in common. "use_hal" and "master" have entirely different histories.

3 changed files with 31 additions and 47 deletions

View File

@ -11,8 +11,7 @@ cortex-m-rt = "0.6.5"
cortex-m-semihosting = "0.3.2" cortex-m-semihosting = "0.3.2"
panic-halt = "0.2.0" panic-halt = "0.2.0"
panic-semihosting = "*" panic-semihosting = "*"
msp432p401r = { path = "../msp432-pac", features = ["rt"] } msp432p401r = { path = "../msp432p401r", features = ["rt"] }
msp432-hal = { path = "../msp432-hal" }
# Uncomment for the panic example. # Uncomment for the panic example.
# panic-itm = "0.4.0" # panic-itm = "0.4.0"

View File

@ -4,4 +4,3 @@ source [find interface/xds110.cfg]
adapter_khz 2500 adapter_khz 2500
transport select swd transport select swd
source [find target/ti_msp432.cfg] source [find target/ti_msp432.cfg]
reset_config none separate

View File

@ -9,22 +9,29 @@ 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::{self, peripheral::syst::SystClkSource};
use cortex_m_rt::entry; use cortex_m_rt::entry;
use msp432p401r as pac; use msp432p401r;
use msp432_hal::prelude::*;
use core::num::Wrapping; 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; const WDOG_PWORD: u8 = 0x5a;
#[entry] #[entry]
fn main() -> ! { fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap(); let cp = cortex_m::Peripherals::take().unwrap();
let p = pac::Peripherals::take().unwrap(); let p = msp432p401r::Peripherals::take().unwrap();
let mut syst = cp.SYST; let mut syst = cp.SYST;
let wdt = p.WDT_A; let wdt = p.WDT_A;
let dio = p.DIO; let dio = p.DIO;
let pins = dio.split();
// disable watchdog timer // disable watchdog timer
wdt.wdtctl.write(|w| unsafe { wdt.wdtctl.write(|w| unsafe {
@ -37,59 +44,38 @@ fn main() -> ! {
syst.set_reload(20_000); syst.set_reload(20_000);
syst.enable_counter(); syst.enable_counter();
// Set pin 1.0 to drive the single color LED // configure digital IO pins
let mut led1 = pins.p1_0.into_strong_output(); dio.padir.modify(|_r, w| unsafe {
w.p1dir().bits(PIN0)
// Set pin 2.0-2.2 to drive the RGB LED .p2dir().bits(PIN0 | PIN1 | PIN2)
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 // Enable pull-up on P1.4 switch
let sw2 = pins.p1_4.into_pullup(); dio.paren.modify(|_r, w| unsafe { w.p1ren().bits(PIN4) });
dio.pads.modify(|_r, w| unsafe { w.p1ds().bits(PIN4) });
// Turn on LED1 // Turn on LED1 on P1.0 and enable pull-up on P1.1 switch
led1.set_high(); dio.paout.write(|w| unsafe {
w.p1out().bits(PIN0 | PIN4)
.p2out().bits(0)
});
let mut count: Wrapping<u16> = Wrapping(0); let mut count: Wrapping<u16> = Wrapping(0);
let mut input: u16; let mut input: u8;
loop { loop {
while !syst.has_wrapped() {} while !syst.has_wrapped() {}
// The button pulls the input to GND // The button pulls the input to GND
input = sw2.read_pin(); input = (dio.pain.read().p1in().bits() & PIN4) >> 4;
count += Wrapping(1); count += Wrapping(1);
let _led1: u8 = ((count.0 & 0x0100) >> 8) as u8; let _led1: u8 = ((count.0 & 0x0100) >> 8) as u8;
let led2: u8 = ((count.0 & 0b0000_0111_0000_0000) >> 8) as u8; let led2: u8 = ((count.0 & 0b0000_0111_0000_0000) >> 8) as u8;
// toggle RGB LEDs // toggle LEDs
dio.paout.write(|w| unsafe {
if led2 & 0b001 == 0 { w.p1out().bits(input | PIN4)
rgb_red.set_high() .p2out().bits(led2)
} else { });
rgb_red.set_low()
}
if led2 & 0b010 == 0 {
rgb_blue.set_high()
} else {
rgb_blue.set_low()
}
if led2 & 0b100 == 0 {
rgb_green.set_high()
} else {
rgb_green.set_low()
}
// set led1 according to sw2
if input != 0 {
led1.set_low()
} else {
led1.set_high()
}
} }
} }