|
195 | 195 | //!
|
196 | 196 | //! /// A synchronized serial interface
|
197 | 197 | //! // NOTE This is a global singleton
|
198 |
| -//! pub struct Serial1(Mutex<..>); |
| 198 | +//! pub struct Serial1; |
199 | 199 | //!
|
200 | 200 | //! // NOTE private
|
201 | 201 | //! static USART1: Mutex<_> = Mutex::new(..);
|
|
204 | 204 | //! type Error = !;
|
205 | 205 | //!
|
206 | 206 | //! fn read(&self) -> Result<u8, nb::Error<Self::Error>> {
|
207 |
| -//! hal::serial::Read::read(&Serial1(USART1.lock())) |
| 207 | +//! hal::serial::Read::read(&Serial(&*USART1.lock())) |
208 | 208 | //! }
|
209 | 209 | //! }
|
210 | 210 | //! ```
|
|
269 | 269 | //! /// `futures` version of `Timer.wait`
|
270 | 270 | //! ///
|
271 | 271 | //! /// This returns a future that must be polled to completion
|
272 |
| -//! fn wait<T>(timer: T) -> impl Future<Item = (), Error = !> |
| 272 | +//! fn wait<T>(timer: T) -> impl Future<Item = T, Error = !> |
273 | 273 | //! where
|
274 | 274 | //! T: hal::Timer,
|
275 | 275 | //! {
|
276 |
| -//! future::poll_fn(move || { |
277 |
| -//! Ok(Async::Ready(try_nb!(timer.wait()))) |
| 276 | +//! future::loop_fn(timer, |timer| { |
| 277 | +//! match timer.wait() { |
| 278 | +//! Ok(()) => Ok(Loop::Break(timer)), |
| 279 | +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(timer)), |
| 280 | +//! } |
278 | 281 | //! })
|
279 | 282 | //! }
|
280 | 283 | //!
|
281 | 284 | //! /// `futures` version of `Serial.read`
|
282 | 285 | //! ///
|
283 | 286 | //! /// This returns a future that must be polled to completion
|
284 |
| -//! fn read<S>(serial: S) -> impl Future<Item = u8, Error = S::Error> |
| 287 | +//! fn read<S>(serial: S) -> impl Future<Item = (S, u8), Error = S::Error> |
285 | 288 | //! where
|
286 | 289 | //! S: hal::serial::Read<u8>,
|
287 | 290 | //! {
|
288 |
| -//! future::poll_fn(move || { |
289 |
| -//! Ok(Async::Ready(try_nb!(serial.read()))) |
| 291 | +//! future::loop_fn(serial, |mut serial| { |
| 292 | +//! match serial.read() { |
| 293 | +//! Ok(byte) => Ok(Loop::Break((serial, byte))), |
| 294 | +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)), |
| 295 | +//! Err(nb::Error::Other(error)) => Err(error), |
| 296 | +//! } |
290 | 297 | //! })
|
291 | 298 | //! }
|
292 | 299 | //!
|
293 | 300 | //! /// `futures` version of `Serial.write`
|
294 | 301 | //! ///
|
295 | 302 | //! /// This returns a future that must be polled to completion
|
296 |
| -//! fn write<S>(serial: S, byte: u8) -> impl Future<Item = (), Error = S::Error> |
| 303 | +//! fn write<S>(serial: S, byte: u8) -> impl Future<Item = S, Error = S::Error> |
297 | 304 | //! where
|
298 | 305 | //! S: hal::serial::Write<u8>,
|
299 | 306 | //! {
|
300 |
| -//! future::poll_fn(move || { |
301 |
| -//! Ok(Async::Ready(try_nb!(serial.write(byte)))) |
| 307 | +//! future::loop_fn(serial, move |mut serial| { |
| 308 | +//! match serial.write(byte) { |
| 309 | +//! Ok(()) => Ok(Loop::Break(serial)), |
| 310 | +//! Err(nb::Error::WouldBlock) => Ok(Loop::Continue(serial)), |
| 311 | +//! Err(nb::Error::Other(error)) => Err(error), |
| 312 | +//! } |
302 | 313 | //! })
|
303 | 314 | //! }
|
304 | 315 | //!
|
|
0 commit comments