Skip to content

Commit 5d0a8e0

Browse files
committed
Fix compile errors
1 parent a7be607 commit 5d0a8e0

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

espflash/src/cli/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use update_informer::{registry, Check};
2020
use crate::{
2121
cli::{monitor::monitor, serial::get_serial_port_info},
2222
elf::{ElfFirmwareImage, FlashFrequency, FlashMode},
23-
error::{Error, NoOtadataError},
23+
error::NoOtadataError,
2424
flasher::FlashSize,
2525
interface::Interface,
2626
partition_table, Chip, Flasher, ImageFormatId, InvalidPartitionTable, MissingPartitionTable,
@@ -132,7 +132,6 @@ pub fn connect(opts: &ConnectOpts, config: &Config) -> Result<Flasher> {
132132
println!("Connecting...\n");
133133

134134
let interface = Interface::new(&port_info, opts, config)
135-
.map_err(Error::from)
136135
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))?;
137136

138137
// NOTE: since `get_serial_port_info` filters out all non-USB serial ports, we

espflash/src/interface.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::io::Read;
22

33
use crate::{cli::ConnectOpts, Config, Error};
4-
use miette::Context;
4+
use miette::{Context, Result};
55
use serialport::{FlowControl, SerialPort, SerialPortInfo};
66

77
#[cfg(feature = "raspberry")]
@@ -36,27 +36,35 @@ fn write_gpio(gpio: &mut OutputPin, level: bool) {
3636
}
3737
}
3838

39+
fn open_port(port_info: &SerialPortInfo) -> Result<Box<dyn SerialPort>> {
40+
serialport::new(&port_info.port_name, 115_200)
41+
.flow_control(FlowControl::None)
42+
.open()
43+
.map_err(Error::from)
44+
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))
45+
}
46+
3947
impl Interface {
4048
#[cfg(feature = "raspberry")]
4149
pub(crate) fn new(
4250
port_info: &SerialPortInfo,
4351
opts: &ConnectOpts,
4452
config: &Config,
45-
) -> Result<Self, Error> {
53+
) -> Result<Self> {
4654
let rts_gpio = opts.rts.or(config.rts);
4755
let dtr_gpio = opts.dtr.or(config.dtr);
4856

4957
if port_info.port_type == serialport::SerialPortType::Unknown && dtr_gpio.is_none() {
5058
// Assume internal UART, which has no DTR pin.
51-
return Err(SerialConfigError::MissingDtrForInternalUart);
59+
return Err(Error::from(SerialConfigError::MissingDtrForInternalUart));
5260
}
5361

5462
let mut gpios = Gpio::new().unwrap();
5563

5664
let rts = if let Some(gpio) = rts_gpio {
5765
match gpios.get(gpio) {
5866
Ok(pin) => Some(pin.into_output()),
59-
Err(_) => return Err(SerialConfigError::GpioUnavailable),
67+
Err(_) => return Err(Error::from(SerialConfigError::GpioUnavailable)),
6068
}
6169
} else {
6270
None
@@ -65,20 +73,14 @@ impl Interface {
6573
let dtr = if let Some(gpio) = dtr_gpio {
6674
match gpios.get(gpio) {
6775
Ok(pin) => Some(pin.into_output()),
68-
Err(_) => return Err(SerialConfigError::GpioUnavailable),
76+
Err(_) => return Err(Error::from(SerialConfigError::GpioUnavailable)),
6977
}
7078
} else {
7179
None
7280
};
7381

74-
let serial = serialport::new(&port_info.port_name, 115_200)
75-
.flow_control(FlowControl::None)
76-
.open()
77-
.map_err(Error::from)
78-
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))?;
79-
8082
Ok(Self {
81-
serial_port: serial,
83+
serial_port: open_port(port_info)?,
8284
rts,
8385
dtr,
8486
})
@@ -89,15 +91,9 @@ impl Interface {
8991
port_info: &SerialPortInfo,
9092
_opts: &ConnectOpts,
9193
_config: &Config,
92-
) -> Result<Self, Error> {
93-
let serial = serialport::new(&port_info.port_name, 115_200)
94-
.flow_control(FlowControl::None)
95-
.open()
96-
.map_err(Error::from)
97-
.wrap_err_with(|| format!("Failed to open serial port {}", port_info.port_name))?;
98-
94+
) -> Result<Self> {
9995
Ok(Self {
100-
serial_port: serial,
96+
serial_port: open_port(port_info)?,
10197
})
10298
}
10399

0 commit comments

Comments
 (0)