Skip to content

Commit 8b078a9

Browse files
aykevldeadprogram
authored andcommitted
machine: remove level triggered pin interrupts
This removes level-triggered interrupts. While working on #3170, I found these level triggered interrupt constants. Apart from them being inconsistent with each other (PinLowLevel vs PinLevelLow) I don't think they are actually used anywhere. In addition, I removed the PinNoInterrupt constant on the esp32c3. This makes the esp32c3 pass the tests in #3170. I looked into level-triggered interrupts and I really couldn't find a good justification for them: - They were added to the esp32c3 and the rp2040 together with other pin interrupt types, meaning they were probably just added because the chip supports the feature and not because they were actually needed. - Level interrupts aren't supported in TinyGo for any other chip, and I haven't seen anybody ask for this feature. - They aren't supported in the nrf series chips _at all_, and with a quick search I found only very little demand for them in general. - I tried to see whether there is any good use case for them, but I couldn't really find one (where an edge triggered interrupt wouldn't work just as well). If there is one where level triggered interrupts are a real advantage over edge triggered interrupts, please let me know. Of course, we shouldn't remove a feature lightly. But in this case, I can't think of an advantage of having this feature. I can think of downsides: more maintenance and having to specify their behavior in the machine package documentation. In general, I would like to keep the machine package clean and only support things that have a proven use case.
1 parent 9e24441 commit 8b078a9

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

src/machine/machine_esp32c3.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ type PinChange uint8
5959

6060
// Pin change interrupt constants for SetInterrupt.
6161
const (
62-
PinNoInterrupt PinChange = iota
63-
PinRising
62+
PinRising PinChange = iota + 1
6463
PinFalling
6564
PinToggle
66-
PinLowLevel
67-
PinHighLevel
6865
)
6966

7067
// Configure this pin with the given configuration.
@@ -190,7 +187,7 @@ func (p Pin) SetInterrupt(change PinChange, callback func(Pin)) (err error) {
190187
return ErrInvalidInputPin
191188
}
192189

193-
if callback == nil || change == PinNoInterrupt {
190+
if callback == nil {
194191
// Disable this pin interrupt
195192
p.pin().ClearBits(esp.GPIO_PIN_PIN_INT_TYPE_Msk | esp.GPIO_PIN_PIN_INT_ENA_Msk)
196193

src/machine/machine_mimxrt1062.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ const (
5454
type PinChange uint8
5555

5656
const (
57-
PinLow PinChange = iota
58-
PinHigh
59-
PinRising
57+
PinRising PinChange = iota + 2
6058
PinFalling
6159
PinToggle
6260
)
@@ -393,7 +391,7 @@ func (p Pin) SetInterrupt(change PinChange, callback func(Pin)) error {
393391
mask := p.getMask()
394392
if nil != callback {
395393
switch change {
396-
case PinLow, PinHigh, PinRising, PinFalling:
394+
case PinRising, PinFalling:
397395
gpio.EDGE_SEL.ClearBits(mask)
398396
var reg *volatile.Register32
399397
var pos uint8

src/machine/machine_rp2040_gpio.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,8 @@ type PinChange uint8
226226

227227
// Pin change interrupt constants for SetInterrupt.
228228
const (
229-
// PinLevelLow triggers whenever pin is at a low (around 0V) logic level.
230-
PinLevelLow PinChange = 1 << iota
231-
// PinLevelLow triggers whenever pin is at a high (around 3V) logic level.
232-
PinLevelHigh
233229
// Edge falling
234-
PinFalling
230+
PinFalling PinChange = 4 << iota
235231
// Edge rising
236232
PinRising
237233
)

0 commit comments

Comments
 (0)