Skip to content

Commit d555956

Browse files
authored
Clean up unused code, optimize comparison in find_serial_port (#302)
* Clean up unused code * Deduplicate and optimize find_serial_port a bit
1 parent 33d7bf7 commit d555956

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

espflash/src/cli/serial.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(not(target_os = "windows"))]
12
use std::fs;
23

34
use crossterm::style::Stylize;
@@ -31,12 +32,8 @@ pub fn get_serial_port_info(
3132
let ports = detect_usb_serial_ports().unwrap_or_default();
3233

3334
if let Some(serial) = &matches.port {
34-
#[cfg(not(target_os = "windows"))]
35-
let serial = fs::canonicalize(serial)?.to_string_lossy().to_string();
3635
find_serial_port(&ports, &serial)
3736
} else if let Some(serial) = &config.connection.serial {
38-
#[cfg(not(target_os = "windows"))]
39-
let serial = fs::canonicalize(serial)?.to_string_lossy().to_string();
4037
find_serial_port(&ports, &serial)
4138
} else {
4239
let (port, matches) = select_serial_port(ports, config)?;
@@ -71,14 +68,19 @@ pub fn get_serial_port_info(
7168
/// Given a vector of `SerialPortInfo` structs, attempt to find and return one
7269
/// whose `port_name` field matches the provided `name` argument.
7370
fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortInfo, Error> {
71+
#[cfg(not(target_os = "windows"))]
72+
let name = fs::canonicalize(name)?;
73+
#[cfg(not(target_os = "windows"))]
74+
let name = name.to_string_lossy();
75+
7476
let port_info = ports
7577
.iter()
76-
.find(|port| port.port_name.to_lowercase() == name.to_lowercase());
78+
.find(|port| port.port_name.eq_ignore_ascii_case(name.as_ref()));
7779

7880
if let Some(port) = port_info {
7981
Ok(port.to_owned())
8082
} else {
81-
Err(Error::SerialNotFound(name.to_owned()))
83+
Err(Error::SerialNotFound(name.to_string()))
8284
}
8385
}
8486

espflash/src/connection.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use std::{io::BufWriter, thread::sleep, time::Duration};
88

99
use binread::{io::Cursor, BinRead, BinReaderExt};
10-
use bytemuck::{Pod, Zeroable};
1110
use log::info;
1211
use serialport::UsbPortInfo;
1312
use slip_codec::SlipDecoder;
@@ -40,15 +39,6 @@ pub struct Connection {
4039
decoder: SlipDecoder,
4140
}
4241

43-
#[derive(Zeroable, Pod, Copy, Clone, Debug)]
44-
#[repr(C)]
45-
struct WriteRegParams {
46-
addr: u32,
47-
value: u32,
48-
mask: u32,
49-
delay_us: u32,
50-
}
51-
5242
impl Connection {
5343
pub fn new(serial: Interface, port_info: UsbPortInfo) -> Self {
5444
Connection {

0 commit comments

Comments
 (0)