sftool_lib/common/
speed.rs1use crate::common::ram_command::{Command, RamCommand, RamOps};
2use crate::common::serial_io::{for_tool, sleep_with_cancel};
3use crate::{Result, SifliToolTrait};
4use std::time::Duration;
5
6pub struct SpeedOps;
8
9impl SpeedOps {
10 pub fn set_speed<T>(tool: &mut T, speed: u32) -> Result<()>
12 where
13 T: SifliToolTrait + RamCommand,
14 {
15 tool.command(Command::SetBaud {
17 baud: speed,
18 delay: 10,
19 })?;
20
21 sleep_with_cancel(&tool.base().cancel_token, Duration::from_millis(50))?;
23
24 let mut io = for_tool(tool);
25 io.set_baud_rate(speed)?;
26 io.clear(serialport::ClearBuffer::All)?;
27 RamOps::wait_for_shell_prompt(&mut io, b"msh >", 200, 5)?;
28
29 Ok(())
30 }
31}