-
Notifications
You must be signed in to change notification settings - Fork 14
Add GPIO interrupt managing methods #44
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
Conversation
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.
Thanks for your PR! Looks great.
I added a few comments. Please, make sure to test my suggestions before pushing them. I currently cannot try it on real HW.
…m Gpio0 to DeviceGpioPins
42f9cfc to
981be9f
Compare
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 added suggestions regarding mutability requirements
e310x-hal/src/device.rs
Outdated
| /// interrupt enable bits in the GPIO peripheral. You must call the | ||
| /// [`enable_exti()`](super::gpio::gpio0::Pin0::enable_exti) method of every pin | ||
| /// to enable their interrupt in the PLIC. | ||
| pub fn enable_interrupts(&self, event: EventType) { |
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.
| pub fn enable_interrupts(&self, event: EventType) { | |
| pub fn enable_interrupts(&mut self, event: EventType) { |
e310x-hal/src/device.rs
Outdated
| } | ||
|
|
||
| /// Disables the specified interrupt event for all the GPIO pins. | ||
| pub fn disable_interrupts(&self, event: EventType) { |
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.
| pub fn disable_interrupts(&self, event: EventType) { | |
| pub fn disable_interrupts(&mut self, event: EventType) { |
e310x-hal/src/device.rs
Outdated
| } | ||
|
|
||
| /// Clears the specified interrupt event pending flag for all the GPIO pins. | ||
| pub fn clear_interrupts(&self, event: EventType) { |
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.
| pub fn clear_interrupts(&self, event: EventType) { | |
| pub fn clear_interrupts(&mut self, event: EventType) { |
e310x-hal/src/gpio.rs
Outdated
| /// # Safety | ||
| /// | ||
| /// Enabling an interrupt source can break mask-based critical sections. | ||
| pub unsafe fn enable_exti(&self, plic: &Plic) { |
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.
| pub unsafe fn enable_exti(&self, plic: &Plic) { | |
| pub unsafe fn enable_exti(&mut self, plic: &Plic) { |
e310x-hal/src/gpio.rs
Outdated
| } | ||
|
|
||
| /// Disables the external interrupt source for the pin. | ||
| pub fn disable_exti(&self, plic: &Plic) { |
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.
| pub fn disable_exti(&self, plic: &Plic) { | |
| pub fn disable_exti(&mut self, plic: &Plic) { |
e310x-hal/src/gpio.rs
Outdated
| /// # Safety | ||
| /// | ||
| /// Changing the priority level can break priority-based critical sections. | ||
| pub unsafe fn set_exti_priority(&self, plic: &Plic, priority: Priority) { |
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.
| pub unsafe fn set_exti_priority(&self, plic: &Plic, priority: Priority) { | |
| pub unsafe fn set_exti_priority(&mut self, plic: &Plic, priority: Priority) { |
e310x-hal/src/gpio.rs
Outdated
| /// interrupt enable bit in the GPIO peripheral. You must call | ||
| /// [`enable_exti()`](Self::enable_exti) to enable the interrupt in | ||
| /// the PLIC. | ||
| pub fn enable_interrupt(&self, event: EventType) { |
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.
| pub fn enable_interrupt(&self, event: EventType) { | |
| pub fn enable_interrupt(&mut self, event: EventType) { |
e310x-hal/src/gpio.rs
Outdated
| } | ||
|
|
||
| /// Disables the selected interrupts for the pin in the interrupt enable registers | ||
| pub fn disable_interrupt(&self, event: EventType) { |
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.
| pub fn disable_interrupt(&self, event: EventType) { | |
| pub fn disable_interrupt(&mut self, event: EventType) { |
e310x-hal/src/gpio.rs
Outdated
| } | ||
|
|
||
| /// Clears pending interrupts for the selected pin interrupts. | ||
| pub fn clear_interrupt(&self, event: EventType) { |
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.
| pub fn clear_interrupt(&self, event: EventType) { | |
| pub fn clear_interrupt(&mut self, event: EventType) { |
| let plic = cp.plic; | ||
| let priorities = plic.priorities(); | ||
| priorities.reset::<ExternalInterrupt>(); | ||
| unsafe { priorities.set_priority(ExternalInterrupt::GPIO9, Priority::P1) }; |
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.
Remove this:
| unsafe { priorities.set_priority(ExternalInterrupt::GPIO9, Priority::P1) }; |
Add methods for the GPIO and Pin structs for the user to easily work with interrupts without dealing with direct register modification.
The button_interrupt.rs example has been adapted to this new functionality.