File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ //! Convenience re-export of multiple traits.
2
+ //!
3
+ //! This allows a HAL user to conveniently import this module and have all the
4
+ //! helper traits already imported.
5
+ //! Otherwise the use of peripherals would require the import of the
6
+ //! corresponding module and the import of the trait, which connects this HAL
7
+ //! to the autogenerated svd2rust API in [crate::stm32].
8
+ //!
9
+ //! # Example
10
+ //!
11
+ //! Consider the following code.
12
+ //!
13
+ //! ```
14
+ //! #[entry]
15
+ //! fn main() -> ! {
16
+ //! let dp = stm32::Peripherals::take().unwrap();
17
+ //! let gpiog = dp.GPIOG.split();
18
+ //! let mut led1 = gpiog.pg13.into_push_pull_output();
19
+ //! led1.set_high().unwrap();
20
+ //! }
21
+ //! ```
22
+ //!
23
+ //! Without the prelude we would have to import the following traits:
24
+ //!
25
+ //! ```
26
+ //! use stm32f4xx_hal::gpio::GpioExt; // for the split method.
27
+ //! use embedded_hal::digital::v2::OutputPin; // for the set_high() function.
28
+ //! // And more use-statements with more complex code.
29
+ //! ```
30
+ //!
31
+ //! These imports are a bit unintuitive, because we can create the objects
32
+ //! without the import. But we need these traits to access most of their
33
+ //! functions.
34
+ //!
35
+ //! The prelude module keeps the import section cleaner:
36
+ //! ```
37
+ //! use stm32f4xx_hal::prelude::*;
38
+ //! ```
1
39
pub use embedded_hal:: digital:: v2:: InputPin as _embedded_hal_digital_v2_InputPin;
2
40
pub use embedded_hal:: digital:: v2:: OutputPin as _embedded_hal_digital_v2_OutputPin;
3
41
pub use embedded_hal:: digital:: v2:: StatefulOutputPin as _embedded_hal_digital_v2_StatefulOutputPin;
You can’t perform that action at this time.
0 commit comments