Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list-all-ports flag and filter the default list #590

Merged
merged 3 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- Add `--list-all-ports` connection argument to avoid serial port filtering (#590)
- Allow config file to live in parent folder (#595)

### Fixed
- Change the `hard_reset` sequence to fix Windows issues (#594)

### Changed
- Non-linux-musl: Only list the available USB Ports by default (#590)
- `FlashData::new` now returns `crate::Error` (#591)
- Moved `reset_after_flash` method to `reset` module (#594)

Expand Down
3 changes: 3 additions & 0 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ pub struct ConnectArgs {
/// Require confirmation before auto-connecting to a recognized device.
#[arg(short = 'C', long)]
pub confirm_port: bool,
/// List all available ports.
#[arg(long)]
pub list_all_ports: bool,
/// Do not use the RAM stub for loading
#[arg(long)]
pub no_stub: bool,
Expand Down
28 changes: 16 additions & 12 deletions espflash/src/cli/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn get_serial_port_info(
// doesn't work (on Windows) with "dummy" device paths like `COM4`. That's
// the reason we need to handle Windows/Posix differently.

let ports = detect_usb_serial_ports().unwrap_or_default();
let ports = detect_usb_serial_ports(matches.list_all_ports).unwrap_or_default();

if let Some(serial) = &matches.port {
find_serial_port(&ports, serial)
Expand Down Expand Up @@ -108,7 +108,7 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
/// Linux we can do some manual parsing of sysfs to get the relevant bits
/// without udev
#[cfg(all(target_os = "linux", target_env = "musl"))]
fn detect_usb_serial_ports() -> Result<Vec<SerialPortInfo>> {
fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>> {
use std::{
fs::{read_link, read_to_string},
path::PathBuf,
Expand Down Expand Up @@ -166,20 +166,24 @@ fn detect_usb_serial_ports() -> Result<Vec<SerialPortInfo>> {

/// Returns a vector with available USB serial ports.
#[cfg(not(all(target_os = "linux", target_env = "musl")))]
fn detect_usb_serial_ports() -> Result<Vec<SerialPortInfo>> {
fn detect_usb_serial_ports(list_all_ports: bool) -> Result<Vec<SerialPortInfo>> {
let ports = available_ports().into_diagnostic()?;
let ports = ports
.into_iter()
.filter(|port_info| {
matches!(
&port_info.port_type,
SerialPortType::UsbPort(..) |
// Allow PciPort. The user may want to use it.
// The port might have been misdetected by the system as PCI.
SerialPortType::PciPort |
// Good luck.
SerialPortType::Unknown
)
if list_all_ports {
matches!(
&port_info.port_type,
SerialPortType::UsbPort(..) |
// Allow PciPort. The user may want to use it.
// The port might have been misdetected by the system as PCI.
SerialPortType::PciPort |
// Good luck.
SerialPortType::Unknown
)
} else {
matches!(&port_info.port_type, SerialPortType::UsbPort(..))
}
})
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion espflash/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub enum Error {
#[error("No serial ports could be detected")]
#[diagnostic(
code(espflash::no_serial),
help("Make sure you have connected a device to the host system")
help("Make sure you have connected a device to the host system. If the device is connected but not listed, try using the `--list-all-ports` flag.")
)]
NoSerial,

Expand Down
Loading