From 4ff12710782aaf250c2d28d51c6c8627a4fce7ec Mon Sep 17 00:00:00 2001 From: Winford Date: Tue, 3 Oct 2023 13:08:20 -0700 Subject: [PATCH] Add gpio:set_int/4 Erlang interface for ESP32 and STM32 ports Allows specifying the pid that `gpio_interrupt` messages are sent to in the 4th parameter of `gpio:set_int/4`. Signed-off-by: Winford --- libs/eavmlib/src/gpio.erl | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/libs/eavmlib/src/gpio.erl b/libs/eavmlib/src/gpio.erl index 7699f90fa..3db8c1ef7 100644 --- a/libs/eavmlib/src/gpio.erl +++ b/libs/eavmlib/src/gpio.erl @@ -36,12 +36,11 @@ read/2, set_direction/3, set_level/3, - set_int/3, + set_int/3, set_int/4, remove_int/2, stop/0, close/1 ]). - -export([ init/1, deinit/1, @@ -252,6 +251,31 @@ set_level(GPIO, Pin, Level) -> set_int(GPIO, Pin, Trigger) -> port:call(GPIO, {set_int, Pin, Trigger}). +%%----------------------------------------------------------------------------- +%% @param GPIO pid that was returned from `gpio:start/0' +%% @param Pin number of the pin to set the interrupt on +%% @param Trigger is the state that will trigger an interrupt +%% @param Pid is the process that will receive the interrupt message +%% @returns ok | error | {error, Reason} +%% @doc Set a GPIO interrupt +%% +%% Available triggers are `none' (which is the same as disabling an +%% interrupt), `rising', `falling', `both' (rising or falling), `low', and +%% `high'. When the interrupt is triggered it will send a tuple: +%% `{gpio_interrupt, Pin}' +%% to the process that set the interrupt. Pin will be the number +%% of the pin that triggered the interrupt. +%% +%% The STM32 port only supports `rising', `falling', or `both'. +%% +%% The rp2040 (Pico) port does not support gpio interrupts at this time. +%% @end +%%----------------------------------------------------------------------------- +-spec set_int(GPIO :: gpio(), Pin :: pin(), Trigger :: trigger(), Pid :: pid()) -> + ok | {error, Reason :: atom()} | error. +set_int(GPIO, Pin, Trigger, Pid) -> + port:call(GPIO, {set_int, Pin, Trigger, Pid}). + %%----------------------------------------------------------------------------- %% @param GPIO pid that was returned from `gpio:start/0' %% @param Pin number of the pin to remove the interrupt