Skip to content

Commit 351a4d9

Browse files
committed
unbox serial
1 parent 4abfa1b commit 351a4d9

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

espflash/src/connection.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use crate::encoder::SlipEncoder;
66
use crate::error::{ConnectionError, Error, RomError};
77
use binread::io::Cursor;
88
use binread::{BinRead, BinReaderExt};
9-
use serial::{BaudRate, SerialPort, SerialPortSettings};
9+
use serial::{BaudRate, SerialPort, SerialPortSettings, SystemPort};
1010
use slip_codec::Decoder;
1111

1212
pub struct Connection {
13-
serial: Box<dyn SerialPort>,
13+
serial: SystemPort,
1414
decoder: Decoder,
1515
}
1616

@@ -25,9 +25,9 @@ pub struct CommandResponse {
2525
}
2626

2727
impl Connection {
28-
pub fn new(serial: impl SerialPort + 'static) -> Self {
28+
pub fn new(serial: SystemPort) -> Self {
2929
Connection {
30-
serial: Box::new(serial),
30+
serial,
3131
decoder: Decoder::new(),
3232
}
3333
}
@@ -99,7 +99,7 @@ impl Connection {
9999
pub fn write_command(
100100
&mut self,
101101
command: u8,
102-
data: impl LazyBytes<Box<dyn SerialPort>>,
102+
data: impl LazyBytes<SystemPort>,
103103
check: u32,
104104
) -> Result<(), Error> {
105105
let mut encoder = SlipEncoder::new(&mut self.serial)?;
@@ -112,7 +112,7 @@ impl Connection {
112112
Ok(())
113113
}
114114

115-
pub fn command<Data: LazyBytes<Box<dyn SerialPort>>>(
115+
pub fn command<Data: LazyBytes<SystemPort>>(
116116
&mut self,
117117
command: u8,
118118
data: Data,
@@ -148,6 +148,10 @@ impl Connection {
148148
self.serial.flush()?;
149149
Ok(())
150150
}
151+
152+
pub fn into_serial(self) -> SystemPort {
153+
self.serial
154+
}
151155
}
152156

153157
pub trait LazyBytes<W: Write> {

espflash/src/flasher.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bytemuck::{__core::time::Duration, bytes_of, Pod, Zeroable};
2-
use serial::{BaudRate, SerialPort};
2+
use serial::{BaudRate, SystemPort};
33
use strum_macros::Display;
44

55
use std::thread::sleep;
@@ -11,7 +11,7 @@ use crate::{
1111
Error, PartitionTable,
1212
};
1313

14-
pub(crate) type Encoder<'a> = SlipEncoder<'a, Box<dyn SerialPort>>;
14+
pub(crate) type Encoder<'a> = SlipEncoder<'a, SystemPort>;
1515

1616
pub(crate) const FLASH_SECTOR_SIZE: usize = 0x1000;
1717
const FLASH_BLOCK_SIZE: usize = 0x100;
@@ -205,10 +205,7 @@ pub struct Flasher {
205205
}
206206

207207
impl Flasher {
208-
pub fn connect(
209-
serial: impl SerialPort + 'static,
210-
speed: Option<BaudRate>,
211-
) -> Result<Self, Error> {
208+
pub fn connect(serial: SystemPort, speed: Option<BaudRate>) -> Result<Self, Error> {
212209
let mut flasher = Flasher {
213210
connection: Connection::new(serial), // default baud is always 115200
214211
chip: Chip::Esp8266, // dummy, set properly later
@@ -537,6 +534,10 @@ impl Flasher {
537534
self.connection.flush()?;
538535
Ok(())
539536
}
537+
538+
pub fn into_serial(self) -> SystemPort {
539+
self.connection.into_serial()
540+
}
540541
}
541542

542543
pub(crate) fn get_erase_size(offset: usize, size: usize) -> usize {

0 commit comments

Comments
 (0)