use crate::common::ram_command::{CommandConfig, RamOps};
use crate::common::sifli_debug::{SifliDebug, SifliUartCommand};
use crate::sf32lb56::SF32LB56Tool;
pub use crate::common::ram_command::{Command, DownloadStub, RamCommand, Response};
impl RamCommand for SF32LB56Tool {
fn command(&mut self, cmd: Command) -> Result<Response, std::io::Error> {
RamOps::send_command_and_wait_response(&mut self.port, cmd, self.base.memory_type.as_str())
}
fn send_data(&mut self, data: &[u8]) -> Result<Response, std::io::Error> {
let config = CommandConfig {
compat_mode: self.base.compat,
..Default::default()
};
RamOps::send_data_and_wait_response(&mut self.port, data, &config)
}
}
impl DownloadStub for SF32LB56Tool {
fn download_stub(&mut self) -> Result<(), std::io::Error> {
self.attempt_connect()?;
self.download_stub_impl()?;
std::thread::sleep(std::time::Duration::from_millis(100));
self.port.clear(serialport::ClearBuffer::All)?;
self.debug_command(SifliUartCommand::Exit)?;
if self.base.memory_type == "sd" {
RamOps::wait_for_shell_prompt(
&mut self.port,
b"sd0 OPEN success",
1000, 5, )
} else {
RamOps::wait_for_shell_prompt(
&mut self.port,
b"msh >",
200, 5, )
}
}
}