Added some stuff for the monitor (can already reboot the target)

This commit is contained in:
2025-09-19 11:04:53 +02:00
parent c803e6514f
commit ebd24ae7b5
6 changed files with 175 additions and 19 deletions

View File

@@ -22,24 +22,10 @@ impl PhysicalTarget {
port.set_read_timeout(Duration::from_millis(100))?;
port.set_dtr(false)?;
std::thread::sleep(Duration::from_millis(100));
for i in (0..5).rev() {
port.write(b"U")?;
let mut buf = [0u8; 1];
port.read(&mut buf)?;
if buf[0] == b'U' { break }
if i == 0 {
Err(Error::other(format!("Invalid sync response: 0x{:02X}", buf[0])))?
}
}
let mut new = Self { port };
new.resync_target()?;
let manufacturer = new.read_info(0x00, 0x00).unwrap();
let family = new.read_info(0x00, 0x01).unwrap();
let name = new.read_info(0x00, 0x02).unwrap();
@@ -50,6 +36,29 @@ impl PhysicalTarget {
Ok(new)
}
pub fn resync_target(&mut self) -> Result<(), Error> {
self.port.set_dtr(true)?;
self.port.set_rts(true)?;
std::thread::sleep(Duration::from_millis(10));
self.port.set_dtr(false)?;
std::thread::sleep(Duration::from_millis(100));
for i in (0..5).rev() {
self.port.write(b"U")?;
let mut buf = [0u8; 1];
self.port.read(&mut buf)?;
if buf[0] == b'U' { break }
if i == 0 {
Err(Error::other(format!("Invalid sync response: 0x{:02X}", buf[0])))?
}
}
Ok(())
}
pub fn read_info(&mut self, category: u8, idx: u8) -> Result<u8, Error> {
self.send_command(0x05, 0, &[category, idx])?;
@@ -126,6 +135,10 @@ impl PhysicalTarget {
Ok(())
}
pub fn port(&mut self) -> &mut SerialPort {
&mut self.port
}
}
impl Target for PhysicalTarget {
@@ -228,7 +241,11 @@ impl Target for PhysicalTarget {
impl Drop for PhysicalTarget {
fn drop(&mut self) {
let _ = self.port.set_dtr(true);
self.port.set_dtr(true).unwrap();
self.port.set_rts(true).unwrap();
std::thread::sleep(Duration::from_millis(100));
self.port.set_dtr(false).unwrap();
self.port.set_rts(false).unwrap();
}
}