avoid bit-picking
This commit is contained in:
parent
d7c906684c
commit
415e6583a2
1 changed files with 19 additions and 29 deletions
|
@ -13,7 +13,12 @@ extern crate panic_semihosting;
|
|||
mod app {
|
||||
use crate::dmx::DMX;
|
||||
use cortex_m::singleton;
|
||||
use stm32f1xx_hal::{gpio, pac, prelude::*, serial, timer};
|
||||
use stm32f1xx_hal::{
|
||||
gpio::{self, ExtiPin},
|
||||
pac,
|
||||
prelude::*,
|
||||
serial, timer,
|
||||
};
|
||||
use systick_monotonic::Systick;
|
||||
|
||||
const DMX_LEN: usize = 512;
|
||||
|
@ -32,6 +37,7 @@ mod app {
|
|||
struct Local {
|
||||
dmx: DMX<DMX_LEN>,
|
||||
led: gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>,
|
||||
int_pin: gpio::gpiob::PB10<gpio::Input<gpio::PullUp>>,
|
||||
int_led: gpio::gpiob::PB0<gpio::Output<gpio::OpenDrain>>,
|
||||
}
|
||||
|
||||
|
@ -63,22 +69,12 @@ mod app {
|
|||
let mut afio = cx.device.AFIO.constrain();
|
||||
let dma1 = cx.device.DMA1.split();
|
||||
|
||||
let _ = gpiob.pb10.into_pull_up_input(&mut gpiob.crh);
|
||||
|
||||
// enable EXTI10 for port B
|
||||
afio.exticr3
|
||||
.exticr3()
|
||||
.write(|w| unsafe { w.exti10().bits(0b0001) });
|
||||
// mask EXTI10
|
||||
cx.device.EXTI.imr.write(|w| w.mr10().set_bit());
|
||||
// EXTI10 on falling edge
|
||||
cx.device.EXTI.ftsr.write(|w| w.tr10().set_bit());
|
||||
|
||||
// set EXTI10 priority
|
||||
unsafe {
|
||||
// pac::NVIC::unmask(pac::Interrupt::EXTI15_10);
|
||||
cx.core.NVIC.set_priority(pac::Interrupt::EXTI15_10, 1);
|
||||
}
|
||||
// setup EXTI10 for Pin B10
|
||||
let mut int_pin = gpiob.pb10.into_pull_up_input(&mut gpiob.crh);
|
||||
int_pin.make_interrupt_source(&mut afio);
|
||||
int_pin.enable_interrupt(&mut cx.device.EXTI);
|
||||
int_pin.trigger_on_edge(&mut cx.device.EXTI, gpio::Edge::Falling);
|
||||
unsafe { cx.core.NVIC.set_priority(pac::Interrupt::EXTI15_10, 1) }; // EXTI10 priority
|
||||
|
||||
// Serial config
|
||||
let serial = serial::Serial::new(
|
||||
|
@ -92,8 +88,6 @@ mod app {
|
|||
&clocks,
|
||||
);
|
||||
|
||||
// rtic::pend(pac::Interrupt::DMA1_CHANNEL4); // ???
|
||||
// let nvic = cx.device.NVIC_STIR;
|
||||
foo::spawn().unwrap();
|
||||
|
||||
(
|
||||
|
@ -112,6 +106,7 @@ mod app {
|
|||
.pc13
|
||||
.into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High),
|
||||
|
||||
int_pin: int_pin,
|
||||
int_led: gpiob
|
||||
.pb0
|
||||
.into_open_drain_output_with_state(&mut gpiob.crl, gpio::PinState::Low),
|
||||
|
@ -138,17 +133,12 @@ mod app {
|
|||
foo::spawn().unwrap();
|
||||
}
|
||||
|
||||
#[task(binds=EXTI15_10, local = [int_led], shared = [delay_us])]
|
||||
#[task(binds = EXTI15_10, local = [int_pin, int_led], shared = [delay_us])]
|
||||
fn bar(mut cx: bar::Context) {
|
||||
let dp = unsafe { pac::Peripherals::steal() };
|
||||
cx.local.int_led.toggle();
|
||||
cx.shared.delay_us.lock(|d| d.delay(100.millis()));
|
||||
|
||||
// EXTI10 must be pending
|
||||
if dp.EXTI.pr.read().pr10().bit() {
|
||||
cx.local.int_led.toggle();
|
||||
cx.shared.delay_us.lock(|d| d.delay(100.millis()));
|
||||
|
||||
// clear EXTI10 pending status
|
||||
dp.EXTI.pr.write(|w| w.pr10().set_bit());
|
||||
}
|
||||
// clear EXTI10 pending status
|
||||
cx.local.int_pin.clear_interrupt_pending_bit()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue