diff --git a/.github/workflows/build-examples.yaml b/.github/workflows/build-examples.yaml index 304ecb6..f777eaf 100644 --- a/.github/workflows/build-examples.yaml +++ b/.github/workflows/build-examples.yaml @@ -10,32 +10,22 @@ on: ["push", "pull_request"] jobs: build_erlang_examples: - name: "Build Erlang Examples" + name: "Build Erlang/Elixir Examples" runs-on: ubuntu-latest strategy: fail-fast: true steps: - - - uses: erlef/setup-beam@v1 - with: - otp-version: "24" - elixir-version: "1.11" - - - name: Checkout repo - uses: actions/checkout@v2 - - # - name: "APT update" - # run: sudo apt update -y - - - name: "Build rebar3" - run: | - cd /tmp - git clone https://github.com/erlang/rebar3.git - cd rebar3 - ./bootstrap - - - name: "Build Erlang Example Programs" - run: | - PATH=/tmp/rebar3:$PATH ./build.sh + - uses: erlef/setup-beam@v1 + with: + otp-version: "26" + elixir-version: "1.18" + rebar3-version: "3.24.0" + + - name: Checkout repo + uses: actions/checkout@v4 + + - name: "Build Erlang/Elixir Example Programs" + run: | + ./build.sh diff --git a/.github/workflows/check-formatting.yaml b/.github/workflows/check-formatting.yaml new file mode 100644 index 0000000..8413b88 --- /dev/null +++ b/.github/workflows/check-formatting.yaml @@ -0,0 +1,49 @@ +# +# Copyright 2022 Davide Bettio +# +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later +# + +name: "Check formatting" + +on: + push: + paths: + - ".github/workflows/**" + - "**/*.ex" + - "**/*.exs" + - "**/*.erl" + pull_request: + paths: + - ".github/workflows/**" + - "**/*.ex" + - "**/*.exs" + - "**/*.erl" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref != 'refs/heads/main' && github.ref || github.run_id }} + cancel-in-progress: true + +jobs: + erlfmt-check: + runs-on: ubuntu-24.04 + container: erlang:28 + steps: + - uses: actions/checkout@v4 + - name: "Check formatting with Erlang fmt" + run: | + cd .. + git clone --depth 1 -b v1.7.0 https://github.com/WhatsApp/erlfmt.git + cd erlfmt + rebar3 as release escriptize + cd ../atomvm_examples + find . -name *.erl | xargs ../erlfmt/_build/release/bin/erlfmt -c + + mix-format-check: + runs-on: ubuntu-24.04 + container: elixir:1.17.1 + steps: + - uses: actions/checkout@v4 + - name: "Check formatting with Elixir mix format" + run: | + mix format --check-formatted "**/*.{ex,exs}" diff --git a/.github/workflows/reuse-lint.yaml b/.github/workflows/reuse-lint.yaml index 9df27c3..df46f4b 100644 --- a/.github/workflows/reuse-lint.yaml +++ b/.github/workflows/reuse-lint.yaml @@ -14,6 +14,6 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: REUSE Compliance Check - uses: fsfe/reuse-action@v1 + - uses: actions/checkout@v4 + - name: REUSE Compliance Check + uses: fsfe/reuse-action@v1 diff --git a/build.sh b/build.sh index 016e957..b8d89b6 100755 --- a/build.sh +++ b/build.sh @@ -26,6 +26,27 @@ for i in ${ERLANG_EXAMPLES}; do cd $i rm -rf _build ${REBAR} atomvm packbeam -l || exit 1 - ${REBAR} as check fmt -c || exit 1 cd .. done +cd .. +cd elixir +ELIXIR_EXAMPLES="$(/bin/ls | grep -v README.md)" +for i in ${ELIXIR_EXAMPLES}; do + cd $i + rm -rf _build + mix deps.get && mix atomvm.packbeam || exit 1 + cd .. +done +cd .. +cd demos +DEMO_EXAMPLES="$(/bin/ls | grep -v README.md)" +for i in ${DEMO_EXAMPLES}; do + cd $i + rm -rf _build + if [ -f mix.exs ]; then + mix deps.get && mix atomvm.packbeam || exit 1 + else + ${REBAR} atomvm packbeam -l || exit 1 + fi + cd .. +done \ No newline at end of file diff --git a/demos/lisp_faces/lib/main.ex b/demos/lisp_faces/lib/main.ex index 5fb7b76..23d59f4 100644 --- a/demos/lisp_faces/lib/main.ex +++ b/demos/lisp_faces/lib/main.ex @@ -41,7 +41,7 @@ defmodule Main do :gen_server.call( t, {:write, - :erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ' running processes.\n'}, + :erlang.integer_to_list(:erlang.system_info(:process_count)) ++ ~c" running processes.\n"}, 60000 ) diff --git a/demos/morse_server/src/morse_server.app.src b/demos/morse_server/src/morse_server.app.src index 0b75f9f..41e653a 100644 --- a/demos/morse_server/src/morse_server.app.src +++ b/demos/morse_server/src/morse_server.app.src @@ -25,8 +25,8 @@ {applications, [ kernel, stdlib ]}, - {env,[]}, + {env, []}, {modules, []}, {licenses, ["Apache 2.0"]}, {links, []} - ]}. +]}. diff --git a/demos/morse_server/src/morse_server.erl b/demos/morse_server/src/morse_server.erl index 0a8990d..f917de0 100644 --- a/demos/morse_server/src/morse_server.erl +++ b/demos/morse_server/src/morse_server.erl @@ -27,7 +27,7 @@ start() -> Config = [ {sta, [ {ssid, esp:nvs_get_binary(atomvm, sta_ssid, <<"myssid">>)}, - {psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)}, + {psk, esp:nvs_get_binary(atomvm, sta_psk, <<"mypsk">>)}, {connected, fun() -> Self ! connected end}, {got_ip, fun(IpInfo) -> Self ! {ok, IpInfo} end}, {disconnected, fun() -> Self ! disconnected end} @@ -41,18 +41,20 @@ start() -> end. handle_req("GET", [], Conn) -> - Body = <<" - -

