summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2019-08-06 11:44:57 -0400
committerBrian Cully <bjc@kublai.com>2019-08-06 11:44:57 -0400
commitd3480939692c24d86d38cc7db70f04ccc76c1493 (patch)
tree57f722dc037b39d1f9f44e01613a5613e2a89d6f /src/main.rs
parent9ff9f51c07f7226d6467bc9db608cc53c82365bd (diff)
downloadbleusb-d3480939692c24d86d38cc7db70f04ccc76c1493.tar.gz
bleusb-d3480939692c24d86d38cc7db70f04ccc76c1493.zip
i²c working.
Diffstat (limited to 'src/main.rs')
-rwxr-xr-xsrc/main.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 071966a..84bc3c0 100755
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,7 +11,7 @@ use core::mem;
use core::panic::PanicInfo;
use cortex_m::asm::wfi;
use cortex_m_rt::{entry, exception, ExceptionFrame};
-use embedded_hal::digital::v2::OutputPin;
+use embedded_hal::{blocking::i2c::Write, digital::v2::OutputPin};
use log::{info, LevelFilter};
use smart_leds::colors;
use smart_leds_trait::SmartLedsWrite;
@@ -31,6 +31,8 @@ static mut LED: usize = 0;
static HANDLERS: HandlerArray = HandlerArray::new();
+const NRF_WIREADDR: u8 = 10;
+
#[entry]
fn main() -> ! {
let mut cp = CorePeripherals::take().expect("taking core peripherals");
@@ -56,6 +58,16 @@ fn main() -> ! {
&mut pins.port,
);
+ let mut i2c_master = hal::i2c_master(
+ &mut clocks,
+ 400_000.hz(),
+ dp.SERCOM2,
+ &mut dp.PM,
+ pins.d0,
+ pins.d2,
+ &mut pins.port,
+ );
+
let mut red_led = pins.d13.into_open_drain_output(&mut pins.port);
red_led.set_low().expect("turning off red LED");
unsafe { LED = mem::transmute(&red_led) }
@@ -98,7 +110,13 @@ fn main() -> ! {
info!("Bootstrap complete.");
+ let mut last_tick = 0;
loop {
+ let tick = rtc::millis();
+ if tick > last_tick + 1024 {
+ last_tick = tick;
+ i2c_master.write(NRF_WIREADDR, b"!").expect("writing i2c");
+ }
wfi()
}
});