Skip to content

Commit f918dd2

Browse files
author
Henrik Alsér
committed
Enable interrupt for channel method instead of bool param
1 parent c27955c commit f918dd2

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

examples/gpiote-demo/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ const APP: () = {
4040
let gpiote = Gpiote::new(ctx.device.GPIOTE);
4141

4242
// Set btn1 to generate event on channel 0 and enable interrupt
43-
gpiote.channel0().input_pin(&btn1).hi_to_lo(true);
43+
gpiote
44+
.channel0()
45+
.input_pin(&btn1)
46+
.hi_to_lo()
47+
.enable_interrupt();
4448

4549
// Set both btn3 & btn4 to generate port event
4650
gpiote.port().input_pin(&btn3).low();
@@ -54,7 +58,7 @@ const APP: () = {
5458
.output_pin(led1)
5559
.task_out_polarity(TaskOutPolarity::Toggle)
5660
.init_high();
57-
gpiote.channel2().input_pin(&btn2).hi_to_lo(false);
61+
gpiote.channel2().input_pin(&btn2).hi_to_lo();
5862
let ppi_channels = ppi::Parts::new(ctx.device.PPI);
5963
let mut channel0 = ppi_channels.ppi0;
6064
channel0.set_task_endpoint(gpiote.channel1().task_out());

nrf-hal-common/src/gpiote.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,41 +181,34 @@ pub struct GpioteChannelEvent<'a, P: GpioteInputPin> {
181181
}
182182

183183
impl<'a, P: GpioteInputPin> GpioteChannelEvent<'_, P> {
184-
pub fn hi_to_lo(&self, enable_interrupt: bool) {
184+
pub fn hi_to_lo(&self) -> &Self {
185185
config_channel_event_pin(self.gpiote, self.channel, self.pin, EventPolarity::HiToLo);
186-
if enable_interrupt {
187-
self.enable_interrupt();
188-
}
186+
self
189187
}
190188

191-
pub fn lo_to_hi(&self, enable_interrupt: bool) {
189+
pub fn lo_to_hi(&self) -> &Self {
192190
config_channel_event_pin(self.gpiote, self.channel, self.pin, EventPolarity::LoToHi);
193-
if enable_interrupt {
194-
self.enable_interrupt();
195-
}
191+
self
196192
}
197193

198-
pub fn toggle(&self, enable_interrupt: bool) {
194+
pub fn toggle(&self) -> &Self {
199195
config_channel_event_pin(self.gpiote, self.channel, self.pin, EventPolarity::Toggle);
200-
if enable_interrupt {
201-
self.enable_interrupt();
202-
}
196+
self
203197
}
204198

205-
pub fn none(&self, enable_interrupt: bool) {
199+
pub fn none(&self) -> &Self {
206200
config_channel_event_pin(self.gpiote, self.channel, self.pin, EventPolarity::None);
207-
if enable_interrupt {
208-
self.enable_interrupt();
209-
}
201+
self
210202
}
211203

212-
pub fn enable_interrupt(&self) {
204+
pub fn enable_interrupt(&self) -> &Self {
213205
// Enable interrupt for pin
214206
unsafe {
215207
self.gpiote
216208
.intenset
217209
.modify(|r, w| w.bits(r.bits() | self.pin.pin() as u32))
218210
}
211+
self
219212
}
220213
}
221214

0 commit comments

Comments
 (0)