Morse Encoder

-
-

Text:

-

GPIO:

- -
- - ">>, + Body = + << + "\n" + " \n" + "

Morse Encoder

\n" + "
\n" + "

Text:

\n" + "

GPIO:

\n" + " \n" + "
\n" + " \n" + " " + >>, http_server:reply(200, Body, Conn); - handle_req("POST", [], Conn) -> ParamsBody = proplists:get_value(body_chunk, Conn), Params = http_server:parse_query_string(ParamsBody), @@ -65,14 +67,21 @@ handle_req("POST", [], Conn) -> spawn(fun() -> blink_led(GPIONum, MorseText) end), - Body = [<<" - -

Text Encoded

">>, - <<"

">>, MorseText, <<" - - ">>], + Body = [ + << + "\n" + " \n" + "

Text Encoded

" + >>, + <<"

">>, + MorseText, + << + "\n" + " \n" + " " + >> + ], http_server:reply(200, Body, Conn); - handle_req(Method, Path, Conn) -> erlang:display(Conn), erlang:display({Method, Path}), @@ -108,14 +117,12 @@ get_gpio() -> undefined -> GPIO = gpio:open(), GPIO; - GPIO -> GPIO end. blink_led(undefined, _L) -> ok; - blink_led(GPIONum, L) -> GPIO = get_gpio(), gpio:set_direction(GPIO, GPIONum, output), @@ -123,19 +130,16 @@ blink_led(GPIONum, L) -> blink_led(_GPIO, _GPIONum, []) -> ok; - blink_led(GPIO, GPIONum, [H | T]) -> case H of $\s -> gpio:set_level(GPIO, GPIONum, low), timer:sleep(120); - $. -> gpio:set_level(GPIO, GPIONum, high), timer:sleep(120), gpio:set_level(GPIO, GPIONum, low), timer:sleep(120); - $- -> gpio:set_level(GPIO, GPIONum, high), timer:sleep(120 * 3), @@ -149,7 +153,6 @@ morse_encode(L) -> morse_encode([], Acc) -> Acc; - morse_encode([H | L], Acc) -> M = to_morse(string:to_upper(H)), morse_encode(L, Acc ++ M). @@ -167,7 +170,7 @@ to_morse(C) -> $7 -> "--... "; $8 -> "---.. "; $9 -> "----. "; - $A -> ".-" ; + $A -> ".-"; $B -> "-... "; $C -> "-.-. "; $D -> "-.. "; diff --git a/elixir/Blinky/lib/Blinky.ex b/elixir/Blinky/lib/Blinky.ex index 53fb110..2b39f82 100644 --- a/elixir/Blinky/lib/Blinky.ex +++ b/elixir/Blinky/lib/Blinky.ex @@ -30,7 +30,7 @@ defmodule Blinky do end defp loop(pin, level) do - :io.format('Setting pin ~p ~p~n', [pin, level]) + :io.format(~c"Setting pin ~p ~p~n", [pin, level]) GPIO.digital_write(pin, level) Process.sleep(1000) loop(pin, toggle(level)) @@ -55,19 +55,25 @@ defmodule Blinky do defp platform_gpio_setup() do case :atomvm.platform() do - :esp32 -> GPIO.set_pin_mode(pin(), :output) - :stm32 -> GPIO.set_pin_mode(pin(), :output) + :esp32 -> + GPIO.set_pin_mode(pin(), :output) + + :stm32 -> + GPIO.set_pin_mode(pin(), :output) + :pico -> case @pin do - {:wl, 0} -> :ok + {:wl, 0} -> + :ok + pin -> GPIO.init(pin) GPIO.set_pin_mode(pin, :output) end + unsupported -> :io.format("Platform ~p is not supported.~n", [unsupported]) :erlang.exit({:error, {:unsupported_platform, unsupported}}) end end - end diff --git a/elixir/HelloWorld/lib/HelloWorld.ex b/elixir/HelloWorld/lib/HelloWorld.ex index 0caae06..a861d7e 100644 --- a/elixir/HelloWorld/lib/HelloWorld.ex +++ b/elixir/HelloWorld/lib/HelloWorld.ex @@ -19,9 +19,7 @@ # defmodule HelloWorld do - def start() do - :io.format('Hello World~n') + :io.format(~c"Hello World~n") end - end diff --git a/elixir/LEDC_Example/lib/LEDC_Example.ex b/elixir/LEDC_Example/lib/LEDC_Example.ex index d859ea6..d29ebdf 100644 --- a/elixir/LEDC_Example/lib/LEDC_Example.ex +++ b/elixir/LEDC_Example/lib/LEDC_Example.ex @@ -39,7 +39,7 @@ defmodule LedcExample do ledc_hs_timer = [ {:duty_resolution, 13}, {:freq_hz, 5000}, - {:speed_mode, LEDC.high_speed_mode}, + {:speed_mode, LEDC.high_speed_mode()}, {:timer_num, @high_speed_timer} ] @@ -48,7 +48,7 @@ defmodule LedcExample do ledc_ls_timer = [ {:duty_resolution, 13}, {:freq_hz, 5000}, - {:speed_mode, LEDC.low_speed_mode}, + {:speed_mode, LEDC.low_speed_mode()}, {:timer_num, @low_speed_timer} ] @@ -59,7 +59,7 @@ defmodule LedcExample do {:channel, 0}, {:duty, 0}, {:gpio_num, @led_1}, - {:speed_mode, LEDC.high_speed_mode}, + {:speed_mode, LEDC.high_speed_mode()}, {:hpoint, 0}, {:timer_sel, @high_speed_timer} ], @@ -67,7 +67,7 @@ defmodule LedcExample do {:channel, 1}, {:duty, 0}, {:gpio_num, @led_2}, - {:speed_mode, LEDC.high_speed_mode}, + {:speed_mode, LEDC.high_speed_mode()}, {:hpoint, 0}, {:timer_sel, @high_speed_timer} ], @@ -75,7 +75,7 @@ defmodule LedcExample do {:channel, 2}, {:duty, 0}, {:gpio_num, @led_3}, - {:speed_mode, LEDC.low_speed_mode}, + {:speed_mode, LEDC.low_speed_mode()}, {:hpoint, 0}, {:timer_sel, @low_speed_timer} ], @@ -83,7 +83,7 @@ defmodule LedcExample do {:channel, 3}, {:duty, 0}, {:gpio_num, @led_4}, - {:speed_mode, LEDC.low_speed_mode}, + {:speed_mode, LEDC.low_speed_mode()}, {:hpoint, 0}, {:timer_sel, @low_speed_timer} ] @@ -95,19 +95,19 @@ defmodule LedcExample do end def loop(ledc_channel) do - :io.format('1. LEDC fade up to duty = ~p~n', [@test_duty]) + :io.format(~c"1. LEDC fade up to duty = ~p~n", [@test_duty]) Enum.each(ledc_channel, fn channel_config -> do_stage_1(channel_config) end) Process.sleep(@test_fade_time) - :io.format('2. LEDC fade down to duty = 0~n') + :io.format(~c"2. LEDC fade down to duty = 0~n") Enum.each(ledc_channel, fn channel_config -> do_stage_2(channel_config) end) Process.sleep(@test_fade_time) - :io.format('3. LEDC set duty = ~p without fade~n', [@test_duty]) + :io.format(~c"3. LEDC set duty = ~p without fade~n", [@test_duty]) Enum.each(ledc_channel, fn channel_config -> do_stage_3(channel_config) end) Process.sleep(@test_fade_time) - :io.format('4. LEDC set duty = 0 without fade~n') + :io.format(~c"4. LEDC set duty = 0 without fade~n") Enum.each(ledc_channel, fn channel_config -> do_stage_4(channel_config) end) Process.sleep(@test_fade_time) @@ -118,14 +118,14 @@ defmodule LedcExample do speed_mode = :proplists.get_value(:speed_mode, channel_config) channel = :proplists.get_value(:channel, channel_config) :ok = LEDC.set_fade_with_time(speed_mode, channel, @test_duty, @test_fade_time) - :ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait) + :ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait()) end defp do_stage_2(channel_config) do speed_mode = :proplists.get_value(:speed_mode, channel_config) channel = :proplists.get_value(:channel, channel_config) :ok = LEDC.set_fade_with_time(speed_mode, channel, 0, @test_fade_time) - :ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait) + :ok = LEDC.fade_start(speed_mode, channel, LEDC.fade_no_wait()) end defp do_stage_3(channel_config) do diff --git a/elixir/LEDC_Example/mix.exs b/elixir/LEDC_Example/mix.exs index 464e77f..ffc31fe 100644 --- a/elixir/LEDC_Example/mix.exs +++ b/elixir/LEDC_Example/mix.exs @@ -23,6 +23,7 @@ defmodule LedcExample.MixProject do def project do [ + app: :LedcExample, version: "0.1.0", elixir: "~> 1.13", start_permanent: Mix.env() == :prod,