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

gpio:set_int(Gpio, Pin, none) -> error #1386

Closed
petermm opened this issue Dec 6, 2024 · 3 comments
Closed

gpio:set_int(Gpio, Pin, none) -> error #1386

petermm opened this issue Dec 6, 2024 · 3 comments

Comments

@petermm
Copy link
Contributor

petermm commented Dec 6, 2024

Somebody struggled and posted this in the Discord. Reading the docs, it seems this code should work

Available triggers are none (which is the same as disabling an interrupt), rising, falling, both (rising or falling), low, and high.

https://www.atomvm.net/doc/main/apidocs/erlang/eavmlib/gpio.html#set-int-3

In my code I want to enable and disable interrupts but get an error when diabling the interrupts.

start() ->
    start(undefined, undefined).

start(_StartType, _StartArgs) ->
    Int_pin = 33,
    Gpio = gpio:open(),
    gpio:set_direction(Gpio, Int_pin, input),
    ok = gpio:set_int(Gpio, Int_pin, rising),
    ok = gpio:set_int(Gpio, Int_pin, none),
    wait_forever().

I get an error on the second gpio:set_int/3 call:

CRASH
======
pid: <0.1.0>

Stacktrace:
[{mpu6050_app,start,2,[{file,"/home/username/mpu6050/src/mpu6050_app.erl"},{line,21}]}]

cp: #CP<module: 4, label: 4, offset: 64>

x[0]: error
x[1]: {badmatch,error}
x[2]: {1,1,39,1,[{4,105}],error}

Problem solved by using:

ok = gpio:remove_int(Gpio, Int_pin)

But there may be a (doc?)/code issue.

@UncleGrumpy
Copy link
Collaborator

This looks like a bug, I will try to look into this over the weekend. You already found the workaround. Thanks for reporting this!

@UncleGrumpy
Copy link
Collaborator

I looked at our handling of gpio interrupts and we do not have a special case necessary to make none remove any interrupts set on the given pin. Since we have a dedicated function to disable the interrupts I think updating the docs makes more sense than making the code more complicated.

UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Dec 16, 2024
Add full implimentation of the documented "none" interrupt trigger. This trigger
has been documented since release-0.5, but was never fully implimented, and its
use results in an error, see issue atomvm#1386.

Closes atomvm#1386

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Dec 16, 2024
Add full implimentation of the documented "none" interrupt trigger. This trigger
has been documented since release-0.5, but was never fully implimented, and its
use results in an error, see issue atomvm#1386.

Closes atomvm#1386

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Dec 16, 2024
Fixes the implementation of the `none` trigger by moving the main functionality
from `gpiodriver_remove_int` into a new `unregister_interrupt_listener` funtion
that is also used when setting the interrupt trigger to `none` to remove an
interrupt.

Closes atomvm#1386

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Dec 16, 2024
Fixes the implementation of the `none` trigger that has been documented since
release-0.5, but was apparently never tested, its use causes a error (see atomvm#1386)

Moves the main functionality from `gpiodriver_remove_int` into a new
`unregister_interrupt_listener` funtion that is also used when setting the
interrupt trigger to `none` to remove an interrupt.

Closes atomvm#1386

Signed-off-by: Winford <winford@object.stream>
UncleGrumpy added a commit to UncleGrumpy/AtomVM that referenced this issue Dec 16, 2024
Fixes the implementation of the `none` trigger that has been documented since release-0.5, but was
apparently never tested, its use causes a error (see atomvm#1386).

Moves the main functionality from `gpiodriver_remove_int` into a new `unregister_interrupt_listener`
funtion that is also used when setting the interrupt trigger to `none` to remove an interrupt.

Closes atomvm#1386

Signed-off-by: Winford <winford@object.stream>
@UncleGrumpy
Copy link
Collaborator

I thought about this a bit more, and after thinking of all the situations where using the none trigger would be preferable, I looked harder and found that it could be supported with minimal changes. See #1399.

bettio added a commit that referenced this issue Dec 17, 2024
Fix broken ESP32 gpio interrupt trigger `none`

Fixes the implementation of the `none` trigger that has been documented since
release-0.5, but was apparently never tested, its use causes a error (see #1386).

Moves the main functionality from `gpiodriver_remove_int` into a new
`unregister_interrupt_listener` funtion that is also used when setting the
interrupt trigger to `none` to remove an interrupt.

Closes #1386

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
@petermm petermm closed this as completed Dec 20, 2024
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

No branches or pull requests

2 participants