Updated to hal 0.9.0
parent
67d19cfccd
commit
d470c5d2e4
|
@ -1 +1,3 @@
|
||||||
/target
|
/target
|
||||||
|
/cross/target
|
||||||
|
SDL2.dll
|
|
@ -115,12 +115,6 @@ version = "1.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cast"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -228,9 +222,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "embedded-dma"
|
name = "embedded-dma"
|
||||||
version = "0.1.2"
|
version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "46c8c02e4347a0267ca60813c952017f4c5948c232474c6010a381a337f1bda4"
|
checksum = "994f7e5b5cb23521c22304927195f236813053eb9c065dd2226a32ba64695446"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
@ -277,6 +271,34 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fugit"
|
||||||
|
version = "0.3.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f6d8595783d5ca52f0e9830036b3d24f359fae0fcc6bb5fde41f2dd82997cb58"
|
||||||
|
dependencies = [
|
||||||
|
"gcd",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fugit-timer"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d9607bfc4c388f9d629704f56ede4a007546cad417b3bcd6fc7c87dc7edce04a"
|
||||||
|
dependencies = [
|
||||||
|
"fugit",
|
||||||
|
"nb 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gcd"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f37978dab2ca789938a83b2f8bc1ef32db6633af9051a6cd409eff72cbaaa79a"
|
||||||
|
dependencies = [
|
||||||
|
"paste",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hash32"
|
name = "hash32"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
@ -375,6 +397,12 @@ dependencies = [
|
||||||
"rtt-target",
|
"rtt-target",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "paste"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error"
|
name = "proc-macro-error"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
|
@ -572,16 +600,18 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "stm32f1xx-hal"
|
name = "stm32f1xx-hal"
|
||||||
version = "0.8.0"
|
version = "0.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e7c0b74aaa4f324fc561619296ada501d064dcaa176ba4ddeacd03795ad72ed"
|
checksum = "1232c561785bdbc59a5ab2b28c5c9429cb9ee9b04687133e59d1a34a39426943"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
"bxcan",
|
"bxcan",
|
||||||
"cast",
|
|
||||||
"cortex-m",
|
"cortex-m",
|
||||||
"cortex-m-rt",
|
"cortex-m-rt",
|
||||||
"embedded-dma",
|
"embedded-dma",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
|
"fugit",
|
||||||
|
"fugit-timer",
|
||||||
"nb 1.0.0",
|
"nb 1.0.0",
|
||||||
"stm32-usbd",
|
"stm32-usbd",
|
||||||
"stm32f1",
|
"stm32f1",
|
||||||
|
|
|
@ -10,7 +10,7 @@ edition = "2021"
|
||||||
cortex-m-rtic = "1.0.0"
|
cortex-m-rtic = "1.0.0"
|
||||||
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
|
panic-rtt-target = { version = "0.1.2", features = ["cortex-m"] }
|
||||||
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
|
rtt-target = { version = "0.3.1", features = ["cortex-m"] }
|
||||||
stm32f1xx-hal = { version = "0.8.0", features = ["rt", "stm32f103", "medium"] }
|
stm32f1xx-hal = { version = "0.9.0", features = ["rt", "stm32f103", "medium"] }
|
||||||
ssd1306 = "0.7.0"
|
ssd1306 = "0.7.0"
|
||||||
switch-hal = "0.4.0"
|
switch-hal = "0.4.0"
|
||||||
bbqueue = "0.5.1"
|
bbqueue = "0.5.1"
|
||||||
|
|
|
@ -22,7 +22,7 @@ mod app {
|
||||||
use rtt_target::{rprintln, rtt_init_print};
|
use rtt_target::{rprintln, rtt_init_print};
|
||||||
use stm32f1xx_hal::prelude::*;
|
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;
|
// Defining this struct makes shared resources available to tasks;
|
||||||
// they will be initialized by the values returned from `init` and
|
// they will be initialized by the values returned from `init` and
|
||||||
|
@ -46,8 +46,8 @@ mod app {
|
||||||
led: board::UserLed,
|
led: board::UserLed,
|
||||||
encoder: board::Encoder,
|
encoder: board::Encoder,
|
||||||
display: board::Display,
|
display: board::Display,
|
||||||
poll_timer: CountDownTimer<TIM2>,
|
poll_timer: CounterHz<TIM2>,
|
||||||
blink_timer: CountDownTimer<TIM3>,
|
blink_timer: CounterHz<TIM3>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This task does startup config; the peripherals are passed in thanks to
|
// This task does startup config; the peripherals are passed in thanks to
|
||||||
|
@ -59,7 +59,10 @@ mod app {
|
||||||
rprintln!("init begin");
|
rprintln!("init begin");
|
||||||
|
|
||||||
let Board { encoder, display, led, mut poll_timer, mut blink_timer } = Board::init(cx.device);
|
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);
|
poll_timer.listen(Event::Update);
|
||||||
|
blink_timer.start(2.Hz()).unwrap();
|
||||||
blink_timer.listen(Event::Update);
|
blink_timer.listen(Event::Update);
|
||||||
|
|
||||||
let delta = 0;
|
let delta = 0;
|
||||||
|
@ -99,6 +102,10 @@ mod app {
|
||||||
// Since `count` is a local, we can have it initialized with a const expr.
|
// Since `count` is a local, we can have it initialized with a const expr.
|
||||||
#[task(local = [count: u16 = 0, encoder], shared = [update])]
|
#[task(local = [count: u16 = 0, encoder], shared = [update])]
|
||||||
fn count_update(mut cx: count_update::Context) {
|
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 delta = cx.local.encoder.poll_count_delta();
|
||||||
let button_up = cx.local.encoder.poll_button_up();
|
let button_up = cx.local.encoder.poll_button_up();
|
||||||
if button_up {
|
if button_up {
|
||||||
|
@ -114,15 +121,15 @@ mod app {
|
||||||
count_update::spawn().unwrap();
|
count_update::spawn().unwrap();
|
||||||
|
|
||||||
// Restart the timer and clear the interrupt flag
|
// Restart the timer and clear the interrupt flag
|
||||||
cx.local.poll_timer.start(60.hz());
|
cx.local.poll_timer.start(30.Hz()).unwrap();
|
||||||
cx.local.poll_timer.clear_update_interrupt_flag();
|
cx.local.poll_timer.clear_interrupt(Event::Update);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interrupt task for TIM3, the LED blink timer
|
// Interrupt task for TIM3, the LED blink timer
|
||||||
#[task(binds = TIM3, priority = 1, local = [led, blink_timer])]
|
#[task(binds = TIM3, priority = 1, local = [led, blink_timer])]
|
||||||
fn tim3(cx: tim3::Context) {
|
fn tim3(cx: tim3::Context) {
|
||||||
cx.local.led.toggle();
|
cx.local.led.toggle();
|
||||||
cx.local.blink_timer.start(2.hz());
|
cx.local.blink_timer.start(2.Hz()).unwrap();
|
||||||
cx.local.blink_timer.clear_update_interrupt_flag();
|
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
|
// 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};
|
pub use stm32::{TIM2, TIM3};
|
||||||
|
|
||||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306, mode::BufferedGraphicsMode};
|
||||||
|
@ -29,8 +29,8 @@ pub struct Board {
|
||||||
pub encoder: Encoder,
|
pub encoder: Encoder,
|
||||||
pub display: Display,
|
pub display: Display,
|
||||||
pub led: UserLed,
|
pub led: UserLed,
|
||||||
pub poll_timer: CountDownTimer<TIM2>,
|
pub poll_timer: CounterHz<TIM2>,
|
||||||
pub blink_timer: CountDownTimer<TIM3>,
|
pub blink_timer: CounterHz<TIM3>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Board {
|
impl Board {
|
||||||
|
@ -44,12 +44,12 @@ impl Board {
|
||||||
let rcc = periphs.RCC.constrain();
|
let rcc = periphs.RCC.constrain();
|
||||||
let clocks = rcc
|
let clocks = rcc
|
||||||
.cfgr
|
.cfgr
|
||||||
.use_hse(8.mhz())
|
.use_hse(8.MHz())
|
||||||
.sysclk(72.mhz())
|
.sysclk(72.MHz())
|
||||||
.hclk(72.mhz())
|
.hclk(72.MHz())
|
||||||
.pclk1(36.mhz())
|
.pclk1(36.MHz())
|
||||||
.pclk2(72.mhz())
|
.pclk2(72.MHz())
|
||||||
.adcclk(12.mhz())
|
.adcclk(12.MHz())
|
||||||
.freeze(&mut flash.acr);
|
.freeze(&mut flash.acr);
|
||||||
|
|
||||||
// LED is on pin C13, configure it for output
|
// LED is on pin C13, configure it for output
|
||||||
|
@ -74,10 +74,9 @@ impl Board {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Use TIM2 for the control polling task
|
// 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
|
// 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
|
// I2C for display is on gpiob B10 and B11
|
||||||
let scl = gpiob.pb10.into_alternate_open_drain(&mut gpiob.crh);
|
let scl = gpiob.pb10.into_alternate_open_drain(&mut gpiob.crh);
|
||||||
let sda = gpiob.pb11.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,
|
periphs.I2C2,
|
||||||
(scl, sda),
|
(scl, sda),
|
||||||
Mode::Fast {
|
Mode::Fast {
|
||||||
frequency: 400_000.hz(),
|
frequency: 400_000.Hz(),
|
||||||
duty_cycle: DutyCycle::Ratio2to1,
|
duty_cycle: DutyCycle::Ratio2to1,
|
||||||
},
|
},
|
||||||
clocks,
|
clocks,
|
||||||
|
@ -171,7 +170,7 @@ impl Encoder {
|
||||||
mapr: &mut hal::afio::MAPR,
|
mapr: &mut hal::afio::MAPR,
|
||||||
&clocks: &hal::rcc::Clocks,
|
&clocks: &hal::rcc::Clocks,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let qei = Timer::tim4(timer, &clocks)
|
let qei = Timer::new(timer, &clocks)
|
||||||
.qei((clk_pin, dt_pin), mapr, QeiOptions::default());
|
.qei((clk_pin, dt_pin), mapr, QeiOptions::default());
|
||||||
let button = button_pin.into_active_low_switch();
|
let button = button_pin.into_active_low_switch();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue