Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b28e26b
Fix typo
hannobraun Oct 24, 2020
a61ef34
Add some whitespace
hannobraun Oct 24, 2020
c310b0d
Group structs and their implementation
hannobraun Oct 24, 2020
a15e2a0
Rename `CTimer` to `CTIMER`
hannobraun Oct 24, 2020
b7151d3
Rename struct field
hannobraun Oct 24, 2020
7573aa0
Define PWM output function via channel trait
hannobraun Oct 24, 2020
e879d9b
Add constructor for `DetachedPwmPin`
hannobraun Oct 24, 2020
791294e
Replace `DetachedPwmPin` with new `Channel` struct
hannobraun Oct 24, 2020
27f5c42
Rename type parameter
hannobraun Oct 24, 2020
a12092b
Replace `CTimerPwmPin` with `Channel`
hannobraun Oct 24, 2020
9c901f8
Rename struct field
hannobraun Oct 24, 2020
cfbfd2e
Remove `number` field of `Channel`
hannobraun Oct 24, 2020
e33cf54
Seal `channels::Trait`
hannobraun Oct 24, 2020
6071839
Generate `Channels` struct
hannobraun Oct 24, 2020
d9f8cff
Add type state to `CTIMER`
hannobraun Oct 24, 2020
3912f61
Rename method
hannobraun Oct 24, 2020
7e53668
Move `reg!` invocations to where they are used
hannobraun Oct 24, 2020
15a2833
Make freeing `CTIMER` possible in any state
hannobraun Oct 24, 2020
b553963
Make uses of channel state more compact
hannobraun Oct 24, 2020
9080fd3
Add peripheral state to `Channel`
hannobraun Oct 24, 2020
3b6e455
Add `Channels` field to `CTIMER`
hannobraun Oct 24, 2020
de6c9c4
Add `CTIMER::disable`
hannobraun Oct 24, 2020
b6f61fc
Move `attach` method from `Channel` to `CTIMER`
hannobraun Oct 24, 2020
923fa1f
Rename struct field
hannobraun Oct 24, 2020
973b691
Move `CTIMER` to `ctimer::peripheral`
hannobraun Oct 24, 2020
0b376fc
Move generated CTIMER types to dedicated module
hannobraun Oct 24, 2020
1ef1f29
Rename module
hannobraun Oct 24, 2020
3419597
Re-export `Channel` from `ctimer`, for convenience
hannobraun Oct 24, 2020
8c01187
Refactor
hannobraun Oct 24, 2020
e4763ab
Set CTIMER period in private method
hannobraun Oct 24, 2020
f5b9c80
Implement `embedded_hal::Pwm` for `CTIMER`
hannobraun Oct 24, 2020
4c1f602
Implement embedded-hal alpha traits for CTIMER
hannobraun Oct 24, 2020
a6d9d58
Fix `set_period` sometimes breaking PWM for a bit
hannobraun Oct 26, 2020
5aa1caf
Add example to demonstrate `set_period`
hannobraun Oct 26, 2020
0c6553b
Improve documentation
hannobraun Oct 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ required-features = ["rt-selected"]
name = "usart_dma"
required-features = ["rt-selected", "845"]

[[example]]
name = "ctimer_blink"
required-features = ["rt-selected", "845"]

[[example]]
name = "ctimer_fade"
required-features = ["rt-selected", "845"]
Expand Down
73 changes: 73 additions & 0 deletions examples/ctimer_blink.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#![no_main]
#![no_std]

extern crate panic_rtt_target;

use lpc8xx_hal::{
cortex_m_rt::entry, ctimer::Channels123, delay::Delay, prelude::*,
CorePeripherals, Peripherals,
};

#[entry]
fn main() -> ! {
rtt_target::rtt_init_print!();

// Get access to the device's peripherals. Since only one instance of this
// struct can exist, the call to `take` returns an `Option<Peripherals>`.
// If we tried to call the method a second time, it would return `None`, but
// we're only calling it the one time here, so we can safely `unwrap` the
// `Option` without causing a panic.
let cp = CorePeripherals::take().unwrap();
let p = Peripherals::take().unwrap();

// Initialize the APIs of the peripherals we need.
let swm = p.SWM.split();
let mut delay = Delay::new(cp.SYST);
let mut syscon = p.SYSCON.split();

let mut handle = swm.handle.enable(&mut syscon.handle);

// Select pin for the RGB LED
let green = p.pins.pio1_0.into_swm_pin();
let blue = p.pins.pio1_1.into_swm_pin();
let red = p.pins.pio1_2.into_swm_pin();

// Configure the LED pins. The API tracks the state of pins at compile time,
// to prevent any mistakes.
let (red, _) = swm.movable_functions.t0_mat0.assign(red, &mut handle);
let (green, _) = swm.movable_functions.t0_mat1.assign(green, &mut handle);
let (blue, _) = swm.movable_functions.t0_mat2.assign(blue, &mut handle);

const MAX_PERIOD: u32 = 12_000_000;
const MIN_PERIOD: u32 = MAX_PERIOD / 12;

let periods = (MIN_PERIOD..MAX_PERIOD).step_by(MIN_PERIOD as usize);

let mut ctimer = p
.CTIMER0
.enable(MAX_PERIOD, 0, &mut syscon.handle)
.attach(red)
.attach(green)
.attach(blue);

loop {
for period in periods.clone().rev() {
ctimer.set_period(period);

ctimer.set_duty(Channels123::Channel1, period / 8);
ctimer.set_duty(Channels123::Channel2, period / 4);
ctimer.set_duty(Channels123::Channel3, period / 2);

delay.delay_ms(period / 12_000);
}
for period in periods.clone() {
ctimer.set_period(period);

ctimer.set_duty(Channels123::Channel1, period / 8);
ctimer.set_duty(Channels123::Channel2, period / 4);
ctimer.set_duty(Channels123::Channel3, period / 2);

delay.delay_ms(period / 12_000);
}
}
}
20 changes: 12 additions & 8 deletions examples/ctimer_fade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ fn main() -> ! {

let mut handle = swm.handle.enable(&mut syscon.handle);

// Use 8 bit pwm
let (red_pwm, green_pwm, blue_pwm) =
p.CTIMER0.start_pwm(256, 0, &mut syscon.handle);

// Select pin for the RGB LED
let green = p.pins.pio1_0.into_swm_pin();
let blue = p.pins.pio1_1.into_swm_pin();
Expand All @@ -41,10 +37,18 @@ fn main() -> ! {
let (green, _) = swm.movable_functions.t0_mat1.assign(green, &mut handle);
let (blue, _) = swm.movable_functions.t0_mat2.assign(blue, &mut handle);

let mut red = red_pwm.attach(red);
let mut green = green_pwm.attach(green);
let mut blue = blue_pwm.attach(blue);
// Fade each color after anothe
// Use 8 bit pwm
let ctimer = p
.CTIMER0
.enable(256, 0, &mut syscon.handle)
.attach(red)
.attach(green)
.attach(blue);
let mut red = ctimer.channels.channel1;
let mut green = ctimer.channels.channel2;
let mut blue = ctimer.channels.channel3;

// Fade each color after another
loop {
for i in 0..red.get_max_duty() {
delay.delay_ms(4_u8);
Expand Down
223 changes: 0 additions & 223 deletions src/ctimer.rs

This file was deleted.

Loading