Skip to content

Commit d986f7e

Browse files
committed
Add GPIO-based RTS/DTR for Raspberry Pi
1 parent 4e4f767 commit d986f7e

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

espflash/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ md5 = "0.7.0"
4747
miette = { version = "5.3.0", features = ["fancy"] }
4848
parse_int = "0.6.0"
4949
regex = "1.6.0"
50+
rppal = { version = "0.13", optional = true }
5051
serde = { version = "1.0.144", features = ["derive"] }
5152
serde-hex = "0.1.0"
5253
serde_json = "1.0.85"
@@ -61,3 +62,7 @@ thiserror = "1.0.34"
6162
toml = "0.5.9"
6263
update-informer = "0.5.0"
6364
xmas-elf = "0.8.0"
65+
66+
[features]
67+
raspberry = ["dep:rppal"]
68+
default = []

espflash/src/cli/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ pub fn connect(opts: &ConnectOpts, config: &Config) -> Result<Flasher> {
146146

147147
let interface = Interface {
148148
serial_port: serial,
149+
#[cfg(feature = "raspberry")]
150+
rts: None,
151+
#[cfg(feature = "raspberry")]
152+
dtr: None,
149153
};
150154

151155
Ok(Flasher::connect(

espflash/src/interface.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,44 @@
11
use serialport::SerialPort;
22

3+
#[cfg(feature = "raspberry")]
4+
use rppal::gpio::OutputPin;
5+
36
/// Wrapper around SerialPort where platform-specific modifications can be implemented.
47
pub struct Interface {
58
pub serial_port: Box<dyn SerialPort>,
9+
#[cfg(feature = "raspberry")]
10+
pub dtr: Option<OutputPin>,
11+
#[cfg(feature = "raspberry")]
12+
pub rts: Option<OutputPin>,
13+
}
14+
15+
#[cfg(feature = "raspberry")]
16+
fn write_gpio(gpio: &mut OutputPin, level: bool) {
17+
if pin_state {
18+
gpio.set_high();
19+
} else {
20+
gpio.set_low();
21+
}
622
}
723

824
impl Interface {
925
pub fn write_data_terminal_ready(&mut self, pin_state: bool) -> serialport::Result<()> {
26+
#[cfg(feature = "raspberry")]
27+
if let Some(gpio) = self.dtr.as_mut() {
28+
write_gpio(gpio, pin_state);
29+
return Ok(());
30+
}
31+
1032
self.serial_port.write_data_terminal_ready(pin_state)
1133
}
1234

1335
pub fn write_request_to_send(&mut self, pin_state: bool) -> serialport::Result<()> {
36+
#[cfg(feature = "raspberry")]
37+
if let Some(gpio) = self.rts.as_mut() {
38+
write_gpio(gpio, pin_state);
39+
return Ok(());
40+
}
41+
1442
self.serial_port.write_request_to_send(pin_state)
1543
}
1644

0 commit comments

Comments
 (0)