Commit 50712777 authored by Per Lindgren's avatar Per Lindgren
Browse files

now with burst

parent 1a5afe5e
......@@ -10,7 +10,10 @@ use panic_halt as _;
use rtic::cyccnt::{Instant, U32Ext as _};
use stm32f4xx_hal::{dwt::Dwt, gpio::Speed, prelude::*, rcc::Clocks, spi::Spi, stm32};
use app::{pmw3389, DwtDelay};
use app::{
pmw3389::{self, Register},
DwtDelay,
};
use rtt_target::{rprint, rprintln, rtt_init_print};
//use crate::hal::gpio::{gpioa::PA0, Edge, Input, PullDown};
......@@ -93,6 +96,40 @@ const APP: () = {
let mut pmw3389 = pmw3389::Pmw3389::new(spi, cs, delay).unwrap();
let mut delay = DwtDelay::new(&mut core.DWT, clocks);
// loop {
// pmw3389.write_register(Register::Motion, 0x01).ok();
// let motion = pmw3389.read_register(Register::Motion).unwrap();
// let xl = pmw3389.read_register(Register::DeltaXL).unwrap();
// let xh = pmw3389.read_register(Register::DeltaXH).unwrap();
// let yl = pmw3389.read_register(Register::DeltaYL).unwrap();
// let yh = pmw3389.read_register(Register::DeltaYH).unwrap();
// let x = (xl as u16 + (xh as u16) << 8) as i16;
// let y = (yl as u16 + (yh as u16) << 8) as i16;
// let surface = motion & 0x08;
// let motion_detect = motion & 0x80;
// rprintln!(
// "motion {}, surface {}, (x, y) {:?}",
// motion_detect,
// surface,
// (x, y),
// );
// delay.delay_ms(200);
// }
// set in burst mode
pmw3389.write_register(Register::MotionBurst, 0x00);
loop {
pmw3389.read_status().unwrap();
delay.delay_ms(200);
}
let id = pmw3389.product_id().unwrap();
rprintln!("id {}", id);
......
......@@ -181,29 +181,29 @@ where
let srom_id = pmw3389.read_register(Register::SROMId)?;
rprintln!("srom_id {}, 0x{:x}", srom_id, srom_id);
loop {
pmw3389.write_register(Register::Motion, 0x01)?;
let motion = pmw3389.read_register(Register::Motion)?;
let xl = pmw3389.read_register(Register::DeltaXL)?;
let xh = pmw3389.read_register(Register::DeltaXH)?;
let yl = pmw3389.read_register(Register::DeltaYL)?;
let yh = pmw3389.read_register(Register::DeltaYH)?;
let x = (xl as u16 + (xh as u16) << 8) as i16;
let y = (yl as u16 + (yh as u16) << 8) as i16;
let surface = motion & 0x08;
let motion_detect = motion & 0x80;
rprintln!(
"motion {}, surface {}, (x, y) {:?}",
motion_detect,
surface,
(x, y),
);
pmw3389.delay.delay_ms(200);
}
// loop {
// pmw3389.write_register(Register::Motion, 0x01)?;
// let motion = pmw3389.read_register(Register::Motion)?;
// let xl = pmw3389.read_register(Register::DeltaXL)?;
// let xh = pmw3389.read_register(Register::DeltaXH)?;
// let yl = pmw3389.read_register(Register::DeltaYL)?;
// let yh = pmw3389.read_register(Register::DeltaYH)?;
// let x = (xl as u16 + (xh as u16) << 8) as i16;
// let y = (yl as u16 + (yh as u16) << 8) as i16;
// let surface = motion & 0x08;
// let motion_detect = motion & 0x80;
// rprintln!(
// "motion {}, surface {}, (x, y) {:?}",
// motion_detect,
// surface,
// (x, y),
// );
// pmw3389.delay.delay_ms(200);
// }
// self.spi.transfer(&mut [Register::MotionBurst.addr()])?;
// self.delay.delay_ms(35); // waits for tSRAD
......@@ -213,7 +213,7 @@ where
// pmw3389.delay.delay_ms(10);
// }
// Ok(pmw3389)
Ok(pmw3389)
}
pub fn read_register(&mut self, reg: Register) -> Result<u8, E> {
......@@ -269,10 +269,14 @@ where
}
/// Read status
pub fn read_status(&mut self, itm: &mut stm32::ITM) -> Result<(), E> {
pub fn read_status(&mut self) -> Result<(), E> {
self.com_begin();
// self.write_register(Register::Motion, 0x01)?;
self.spi.transfer(&mut [Register::MotionBurst.addr()])?;
// self.write_register(Register::MotionBurst, 0x00);
self.delay.delay_us(35); // waits for tSRAD
// read burst buffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment