Skip to content

Commit d953813

Browse files
committed
Allow specifying RTS/DTR GPIO numbers
1 parent 33f79cc commit d953813

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

espflash/src/cli/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pub struct Config {
1212
pub connection: Connection,
1313
#[serde(default)]
1414
pub usb_device: Vec<UsbDevice>,
15+
#[cfg(feature = "raspberry")]
16+
pub rts: Option<u8>,
17+
#[cfg(feature = "raspberry")]
18+
pub dtr: Option<u8>,
1519
#[serde(skip)]
1620
save_path: PathBuf,
1721
}

espflash/src/cli/mod.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ pub struct ConnectOpts {
4646
#[clap(long)]
4747
pub monitor_speed: Option<u32>,
4848

49+
/// DTR pin to use for the internal UART hardware.
50+
#[cfg(feature = "raspberry")]
51+
#[cfg_attr(feature = "raspberry", clap(long))]
52+
pub dtr: Option<u8>,
53+
54+
/// RTS pin to use for the internal UART hardware.
55+
#[cfg(feature = "raspberry")]
56+
#[cfg_attr(feature = "raspberry", clap(long))]
57+
pub rts: Option<u8>,
58+
4959
/// Use RAM stub for loading
5060
#[clap(long)]
5161
pub use_stub: bool,
@@ -147,14 +157,10 @@ pub fn connect(opts: &ConnectOpts, config: &Config) -> Result<Flasher> {
147157
}
148158
_ => unreachable!(),
149159
};
160+
#[cfg(feature = "raspberry")]
161+
let mut gpios = rppal::Gpio::new().unwrap();
150162

151-
let interface = Interface {
152-
serial_port: serial,
153-
#[cfg(feature = "raspberry")]
154-
rts: None,
155-
#[cfg(feature = "raspberry")]
156-
dtr: None,
157-
};
163+
let interface = Interface::new(serial, opts, config);
158164

159165
Ok(Flasher::connect(
160166
interface,

espflash/src/interface.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use serialport::SerialPort;
33
#[cfg(feature = "raspberry")]
44
use rppal::gpio::OutputPin;
55

6+
use crate::{cli::ConnectOpts, Config};
7+
68
/// Wrapper around SerialPort where platform-specific modifications can be implemented.
79
pub struct Interface {
810
pub serial_port: Box<dyn SerialPort>,
@@ -22,6 +24,29 @@ fn write_gpio(gpio: &mut OutputPin, level: bool) {
2224
}
2325

2426
impl Interface {
27+
#[cfg(feature = "raspberry")]
28+
pub(crate) fn new(serial: Box<dyn SerialPort>, opts: &ConnectOpts, config: &Config) -> Self {
29+
Self {
30+
serial_port: serial,
31+
rts: opts
32+
.rts
33+
.or(config.rts)
34+
.map(|num| gpios.get(num).into_output()),
35+
36+
dtr: opts
37+
.dtr
38+
.or(config.dtr)
39+
.map(|num| gpios.get(num).into_output()),
40+
}
41+
}
42+
43+
#[cfg(not(feature = "raspberry"))]
44+
pub(crate) fn new(serial: Box<dyn SerialPort>, _opts: &ConnectOpts, _config: &Config) -> Self {
45+
Self {
46+
serial_port: serial,
47+
}
48+
}
49+
2550
pub fn write_data_terminal_ready(&mut self, pin_state: bool) -> serialport::Result<()> {
2651
#[cfg(feature = "raspberry")]
2752
if let Some(gpio) = self.dtr.as_mut() {

0 commit comments

Comments
 (0)