diff options
Diffstat (limited to 'embassy-net-esp-hosted/src/lib.rs')
| -rw-r--r-- | embassy-net-esp-hosted/src/lib.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/embassy-net-esp-hosted/src/lib.rs b/embassy-net-esp-hosted/src/lib.rs index d61eaef3a..c78578bf1 100644 --- a/embassy-net-esp-hosted/src/lib.rs +++ b/embassy-net-esp-hosted/src/lib.rs | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![doc = include_str!("../README.md")] | ||
| 3 | #![warn(missing_docs)] | ||
| 2 | 4 | ||
| 3 | use embassy_futures::select::{select4, Either4}; | 5 | use embassy_futures::select::{select4, Either4}; |
| 4 | use embassy_net_driver_channel as ch; | 6 | use embassy_net_driver_channel as ch; |
| @@ -97,12 +99,14 @@ enum InterfaceType { | |||
| 97 | const MAX_SPI_BUFFER_SIZE: usize = 1600; | 99 | const MAX_SPI_BUFFER_SIZE: usize = 1600; |
| 98 | const HEARTBEAT_MAX_GAP: Duration = Duration::from_secs(20); | 100 | const HEARTBEAT_MAX_GAP: Duration = Duration::from_secs(20); |
| 99 | 101 | ||
| 102 | /// State for the esp-hosted driver. | ||
| 100 | pub struct State { | 103 | pub struct State { |
| 101 | shared: Shared, | 104 | shared: Shared, |
| 102 | ch: ch::State<MTU, 4, 4>, | 105 | ch: ch::State<MTU, 4, 4>, |
| 103 | } | 106 | } |
| 104 | 107 | ||
| 105 | impl State { | 108 | impl State { |
| 109 | /// Create a new state. | ||
| 106 | pub fn new() -> Self { | 110 | pub fn new() -> Self { |
| 107 | Self { | 111 | Self { |
| 108 | shared: Shared::new(), | 112 | shared: Shared::new(), |
| @@ -111,8 +115,13 @@ impl State { | |||
| 111 | } | 115 | } |
| 112 | } | 116 | } |
| 113 | 117 | ||
| 118 | /// Type alias for network driver. | ||
| 114 | pub type NetDriver<'a> = ch::Device<'a, MTU>; | 119 | pub type NetDriver<'a> = ch::Device<'a, MTU>; |
| 115 | 120 | ||
| 121 | /// Create a new esp-hosted driver using the provided state, SPI peripheral and pins. | ||
| 122 | /// | ||
| 123 | /// Returns a device handle for interfacing with embassy-net, a control handle for | ||
| 124 | /// interacting with the driver, and a runner for communicating with the WiFi device. | ||
| 116 | pub async fn new<'a, SPI, IN, OUT>( | 125 | pub async fn new<'a, SPI, IN, OUT>( |
| 117 | state: &'a mut State, | 126 | state: &'a mut State, |
| 118 | spi: SPI, | 127 | spi: SPI, |
| @@ -144,6 +153,7 @@ where | |||
| 144 | (device, Control::new(state_ch, &state.shared), runner) | 153 | (device, Control::new(state_ch, &state.shared), runner) |
| 145 | } | 154 | } |
| 146 | 155 | ||
| 156 | /// Runner for communicating with the WiFi device. | ||
| 147 | pub struct Runner<'a, SPI, IN, OUT> { | 157 | pub struct Runner<'a, SPI, IN, OUT> { |
| 148 | ch: ch::Runner<'a, MTU>, | 158 | ch: ch::Runner<'a, MTU>, |
| 149 | state_ch: ch::StateRunner<'a>, | 159 | state_ch: ch::StateRunner<'a>, |
| @@ -166,6 +176,7 @@ where | |||
| 166 | { | 176 | { |
| 167 | async fn init(&mut self) {} | 177 | async fn init(&mut self) {} |
| 168 | 178 | ||
| 179 | /// Run the packet processing. | ||
| 169 | pub async fn run(mut self) -> ! { | 180 | pub async fn run(mut self) -> ! { |
| 170 | debug!("resetting..."); | 181 | debug!("resetting..."); |
| 171 | self.reset.set_low().unwrap(); | 182 | self.reset.set_low().unwrap(); |
