|
258 | 258 | //! # fn main() {}
|
259 | 259 | //! ```
|
260 | 260 | //!
|
261 |
| -//! - Blocking serial read with timeout |
262 |
| -//! |
263 |
| -//! ``` |
264 |
| -//! use embedded_hal as hal; |
265 |
| -//! use hal::nb; |
266 |
| -//! |
267 |
| -//! use hal::serial::nb::Write; |
268 |
| -//! use hal::timer::nb::CountDown; |
269 |
| -//! |
270 |
| -//! enum Error<SE, TE> { |
271 |
| -//! /// Serial interface error |
272 |
| -//! Serial(SE), |
273 |
| -//! /// Timeout error |
274 |
| -//! TimedOut(TE), |
275 |
| -//! } |
276 |
| -//! |
277 |
| -//! fn read_with_timeout<S, T>( |
278 |
| -//! serial: &mut S, |
279 |
| -//! timer: &mut T, |
280 |
| -//! timeout: T::Time, |
281 |
| -//! ) -> Result<u8, Error<S::Error, T::Error>> |
282 |
| -//! where |
283 |
| -//! T: hal::timer::nb::CountDown<Error = ()>, |
284 |
| -//! S: hal::serial::nb::Read<u8>, |
285 |
| -//! { |
286 |
| -//! timer.start(timeout).map_err(Error::TimedOut)?; |
287 |
| -//! |
288 |
| -//! loop { |
289 |
| -//! match serial.read() { |
290 |
| -//! // raise error |
291 |
| -//! Err(nb::Error::Other(e)) => return Err(Error::Serial(e)), |
292 |
| -//! Err(nb::Error::WouldBlock) => { |
293 |
| -//! // no data available yet, check the timer below |
294 |
| -//! }, |
295 |
| -//! Ok(byte) => return Ok(byte), |
296 |
| -//! } |
297 |
| -//! |
298 |
| -//! match timer.wait() { |
299 |
| -//! Err(nb::Error::Other(e)) => { |
300 |
| -//! // The error type specified by `timer.wait()` is `!`, which |
301 |
| -//! // means no error can actually occur. The Rust compiler |
302 |
| -//! // still forces us to provide this match arm, though. |
303 |
| -//! unreachable!() |
304 |
| -//! }, |
305 |
| -//! // no timeout yet, try again |
306 |
| -//! Err(nb::Error::WouldBlock) => continue, |
307 |
| -//! Ok(()) => return Err(Error::TimedOut(())), |
308 |
| -//! } |
309 |
| -//! } |
310 |
| -//! } |
311 |
| -//! |
312 |
| -//! # fn main() {} |
313 |
| -//! ``` |
314 |
| -//! |
315 | 261 | //! - Buffered serial interface with periodic flushing in interrupt handler
|
316 | 262 | //!
|
317 | 263 | //! ```
|
@@ -411,16 +357,12 @@ pub mod fmt;
|
411 | 357 | pub use nb;
|
412 | 358 | pub mod adc;
|
413 | 359 | pub mod can;
|
414 |
| -pub mod capture; |
415 | 360 | pub mod delay;
|
416 | 361 | pub mod digital;
|
417 | 362 | pub mod i2c;
|
418 |
| -pub mod pwm; |
419 | 363 | pub mod qei;
|
420 | 364 | pub mod serial;
|
421 | 365 | pub mod spi;
|
422 |
| -pub mod timer; |
423 |
| -pub mod watchdog; |
424 | 366 |
|
425 | 367 | mod private {
|
426 | 368 | use crate::i2c::{SevenBitAddress, TenBitAddress};
|
|
0 commit comments