avoid bit-picking

This commit is contained in:
Jörn-Michael Miehe 2024-03-23 15:24:11 +00:00
parent d7c906684c
commit 415e6583a2

View file

@ -13,7 +13,12 @@ extern crate panic_semihosting;
mod app { mod app {
use crate::dmx::DMX; use crate::dmx::DMX;
use cortex_m::singleton; 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; use systick_monotonic::Systick;
const DMX_LEN: usize = 512; const DMX_LEN: usize = 512;
@ -32,6 +37,7 @@ mod app {
struct Local { struct Local {
dmx: DMX<DMX_LEN>, dmx: DMX<DMX_LEN>,
led: gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>, 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>>, int_led: gpio::gpiob::PB0<gpio::Output<gpio::OpenDrain>>,
} }
@ -63,22 +69,12 @@ mod app {
let mut afio = cx.device.AFIO.constrain(); let mut afio = cx.device.AFIO.constrain();
let dma1 = cx.device.DMA1.split(); let dma1 = cx.device.DMA1.split();
let _ = gpiob.pb10.into_pull_up_input(&mut gpiob.crh); // setup EXTI10 for Pin B10
let mut int_pin = gpiob.pb10.into_pull_up_input(&mut gpiob.crh);
// enable EXTI10 for port B int_pin.make_interrupt_source(&mut afio);
afio.exticr3 int_pin.enable_interrupt(&mut cx.device.EXTI);
.exticr3() int_pin.trigger_on_edge(&mut cx.device.EXTI, gpio::Edge::Falling);
.write(|w| unsafe { w.exti10().bits(0b0001) }); unsafe { cx.core.NVIC.set_priority(pac::Interrupt::EXTI15_10, 1) }; // EXTI10 priority
// 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);
}
// Serial config // Serial config
let serial = serial::Serial::new( let serial = serial::Serial::new(
@ -92,8 +88,6 @@ mod app {
&clocks, &clocks,
); );
// rtic::pend(pac::Interrupt::DMA1_CHANNEL4); // ???
// let nvic = cx.device.NVIC_STIR;
foo::spawn().unwrap(); foo::spawn().unwrap();
( (
@ -112,6 +106,7 @@ mod app {
.pc13 .pc13
.into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High), .into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High),
int_pin: int_pin,
int_led: gpiob int_led: gpiob
.pb0 .pb0
.into_open_drain_output_with_state(&mut gpiob.crl, gpio::PinState::Low), .into_open_drain_output_with_state(&mut gpiob.crl, gpio::PinState::Low),
@ -138,17 +133,12 @@ mod app {
foo::spawn().unwrap(); 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) { 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 // clear EXTI10 pending status
if dp.EXTI.pr.read().pr10().bit() { cx.local.int_pin.clear_interrupt_pending_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());
}
} }
} }