Expand description

Convenience re-export of multiple traits.

This allows a HAL user to conveniently import this module and have all the helper traits already imported. Otherwise the use of peripherals would require the import of the corresponding module and the import of the trait, which connects this HAL to the autogenerated svd2rust API in crate::pac.

Example

Consider the following code.

#[entry]
fn main() -> ! {
    let dp = pac::Peripherals::take().unwrap();
    let gpiog = dp.GPIOG.split();
    let mut led1 = gpiog.pg13.into_push_pull_output();
    led1.set_high().unwrap();
}

Without the prelude we would have to import the following traits:

use stm32f4xx_hal::gpio::GpioExt; // for the split method.
use embedded_hal::digital::v2::OutputPin; // for the set_high() function.
// And more use-statements with more complex code.

These imports are a bit unintuitive, because we can create the objects without the import. But we need these traits to access most of their functions.

The prelude module keeps the import section cleaner:

use stm32f4xx_hal::prelude::*;

Re-exports

pub use crate::can::CanExt as _stm32f4xx_hal_can_CanExt;
pub use crate::dac::DacExt as _stm32f4xx_hal_dac_DacExt;
pub use crate::gpio::GpioExt as _stm32f4xx_hal_gpio_GpioExt;
pub use crate::i2c::I2cExt as _stm32f4xx_hal_i2c_I2cExt;
pub use crate::i2s::I2sExt as _stm32f4xx_hal_i2s_I2sExt;
pub use crate::qei::QeiExt as _stm32f4xx_hal_QeiExt;
pub use crate::rcc::RccExt as _stm32f4xx_hal_rcc_RccExt;
pub use crate::rng::RngExt as _stm32f4xx_hal_rng_RngExt;
pub use crate::serial::SerialExt as _stm32f4xx_hal_serial_SerialExt;
pub use crate::spi::SpiExt as _stm32f4xx_hal_spi_SpiExt;
pub use crate::syscfg::SysCfgExt as _stm32f4xx_hal_syscfg_SysCfgExt;
pub use crate::time::U32Ext as _stm32f4xx_hal_time_U32Ext;
pub use crate::timer::PwmExt as _stm32f4xx_hal_timer_PwmExt;
pub use crate::timer::SysTimerExt as _stm32f4xx_hal_timer_SysCounterExt;
pub use crate::timer::TimerExt as _stm32f4xx_hal_timer_TimerExt;

Traits

Input capture

Pulse Width Modulation

Quadrature encoder interface

ADCs that sample on single channels per request, and do so at the time of the request.

Write half of a serial interface (blocking variant)

Read half of a serial interface

Write half of a serial interface

Full duplex (master mode)

Extension trait for simple short-hands for u32 Durations

Extension trait for simple short-hands for u32 Rate

External Interrupt Pin