sftool_lib/common/
speed.rs1use crate::SifliToolTrait;
2use crate::common::ram_command::{Command, RamCommand};
3use std::io::Write;
4use std::time::Duration;
5
6pub struct SpeedOps;
8
9impl SpeedOps {
10 pub fn set_speed<T>(tool: &mut T, speed: u32) -> Result<(), std::io::Error>
12 where
13 T: SifliToolTrait + RamCommand,
14 {
15 tool.command(Command::SetBaud {
17 baud: speed,
18 delay: 500,
19 })?;
20
21 tool.port().set_baud_rate(speed)?;
23
24 std::thread::sleep(Duration::from_millis(300));
26
27 tool.port().write_all("\r\n".as_bytes())?;
29 tool.port().flush()?;
30
31 std::thread::sleep(Duration::from_millis(300));
33
34 tool.port().clear(serialport::ClearBuffer::All)?;
36
37 Ok(())
38 }
39}