Skip to content

Add Gpiote module (open for feedback)#167

Merged
jonas-schievink merged 12 commits intonrf-rs:masterfrom
kalkyl:gpiote
Jul 11, 2020
Merged

Add Gpiote module (open for feedback)#167
jonas-schievink merged 12 commits intonrf-rs:masterfrom
kalkyl:gpiote

Conversation

@kalkyl
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread nrf-hal-common/src/gpiote.rs Outdated
@jonas-schievink
Copy link
Copy Markdown
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