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 Dec 19, 2023
1 parent f4fae85 commit 61e8d49
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `esp:get_default_mac/0` for retrieving the default MAC address on ESP32.
- Added support for `pico` and `poci` as an alternative to `mosi` and `miso` for SPI
- ESP32: Added support to SPI peripherals other than hspi and vspi
- Added `gpio:set_int/4`, with the 4th parameter being the pid() or registered name of the process to receive interrupt messages

### Changed

Expand Down
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 61e8d49

Please sign in to comment.