Updated to hal 0.9.0
This commit is contained in:
@@ -22,7 +22,7 @@ mod app {
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use stm32f1xx_hal::prelude::*;
|
||||
|
||||
use blue_pill_ui::board::{self, Board, CountDownTimer, TIM2, TIM3, Event};
|
||||
use blue_pill_ui::board::{self, Board, CounterHz, TIM2, TIM3, Event};
|
||||
|
||||
// Defining this struct makes shared resources available to tasks;
|
||||
// they will be initialized by the values returned from `init` and
|
||||
@@ -46,8 +46,8 @@ mod app {
|
||||
led: board::UserLed,
|
||||
encoder: board::Encoder,
|
||||
display: board::Display,
|
||||
poll_timer: CountDownTimer<TIM2>,
|
||||
blink_timer: CountDownTimer<TIM3>,
|
||||
poll_timer: CounterHz<TIM2>,
|
||||
blink_timer: CounterHz<TIM3>,
|
||||
}
|
||||
|
||||
// This task does startup config; the peripherals are passed in thanks to
|
||||
@@ -59,7 +59,10 @@ mod app {
|
||||
rprintln!("init begin");
|
||||
|
||||
let Board { encoder, display, led, mut poll_timer, mut blink_timer } = Board::init(cx.device);
|
||||
|
||||
poll_timer.start(30.Hz()).unwrap();
|
||||
poll_timer.listen(Event::Update);
|
||||
blink_timer.start(2.Hz()).unwrap();
|
||||
blink_timer.listen(Event::Update);
|
||||
|
||||
let delta = 0;
|
||||
@@ -99,6 +102,10 @@ mod app {
|
||||
// Since `count` is a local, we can have it initialized with a const expr.
|
||||
#[task(local = [count: u16 = 0, encoder], shared = [update])]
|
||||
fn count_update(mut cx: count_update::Context) {
|
||||
// Skip update if the idle thread hasn't consumed it yet
|
||||
if cx.shared.update.lock(|upd| upd.is_some()) {
|
||||
return;
|
||||
}
|
||||
let delta = cx.local.encoder.poll_count_delta();
|
||||
let button_up = cx.local.encoder.poll_button_up();
|
||||
if button_up {
|
||||
@@ -114,15 +121,15 @@ mod app {
|
||||
count_update::spawn().unwrap();
|
||||
|
||||
// Restart the timer and clear the interrupt flag
|
||||
cx.local.poll_timer.start(60.hz());
|
||||
cx.local.poll_timer.clear_update_interrupt_flag();
|
||||
cx.local.poll_timer.start(30.Hz()).unwrap();
|
||||
cx.local.poll_timer.clear_interrupt(Event::Update);
|
||||
}
|
||||
|
||||
// Interrupt task for TIM3, the LED blink timer
|
||||
#[task(binds = TIM3, priority = 1, local = [led, blink_timer])]
|
||||
fn tim3(cx: tim3::Context) {
|
||||
cx.local.led.toggle();
|
||||
cx.local.blink_timer.start(2.hz());
|
||||
cx.local.blink_timer.clear_update_interrupt_flag();
|
||||
cx.local.blink_timer.start(2.Hz()).unwrap();
|
||||
cx.local.blink_timer.clear_interrupt(Event::Update);
|
||||
}
|
||||
}
|
||||
|
@@ -10,7 +10,7 @@ use hal::{
|
||||
};
|
||||
|
||||
// re-export some of the types from the HAL we're not wrapping
|
||||
pub use hal::timer::{Event, CountDownTimer};
|
||||
pub use hal::timer::{Event, CounterHz};
|
||||
pub use stm32::{TIM2, TIM3};
|
||||
|
||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
|
||||
@@ -29,8 +29,8 @@ pub struct Board {
|
||||
pub encoder: Encoder,
|
||||
pub display: Display,
|
||||
pub led: UserLed,
|
||||
pub poll_timer: CountDownTimer<TIM2>,
|
||||
pub blink_timer: CountDownTimer<TIM3>,
|
||||
pub poll_timer: CounterHz<TIM2>,
|
||||
pub blink_timer: CounterHz<TIM3>,
|
||||
}
|
||||
|
||||
impl Board {
|
||||
@@ -44,12 +44,12 @@ impl Board {
|
||||
let rcc = periphs.RCC.constrain();
|
||||
let clocks = rcc
|
||||
.cfgr
|
||||
.use_hse(8.mhz())
|
||||
.sysclk(72.mhz())
|
||||
.hclk(72.mhz())
|
||||
.pclk1(36.mhz())
|
||||
.pclk2(72.mhz())
|
||||
.adcclk(12.mhz())
|
||||
.use_hse(8.MHz())
|
||||
.sysclk(72.MHz())
|
||||
.hclk(72.MHz())
|
||||
.pclk1(36.MHz())
|
||||
.pclk2(72.MHz())
|
||||
.adcclk(12.MHz())
|
||||
.freeze(&mut flash.acr);
|
||||
|
||||
// LED is on pin C13, configure it for output
|
||||
@@ -74,10 +74,9 @@ impl Board {
|
||||
);
|
||||
|
||||
// Use TIM2 for the control polling task
|
||||
let poll_timer = Timer::tim2(periphs.TIM2, &clocks).start_count_down(1.hz());
|
||||
|
||||
let poll_timer = Timer::new(periphs.TIM2, &clocks).counter_hz();
|
||||
// Use TIM3 for the LED blinker task
|
||||
let blink_timer = Timer::tim3(periphs.TIM3, &clocks).start_count_down(2.hz());
|
||||
let blink_timer = Timer::new(periphs.TIM3, &clocks).counter_hz();
|
||||
// I2C for display is on gpiob B10 and B11
|
||||
let scl = gpiob.pb10.into_alternate_open_drain(&mut gpiob.crh);
|
||||
let sda = gpiob.pb11.into_alternate_open_drain(&mut gpiob.crh);
|
||||
@@ -86,7 +85,7 @@ impl Board {
|
||||
periphs.I2C2,
|
||||
(scl, sda),
|
||||
Mode::Fast {
|
||||
frequency: 400_000.hz(),
|
||||
frequency: 400_000.Hz(),
|
||||
duty_cycle: DutyCycle::Ratio2to1,
|
||||
},
|
||||
clocks,
|
||||
@@ -171,7 +170,7 @@ impl Encoder {
|
||||
mapr: &mut hal::afio::MAPR,
|
||||
&clocks: &hal::rcc::Clocks,
|
||||
) -> Self {
|
||||
let qei = Timer::tim4(timer, &clocks)
|
||||
let qei = Timer::new(timer, &clocks)
|
||||
.qei((clk_pin, dt_pin), mapr, QeiOptions::default());
|
||||
let button = button_pin.into_active_low_switch();
|
||||
|
||||
|
Reference in New Issue
Block a user