diff --git a/examples/blinky-blocking.rs b/examples/blinky-blocking.rs index 8f581601935538d8254b286c76dbd2d137097b7b..d0045e6a207b4b7e5d4590059a18aaa5ed9cb4d4 100644 --- a/examples/blinky-blocking.rs +++ b/examples/blinky-blocking.rs @@ -3,63 +3,42 @@ #![allow(unreachable_code)] // for the `block!` macro #![deny(unsafe_code)] #![deny(warnings)] -#![feature(const_fn)] -#![feature(used)] +#![feature(proc_macro)] #![no_std] extern crate blue_pill; -extern crate embedded_hal as hal; - -// version = "0.2.3" -extern crate cortex_m_rt; - -// version = "0.1.0" -#[macro_use] extern crate cortex_m_rtfm as rtfm; -#[macro_use] +#[macro_use(block)] extern crate nb; +use blue_pill::Timer; use blue_pill::led::{self, Green}; +use blue_pill::prelude::*; use blue_pill::time::Hertz; -use blue_pill::{Timer, stm32f103xx}; -use hal::prelude::*; -use rtfm::{P0, T0, TMax}; +use rtfm::app; -// CONFIGURATION const FREQUENCY: Hertz = Hertz(1); -// RESOURCES -peripherals!(stm32f103xx, { - GPIOC: Peripheral { - ceiling: C0, - }, - RCC: Peripheral { - ceiling: C0, - }, - TIM3: Peripheral { - ceiling: C0, - }, -}); +app! { + device: blue_pill::stm32f103xx, -// INITIALIZATION PHASE -fn init(ref prio: P0, thr: &TMax) { - let gpioc = &GPIOC.access(prio, thr); - let rcc = &RCC.access(prio, thr); - let tim3 = TIM3.access(prio, thr); + idle: { + resources: [TIM3], + } +} - let timer = Timer(&*tim3); +fn init(p: init::Peripherals) { + led::init(p.GPIOC, p.RCC); - led::init(gpioc, rcc); - timer.init(FREQUENCY.invert(), rcc); -} + let timer = Timer(&*p.TIM3); -// IDLE LOOP -fn idle(ref prio: P0, ref thr: T0) -> ! { - let tim3 = TIM3.access(prio, thr); + timer.init(FREQUENCY.invert(), p.RCC); +} - let timer = Timer(&*tim3); +fn idle(r: idle::Resources) -> ! { + let timer = Timer(&*r.TIM3); timer.resume(); let mut state = false; @@ -75,6 +54,3 @@ fn idle(ref prio: P0, ref thr: T0) -> ! { } } } - -// TASKS -tasks!(stm32f103xx, {}); diff --git a/examples/capture1.rs b/examples/capture1.rs index 00ec6e7ddb29d0c5ba8f2ae089599df219d7505f..f07ee8a92c6990d40bc6ebe53eee2daf5a106bc5 100644 --- a/examples/capture1.rs +++ b/examples/capture1.rs @@ -37,7 +37,7 @@ fn idle(r: idle::Resources) -> ! { const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; - let capture = Capture(&**r.TIM1); + let capture = Capture(&*r.TIM1); for c in &CHANNELS { capture.enable(*c); diff --git a/examples/capture2.rs b/examples/capture2.rs index f3936e5b89189df7643f338c897676e0cedab407..70b89ef0f1b0cf9a1cfac67102a98bb670ca6699 100644 --- a/examples/capture2.rs +++ b/examples/capture2.rs @@ -37,7 +37,7 @@ fn idle(r: idle::Resources) -> ! { const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; - let capture = Capture(&**r.TIM2); + let capture = Capture(&*r.TIM2); for c in &CHANNELS { capture.enable(*c); diff --git a/examples/capture3.rs b/examples/capture3.rs index 835d0af302fe8e8563de5d7f49661c47b17daf4a..f3bc006cc83c04ce7385616639bbf15711e5de0d 100644 --- a/examples/capture3.rs +++ b/examples/capture3.rs @@ -36,7 +36,7 @@ fn init(p: init::Peripherals) { fn idle(r: idle::Resources) -> ! { const CHANNELS: [Channel; 2] = [Channel::_1, Channel::_2]; - let capture = Capture(&**r.TIM3); + let capture = Capture(&*r.TIM3); for c in &CHANNELS { capture.enable(*c); diff --git a/examples/capture4.rs b/examples/capture4.rs index b156b6cb49caa84a331ddc520fb2f0341a401c25..3ea4494c3ee043dfb7e65c26785f3b13c1040573 100644 --- a/examples/capture4.rs +++ b/examples/capture4.rs @@ -37,7 +37,7 @@ fn idle(r: idle::Resources) -> ! { const CHANNELS: [Channel; 4] = [Channel::_1, Channel::_2, Channel::_3, Channel::_4]; - let capture = Capture(&**r.TIM4); + let capture = Capture(&*r.TIM4); for c in &CHANNELS { capture.enable(*c); diff --git a/examples/hello-world.rs b/examples/hello-world.rs new file mode 100644 index 0000000000000000000000000000000000000000..e053bdb796d156a1a77e06619414bdd99b9f0725 --- /dev/null +++ b/examples/hello-world.rs @@ -0,0 +1,44 @@ +//! Prints "Hello" and then "World" in the OpenOCD console + +#![deny(unsafe_code)] +#![deny(warnings)] +#![feature(const_fn)] +#![feature(proc_macro)] +#![no_std] + +extern crate blue_pill; +extern crate cortex_m_rtfm as rtfm; +extern crate cortex_m_semihosting as semihosting; + +use core::fmt::Write; + +use rtfm::app; +use semihosting::hio::{self, HStdout}; + +app! { + device: blue_pill::stm32f103xx, + + resources: { + static HSTDOUT: Option<HStdout> = None; + }, + + idle: { + resources: [HSTDOUT], + }, +} + +fn init(_p: init::Peripherals, r: init::Resources) { + let mut hstdout = hio::hstdout().unwrap(); + + writeln!(hstdout, "Hello").unwrap(); + + **r.HSTDOUT = Some(hstdout); +} + +fn idle(r: idle::Resources) -> ! { + writeln!(r.HSTDOUT.as_mut().unwrap(), "World").unwrap(); + + loop { + rtfm::wfi(); + } +} diff --git a/examples/hello.rs b/examples/hello.rs index f2c0938c400f26d6f29d91fba7fd5c2d67c91e90..63833fc7e524eeebb6e67eee84ca362277e14fc8 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -1,49 +1,28 @@ -//! Prints "Hello" and then "World" on the OpenOCD console +//! Prints "Hello, World" in the OpenOCD console #![deny(unsafe_code)] #![deny(warnings)] -#![feature(const_fn)] #![feature(proc_macro)] #![no_std] extern crate blue_pill; -extern crate cortex_m; extern crate cortex_m_rtfm as rtfm; -extern crate cortex_m_semihosting; +extern crate cortex_m_semihosting as semihosting; use core::fmt::Write; -use cortex_m_semihosting::hio::{self, HStdout}; use rtfm::app; +use semihosting::hio; app! { device: blue_pill::stm32f103xx, - - resources: { - static HSTDOUT: Option<HStdout> = None; - }, - - idle: { - resources: [HSTDOUT], - }, } -// INITIALIZATION PHASE -fn init(_p: init::Peripherals, r: init::Resources) { - let mut hstdout = hio::hstdout().unwrap(); - - writeln!(hstdout, "Hello").unwrap(); +fn init(_p: init::Peripherals) {} - **r.HSTDOUT = Some(hstdout); -} - -// IDLE LOOP -fn idle(r: idle::Resources) -> ! { - if let Some(mut hstdout) = r.HSTDOUT.take() { - writeln!(hstdout, "World").unwrap(); - } +fn idle() -> ! { + writeln!(hio::hstdout().unwrap(), "Hello, world!").unwrap(); - // Sleep loop { rtfm::wfi(); } diff --git a/examples/spi1.rs b/examples/spi1.rs index 0b8b2c6da29ccaa0325689898f9b16b3c836cd24..cbcd2318aa659b81e5a8b4f97c35060f5b7d977c 100644 --- a/examples/spi1.rs +++ b/examples/spi1.rs @@ -41,7 +41,7 @@ fn idle(r: idle::Resources) -> ! { // Read mode pub const R: u8 = 1 << 7; - let spi = Spi(&**r.SPI1); + let spi = Spi(&*r.SPI1); rtfm::bkpt(); diff --git a/examples/spi2.rs b/examples/spi2.rs index 2f352f0337c5dcd6a0420782c18e8be359ea1817..7436e244abc788faf4c428eb60c7c4ff04933c1d 100644 --- a/examples/spi2.rs +++ b/examples/spi2.rs @@ -41,7 +41,7 @@ fn idle(r: idle::Resources) -> ! { // Read mode pub const R: u8 = 1 << 7; - let spi = Spi(&**r.SPI2); + let spi = Spi(&*r.SPI2); rtfm::bkpt(); diff --git a/examples/wait1.rs b/examples/wait1.rs index 4b3a8118e97f33b09512b7fb0b964b7ab2d84ff4..bfe353cafdaf4c01bddc4c80a35867d18771c05c 100644 --- a/examples/wait1.rs +++ b/examples/wait1.rs @@ -34,7 +34,7 @@ fn init(p: init::Peripherals) { } fn idle(r: idle::Resources) -> ! { - let timer = Timer(&**r.TIM1); + let timer = Timer(&*r.TIM1); let mut state = false; loop { diff --git a/examples/wait2.rs b/examples/wait2.rs index 61e0403d54e9f565c2fabca8004efd28d929d673..daad69e34212ef0f281868e9f89762257df40148 100644 --- a/examples/wait2.rs +++ b/examples/wait2.rs @@ -33,7 +33,7 @@ fn init(p: init::Peripherals) { } fn idle(r: idle::Resources) -> ! { - let timer = Timer(&**r.TIM2); + let timer = Timer(&*r.TIM2); let mut state = false; loop { diff --git a/examples/wait3.rs b/examples/wait3.rs index 8b058617230265b17e36a6daf63f2d5b874131be..6023c5de8ddf85485be382e8bc373c9a7f55e255 100644 --- a/examples/wait3.rs +++ b/examples/wait3.rs @@ -34,7 +34,7 @@ fn init(p: init::Peripherals) { } fn idle(r: idle::Resources) -> ! { - let timer = Timer(&**r.TIM3); + let timer = Timer(&*r.TIM3); let mut state = false; loop { diff --git a/examples/wait4.rs b/examples/wait4.rs index cc6b2dfcda47f8452e1f76806be7e0a177c9b92d..fe14a34de746e301a565342cd108b54aa26ccd29 100644 --- a/examples/wait4.rs +++ b/examples/wait4.rs @@ -34,7 +34,7 @@ fn init(p: init::Peripherals) { } fn idle(r: idle::Resources) -> ! { - let timer = Timer(&**r.TIM4); + let timer = Timer(&*r.TIM4); let mut state = false; loop { diff --git a/examples/ws2812.rs b/examples/ws2812.rs index 59dc20bb7249a49a09630018ce4eb051d3485be8..5f61faa7b1cdf5b1a77241bb1da8c8d22d504fcd 100644 --- a/examples/ws2812.rs +++ b/examples/ws2812.rs @@ -17,7 +17,7 @@ use blue_pill::dma::{Buffer, Dma1Channel2}; use blue_pill::prelude::*; use blue_pill::time::Hertz; use blue_pill::{Channel, Pwm}; -use rtfm::app; +use rtfm::{app, Static}; // CONFIGURATION const FREQUENCY: Hertz = Hertz(200_000); @@ -52,11 +52,12 @@ fn init(p: init::Peripherals, r: init::Resources) { } fn idle(r: idle::Resources) -> ! { - let pwm = Pwm(&**r.TIM2); + let pwm = Pwm(&*r.TIM2); + let buffer = Static::wrap_mut(r.BUFFER); - pwm.set_duties(r.DMA1, Channel::_1, r.BUFFER).unwrap(); + pwm.set_duties(r.DMA1, Channel::_1, buffer).unwrap(); - block!(r.BUFFER.release(r.DMA1)).unwrap(); + block!(buffer.release(r.DMA1)).unwrap(); rtfm::bkpt(); diff --git a/src/lib.rs b/src/lib.rs index 83a783225ce7cb3a66b30d6f6244bd807927cd0f..3e15a7fef9c0f95ea5e1054affc29843c3295abb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,6 @@ #![no_std] extern crate cast; -extern crate either; extern crate embedded_hal as hal; extern crate nb; extern crate static_ref;