Skip to content

Commit

Permalink
Initial support for pico-w networking
Browse files Browse the repository at this point in the history
Add network driver and implement connection to an access point.
Driver is compatible with esp32 and uses the same erlang module.
Also add ability to run ports with Pico.

Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Oct 7, 2023
1 parent 76f1521 commit 568984a
Show file tree
Hide file tree
Showing 7 changed files with 457 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for `atomvm:posix_clock_settime/2`
- Added support for creations of binaries with unaligned strings
- Added `-h` and `-v` flags to generic_unix AtomVM command
- Added support initial for Pico-W with the on-board LED
- Added initial support for Pico-W: on-board LED, connection to wifi network.

### Changed
- Changed offset of atomvmlib and of program on Pico. See also UPDATING.md.
Expand Down
1 change: 1 addition & 0 deletions examples/erlang/rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ pack_uf2(hello_pico hello_pico)
pack_uf2(pico_blink pico_blink)
pack_uf2(pico_rtc pico_rtc)
pack_uf2(picow_blink picow_blink)
pack_uf2(picow_wifi_sta picow_wifi_sta)
49 changes: 49 additions & 0 deletions examples/erlang/rp2040/picow_wifi_sta.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
%
% This file is part of AtomVM.
%
% Copyright 2023 Paul Guyot <[email protected]>
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.
%
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
%

-module(picow_wifi_sta).

-export([start/0]).

start() ->
Config = [
{sta, [
{ssid, <<"myssid">>},
{psk, <<"mypsk">>},
{connected, fun connected/0},
{got_ip, fun got_ip/1},
{disconnected, fun disconnected/0}
]}
],
case network:start(Config) of
{ok, _Pid} ->
timer:sleep(infinity);
Error ->
erlang:display(Error)
end.

connected() ->
io:format("Connected to access point.\n").

got_ip({IPv4, Netmask, Gateway}) ->
io:format("Got IP: ip=~p, netmask=~p, gateway=~p.\n", [IPv4, Netmask, Gateway]).

disconnected() ->
io:format("Disconnected from access point.\n").
4 changes: 3 additions & 1 deletion src/platforms/rp2040/src/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ set(HEADER_FILES

set(SOURCE_FILES
gpiodriver.c
networkdriver.c
platform_defaultatoms.c
platform_nifs.c
smp.c
Expand Down Expand Up @@ -66,6 +67,7 @@ endif()

if (PICO_CYW43_SUPPORTED)
target_link_libraries(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC pico_cyw43_arch_lwip_threadsafe_background)
target_link_options(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC "SHELL:-Wl,-u -Wl,networkregister_port_driver")
endif()

target_link_options(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC -Wl,-u -Wl,gpio_nif)
target_link_options(libAtomVM${PLATFORM_LIB_SUFFIX} PUBLIC "SHELL:-Wl,-u -Wl,gpio_nif")
Loading

0 comments on commit 568984a

Please sign in to comment.