-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Install Command using probe-rs (#32)
Signed-off-by: Ana Micu <[email protected]> Co-authored-by: Ana Micu <[email protected]>
- Loading branch information
1 parent
7db3faa
commit 6851460
Showing
10 changed files
with
528 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::time::Duration; | ||
|
||
use probe_rs::{probe::DebugProbeInfo, Permissions, Session}; | ||
use tokio_serial::{FlowControl, Parity, SerialPort, SerialStream, StopBits}; | ||
|
||
use crate::errors::TockloaderError; | ||
|
||
pub enum ConnectionInfo { | ||
SerialInfo(String), | ||
ProbeInfo(DebugProbeInfo), | ||
} | ||
|
||
impl From<String> for ConnectionInfo { | ||
fn from(value: String) -> Self { | ||
ConnectionInfo::SerialInfo(value) | ||
} | ||
} | ||
|
||
pub enum Connection { | ||
ProbeRS(Session), | ||
Serial(SerialStream), | ||
} | ||
|
||
impl Connection { | ||
pub fn open(info: ConnectionInfo, chip: Option<String>) -> Result<Connection, TockloaderError> { | ||
match info { | ||
ConnectionInfo::SerialInfo(serial_info) => { | ||
let builder = tokio_serial::new(serial_info, 115200); | ||
match SerialStream::open(&builder) { | ||
Ok(mut port) => { | ||
port.set_parity(Parity::None).unwrap(); | ||
port.set_stop_bits(StopBits::One).unwrap(); | ||
port.set_flow_control(FlowControl::None).unwrap(); | ||
port.set_timeout(Duration::from_millis(500)).unwrap(); | ||
port.write_request_to_send(false).unwrap(); | ||
port.write_data_terminal_ready(false).unwrap(); | ||
Ok(Connection::Serial(port)) | ||
} | ||
Err(_) => { | ||
//TODO(Micu Ana): Add error handling | ||
Err(TockloaderError::NoPortAvailable) | ||
} | ||
} | ||
} | ||
ConnectionInfo::ProbeInfo(probe_info) => { | ||
//TODO(Micu Ana): Add error handling | ||
let probe = probe_info.open().unwrap(); | ||
match probe.attach(chip.unwrap(), Permissions::default()) { | ||
Ok(session) => Ok(Connection::ProbeRS(session)), | ||
Err(_) => { | ||
//TODO(Micu Ana): Add error handling | ||
Err(TockloaderError::NoPortAvailable) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.