@@ -312,15 +312,51 @@ WARNING: use --release
312312 peripherals and/or devices.
313313" }
314314
315- /// A marker trait for initializing drivers in a specific mode.
315+ /// A marker trait for driver modes.
316+ ///
317+ /// Different driver modes offer different features and different API. Using
318+ /// this trait as a generic parameter ensures that the driver is initialized in
319+ /// the correct mode.
316320pub trait DriverMode : crate :: private:: Sealed { }
317321
318- /// Driver initialized in blocking mode.
322+ /// Marker type signalling that a driver is initialized in blocking mode.
323+ ///
324+ /// Drivers are constructed in blocking mode by default. To learn about the
325+ /// differences between blocking and async drivers, see the [`Async`] mode
326+ /// documentation.
319327#[ derive( Debug ) ]
328+ #[ non_exhaustive]
320329pub struct Blocking ;
321330
322- /// Driver initialized in async mode.
331+ /// Marker type signalling that a driver is initialized in async mode.
332+ ///
333+ /// Drivers are constructed in blocking mode by default. To set up an async
334+ /// driver, a [`Blocking`] driver must be converted to an `Async` driver using
335+ /// the `into_async` method. Drivers can be converted back to blocking mode
336+ /// using the `into_blocking` method.
337+ ///
338+ /// Async mode drivers offer most of the same features as blocking drivers, but
339+ /// with the addition of async APIs. Interrupt-related functions are not
340+ /// available in async mode, as they are handled by the driver's interrupt
341+ /// handlers.
342+ ///
343+ /// Note that async functions usually take up more space than their blocking
344+ /// counterparts, and they are generally slower. This is because async functions
345+ /// are implemented using a state machine that is driven by interrupts and is
346+ /// polled by a runtime. For short operations, the overhead of the state machine
347+ /// can be significant. Consider using the blocking functions on the async
348+ /// driver for small transfers.
349+ ///
350+ /// When initializing an async driver, the driver disables user-specified
351+ /// interrupt handlers, and sets up internal interrupt handlers that drive the
352+ /// driver's async API. The driver's interrupt handlers run on the same core as
353+ /// the driver was initialized on. This means that the driver can not be sent
354+ /// across threads, to prevent incorrect concurrent access to the peripheral.
355+ ///
356+ /// Switching back to blocking mode will disable the interrupt handlers and
357+ /// return the driver to a state where it can be sent across threads.
323358#[ derive( Debug ) ]
359+ #[ non_exhaustive]
324360pub struct Async ( PhantomData < * const ( ) > ) ;
325361
326362unsafe impl Sync for Async { }
0 commit comments