Skip to content

Commit

Permalink
UART: migrate deprecated keys
Browse files Browse the repository at this point in the history
In order to provide compatibility deprecated config entries are translated,
such as `tx_pin` to `tx` and a warning is printed.

Signed-off-by: Davide Bettio <davide@uninstall.it>
  • Loading branch information
bettio committed Dec 16, 2023
1 parent 0431a57 commit b52eadf
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion libs/eavmlib/src/uart.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open(Name, Opts) ->
open_port({spawn, "uart"}, [{peripheral, Name} | Opts]).

open(Opts) ->
open_port({spawn, "uart"}, Opts).
open_port({spawn, "uart"}, migrate_config(Opts)).

close(Pid) ->
port:call(Pid, close).
Expand Down Expand Up @@ -57,3 +57,24 @@ is_iolist([H | T]) ->
end;
is_iolist(_) ->
false.

migrate_config([]) ->
[];
migrate_config([{K, V} | T]) ->
NewK = rename_key(K),
warn_deprecated(K, NewK),
[{NewK, V} | migrate_config(T)].

rename_key(Key) ->
case Key of
rx_pin -> rx;
tx_pin -> tx;
rts_pin -> rts;
cts_pin -> cts;
Any -> Any
end.

warn_deprecated(Key, Key) ->
ok;
warn_deprecated(OldKey, NewKey) ->
io:format("UART: found deprecated ~p, use ~p instead!!!~n", [OldKey, NewKey]).

0 comments on commit b52eadf

Please sign in to comment.