[go: up one dir, main page]

Skip to content
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

Demonstrate GPIO interrupts on the LPC55S69-EVK board. #1919

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lzrd
Copy link
Contributor
@lzrd lzrd commented Nov 17, 2024

Pressing the USER button generates an interrupt to the button task.

A single press will increment the RGB pattern.

Quick (~1.5s) successive presses 2nd, 3rd, and subsequent will respecitvely

  • turn off LEDs
  • blink LEDs
  • cycle through RBG pattern including all off.

Minor updates to other app.toml files:

  • add pint and inputmux peripherals to their gpio_driver tasks.
  • when compiling all targets, some needed slight allocation adjustments not related to this PR.

Pressing the USER button generates an interrupt to the button task.

A single press will increment the RGB pattern.

Quick (~1.5s) successive presses 2nd, 3rd, and subsequent will respecitvely
  - turn off LEDs
  - blink LEDs
  - cycle through RBG pattern including all off.

Minor updates to other app.toml files:
  - add `pint` and `inputmux` peripherals to their `gpio_driver` tasks.
  - when compiling all targets, some needed slight allocation
    adjustments not related to this PR.
// Ensure that the pin is configured as an input during
// PINT setup. XXX remove if not needed.
let (tport, tpin) = gpio_port_pin_validate(pin);
self.set_pin_direction(tport, tpin, Direction::Input);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The data sheet says that the pin must be an input. But we are going to be turning the SP_RESET line back and forth between input and output. The minimal effective procedure needs to be worked out to avoid spurious interrupts when driving SP_RESET and not losing them when detecting SP_RESET.

// Functions for managing GPIO interrupts:
//

fn clear_rising(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a fan of these discrete enable/disable/detect/status calls. Other environments (zephyr, NXP SDK) bundle these together at initial config time or run time.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. Can we make this part of the config?

};

// XXX for now at least, setting up a PINT pin will set dir to Input
server.gpio.disable_rising(BUTTON_PINT_MASK);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some of these calls are redundant with the reset state of the PINT peripheral and can be removed.

@lzrd
Copy link
Contributor Author
lzrd commented Nov 17, 2024

Note: This implementation only implements edge-detection interrupts and ignores level-detection.

aapoalas

This comment was marked as off-topic.

@@ -49,7 +49,7 @@ task-slots = ["sys", "user_leds"]

[tasks.net]
name = "task-net"
stacksize = 3000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this strictly necessary or can this be split out into a separate change?

if pins.iter().any(|p| p.name.is_some()) {
writeln!(&mut buf, "use drv_lpc55_gpio_api::Pin;")?;
writeln!(&mut file, "use drv_lpc55_gpio_api::Pin;")?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't look write, the goal was to write everything into the buf first and then write to the file at the end

// Functions for managing GPIO interrupts:
//

fn clear_rising(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. Can we make this part of the config?

Comment on lines +175 to +178
unsafe {
self.inputmux.pintsel[pint_slot as usize]
.write(|w| w.bits(pin as u32));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the intpin API which would let us wrap the unsafe a bit tighter or does that not work with our hubris design?

fn set_pin_direction(&self, port: usize, pin: usize, dir: Direction) {
match dir {
Direction::Input => self.gpio.dirclr[port]
.write(|w| unsafe { w.dirclrp().bits(1 << pin) }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The unsafe is a quirk of how the lpc55-pac is generated. Adding a safety comment for this is unlikely to be useful.

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.

3 participants