From d3480939692c24d86d38cc7db70f04ccc76c1493 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 6 Aug 2019 11:44:57 -0400 Subject: =?UTF-8?q?i=C2=B2c=20working.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/main.rs') 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() } }); -- cgit v1.2.3