diff options
Diffstat (limited to 'ble/src/main.rs')
-rw-r--r-- | ble/src/main.rs | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/ble/src/main.rs b/ble/src/main.rs index 4430e98..2da6de9 100644 --- a/ble/src/main.rs +++ b/ble/src/main.rs @@ -3,6 +3,7 @@ #![no_std] #![no_main] +mod i2c; mod logger; mod macros; mod rtc; @@ -21,12 +22,15 @@ use nrf52840_mdk_bsp::{ hal::{ gpio::{Floating, Input, Level, Output, Pin, PushPull}, target::{interrupt, Interrupt, UARTE0}, + twis::{self, Twis}, uarte::{self, Baudrate as UartBaudrate, Parity as UartParity, Uarte}, Clocks, Rtc, }, Board, }; +const I2C_ADDR: u8 = 4; + // TODO: // * set up serial reader for trinket // * set up i²c interface for keyboard reports @@ -49,6 +53,14 @@ fn main() -> ! { let mut nvic = nrf52.NVIC; let mut rtc_handler = rtc::setup(Rtc::new(nrf52.RTC0), Clocks::new(nrf52.CLOCK)); + let mut twis_handler = i2c::setup(Twis::new( + I2C_ADDR, + nrf52.TWIS0, + twis::Pins { + scl: nrf52.pins.P0_06.into_floating_input().degrade(), + sda: nrf52.pins.P0_07.into_floating_input().degrade(), + }, + )); let txp = nrf52 .pins @@ -61,6 +73,8 @@ fn main() -> ! { HANDLERS.with_overrides(|hs| { hs.register(0, &mut rtc_handler); nvic.enable(Interrupt::RTC0); + hs.register(1, &mut twis_handler); + nvic.enable(Interrupt::SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0); info!("Bootstrap complete."); @@ -74,6 +88,7 @@ fn main() -> ! { trace!("."); write!(uarte1, "!").expect("uarte1 write"); } + wfi(); } }); @@ -87,8 +102,8 @@ where Uarte::new( uarte, uarte::Pins { - txd: tx.into_push_pull_output(Level::High), - rxd: rx.into_floating_input(), + txd: tx, + rxd: rx, cts: None, rts: None, }, @@ -112,3 +127,8 @@ fn HardFault(ef: &ExceptionFrame) -> ! { fn RTC0() { HANDLERS.call(0); } + +#[interrupt] +fn SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0() { + HANDLERS.call(1); +} |