sync working dir
This commit is contained in:
parent
8a10953cc4
commit
06b955875c
2 changed files with 402 additions and 3629 deletions
|
|
@ -15,6 +15,8 @@ use core::str::from_utf8;
|
|||
use bt_hci::cmd::info;
|
||||
use cyw43_pio::PioSpi;
|
||||
use embassy_rp::i2c::{Async, I2c};
|
||||
use embassy_rp::pwm::{self, Pwm};
|
||||
use fixed::FixedU16;
|
||||
use log::*;
|
||||
//use embassy_rp::i2c::InterruptHandler;
|
||||
use embassy_executor::Spawner;
|
||||
|
|
@ -71,6 +73,16 @@ async fn main(spawner: Spawner) {
|
|||
let driver = Driver::new(p.USB, Irqs);
|
||||
spawner.spawn(logger_task(driver)).unwrap();
|
||||
|
||||
let mut flipper = Output::new(p.PIN_22, Level::Low);
|
||||
|
||||
let mut c: pwm::Config = Default::default();
|
||||
c.divider = 255.into();
|
||||
c.top = 8715;
|
||||
c.compare_b = 7210;
|
||||
c.compare_a = 2240;
|
||||
let mut pwm = Pwm::new_output_ab(p.PWM_SLICE1, p.PIN_18, p.PIN_19, c.clone());
|
||||
flipper.set_high();
|
||||
|
||||
let sda = p.PIN_26;
|
||||
let scl = p.PIN_27;
|
||||
let config = embassy_rp::i2c::Config::default();
|
||||
|
|
@ -128,291 +140,302 @@ async fn main(spawner: Spawner) {
|
|||
|
||||
//embassy_time::Timer::after_millis(7000).await;
|
||||
|
||||
async fn write_to_device<'a, T,const N: usize>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, data: [[u8;2];N])
|
||||
where T: embassy_rp::i2c::Instance {
|
||||
for transaction in data {
|
||||
let _ = bus.write_async(addr, transaction).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn write_flag<'a, T>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, reg: u8, bit: u8, value: bool)
|
||||
where T: embassy_rp::i2c::Instance {
|
||||
let mut initial: [u8;1] = [0];
|
||||
let _ = bus.write_read_async(addr, [reg], &mut initial).await;
|
||||
let mask = 1 << bit;
|
||||
if value {
|
||||
initial[0] |= mask;
|
||||
} else {
|
||||
initial[0] &= !mask;
|
||||
}
|
||||
let _ = bus.write_async(addr, [reg, initial[0]]).await;
|
||||
}
|
||||
|
||||
let id = 0x29;
|
||||
Timer::after_millis(50).await; // sensor boot
|
||||
write_to_device(&mut bus, id, [
|
||||
[0x88, 0x00],
|
||||
[0x80, 0x01],
|
||||
[0xFF, 0x01],
|
||||
[0x00, 0x00],
|
||||
]).await;
|
||||
let mut stop: [u8;1] = [0];
|
||||
let _ = bus.write_read_async(id, [0x91], &mut stop);
|
||||
write_to_device(&mut bus, id, [
|
||||
[0x00, 0x01],
|
||||
[0xFF, 0x00],
|
||||
[0x80, 0x00],
|
||||
]).await;
|
||||
|
||||
// disable SIGNAL_RATE_MSRC (bit 1) and SIGNAL_RATE_PRE_RANGE (bit 4) limit checks
|
||||
write_flag(&mut bus, id, 0x60, 1, true).await;
|
||||
write_flag(&mut bus, id, 0x60, 4, true).await;
|
||||
|
||||
let mega_counts_per_second = 0.25;
|
||||
let mega_counts_per_second: u16 = (mega_counts_per_second * (1<<7) as f64) as u16;
|
||||
let _ = bus.write_async(id, [FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT as u8,
|
||||
(mega_counts_per_second >> 8) as u8,
|
||||
(mega_counts_per_second & 255) as u8
|
||||
]).await;
|
||||
|
||||
// get spad info
|
||||
let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0xFF]).await;
|
||||
|
||||
write_to_device(&mut bus, id , [
|
||||
[0x80, 0x01],
|
||||
[0xff, 0x01],
|
||||
[0x00, 0x00],
|
||||
[0xff, 0x06],
|
||||
]).await;
|
||||
write_flag(&mut bus, id, 0x83, 3, true).await;
|
||||
write_to_device(&mut bus, id , [
|
||||
[0xff, 0x07],
|
||||
[0x81, 0x01],
|
||||
[0x80, 0x01],
|
||||
[0x94, 0x6b],
|
||||
[0x83, 0x00],
|
||||
]).await;
|
||||
debug!("starting spad wait");
|
||||
loop {
|
||||
let mut wait: [u8;1] = [0];
|
||||
let _ = bus.write_read_async(id, [0x83], &mut wait).await;
|
||||
if wait[0] != 0 {
|
||||
break;
|
||||
}
|
||||
Timer::after_micros(5).await;
|
||||
}
|
||||
debug!("ended spad wait");
|
||||
|
||||
let _ = bus.write_async(id, [0x83, 0x01]).await;
|
||||
|
||||
let mut value: [u8;1] = [0];
|
||||
let _ = bus.write_read_async(id, [0x92], &mut value).await;
|
||||
write_to_device(&mut bus, id, [
|
||||
[0x81, 0x00],
|
||||
[0xff, 0x06],
|
||||
]).await;
|
||||
write_flag(&mut bus, id, 0x83, 3, false).await;
|
||||
write_to_device(&mut bus, id, [
|
||||
[0xff, 0x01],
|
||||
[0x00, 0x01],
|
||||
[0xff, 0x00],
|
||||
[0x80, 0x00],
|
||||
]).await;
|
||||
let count = value[0] & 0x7f;
|
||||
let is_aperture = value[0] & 0b10000000;
|
||||
let is_aperture = is_aperture != 0;
|
||||
// TODO: vl53l0x.py post line 200
|
||||
|
||||
let mut spad_map: [u8;6]=[0;6];
|
||||
let _ = bus.write_read_async(id, [GLOBAL_CONFIG_SPAD_ENABLES_REF_0 as u8], &mut spad_map);
|
||||
|
||||
write_to_device(&mut bus, id, [
|
||||
[0xff, 0x01],
|
||||
[DYNAMIC_SPAD_REF_EN_START_OFFSET as u8, 0x00],
|
||||
[DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD as u8, 0x2c],
|
||||
[0xff, 0x00],
|
||||
[DYNAMIC_SPAD_REF_EN_START_OFFSET as u8, 0xb4],
|
||||
]).await;
|
||||
|
||||
let mut spads_enabled = 0;
|
||||
for i in 0..48 {
|
||||
if i < 12 && is_aperture || spads_enabled >= count {
|
||||
spad_map[i/8] &= !(1<< (i>>2));
|
||||
} else if (spad_map[i/8] & (1<< (i>>2))) != 0 {
|
||||
spads_enabled += 1;
|
||||
}
|
||||
}
|
||||
|
||||
let mut spad_write: [u8;7] = [0;7];
|
||||
spad_write[0] = GLOBAL_CONFIG_SPAD_ENABLES_REF_0 as u8;
|
||||
spad_write[1..].clone_from_slice(&spad_map);
|
||||
let _ = bus.write_async(id, spad_write).await;
|
||||
|
||||
|
||||
write_to_device(&mut bus, id, [
|
||||
[0xFF, 0x01],
|
||||
[0x00, 0x00],
|
||||
[0xFF, 0x00],
|
||||
[0x09, 0x00],
|
||||
[0x10, 0x00],
|
||||
[0x11, 0x00],
|
||||
[0x24, 0x01],
|
||||
[0x25, 0xFF],
|
||||
[0x75, 0x00],
|
||||
[0xFF, 0x01],
|
||||
[0x4E, 0x2C],
|
||||
[0x48, 0x00],
|
||||
[0x30, 0x20],
|
||||
[0xFF, 0x00],
|
||||
[0x30, 0x09],
|
||||
[0x54, 0x00],
|
||||
[0x31, 0x04],
|
||||
[0x32, 0x03],
|
||||
[0x40, 0x83],
|
||||
[0x46, 0x25],
|
||||
[0x60, 0x00],
|
||||
[0x27, 0x00],
|
||||
[0x50, 0x06],
|
||||
[0x51, 0x00],
|
||||
[0x52, 0x96],
|
||||
[0x56, 0x08],
|
||||
[0x57, 0x30],
|
||||
[0x61, 0x00],
|
||||
[0x62, 0x00],
|
||||
[0x64, 0x00],
|
||||
[0x65, 0x00],
|
||||
[0x66, 0xA0],
|
||||
[0xFF, 0x01],
|
||||
[0x22, 0x32],
|
||||
[0x47, 0x14],
|
||||
[0x49, 0xFF],
|
||||
[0x4A, 0x00],
|
||||
[0xFF, 0x00],
|
||||
[0x7A, 0x0A],
|
||||
[0x7B, 0x00],
|
||||
[0x78, 0x21],
|
||||
[0xFF, 0x01],
|
||||
[0x23, 0x34],
|
||||
[0x42, 0x00],
|
||||
[0x44, 0xFF],
|
||||
[0x45, 0x26],
|
||||
[0x46, 0x05],
|
||||
[0x40, 0x40],
|
||||
[0x0E, 0x06],
|
||||
[0x20, 0x1A],
|
||||
[0x43, 0x40],
|
||||
[0xFF, 0x00],
|
||||
[0x34, 0x03],
|
||||
[0x35, 0x44],
|
||||
[0xFF, 0x01],
|
||||
[0x31, 0x04],
|
||||
[0x4B, 0x09],
|
||||
[0x4C, 0x05],
|
||||
[0x4D, 0x04],
|
||||
[0xFF, 0x00],
|
||||
[0x44, 0x00],
|
||||
[0x45, 0x20],
|
||||
[0x47, 0x08],
|
||||
[0x48, 0x28],
|
||||
[0x67, 0x00],
|
||||
[0x70, 0x04],
|
||||
[0x71, 0x01],
|
||||
[0x72, 0xFE],
|
||||
[0x76, 0x00],
|
||||
[0x77, 0x00],
|
||||
[0xFF, 0x01],
|
||||
[0x0D, 0x01],
|
||||
[0xFF, 0x00],
|
||||
[0x80, 0x01],
|
||||
[0x01, 0xF8],
|
||||
[0xFF, 0x01],
|
||||
[0x8E, 0x01],
|
||||
[0x00, 0x01],
|
||||
[0xFF, 0x00],
|
||||
[0x80, 0x00],
|
||||
]).await;
|
||||
//write_flag(&mut bus, id, GPIO_HV_MUX_ACTIVE_HIGH as u8, 4, false).await;
|
||||
//let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0x01]).await;
|
||||
//calibrate(&mut bus, id, 0x40).await;
|
||||
//let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0x02]).await;
|
||||
//calibrate(&mut bus, id, 0x00).await;
|
||||
//let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0xe8]).await;
|
||||
|
||||
async fn calibrate<'a, T>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, data: u8)
|
||||
where T: embassy_rp::i2c::Instance {
|
||||
let _ = bus.write_async(addr, [SYSRANGE_START as u8 ,data | 0x01]).await;
|
||||
debug!("started calib wait");
|
||||
loop {
|
||||
let mut wait: [u8;1] = [0];
|
||||
let _ = bus.write_read_async(addr, [0x13], &mut wait).await;
|
||||
if wait[0] & 0x07 != 0 {
|
||||
break;
|
||||
}
|
||||
Timer::after_micros(5).await;
|
||||
}
|
||||
debug!("ended calib wait");
|
||||
write_to_device(bus, addr, [
|
||||
[SYSTEM_INTERRUPT_CLEAR as u8, 0x01],
|
||||
[SYSRANGE_START as u8, 0x00],
|
||||
]).await;
|
||||
}
|
||||
|
||||
|
||||
//TODO VL53L0X.cpp L 236-280
|
||||
|
||||
|
||||
// start continuous mode
|
||||
write_to_device(&mut bus, id, [
|
||||
[0x80, 0x01],
|
||||
[0xFF, 0x01],
|
||||
[0x00, 0x00],
|
||||
[0x91, stop[0]],
|
||||
[0x00, 0x01],
|
||||
[0xFF, 0x00],
|
||||
[0x80, 0x00],
|
||||
//[0x04, 0x00], // measurement delay
|
||||
[0x00, 0x02], // back to back shots
|
||||
]).await;
|
||||
|
||||
//let _ = bus.write_async(0x88u16, [0x00]).await;
|
||||
//let _ = bus.write_async(0x80u16, [0x01]).await;
|
||||
//let _ = bus.write_async(0xFFu16, [0x01]).await;
|
||||
//let _ = bus.write_async(0x00u16, [0x00]).await;
|
||||
//let _ = bus.write_async(0x00u16, [0x01]).await;
|
||||
//let _ = bus.write_async(0xFFu16, [0x00]).await;
|
||||
//let _ = bus.write_async(0x80u16, [0x00]).await;
|
||||
|
||||
//loop {
|
||||
// debug!("starting wait part 1");
|
||||
// loop {
|
||||
// let mut wait: [u8;1] = [0];
|
||||
// let _ = bus.write_read_async(id, [SYSRANGE_START as u8], &mut wait).await;
|
||||
// debug!("{wait:?}");
|
||||
// if wait[0] & 0x01 != 0 {
|
||||
// break;
|
||||
// }
|
||||
// Timer::after_micros(5).await;
|
||||
//async fn write_to_device<'a, T,const N: usize>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, data: [[u8;2];N])
|
||||
//where T: embassy_rp::i2c::Instance {
|
||||
// for transaction in data {
|
||||
// let _ = bus.write_async(addr, transaction).await;
|
||||
// }
|
||||
// debug!("starting wait part 2");
|
||||
//}
|
||||
|
||||
//async fn write_flag<'a, T>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, reg: u8, bit: u8, value: bool)
|
||||
//where T: embassy_rp::i2c::Instance {
|
||||
// let mut initial: [u8;1] = [0];
|
||||
// let _ = bus.write_read_async(addr, [reg], &mut initial).await;
|
||||
// let mask = 1 << bit;
|
||||
// if value {
|
||||
// initial[0] |= mask;
|
||||
// } else {
|
||||
// initial[0] &= !mask;
|
||||
// }
|
||||
// let _ = bus.write_async(addr, [reg, initial[0]]).await;
|
||||
//}
|
||||
|
||||
//let id = 0x29;
|
||||
//Timer::after_millis(50).await; // sensor boot
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0x88, 0x00],
|
||||
// [0x80, 0x01],
|
||||
// [0xFF, 0x01],
|
||||
// [0x00, 0x00],
|
||||
//]).await;
|
||||
//let mut stop: [u8;1] = [0];
|
||||
//let _ = bus.write_read_async(id, [0x91], &mut stop);
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0x00, 0x01],
|
||||
// [0xFF, 0x00],
|
||||
// [0x80, 0x00],
|
||||
//]).await;
|
||||
//
|
||||
//// disable SIGNAL_RATE_MSRC (bit 1) and SIGNAL_RATE_PRE_RANGE (bit 4) limit checks
|
||||
//write_flag(&mut bus, id, 0x60, 1, true).await;
|
||||
//write_flag(&mut bus, id, 0x60, 4, true).await;
|
||||
|
||||
//let mega_counts_per_second = 0.25;
|
||||
//let mega_counts_per_second: u16 = (mega_counts_per_second * (1<<7) as f64) as u16;
|
||||
//let _ = bus.write_async(id, [FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT as u8,
|
||||
// (mega_counts_per_second >> 8) as u8,
|
||||
// (mega_counts_per_second & 255) as u8
|
||||
//]).await;
|
||||
|
||||
//// get spad info
|
||||
//let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0xFF]).await;
|
||||
|
||||
//write_to_device(&mut bus, id , [
|
||||
// [0x80, 0x01],
|
||||
// [0xff, 0x01],
|
||||
// [0x00, 0x00],
|
||||
// [0xff, 0x06],
|
||||
//]).await;
|
||||
//write_flag(&mut bus, id, 0x83, 3, true).await;
|
||||
//write_to_device(&mut bus, id , [
|
||||
// [0xff, 0x07],
|
||||
// [0x81, 0x01],
|
||||
// [0x80, 0x01],
|
||||
// [0x94, 0x6b],
|
||||
// [0x83, 0x00],
|
||||
//]).await;
|
||||
//debug!("starting spad wait");
|
||||
//loop {
|
||||
// let mut wait: [u8;1] = [0];
|
||||
// let _ = bus.write_read_async(id, [0x83], &mut wait).await;
|
||||
// if wait[0] != 0 {
|
||||
// break;
|
||||
// }
|
||||
// Timer::after_micros(5).await;
|
||||
//}
|
||||
//debug!("ended spad wait");
|
||||
|
||||
//let _ = bus.write_async(id, [0x83, 0x01]).await;
|
||||
|
||||
//let mut value: [u8;1] = [0];
|
||||
//let _ = bus.write_read_async(id, [0x92], &mut value).await;
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0x81, 0x00],
|
||||
// [0xff, 0x06],
|
||||
//]).await;
|
||||
//write_flag(&mut bus, id, 0x83, 3, false).await;
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0xff, 0x01],
|
||||
// [0x00, 0x01],
|
||||
// [0xff, 0x00],
|
||||
// [0x80, 0x00],
|
||||
//]).await;
|
||||
//let count = value[0] & 0x7f;
|
||||
//let is_aperture = value[0] & 0b10000000;
|
||||
//let is_aperture = is_aperture != 0;
|
||||
//// TODO: vl53l0x.py post line 200
|
||||
|
||||
//let mut spad_map: [u8;6]=[0;6];
|
||||
//let _ = bus.write_read_async(id, [GLOBAL_CONFIG_SPAD_ENABLES_REF_0 as u8], &mut spad_map);
|
||||
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0xff, 0x01],
|
||||
// [DYNAMIC_SPAD_REF_EN_START_OFFSET as u8, 0x00],
|
||||
// [DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD as u8, 0x2c],
|
||||
// [0xff, 0x00],
|
||||
// [DYNAMIC_SPAD_REF_EN_START_OFFSET as u8, 0xb4],
|
||||
//]).await;
|
||||
|
||||
//let mut spads_enabled = 0;
|
||||
//for i in 0..48 {
|
||||
// if i < 12 && is_aperture || spads_enabled >= count {
|
||||
// spad_map[i/8] &= !(1<< (i>>2));
|
||||
// } else if (spad_map[i/8] & (1<< (i>>2))) != 0 {
|
||||
// spads_enabled += 1;
|
||||
// }
|
||||
//}
|
||||
|
||||
//let mut spad_write: [u8;7] = [0;7];
|
||||
//spad_write[0] = GLOBAL_CONFIG_SPAD_ENABLES_REF_0 as u8;
|
||||
//spad_write[1..].clone_from_slice(&spad_map);
|
||||
//let _ = bus.write_async(id, spad_write).await;
|
||||
|
||||
//
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0xFF, 0x01],
|
||||
// [0x00, 0x00],
|
||||
// [0xFF, 0x00],
|
||||
// [0x09, 0x00],
|
||||
// [0x10, 0x00],
|
||||
// [0x11, 0x00],
|
||||
// [0x24, 0x01],
|
||||
// [0x25, 0xFF],
|
||||
// [0x75, 0x00],
|
||||
// [0xFF, 0x01],
|
||||
// [0x4E, 0x2C],
|
||||
// [0x48, 0x00],
|
||||
// [0x30, 0x20],
|
||||
// [0xFF, 0x00],
|
||||
// [0x30, 0x09],
|
||||
// [0x54, 0x00],
|
||||
// [0x31, 0x04],
|
||||
// [0x32, 0x03],
|
||||
// [0x40, 0x83],
|
||||
// [0x46, 0x25],
|
||||
// [0x60, 0x00],
|
||||
// [0x27, 0x00],
|
||||
// [0x50, 0x06],
|
||||
// [0x51, 0x00],
|
||||
// [0x52, 0x96],
|
||||
// [0x56, 0x08],
|
||||
// [0x57, 0x30],
|
||||
// [0x61, 0x00],
|
||||
// [0x62, 0x00],
|
||||
// [0x64, 0x00],
|
||||
// [0x65, 0x00],
|
||||
// [0x66, 0xA0],
|
||||
// [0xFF, 0x01],
|
||||
// [0x22, 0x32],
|
||||
// [0x47, 0x14],
|
||||
// [0x49, 0xFF],
|
||||
// [0x4A, 0x00],
|
||||
// [0xFF, 0x00],
|
||||
// [0x7A, 0x0A],
|
||||
// [0x7B, 0x00],
|
||||
// [0x78, 0x21],
|
||||
// [0xFF, 0x01],
|
||||
// [0x23, 0x34],
|
||||
// [0x42, 0x00],
|
||||
// [0x44, 0xFF],
|
||||
// [0x45, 0x26],
|
||||
// [0x46, 0x05],
|
||||
// [0x40, 0x40],
|
||||
// [0x0E, 0x06],
|
||||
// [0x20, 0x1A],
|
||||
// [0x43, 0x40],
|
||||
// [0xFF, 0x00],
|
||||
// [0x34, 0x03],
|
||||
// [0x35, 0x44],
|
||||
// [0xFF, 0x01],
|
||||
// [0x31, 0x04],
|
||||
// [0x4B, 0x09],
|
||||
// [0x4C, 0x05],
|
||||
// [0x4D, 0x04],
|
||||
// [0xFF, 0x00],
|
||||
// [0x44, 0x00],
|
||||
// [0x45, 0x20],
|
||||
// [0x47, 0x08],
|
||||
// [0x48, 0x28],
|
||||
// [0x67, 0x00],
|
||||
// [0x70, 0x04],
|
||||
// [0x71, 0x01],
|
||||
// [0x72, 0xFE],
|
||||
// [0x76, 0x00],
|
||||
// [0x77, 0x00],
|
||||
// [0xFF, 0x01],
|
||||
// [0x0D, 0x01],
|
||||
// [0xFF, 0x00],
|
||||
// [0x80, 0x01],
|
||||
// [0x01, 0xF8],
|
||||
// [0xFF, 0x01],
|
||||
// [0x8E, 0x01],
|
||||
// [0x00, 0x01],
|
||||
// [0xFF, 0x00],
|
||||
// [0x80, 0x00],
|
||||
|
||||
// [SYSTEM_INTERRUPT_CONFIG_GPIO as u8, 0x04],
|
||||
//]).await;
|
||||
////write_flag(&mut bus, id, GPIO_HV_MUX_ACTIVE_HIGH as u8, 4, false).await;
|
||||
////let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0x01]).await;
|
||||
////calibrate(&mut bus, id, 0x40).await;
|
||||
////let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0x02]).await;
|
||||
////calibrate(&mut bus, id, 0x00).await;
|
||||
////let _ = bus.write_async(id, [SYSTEM_SEQUENCE_CONFIG as u8, 0xe8]).await;
|
||||
|
||||
//async fn calibrate<'a, T>(bus: &mut embassy_rp::i2c::I2c<'a, T,Async>, addr: u16, data: u8)
|
||||
//where T: embassy_rp::i2c::Instance {
|
||||
// let _ = bus.write_async(addr, [SYSRANGE_START as u8 ,data | 0x01]).await;
|
||||
// debug!("started calib wait");
|
||||
// loop {
|
||||
// let mut wait: [u8;1] = [0];
|
||||
// let _ = bus.write_read_async(id, [RESULT_INTERRUPT_STATUS as u8], &mut wait).await;
|
||||
// let _ = bus.write_read_async(addr, [0x13], &mut wait).await;
|
||||
// if wait[0] & 0x07 != 0 {
|
||||
// break;
|
||||
// }
|
||||
// Timer::after_micros(5).await;
|
||||
// }
|
||||
// debug!("ending wait part 2");
|
||||
// let mut output: [u8; 2] = [0;2];
|
||||
// let _ = bus.write_read_async(id, [0x14], &mut output).await;
|
||||
// let _ = bus.write_async(id, [0x0B, 0x01]).await;
|
||||
// info!("{:?}",output);
|
||||
// Timer::after_millis(20).await;
|
||||
// debug!("ended calib wait");
|
||||
// write_to_device(bus, addr, [
|
||||
// [SYSTEM_INTERRUPT_CLEAR as u8, 0x01],
|
||||
// [SYSRANGE_START as u8, 0x00],
|
||||
// ]).await;
|
||||
//}
|
||||
|
||||
|
||||
////TODO VL53L0X.cpp L 236-280
|
||||
|
||||
|
||||
//// start continuous mode
|
||||
//write_to_device(&mut bus, id, [
|
||||
// [0x80, 0x01],
|
||||
// [0xFF, 0x01],
|
||||
// [0x00, 0x00],
|
||||
// [0x91, stop[0]],
|
||||
// [0x00, 0x01],
|
||||
// [0xFF, 0x00],
|
||||
// [0x80, 0x00],
|
||||
// //[0x04, 0x00], // measurement delay
|
||||
// [0x00, 0x02], // back to back shots
|
||||
//]).await;
|
||||
|
||||
////let _ = bus.write_async(0x88u16, [0x00]).await;
|
||||
////let _ = bus.write_async(0x80u16, [0x01]).await;
|
||||
////let _ = bus.write_async(0xFFu16, [0x01]).await;
|
||||
////let _ = bus.write_async(0x00u16, [0x00]).await;
|
||||
////let _ = bus.write_async(0x00u16, [0x01]).await;
|
||||
////let _ = bus.write_async(0xFFu16, [0x00]).await;
|
||||
////let _ = bus.write_async(0x80u16, [0x00]).await;
|
||||
//
|
||||
////loop {
|
||||
//// debug!("starting wait part 1");
|
||||
//// loop {
|
||||
//// let mut wait: [u8;1] = [0];
|
||||
//// let _ = bus.write_read_async(id, [SYSRANGE_START as u8], &mut wait).await;
|
||||
//// debug!("{wait:?}");
|
||||
//// if wait[0] & 0x01 != 0 {
|
||||
//// break;
|
||||
//// }
|
||||
//// Timer::after_micros(5).await;
|
||||
//// }
|
||||
//// debug!("starting wait part 2");
|
||||
//// loop {
|
||||
//// let mut wait: [u8;1] = [0];
|
||||
//// let _ = bus.write_read_async(id, [RESULT_INTERRUPT_STATUS as u8], &mut wait).await;
|
||||
//// if wait[0] & 0x07 != 0 {
|
||||
//// break;
|
||||
//// }
|
||||
//// Timer::after_micros(5).await;
|
||||
//// }
|
||||
//// debug!("ending wait part 2");
|
||||
//// let mut output: [u8; 2] = [0;2];
|
||||
//// let _ = bus.write_read_async(id, [0x14], &mut output).await;
|
||||
//// let _ = bus.write_async(id, [0x0B, 0x01]).await;
|
||||
//// info!("out: {:?}",output);
|
||||
//// Timer::after_millis(20).await;
|
||||
////}
|
||||
|
||||
loop {
|
||||
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
|
||||
socket.set_timeout(Some(Duration::from_secs(10)));
|
||||
socket.set_timeout(Some(Duration::from_secs(3)));
|
||||
|
||||
let mut c: pwm::Config = Default::default();
|
||||
c.divider = 255.into();
|
||||
c.top = 8715;
|
||||
c.compare_b = 0;
|
||||
c.compare_a = 0;
|
||||
pwm.set_config(&c);
|
||||
|
||||
flipper.set_low();
|
||||
|
||||
control.gpio_set(0, false).await;
|
||||
info!("Listening on TCP:1234...");
|
||||
|
|
@ -469,8 +492,24 @@ async fn main(spawner: Spawner) {
|
|||
info!("recd {:#02x}", response[0]);
|
||||
let _ = hex::encode_to_slice(response, &mut buf);
|
||||
n = 4;
|
||||
},
|
||||
'D' => {
|
||||
let left: [u8;2] = hex::FromHex::from_hex(segs.next().unwrap()).unwrap();
|
||||
let right: [u8;2] = hex::FromHex::from_hex(segs.next().unwrap()).unwrap();
|
||||
info!("left {:?}, right {left:?}", right);
|
||||
|
||||
|
||||
let left = u16::from_be_bytes(left);
|
||||
c.compare_a = left;
|
||||
let right = u16::from_be_bytes(right);
|
||||
c.compare_b = right;
|
||||
info!("left {:?}, right {left:?}", right);
|
||||
pwm.set_config(&c);
|
||||
},
|
||||
'F' => {
|
||||
flipper.set_high();
|
||||
},
|
||||
'L' => {
|
||||
flipper.set_low();
|
||||
},
|
||||
_ => {}
|
||||
|
||||
|
|
|
|||
91
controller/src/vl53l0.rs
Normal file
91
controller/src/vl53l0.rs
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
use core::ops::Deref;
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum RegAddr
|
||||
{
|
||||
SYSRANGE_START = 0x00,
|
||||
|
||||
SYSTEM_THRESH_HIGH = 0x0C,
|
||||
SYSTEM_THRESH_LOW = 0x0E,
|
||||
|
||||
SYSTEM_SEQUENCE_CONFIG = 0x01,
|
||||
SYSTEM_RANGE_CONFIG = 0x09,
|
||||
SYSTEM_INTERMEASUREMENT_PERIOD = 0x04,
|
||||
|
||||
SYSTEM_INTERRUPT_CONFIG_GPIO = 0x0A,
|
||||
|
||||
GPIO_HV_MUX_ACTIVE_HIGH = 0x84,
|
||||
|
||||
SYSTEM_INTERRUPT_CLEAR = 0x0B,
|
||||
|
||||
RESULT_INTERRUPT_STATUS = 0x13,
|
||||
RESULT_RANGE_STATUS = 0x14,
|
||||
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_RTN = 0xBC,
|
||||
//RESULT_CORE_RANGING_TOTAL_EVENTS_RTN = 0xC0,
|
||||
RESULT_CORE_AMBIENT_WINDOW_EVENTS_REF = 0xD0,
|
||||
RESULT_CORE_RANGING_TOTAL_EVENTS_REF = 0xD4,
|
||||
RESULT_PEAK_SIGNAL_RATE_REF = 0xB6,
|
||||
|
||||
ALGO_PART_TO_PART_RANGE_OFFSET_MM = 0x28,
|
||||
|
||||
I2C_SLAVE_DEVICE_ADDRESS = 0x8A,
|
||||
|
||||
MSRC_CONFIG_CONTROL = 0x60,
|
||||
|
||||
PRE_RANGE_CONFIG_MIN_SNR = 0x27,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_LOW = 0x56,
|
||||
PRE_RANGE_CONFIG_VALID_PHASE_HIGH = 0x57,
|
||||
PRE_RANGE_MIN_COUNT_RATE_RTN_LIMIT = 0x64,
|
||||
|
||||
FINAL_RANGE_CONFIG_MIN_SNR = 0x67,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_LOW = 0x47,
|
||||
FINAL_RANGE_CONFIG_VALID_PHASE_HIGH = 0x48,
|
||||
FINAL_RANGE_CONFIG_MIN_COUNT_RATE_RTN_LIMIT = 0x44,
|
||||
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_HI = 0x61,
|
||||
PRE_RANGE_CONFIG_SIGMA_THRESH_LO = 0x62,
|
||||
|
||||
PRE_RANGE_CONFIG_VCSEL_PERIOD = 0x50,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x51,
|
||||
PRE_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x52,
|
||||
|
||||
SYSTEM_HISTOGRAM_BIN = 0x81,
|
||||
HISTOGRAM_CONFIG_INITIAL_PHASE_SELECT = 0x33,
|
||||
HISTOGRAM_CONFIG_READOUT_CTRL = 0x55,
|
||||
|
||||
FINAL_RANGE_CONFIG_VCSEL_PERIOD = 0x70,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_HI = 0x71,
|
||||
FINAL_RANGE_CONFIG_TIMEOUT_MACROP_LO = 0x72,
|
||||
CROSSTALK_COMPENSATION_PEAK_RATE_MCPS = 0x20,
|
||||
|
||||
MSRC_CONFIG_TIMEOUT_MACROP = 0x46,
|
||||
|
||||
SOFT_RESET_GO2_SOFT_RESET_N = 0xBF,
|
||||
IDENTIFICATION_MODEL_ID = 0xC0,
|
||||
IDENTIFICATION_REVISION_ID = 0xC2,
|
||||
|
||||
OSC_CALIBRATE_VAL = 0xF8,
|
||||
|
||||
GLOBAL_CONFIG_VCSEL_WIDTH = 0x32,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_0 = 0xB0,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_1 = 0xB1,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_2 = 0xB2,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_3 = 0xB3,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_4 = 0xB4,
|
||||
GLOBAL_CONFIG_SPAD_ENABLES_REF_5 = 0xB5,
|
||||
|
||||
//GLOBAL_CONFIG_REF_EN_START_SELECT = 0xB6,
|
||||
DYNAMIC_SPAD_NUM_REQUESTED_REF_SPAD = 0x4E,
|
||||
DYNAMIC_SPAD_REF_EN_START_OFFSET = 0x4F,
|
||||
POWER_MANAGEMENT_GO1_POWER_FORCE = 0x80,
|
||||
|
||||
VHV_CONFIG_PAD_SCL_SDA__EXTSUP_HV = 0x89,
|
||||
|
||||
ALGO_PHASECAL_LIM = 0x30,
|
||||
//ALGO_PHASECAL_CONFIG_TIMEOUT = 0x30,
|
||||
}
|
||||
|
||||
struct Vl53l0x {
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue