aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-ppp/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net-ppp/src/lib.rs')
-rw-r--r--embassy-net-ppp/src/lib.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/embassy-net-ppp/src/lib.rs b/embassy-net-ppp/src/lib.rs
index 66496ee0a..54a98c95f 100644
--- a/embassy-net-ppp/src/lib.rs
+++ b/embassy-net-ppp/src/lib.rs
@@ -11,7 +11,7 @@ use core::mem::MaybeUninit;
11use embassy_futures::select::{select, Either}; 11use embassy_futures::select::{select, Either};
12use embassy_net_driver_channel as ch; 12use embassy_net_driver_channel as ch;
13use embassy_net_driver_channel::driver::LinkState; 13use embassy_net_driver_channel::driver::LinkState;
14use embedded_io_async::{BufRead, Write, WriteAllError}; 14use embedded_io_async::{BufRead, Write};
15use ppproto::pppos::{BufferFullError, PPPoS, PPPoSAction}; 15use ppproto::pppos::{BufferFullError, PPPoS, PPPoSAction};
16pub use ppproto::{Config, Ipv4Status}; 16pub use ppproto::{Config, Ipv4Status};
17 17
@@ -49,23 +49,12 @@ pub enum RunError<E> {
49 Read(E), 49 Read(E),
50 /// Writing to the serial port failed. 50 /// Writing to the serial port failed.
51 Write(E), 51 Write(E),
52 /// Writing to the serial port wrote zero bytes, indicating it can't accept more data.
53 WriteZero,
54 /// Writing to the serial got EOF. 52 /// Writing to the serial got EOF.
55 Eof, 53 Eof,
56 /// PPP protocol was terminated by the peer 54 /// PPP protocol was terminated by the peer
57 Terminated, 55 Terminated,
58} 56}
59 57
60impl<E> From<WriteAllError<E>> for RunError<E> {
61 fn from(value: WriteAllError<E>) -> Self {
62 match value {
63 WriteAllError::Other(e) => Self::Write(e),
64 WriteAllError::WriteZero => Self::WriteZero,
65 }
66 }
67}
68
69impl<'d> Runner<'d> { 58impl<'d> Runner<'d> {
70 /// You must call this in a background task for the driver to operate. 59 /// You must call this in a background task for the driver to operate.
71 /// 60 ///
@@ -125,7 +114,7 @@ impl<'d> Runner<'d> {
125 buf[..pkt.len()].copy_from_slice(pkt); 114 buf[..pkt.len()].copy_from_slice(pkt);
126 rx_chan.rx_done(pkt.len()); 115 rx_chan.rx_done(pkt.len());
127 } 116 }
128 PPPoSAction::Transmit(n) => rw.write_all(&tx_buf[..n]).await?, 117 PPPoSAction::Transmit(n) => rw.write_all(&tx_buf[..n]).await.map_err(RunError::Write)?,
129 } 118 }
130 119
131 let status = ppp.status(); 120 let status = ppp.status();
@@ -148,7 +137,7 @@ impl<'d> Runner<'d> {
148 } 137 }
149 Either::Second(pkt) => { 138 Either::Second(pkt) => {
150 match ppp.send(pkt, &mut tx_buf) { 139 match ppp.send(pkt, &mut tx_buf) {
151 Ok(n) => rw.write_all(&tx_buf[..n]).await?, 140 Ok(n) => rw.write_all(&tx_buf[..n]).await.map_err(RunError::Write)?,
152 Err(BufferFullError) => unreachable!(), 141 Err(BufferFullError) => unreachable!(),
153 } 142 }
154 tx_chan.tx_done(); 143 tx_chan.tx_done();