From 506c946e839ff7d167e8a0788e4c5b5c29a3f6b3 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio <jorge@japaric.io> Date: Mon, 2 Oct 2017 15:12:42 +0200 Subject: [PATCH] LED should be a `const` not a type alias --- examples/blinky-blocking.rs | 6 +++--- examples/blinky-rtc.rs | 6 +++--- examples/blinky.rs | 6 +++--- examples/capture1.rs | 3 +-- examples/capture2.rs | 3 +-- examples/capture4.rs | 3 +-- examples/concurrent.rs | 6 +++--- examples/led.rs | 4 ++-- examples/preemption.rs | 6 +++--- examples/pwm-control.rs | 5 +---- examples/pwm1.rs | 3 +-- examples/pwm2.rs | 3 +-- examples/pwm4.rs | 3 +-- examples/sharing.rs | 6 +++--- examples/wait1.rs | 6 +++--- examples/wait2.rs | 6 +++--- examples/wait3.rs | 6 +++--- examples/wait4.rs | 6 +++--- src/led.rs | 2 +- 19 files changed, 40 insertions(+), 49 deletions(-) diff --git a/examples/blinky-blocking.rs b/examples/blinky-blocking.rs index 8c529f9..adf9d1f 100644 --- a/examples/blinky-blocking.rs +++ b/examples/blinky-blocking.rs @@ -14,7 +14,7 @@ extern crate cortex_m_rtfm as rtfm; extern crate nb; use blue_pill::Timer; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use rtfm::{app, Threshold}; @@ -48,9 +48,9 @@ fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { state = !state; if state { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } } diff --git a/examples/blinky-rtc.rs b/examples/blinky-rtc.rs index 6583a5b..10940fb 100644 --- a/examples/blinky-rtc.rs +++ b/examples/blinky-rtc.rs @@ -9,7 +9,7 @@ extern crate cortex_m_rtfm as rtfm; use blue_pill::Rtc; use blue_pill::rtc::{RtcClkSource, RtcEvent}; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::stm32f103xx::Interrupt; use rtfm::{app, Threshold}; @@ -54,8 +54,8 @@ fn toggle(_t: &mut Threshold, r: RTC::Resources) { **r.ON = !**r.ON; if **r.ON { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } diff --git a/examples/blinky.rs b/examples/blinky.rs index 31122c5..107d2c8 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -8,7 +8,7 @@ extern crate blue_pill; extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use cortex_m::peripheral::SystClkSource; use rtfm::{app, Threshold}; @@ -48,8 +48,8 @@ fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) { **r.ON = !**r.ON; if **r.ON { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } diff --git a/examples/capture1.rs b/examples/capture1.rs index a413904..9cd5fc5 100644 --- a/examples/capture1.rs +++ b/examples/capture1.rs @@ -33,8 +33,7 @@ fn init(p: init::Peripherals) { } fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; let capture = Capture(&*r.TIM1); diff --git a/examples/capture2.rs b/examples/capture2.rs index bb08c50..42922e9 100644 --- a/examples/capture2.rs +++ b/examples/capture2.rs @@ -33,8 +33,7 @@ fn init(p: init::Peripherals) { } fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; let capture = Capture(&*r.TIM2); diff --git a/examples/capture4.rs b/examples/capture4.rs index 2073106..d123f43 100644 --- a/examples/capture4.rs +++ b/examples/capture4.rs @@ -32,8 +32,7 @@ fn init(p: init::Peripherals) { } fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; let capture = Capture(&*r.TIM4); diff --git a/examples/concurrent.rs b/examples/concurrent.rs index d0ea6f1..009a959 100644 --- a/examples/concurrent.rs +++ b/examples/concurrent.rs @@ -9,7 +9,7 @@ extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; use blue_pill::Serial; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::serial::Event; use blue_pill::time::Hertz; @@ -69,8 +69,8 @@ fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) { **r.ON = !**r.ON; if **r.ON { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } diff --git a/examples/led.rs b/examples/led.rs index a8473b7..e89b13b 100644 --- a/examples/led.rs +++ b/examples/led.rs @@ -8,7 +8,7 @@ extern crate blue_pill; extern crate cortex_m_rtfm as rtfm; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use rtfm::app; app! { @@ -20,7 +20,7 @@ fn init(p: init::Peripherals) { } fn idle() -> ! { - PC13.on(); + LED.on(); // Sleep loop { diff --git a/examples/preemption.rs b/examples/preemption.rs index 69bac66..99b968e 100644 --- a/examples/preemption.rs +++ b/examples/preemption.rs @@ -9,7 +9,7 @@ extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; use blue_pill::Serial; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::serial::Event; use blue_pill::time::Hertz; @@ -79,8 +79,8 @@ fn toggle(t: &mut Threshold, mut r: SYS_TICK::Resources) { **r.ON = !**r.ON; if **r.ON { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } diff --git a/examples/pwm-control.rs b/examples/pwm-control.rs index a72977f..20d3b86 100644 --- a/examples/pwm-control.rs +++ b/examples/pwm-control.rs @@ -66,10 +66,7 @@ fn rx(_t: &mut Threshold, r: USART1::Resources) { match byte { b'+' => { let max = pwm.get_max_duty(); - pwm.set_duty( - Channel::_1, - if duty < max { duty + 1 } else { max }, - ); + pwm.set_duty(Channel::_1, if duty < max { duty + 1 } else { max }); } b'-' => { pwm.set_duty(Channel::_1, duty.checked_sub(1).unwrap_or(0)); diff --git a/examples/pwm1.rs b/examples/pwm1.rs index 60d520c..a95b114 100644 --- a/examples/pwm1.rs +++ b/examples/pwm1.rs @@ -26,8 +26,7 @@ fn init(p: init::Peripherals) { pwm.init(FREQUENCY.invert(), p.AFIO, p.GPIOA, p.RCC); let duty = pwm.get_max_duty() / 16; - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; for c in &CHANNELS { pwm.set_duty(*c, duty); diff --git a/examples/pwm2.rs b/examples/pwm2.rs index 5b6773f..f727b55 100644 --- a/examples/pwm2.rs +++ b/examples/pwm2.rs @@ -25,8 +25,7 @@ fn init(p: init::Peripherals) { pwm.init(FREQUENCY.invert(), p.AFIO, None, p.GPIOA, p.RCC); let duty = pwm.get_max_duty() / 16; - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; for c in &CHANNELS { pwm.set_duty(*c, duty); diff --git a/examples/pwm4.rs b/examples/pwm4.rs index c5d6b7f..db0210b 100644 --- a/examples/pwm4.rs +++ b/examples/pwm4.rs @@ -25,8 +25,7 @@ fn init(p: init::Peripherals) { pwm.init(FREQUENCY.invert(), p.AFIO, None, p.GPIOB, p.RCC); let duty = pwm.get_max_duty() / 16; - const CHANNELS: [Channel; 4] = - [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; + const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; for c in &CHANNELS { pwm.set_duty(*c, duty); diff --git a/examples/sharing.rs b/examples/sharing.rs index dcf0934..b8439c1 100644 --- a/examples/sharing.rs +++ b/examples/sharing.rs @@ -9,7 +9,7 @@ extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; use blue_pill::Serial; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::serial::Event; use blue_pill::time::Hertz; @@ -74,8 +74,8 @@ fn toggle(_t: &mut Threshold, r: SYS_TICK::Resources) { **r.ON = !**r.ON; if **r.ON { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } diff --git a/examples/wait1.rs b/examples/wait1.rs index 0675e3b..4c2faff 100644 --- a/examples/wait1.rs +++ b/examples/wait1.rs @@ -9,7 +9,7 @@ extern crate blue_pill; extern crate cortex_m_rtfm as rtfm; use blue_pill::Timer; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use rtfm::{app, Threshold}; @@ -43,9 +43,9 @@ fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { state = !state; if state { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } } diff --git a/examples/wait2.rs b/examples/wait2.rs index 8cfe53a..8f25e5a 100644 --- a/examples/wait2.rs +++ b/examples/wait2.rs @@ -9,7 +9,7 @@ extern crate blue_pill; extern crate cortex_m_rtfm as rtfm; use blue_pill::Timer; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use rtfm::{app, Threshold}; @@ -42,9 +42,9 @@ fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { state = !state; if state { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } } diff --git a/examples/wait3.rs b/examples/wait3.rs index ae367f4..1c650cf 100644 --- a/examples/wait3.rs +++ b/examples/wait3.rs @@ -9,7 +9,7 @@ extern crate blue_pill; extern crate cortex_m_rtfm as rtfm; use blue_pill::Timer; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use rtfm::{app, Threshold}; @@ -43,9 +43,9 @@ fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { state = !state; if state { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } } diff --git a/examples/wait4.rs b/examples/wait4.rs index 94284bb..be5c7ce 100644 --- a/examples/wait4.rs +++ b/examples/wait4.rs @@ -9,7 +9,7 @@ extern crate blue_pill; extern crate cortex_m_rtfm as rtfm; use blue_pill::Timer; -use blue_pill::led::{self, PC13}; +use blue_pill::led::{self, LED}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use rtfm::{app, Threshold}; @@ -43,9 +43,9 @@ fn idle(_t: &mut Threshold, r: idle::Resources) -> ! { state = !state; if state { - PC13.on(); + LED.on(); } else { - PC13.off(); + LED.off(); } } } diff --git a/src/led.rs b/src/led.rs index 5aa0de4..e9b24f2 100644 --- a/src/led.rs +++ b/src/led.rs @@ -5,7 +5,7 @@ use stm32f103xx::{GPIOC, RCC}; /// LED connected to pin PC13 -pub type LED = PC13; +pub const LED: PC13 = PC13; /// Pin PC13. There's an LED connected to this pin pub struct PC13; -- GitLab