Skip to content

Commit

Permalink
Add gpio:set_int/4 Erlang interface for ESP32 and STM32 ports
Browse files Browse the repository at this point in the history
Allows specifying the pid that `gpio_interrupt` messages are sent to in the 4th
parameter of `gpio:set_int/4`.

Signed-off-by: Winford <[email protected]>
  • Loading branch information
UncleGrumpy committed Oct 26, 2023
1 parent 0bb105c commit 76f17c6
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions libs/eavmlib/src/gpio.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 76f17c6

Please sign in to comment.