-
Notifications
You must be signed in to change notification settings - Fork 21
Simplify Button interrupt logic. #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,10 @@ pub enum TriggerMode { | |
/// | ||
/// ``` | ||
/// let device_periphs = pac::Peripherals::take().unwrap(); | ||
/// button::interrupt::enable(&device_periphs.EXTI, &device_periphs.SYSCFG, TriggerMode::Rising); | ||
/// let mut reset_and_clock_control = device_periphs.RCC.constrain(); | ||
/// let syscfg = device_periphs.SYSCFG.constrain(&mut reset_and_clock_control.apb2) | ||
/// | ||
/// button::interrupt::enable(&device_periphs.EXTI, &syscfg, TriggerMode::Rising); | ||
/// ``` | ||
pub fn enable(external_interrupts: &EXTI, sysconfig: &SYSCFG, mode: TriggerMode) { | ||
// See chapter 14 of the reference manual | ||
|
@@ -59,20 +62,19 @@ pub fn enable(external_interrupts: &EXTI, sysconfig: &SYSCFG, mode: TriggerMode) | |
} | ||
|
||
fn configure_exti0(interrupt_mask: &IMR1) { | ||
interrupt_mask.modify(|_, w| w.mr0().set_bit()) | ||
interrupt_mask.modify(|_, w| w.mr0().unmasked()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking out loud: are There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They’re not a Rust pattern. I was just naming things so I could understand the code without looking at the controller’s datasheet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’ll be honest, I’ll need to look up the difference between |
||
} | ||
|
||
fn map_exti0_to_pa0(external_interrupt_config: &EXTICR1) { | ||
const PORT_A_CONFIG: u8 = 0x000; | ||
external_interrupt_config.modify(|_, w| unsafe { w.exti0().bits(PORT_A_CONFIG) }); | ||
external_interrupt_config.modify(|_, w| w.exti0().pa0()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh. I wonder when the HAL added this. |
||
} | ||
|
||
fn configure_rising_edge_trigger(rising_trigger_select: &RTSR1) { | ||
rising_trigger_select.modify(|_, w| w.tr0().set_bit()) | ||
rising_trigger_select.modify(|_, w| w.tr0().enabled()) | ||
} | ||
|
||
fn configure_falling_edge_trigger(falling_trigger_select: &FTSR1) { | ||
falling_trigger_select.modify(|_, w| w.tr0().set_bit()) | ||
falling_trigger_select.modify(|_, w| w.tr0().enabled()) | ||
} | ||
|
||
fn enable_exti0() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: look up the APB2 register
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not familiar with it, just figured from the docs that I need SYSCFG configured, so I passed in whatever the HAL asked me to pass in.