[][src]Struct dma_gpio::pi::BoardBuilder

pub struct BoardBuilder { /* fields omitted */ }

Struct for initialzing Board and configuring the settings.

BoardBuilder is the only way to initialize Board struct. You can configure different settings for DMA and PWM using this struct.

Examples

Building with default settings

use dma_gpio::pi::BoardBuilder;
 
fn main() {
    let mut board = BoardBuilder::new().build().unwrap();

    ...
     
}
 

This example will enable 9 pins (4, 17, 18, 27, 21, 22, 23, 24, 25) for use.

PWM clock will run at 500MHz/500 = 1 MHz.

Each cycle will be 2000/1MHz = 2000 us.

Sample Delay will be 10/1MHz = 10 us.

This will create 2000/10 = 200 samples, and 200*2 = 400 Control Blocks.

This means that PWM can have 0.005 (0.5 %) increment from 0.00 (0 %) to 1.00 (100 %), with each delay taking 10 us per sample.

Overall GPIO frequency will be 1/2000us = 500 Hz

Building with custom settings

use dma_gpio::pi::BoardBuilder;
 
fn main() {
    let mut board = BoardBuilder::new()
        .divide_pwm(50)
        .set_cycle_time(400)
        .set_sample_delay(2)
        .build_with_pins(vec![21, 22]).unwrap();
     
    ...
     
}
 

This example will enable 2 pins (21, 22) for use.

PWM clock will run at 500MHz/50 = 10 MHz.

Each cycle will be 400/10MHz = 40 us.

Sample Delay will be 2/10MHz = 0.2 us.

This will create 400/2 = 200 samples, and 200*2 = 400 Control Blocks.

This means that PWM can have 0.005 (5 %) increment from 0.00 (0 %) to 1.00 (100 %), with each delay taking 0.2 us per sample.

Theoratical GPIO frequency will be 1/40us = 25 KHz.

However, because the limiting speed of DMA is around ~1.6 MHz,

the actual frequency will be around 8 KHz with PWM (1.6 MHz/200 Samples).

Methods

impl BoardBuilder[src]

pub fn new() -> Self[src]

Creates new instance of BoardBuilder.

pub fn build(&self) -> Result<Board, Error>[src]

Builds and returns Result<Board>.

Example

...
 
fn main() {
    let mut board = BoardBuilder::new().build().unwrap();
     
    ...
     
}

pub fn build_with_pins(self, pins: Vec<u8>) -> Result<Board, Error>[src]

Builds and returns Result<Board> with specific pins.

Be sure to look out for banned pins: [6, 28, 29, 30, 31, 40, 45, 46, 47, 48, 49, 50, 51, 52, 53]

Example

...
 
fn main() {
    let mut board = BoardBuilder::new().build_with_pins(vec![21, 22]).unwrap();
     
    ...
     
}

pub fn use_pcm(self) -> Self[src]

Use pcm instead of pwm for dma scheduling

Example

...
 
fn main() {
    let mut board = BoardBuilder::new().use_pcm().build().unwrap();
     
    ...
     
}

pub fn divide_pwm(self, divisor: usize) -> Self[src]

Set value for PWM DIV.

See this example for more details on how it works.

Example

value of 50 will give 500MHz/50 = 10 MHz frequency of PWM clock.

...
 
fn main() {
    let mut board = BoardBuilder::new().divide_pwm(50).build().unwrap();
     
    ...
     
}

pub fn set_cycle_time(self, units: usize) -> Self[src]

Set cycle time.

See this example for more details on how it works.

Example

...
 
fn main() {
    let mut board = BoardBuilder::new()
        .set_cycle_time(400)
        .set_sample_delay(20)
        .build().unwrap();
     
    ...
     
}

pub fn set_sample_delay(self, units: usize) -> Self[src]

Set sample delay.

See this example for more details on how it works.

Example

...
 
fn main() {
    let mut board = BoardBuilder::new()
        .set_cycle_time(400)
        .set_sample_delay(20)
        .build().unwrap();
     
    ...
     
}

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]