Skip to content

Commit 419eeab

Browse files
committed
Allow specifying RTS/DTR GPIO numbers
1 parent d986f7e commit 419eeab

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
@@ -42,6 +42,16 @@ pub struct ConnectOpts {
4242
#[clap(long)]
4343
pub speed: Option<u32>,
4444

45+
/// DTR pin to use for the internal UART hardware.
46+
#[cfg(feature = "raspberry")]
47+
#[cfg_attr(feature = "raspberry", clap(long))]
48+
pub dtr: Option<u8>,
49+
50+
/// RTS pin to use for the internal UART hardware.
51+
#[cfg(feature = "raspberry")]
52+
#[cfg_attr(feature = "raspberry", clap(long))]
53+
pub rts: Option<u8>,
54+
4555
/// Use RAM stub for loading
4656
#[clap(long)]
4757
pub use_stub: bool,
@@ -143,14 +153,10 @@ pub fn connect(opts: &ConnectOpts, config: &Config) -> Result<Flasher> {
143153
}
144154
_ => unreachable!(),
145155
};
156+
#[cfg(feature = "raspberry")]
157+
let mut gpios = rppal::Gpio::new().unwrap();
146158

147-
let interface = Interface {
148-
serial_port: serial,
149-
#[cfg(feature = "raspberry")]
150-
rts: None,
151-
#[cfg(feature = "raspberry")]
152-
dtr: None,
153-
};
159+
let interface = Interface::new(serial, opts, config);
154160

155161
Ok(Flasher::connect(
156162
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)