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

Add Gpiote module (open for feedback) #167

Merged
merged 12 commits into from
Jul 11, 2020
Merged

Conversation

kalkyl
Copy link
Contributor

@kalkyl kalkyl commented Jul 2, 2020

Hi nRF team!

Here's a starting point of a Gpiote module, based on how i've been using it in my projects.
Let's discuss a suitable api, at the moment it looks like this:

let gpiote = gpiote::Gpiote::new(p.GPIOTE);

Example how to configure an input pin as an event source for channel 0, triggering on hi-to-low transition and firing the GPIO interrupt:
let btn1 = p0.p0_11.into_pullup_input().degrade();
gpiote.channel0().input_pin(&btn1).hi_to_lo().enable_interrupt();

Or using port event:
gpiote.port().input_pin(&btn1).low();
gpiote.port().input_pin(&btn3).low();
gpiote.port().enable_interrupt();

In the GPIOTE ISR, check for triggered events like:
gpiote.channel0().is_event_triggered()
Reset channel events like:
gpiote.channel0().reset_events();
Reset port events like
gpiote.port().reset_events();
Or globally reset all events like:
gpiote.reset_events();

Task output pins are configured like:
let led1 = p0.p0_13.into_push_pull_output(Level::High).degrade();
gpiote.channel1().output_pin(led1).init_high();

The assigned output pin is consumed because when an output pin is in task mode, it can no longer be used with the normal gpio api, instead you would use the provided task functions set(), clear() and out().

All configuations available in the registers are implemented aswell as far as i can tell.

Here's a demo using interrupts and PPI with the onboard buttons and leds of the nrf52840-DK:
https://github.com/kalkyl/nrf-hal/blob/gpiote/examples/gpiote-demo/src/main.rs

Cheers!

EDIT: Updated with the latest version of the api

@kalkyl
Copy link
Contributor Author

kalkyl commented Jul 2, 2020

Added an example for the nRF52840-DK with both interrupt- and PPI usage with the onboard buttons and leds:
https://github.com/kalkyl/nrf-hal/blob/gpiote/examples/gpiote-demo/src/main.rs

@jonas-schievink
Copy link
Contributor

Looks good, thanks! I'll leave this open for a while to see if anyone else has opinions.

@jonas-schievink jonas-schievink merged commit 897b576 into nrf-rs:master Jul 11, 2020
@kalkyl kalkyl deleted the gpiote branch September 4, 2020 13:40
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