Hacky read workaround

This commit is contained in:
hodasemi 2023-03-25 15:41:15 +01:00
parent 273dbaa630
commit f9f324475b
2 changed files with 46 additions and 22 deletions

View file

@ -131,10 +131,15 @@ fn main() -> ! {
critical_section::with(|_| {
let serial = custom_hid::serial();
serial.send_text("---");
serial.send_number(mouse_sensor.operation_mode(), 10);
serial.send_text(" - ");
serial.send_number(0xB8, 10);
// serial.send_text("---");
// serial.send_number(mouse_sensor.product_id_1(), 10);
// serial.send_text(" - ");
// serial.send_number(0x30, 10);
// serial.send_text("---");
// serial.send_number(mouse_sensor.product_id_2(), 10);
// serial.send_text(" - ");
// serial.send_number(0x02, 10);
// custom_hid::serial().send_number(mouse_sensor.product_id_2(), 10);
});

View file

@ -109,16 +109,27 @@ where
log,
};
if me.led.set_low().is_err() {
(me.log)("led low failed");
if me.led.set_high().is_err() {
(me.log)("led high failed");
}
if !me.verify_product_id_1() || !me.verify_product_id_2() {
if me.led.set_high().is_err() {
(me.log)("led high failed");
// verify initialization
loop {
if me.verify_product_id_1() {
break;
}
}
loop {
if me.verify_product_id_2() {
break;
}
}
if me.led.set_low().is_err() {
(me.log)("led low failed");
}
me
}
@ -144,21 +155,29 @@ where
}
pub fn read(&mut self, address: u8) -> u8 {
self.access(|me| {
if me.spi.send(address & Self::READ).is_err() {
(me.log)("send address (read) failed");
}
me.delay.delay_us(50);
match me.spi.read() {
Ok(res) => res,
Err(_) => {
(me.log)("read failed");
0
loop {
let res = self.access(|me| {
if me.spi.send(address & Self::READ).is_err() {
(me.log)("send address (read) failed");
}
if me.spi.send(0).is_err() {
(me.log)("send dummy (read) failed");
}
match me.spi.read() {
Ok(r) => r << 1,
Err(_) => {
(me.log)("read failed");
0
}
}
});
if res != address {
return res;
}
})
}
}
pub fn write(&mut self, address: u8, value: u8) {