Skip to content

Conversation

@dmunizu
Copy link

@dmunizu dmunizu commented Oct 15, 2025

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.

Copy link
Member

@romancardenas romancardenas left a 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.

Copy link
Member

@romancardenas romancardenas left a 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

/// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn enable_interrupts(&self, event: EventType) {
pub fn enable_interrupts(&mut self, event: EventType) {

}

/// Disables the specified interrupt event for all the GPIO pins.
pub fn disable_interrupts(&self, event: EventType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn disable_interrupts(&self, event: EventType) {
pub fn disable_interrupts(&mut self, event: EventType) {

}

/// Clears the specified interrupt event pending flag for all the GPIO pins.
pub fn clear_interrupts(&self, event: EventType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn clear_interrupts(&self, event: EventType) {
pub fn clear_interrupts(&mut self, event: EventType) {

/// # Safety
///
/// Enabling an interrupt source can break mask-based critical sections.
pub unsafe fn enable_exti(&self, plic: &Plic) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub unsafe fn enable_exti(&self, plic: &Plic) {
pub unsafe fn enable_exti(&mut self, plic: &Plic) {

}

/// Disables the external interrupt source for the pin.
pub fn disable_exti(&self, plic: &Plic) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn disable_exti(&self, plic: &Plic) {
pub fn disable_exti(&mut self, plic: &Plic) {

/// # Safety
///
/// Changing the priority level can break priority-based critical sections.
pub unsafe fn set_exti_priority(&self, plic: &Plic, priority: Priority) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub unsafe fn set_exti_priority(&self, plic: &Plic, priority: Priority) {
pub unsafe fn set_exti_priority(&mut self, plic: &Plic, priority: Priority) {

/// 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn enable_interrupt(&self, event: EventType) {
pub fn enable_interrupt(&mut self, event: EventType) {

}

/// Disables the selected interrupts for the pin in the interrupt enable registers
pub fn disable_interrupt(&self, event: EventType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn disable_interrupt(&self, event: EventType) {
pub fn disable_interrupt(&mut self, event: EventType) {

}

/// Clears pending interrupts for the selected pin interrupts.
pub fn clear_interrupt(&self, event: EventType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this:

Suggested change
unsafe { priorities.set_priority(ExternalInterrupt::GPIO9, Priority::P1) };

@romancardenas romancardenas merged commit cafe827 into riscv-rust:master Oct 23, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants