-
Notifications
You must be signed in to change notification settings - Fork 139
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Added an example for the nRF52840-DK with both interrupt- and PPI usage with the onboard buttons and leds: |
Looks good, thanks! I'll leave this open for a while to see if anyone else has opinions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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()
andout()
.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