Skip to content

Commit

Permalink
SPI: add support to pico and poci terms
Browse files Browse the repository at this point in the history
Add support to alternatives to `mosi` and `miso` as described in
https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/ .

Signed-off-by: Davide Bettio <davide@uninstall.it>
  • Loading branch information
bettio committed Dec 15, 2023
1 parent 17e6c6e commit ccab726
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- 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

## [0.6.0-alpha.2] - 2023-12-10

Expand Down
32 changes: 17 additions & 15 deletions libs/eavmlib/src/spi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -330,34 +330,36 @@ migrate_deprecated(MaybeDeprecated) ->
migrate_deprecated_iter(none, Accum) ->
Accum;
migrate_deprecated_iter({K, V, Iter}, Accum) ->
NewK = replace_key(K),
warn_deprecated(K, NewK),
{Status, NewK} = replace_key(K),
warn_deprecated(Status, K, NewK),
migrate_deprecated_iter(maps:next(Iter), Accum#{NewK => V}).

%% @private
migrate_deprecated_fold({K, V}, Accum) ->
NewK = replace_key(K),
warn_deprecated(K, NewK),
{Status, NewK} = replace_key(K),
warn_deprecated(Status, K, NewK),
[{NewK, V} | Accum];
migrate_deprecated_fold(E, Accum) ->
[E | Accum].

%% @private
replace_key(Key) ->
case Key of
miso_io_num -> miso;
mosi_io_num -> mosi;
sclk_io_num -> sclk;
spi_cs_io_num -> cs;
spi_clock_hz -> clock_speed_hz;
spi_peripheral -> peripheral;
Any -> Any
pico -> {rename, mosi};
poci -> {rename, miso};
miso_io_num -> {warning, miso};
mosi_io_num -> {warning, mosi};
sclk_io_num -> {warning, sclk};
spi_cs_io_num -> {warning, cs};
spi_clock_hz -> {warning, clock_speed_hz};
spi_peripheral -> {warning, peripheral};
Any -> {ok, Any}
end.

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

%% @private
validate_integer_entry(Key, Map) ->
Expand Down

0 comments on commit ccab726

Please sign in to comment.