summaryrefslogtreecommitdiffstats
path: root/ble/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ble/src/main.rs')
-rw-r--r--ble/src/main.rs47
1 files changed, 32 insertions, 15 deletions
diff --git a/ble/src/main.rs b/ble/src/main.rs
index 71e3b82..36c3228 100644
--- a/ble/src/main.rs
+++ b/ble/src/main.rs
@@ -3,6 +3,7 @@
#![no_std]
#![no_main]
+mod ble;
mod i2c;
mod logger;
mod macros;
@@ -13,7 +14,7 @@ use clint::HandlerArray;
use core::mem;
use cortex_m::asm::wfi;
use cortex_m_rt::{entry, exception, ExceptionFrame};
-use log::{info, LevelFilter};
+use log::{info, log, Level as LogLevel, LevelFilter};
#[allow(unused_imports)]
extern crate panic_semihosting;
@@ -32,8 +33,7 @@ use nrf52840_mdk_bsp::{
const I2C_ADDR: u8 = 4;
// TODO:
-// * set up serial reader for trinket
-// * and, finally, bluetooth
+// * bluetooth
// Interrupt handler table.
static HANDLERS: HandlerArray = HandlerArray::new();
@@ -48,6 +48,19 @@ fn main() -> ! {
log::set_logger(logger_ref).expect("setting logger");
log::set_max_level(LevelFilter::Trace);
+ // TODO: use hal interface for this.
+ nrf52
+ .CLOCK
+ .tasks_hfclkstart
+ .write(|w| w.tasks_hfclkstart().set_bit());
+ while nrf52
+ .CLOCK
+ .events_hfclkstarted
+ .read()
+ .events_hfclkstarted()
+ .bit_is_clear()
+ {}
+
nrf52.RTC0.intenset.write(|w| w.tick().set());
let mut nvic = nrf52.NVIC;
@@ -70,6 +83,8 @@ fn main() -> ! {
let uarte1 = uarte1(nrf52.UARTE1, txp, rxp);
let (mut uarte1_reader, mut uarte1_handler) = uarte1::setup(uarte1);
+ //ble::setup(nrf52.RADIO, nrf52.TIMER0, nrf52.FICR);
+
HANDLERS.with_overrides(|hs| {
hs.register(0, &mut rtc_handler);
nvic.enable(Interrupt::RTC0);
@@ -80,16 +95,19 @@ fn main() -> ! {
info!("Bootstrap complete.");
- let mut last_tick = rtc::millis();
- last_tick -= last_tick % 1024;
- let mut buf: [u8; 256] = [0; 256];
+ // Buffer is just scratch space that always gets written to
+ // before it's read.
+ let mut buf: [u8; 256] =
+ unsafe { core::mem::MaybeUninit::<[u8; 256]>::uninit().assume_init() };
+
+ // TODO: there's some kind of weird multi-millisecond latency
+ // somewhere. It may be in one of the interrupt handlers, so
+ // maybe stick a counter on them for every time they're fired
+ // and then spit out stats once/second from here.
+ //
+ // May need to keep total-time-spent inside the handlers as
+ // well. This lag is infuriatingly hidden.
loop {
- let tick = rtc::millis();
- if tick >= last_tick + 1024 {
- last_tick = tick;
- last_tick -= last_tick % 1024;
- }
-
let mut len = twis_reader.shift_into(&mut buf);
while len > 0 {
info!("i²c data: {:?}", &buf[0..len]);
@@ -98,9 +116,8 @@ fn main() -> ! {
let mut len = uarte1_reader.shift_into(&mut buf);
while len > 0 {
- info!(
- "serial {}: {}",
- len,
+ log!(target: "usb", LogLevel::Info,
+ "{}",
core::str::from_utf8(&buf[0..len]).expect("utf8conv")
);
len = uarte1_reader.shift_into(&mut buf);