From eac8c684153474a3637899fb2a4613869d0c8dad Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 10 Mar 2022 22:38:49 +0000 Subject: [PATCH 01/12] CI: Build MicroPython for multiple boards --- .github/workflows/micropython.yml | 78 ++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 32568c86..3b17b3bb 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -10,22 +10,11 @@ env: # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) MICROPYTHON_VERSION: v1.18 BUILD_TYPE: Release - BOARD_TYPE: PICO jobs: - build: - name: ${{matrix.name}} - strategy: - matrix: - include: - - os: ubuntu-20.04 - name: Linux - cache-key: linux - cmake-args: '-DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk' - apt-packages: clang-tidy gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib - - runs-on: ${{matrix.os}} - + deps: + runs-on: ubuntu-20.04 + name: Dependencies steps: # Check out MicroPython - name: Checkout MicroPython @@ -46,12 +35,6 @@ jobs: run: | cp -r pimoroni-pico-${GITHUB_SHA}/micropython/modules_py/* micropython/ports/rp2/modules/ - # Linux deps - - name: Install deps - if: runner.os == 'Linux' - run: | - sudo apt update && sudo apt install ${{matrix.apt-packages}} - - name: Fetch base MicroPython submodules shell: bash working-directory: micropython @@ -67,21 +50,62 @@ jobs: working-directory: micropython/mpy-cross run: make + - name: Cache + uses: actions/cache@v2 + with: + path: ${{runner.workspace}} + key: workspace-micropython-${{github.ref}}-${{github.sha}} + restore-keys: | + workspace-${{github.ref}} + workspace-micropython- + + build: + needs: deps + runs-on: ubuntu-20.04 + strategy: + matrix: + board: [PICO, PIMORONI_TINY2040, PIMORONI_PICOLIPO_16MB] + + steps: + - name: Cache + uses: actions/cache@v2 + with: + path: /home/runner/.ccache + key: ccache-micropython-${{github.ref}}-${{github.sha}} + restore-keys: | + ccache-micropython-${{github.ref}} + ccache-micropython- + + - name: Cache + uses: actions/cache@v2 + with: + path: ${{runner.workspace}} + key: workspace-micropython-${{github.ref}}-${{github.sha}} + restore-keys: | + workspace-${{github.ref}} + workspace-micropython- + + - name: Install Compiler & CCache + if: runner.os == 'Linux' + run: | + sudo apt update && sudo apt install ccache gcc-arm-none-eabi + - name: Build MicroPython shell: bash working-directory: micropython/ports/rp2 - run: make USER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake -j2 + run: | + make USER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake BOARD=${{matrix.board}} -j2 - name: Rename .uf2 for artifact shell: bash - working-directory: micropython/ports/rp2/build-${{env.BOARD_TYPE}} - run: cp firmware.uf2 ${{github.event.repository.name}}-${{github.event.release.tag_name}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + working-directory: micropython/ports/rp2/build-${{matrix.board}} + run: cp firmware.uf2 ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - name: Store .uf2 as artifact uses: actions/upload-artifact@v2 with: - name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{github.event.repository.name}}-${{github.event.release.tag_name}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + path: micropython/ports/rp2/build-${{matrix.board}}/${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - name: Upload .uf2 if: github.event_name == 'release' @@ -89,7 +113,7 @@ jobs: env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: - asset_path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/firmware.uf2 + asset_path: micropython/ports/rp2/build-${{matrix.board}}/firmware.uf2 upload_url: ${{github.event.release.upload_url}} - asset_name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + asset_name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 asset_content_type: application/octet-stream From 8f0f4d0510c43fb818bd7f88e83ff489066ecb5a Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 10 Mar 2022 23:44:01 +0000 Subject: [PATCH 02/12] CI: Prettier names for .uf2 files --- .github/workflows/micropython.yml | 39 ++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 3b17b3bb..49d821a7 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -7,9 +7,7 @@ on: types: [created] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) MICROPYTHON_VERSION: v1.18 - BUILD_TYPE: Release jobs: deps: @@ -61,13 +59,24 @@ jobs: build: needs: deps + name: Build ${{matrix.board}} runs-on: ubuntu-20.04 strategy: matrix: - board: [PICO, PIMORONI_TINY2040, PIMORONI_PICOLIPO_16MB] + include: + - name: pico + board: PICO + - name: tiny2040 + board: PIMORONI_TINY2040 + - name: picolipo_16mb + board: PIMORONI_PICOLIPO_16MB + + env: + # MicroPython version will be contained in github.event.release.tag_name for releases + RELEASE_FILE: pimoroni-${{matrix.name}}-${{github.event.release.tag_name || github.sha}}-micropython.uf2 steps: - - name: Cache + - name: Compiler Cache uses: actions/cache@v2 with: path: /home/runner/.ccache @@ -76,7 +85,7 @@ jobs: ccache-micropython-${{github.ref}} ccache-micropython- - - name: Cache + - name: Workspace Cache uses: actions/cache@v2 with: path: ${{runner.workspace}} @@ -89,23 +98,31 @@ jobs: if: runner.os == 'Linux' run: | sudo apt update && sudo apt install ccache gcc-arm-none-eabi - + + - name: Configure MicroPython + shell: bash + working-directory: micropython/ports/rp2 + run: | + cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake -DMICROPY_BOARD=${{matrix.board}} + - name: Build MicroPython shell: bash working-directory: micropython/ports/rp2 run: | - make USER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake BOARD=${{matrix.board}} -j2 + ccache --zero-stats || true + cmake --build build-${{matrix.board}} -j 2 + ccache --show-stats || true - name: Rename .uf2 for artifact shell: bash working-directory: micropython/ports/rp2/build-${{matrix.board}} - run: cp firmware.uf2 ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + run: cp firmware.uf2 $RELEASE_FILE - name: Store .uf2 as artifact uses: actions/upload-artifact@v2 with: - name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - path: micropython/ports/rp2/build-${{matrix.board}}/${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + name: ${{env.RELEASE_FILE}} + path: micropython/ports/rp2/build-${{matrix.board}}/${{env.RELEASE_FILE}} - name: Upload .uf2 if: github.event_name == 'release' @@ -115,5 +132,5 @@ jobs: with: asset_path: micropython/ports/rp2/build-${{matrix.board}}/firmware.uf2 upload_url: ${{github.event.release.upload_url}} - asset_name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-${{matrix.board}}-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + asset_name: ${{env.RELEASE_FILE}} asset_content_type: application/octet-stream From fccdbd28af86cfe00190eec44d0187e90d0c683f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 00:29:47 +0000 Subject: [PATCH 03/12] CI: Use ccache --- .github/workflows/micropython.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 49d821a7..916199ee 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -80,10 +80,10 @@ jobs: uses: actions/cache@v2 with: path: /home/runner/.ccache - key: ccache-micropython-${{github.ref}}-${{github.sha}} + key: ccache-micropython-${{matrix.name}}-${{github.ref}}-${{github.sha}} restore-keys: | - ccache-micropython-${{github.ref}} - ccache-micropython- + ccache-micropython-${{matrix.name}}-${{github.ref}} + ccache-micropython-${{matrix.name}}- - name: Workspace Cache uses: actions/cache@v2 @@ -103,7 +103,7 @@ jobs: shell: bash working-directory: micropython/ports/rp2 run: | - cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake -DMICROPY_BOARD=${{matrix.board}} + cmake -S . -B build-${{matrix.board}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/micropython.cmake -DMICROPY_BOARD=${{matrix.board}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Build MicroPython shell: bash From 8e8ac885e240e526cd37e80d74556ff606665be0 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 00:53:39 +0000 Subject: [PATCH 04/12] CI: Do not regen workspace cache --- .github/workflows/micropython.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 916199ee..dad94e90 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -14,8 +14,19 @@ jobs: runs-on: ubuntu-20.04 name: Dependencies steps: + - name: Workspace Cache + id: cache + uses: actions/cache@v2 + with: + path: ${{runner.workspace}} + key: workspace-micropython-${{github.ref}}-${{github.sha}} + restore-keys: | + workspace-${{github.ref}} + workspace-micropython- + # Check out MicroPython - name: Checkout MicroPython + if: steps.cache.outputs.cache-hit != 'true' uses: actions/checkout@v2 with: repository: micropython/micropython @@ -24,39 +35,35 @@ jobs: path: micropython - uses: actions/checkout@v2 + if: steps.cache.outputs.cache-hit != 'true' with: submodules: true path: pimoroni-pico-${{ github.sha }} # Copy Python module files - name: Copy modules + if: steps.cache.outputs.cache-hit != 'true' run: | cp -r pimoroni-pico-${GITHUB_SHA}/micropython/modules_py/* micropython/ports/rp2/modules/ - name: Fetch base MicroPython submodules + if: steps.cache.outputs.cache-hit != 'true' shell: bash working-directory: micropython run: git submodule update --init - name: Fetch Pico SDK submodules + if: steps.cache.outputs.cache-hit != 'true' shell: bash working-directory: micropython/lib/pico-sdk run: git submodule update --init - name: Build mpy-cross + if: steps.cache.outputs.cache-hit != 'true' shell: bash working-directory: micropython/mpy-cross run: make - - name: Cache - uses: actions/cache@v2 - with: - path: ${{runner.workspace}} - key: workspace-micropython-${{github.ref}}-${{github.sha}} - restore-keys: | - workspace-${{github.ref}} - workspace-micropython- - build: needs: deps name: Build ${{matrix.board}} From 6af3e22bc3a6891f5722d98cdcf385d3612caf2a Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 00:57:56 +0000 Subject: [PATCH 05/12] CI: Always checkout latest --- .github/workflows/micropython.yml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index dad94e90..f0043203 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -34,18 +34,6 @@ jobs: submodules: false # MicroPython submodules are hideously broken path: micropython - - uses: actions/checkout@v2 - if: steps.cache.outputs.cache-hit != 'true' - with: - submodules: true - path: pimoroni-pico-${{ github.sha }} - - # Copy Python module files - - name: Copy modules - if: steps.cache.outputs.cache-hit != 'true' - run: | - cp -r pimoroni-pico-${GITHUB_SHA}/micropython/modules_py/* micropython/ports/rp2/modules/ - - name: Fetch base MicroPython submodules if: steps.cache.outputs.cache-hit != 'true' shell: bash @@ -105,6 +93,16 @@ jobs: if: runner.os == 'Linux' run: | sudo apt update && sudo apt install ccache gcc-arm-none-eabi + + - uses: actions/checkout@v2 + with: + submodules: true + path: pimoroni-pico-${{ github.sha }} + + # Copy Python module files + - name: Copy modules + run: | + cp -r pimoroni-pico-${GITHUB_SHA}/micropython/modules_py/* micropython/ports/rp2/modules/ - name: Configure MicroPython shell: bash From 97de2e90e19a33515cc4837fcbba4570cbd197ff Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 01:06:19 +0000 Subject: [PATCH 06/12] CI: Key cache on MicroPython version --- .github/workflows/micropython.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index f0043203..258f0ca8 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -19,10 +19,9 @@ jobs: uses: actions/cache@v2 with: path: ${{runner.workspace}} - key: workspace-micropython-${{github.ref}}-${{github.sha}} + key: workspace-micropython-${{env.MICROPYTHON_VERSION}} restore-keys: | - workspace-${{github.ref}} - workspace-micropython- + workspace-micropython-${{env.MICROPYTHON_VERSION}} # Check out MicroPython - name: Checkout MicroPython @@ -84,10 +83,9 @@ jobs: uses: actions/cache@v2 with: path: ${{runner.workspace}} - key: workspace-micropython-${{github.ref}}-${{github.sha}} + key: workspace-micropython-${{env.MICROPYTHON_VERSION}} restore-keys: | - workspace-${{github.ref}} - workspace-micropython- + workspace-micropython-${{env.MICROPYTHON_VERSION}} - name: Install Compiler & CCache if: runner.os == 'Linux' From 2fd0330f630b0550853d5a6779967fb229412d1f Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 09:21:09 +0000 Subject: [PATCH 07/12] CI: Move modules_py copy to CMake --- .github/workflows/micropython.yml | 5 ----- micropython/modules/micropython.cmake | 3 +++ micropython/modules_py/modules_py.cmake | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 micropython/modules_py/modules_py.cmake diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 258f0ca8..6c679013 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -97,11 +97,6 @@ jobs: submodules: true path: pimoroni-pico-${{ github.sha }} - # Copy Python module files - - name: Copy modules - run: | - cp -r pimoroni-pico-${GITHUB_SHA}/micropython/modules_py/* micropython/ports/rp2/modules/ - - name: Configure MicroPython shell: bash working-directory: micropython/ports/rp2 diff --git a/micropython/modules/micropython.cmake b/micropython/modules/micropython.cmake index 7f554695..4f2ea23b 100644 --- a/micropython/modules/micropython.cmake +++ b/micropython/modules/micropython.cmake @@ -1,6 +1,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/../../) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../") include(pimoroni_i2c/micropython) @@ -41,3 +42,5 @@ include(pico_wireless/micropython) include(plasma/micropython) include(hub75/micropython) include(ulab/code/micropython) + +include(modules_py/modules_py) \ No newline at end of file diff --git a/micropython/modules_py/modules_py.cmake b/micropython/modules_py/modules_py.cmake new file mode 100644 index 00000000..3b18ff34 --- /dev/null +++ b/micropython/modules_py/modules_py.cmake @@ -0,0 +1,20 @@ +function (copy_module TARGET SRC DST) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py + + COMMAND + cp ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py + + DEPENDS ${src} + ) + + target_sources(${TARGET} INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/../modules/${DST}.py) +endfunction() + +# Create a dummy usermod to hang our .py copies from +add_library(usermod_modules_py INTERFACE) +target_link_libraries(usermod INTERFACE usermod_modules_py) + +# .py files to copy from modules_py to ports/rp2/modules +copy_module(usermod_modules_py ${CMAKE_CURRENT_LIST_DIR}/picosystem.py picosystem) +copy_module(usermod_modules_py ${CMAKE_CURRENT_LIST_DIR}/pimoroni.py pimoroni) From 576a2d9ebfaef8455caed37d65c4e1f7578b7bba Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 09:33:51 +0000 Subject: [PATCH 08/12] CI: Add Pico LiPo 4MB --- .github/workflows/micropython.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 6c679013..c94c05ba 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -62,6 +62,8 @@ jobs: board: PICO - name: tiny2040 board: PIMORONI_TINY2040 + - name: picolipo_4mb + board: PIMORONI_PICOLIPO_4MB - name: picolipo_16mb board: PIMORONI_PICOLIPO_16MB From ac12fa236b2143c0bb350c975671651a60fffff8 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 10:00:27 +0000 Subject: [PATCH 09/12] CI: Update Badger 2040 workflow --- .github/workflows/micropython-badger2040.yml | 109 ++++++++++++------- 1 file changed, 72 insertions(+), 37 deletions(-) diff --git a/.github/workflows/micropython-badger2040.yml b/.github/workflows/micropython-badger2040.yml index 3c14439f..ad9186e6 100644 --- a/.github/workflows/micropython-badger2040.yml +++ b/.github/workflows/micropython-badger2040.yml @@ -7,28 +7,28 @@ on: types: [created] env: - # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) MICROPYTHON_VERSION: v1.18 - BUILD_TYPE: Release - BOARD_TYPE: PICO + BOARD_TYPE: PICO + # MicroPython version will be contained in github.event.release.tag_name for releases + RELEASE_FILE: pimoroni-badger2040-${{github.event.release.tag_name || github.sha}}-micropython.uf2 jobs: - build: - name: ${{matrix.name}} - strategy: - matrix: - include: - - os: ubuntu-20.04 - name: Linux - cache-key: linux - cmake-args: '-DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk' - apt-packages: clang-tidy gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib - - runs-on: ${{matrix.os}} - + deps: + runs-on: ubuntu-20.04 + name: Dependencies steps: + - name: Workspace Cache + id: cache + uses: actions/cache@v2 + with: + path: ${{runner.workspace}} + key: workspace-micropython-${{env.MICROPYTHON_VERSION}} + restore-keys: | + workspace-micropython-${{env.MICROPYTHON_VERSION}} + # Check out MicroPython - name: Checkout MicroPython + if: steps.cache.outputs.cache-hit != 'true' uses: actions/checkout@v2 with: repository: micropython/micropython @@ -36,6 +36,47 @@ jobs: submodules: false # MicroPython submodules are hideously broken path: micropython + - name: Fetch base MicroPython submodules + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + working-directory: micropython + run: git submodule update --init + + - name: Fetch Pico SDK submodules + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + working-directory: micropython/lib/pico-sdk + run: git submodule update --init + + - name: Build mpy-cross + if: steps.cache.outputs.cache-hit != 'true' + shell: bash + working-directory: micropython/mpy-cross + run: make + + build: + needs: deps + name: Build Badger 2040 + runs-on: ubuntu-20.04 + + steps: + - name: Compiler Cache + uses: actions/cache@v2 + with: + path: /home/runner/.ccache + key: ccache-micropython-badger2040-${{github.ref}}-${{github.sha}} + restore-keys: | + ccache-micropython-badger2040-${{github.ref}} + ccache-micropython-badger2040- + + - name: Workspace Cache + uses: actions/cache@v2 + with: + path: ${{runner.workspace}} + key: workspace-micropython-${{env.MICROPYTHON_VERSION}} + restore-keys: | + workspace-micropython-${{env.MICROPYTHON_VERSION}} + - uses: actions/checkout@v2 with: submodules: true @@ -43,48 +84,42 @@ jobs: # Copy Python module files - name: HACK - Copy board config fixup + if: env.BOARD_TYPE == 'PICO' run: | cp pimoroni-pico-${GITHUB_SHA}/micropython/badger2040-mpconfigboard.h micropython/ports/rp2/boards/PICO/mpconfigboard.h # Linux deps - - name: Install deps + - name: Install Compiler & CCache if: runner.os == 'Linux' run: | - sudo apt update && sudo apt install ${{matrix.apt-packages}} + sudo apt update && sudo apt install ccache gcc-arm-none-eabi python3 -m pip install pillow - - name: Fetch base MicroPython submodules + - name: Configure MicroPython shell: bash - working-directory: micropython - run: git submodule update --init - - - name: Fetch Pico SDK submodules - shell: bash - working-directory: micropython/lib/pico-sdk - run: git submodule update --init - - - name: Build mpy-cross - shell: bash - working-directory: micropython/mpy-cross - run: make + working-directory: micropython/ports/rp2 + run: | + cmake -S . -B build-${{env.BOARD_TYPE}} -DPICO_BUILD_DOCS=0 -DUSER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/badger2040-micropython.cmake -DMICROPY_BOARD=${{env.BOARD_TYPE}} -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache - name: Build MicroPython shell: bash working-directory: micropython/ports/rp2 - run: make USER_C_MODULES=../../../pimoroni-pico-${GITHUB_SHA}/micropython/modules/badger2040-micropython.cmake -j2 + run: | + ccache --zero-stats || true + cmake --build build-${{env.BOARD_TYPE}} -j 2 + ccache --show-stats || true - name: Rename .uf2 for artifact shell: bash working-directory: micropython/ports/rp2/build-${{env.BOARD_TYPE}} run: | - cp firmware.uf2 ${{github.event.repository.name}}-${{github.sha}}-badger2040-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - cp firmware.uf2 ${{github.event.repository.name}}-${{github.event.release.tag_name}}-badger2040-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + cp firmware.uf2 ${{env.RELEASE_FILE}} - name: Store .uf2 as artifact uses: actions/upload-artifact@v2 with: - name: ${{github.event.repository.name}}-${{github.sha}}-badger2040-micropython-${{env.MICROPYTHON_VERSION}}.uf2 - path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{github.event.repository.name}}-${{github.sha}}-badger2040-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + name: ${{env.RELEASE_FILE}} + path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/${{env.RELEASE_FILE}} - name: Upload .uf2 if: github.event_name == 'release' @@ -94,5 +129,5 @@ jobs: with: asset_path: micropython/ports/rp2/build-${{env.BOARD_TYPE}}/firmware.uf2 upload_url: ${{github.event.release.upload_url}} - asset_name: ${{github.event.repository.name}}-${{github.event.release.tag_name}}-badger2040-micropython-${{env.MICROPYTHON_VERSION}}.uf2 + asset_name: ${{env.RELEASE_FILE}} asset_content_type: application/octet-stream From df090ac8e88f0d71cddece219bc0de9a051b9e75 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 10:24:39 +0000 Subject: [PATCH 10/12] CI: Cache CMake build --- .github/workflows/cmake.yml | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index faa9b161..4f6af635 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -18,7 +18,7 @@ jobs: name: Linux cache-key: linux cmake-args: '-DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk -DPICO_SDK_POST_LIST_DIRS=$GITHUB_WORKSPACE/pico-extras' - apt-packages: clang-tidy gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib + apt-packages: ccache gcc-arm-none-eabi runs-on: ${{matrix.os}} @@ -26,6 +26,15 @@ jobs: PICO_SDK_PATH: $GITHUB_WORKSPACE/pico-sdk steps: + - name: Compiler Cache + uses: actions/cache@v2 + with: + path: /home/runner/.ccache + key: ccache-cmake-${{github.ref}}-${{github.sha}} + restore-keys: | + ccache-cmake-${{github.ref}} + ccache-cmake + - uses: actions/checkout@v2 with: submodules: true @@ -44,7 +53,7 @@ jobs: with: repository: raspberrypi/pico-extras path: pico-extras - submodules: false # lwip breaks audio submodule fetchin + submodules: false # lwip breaks audio submodule fetching # Linux deps - name: Install deps @@ -58,10 +67,12 @@ jobs: - name: Configure CMake shell: bash working-directory: ${{runner.workspace}}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE ${{matrix.cmake-args}} + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ${{matrix.cmake-args}} - name: Build working-directory: ${{runner.workspace}}/build shell: bash run: | + ccache --zero-stats || true cmake --build . --config $BUILD_TYPE -j 2 + ccache --show-stats || true From b7061b9dd70ce32d9404669626d77272d2265e3b Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 10:48:36 +0000 Subject: [PATCH 11/12] CI: EXPERIMENTAL: wget ARM GCC toolchain --- .github/workflows/cmake.yml | 13 +++++++++++-- .github/workflows/micropython-badger2040.yml | 11 ++++++++++- .github/workflows/micropython-with-blinka.yml | 11 ++++++++++- .github/workflows/micropython.yml | 11 ++++++++++- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 4f6af635..412b1f83 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -18,7 +18,7 @@ jobs: name: Linux cache-key: linux cmake-args: '-DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk -DPICO_SDK_POST_LIST_DIRS=$GITHUB_WORKSPACE/pico-extras' - apt-packages: ccache gcc-arm-none-eabi + apt-packages: ccache runs-on: ${{matrix.os}} @@ -61,13 +61,22 @@ jobs: run: | sudo apt update && sudo apt install ${{matrix.apt-packages}} + - name: Install ARM Toolchain + if: runner.os == 'Linux' + working-directory: ${{runner.workspace}} + run: | + wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 + tar xf gcc-*.tar.bz2 + cd gcc*/bin + pwd >> $GITHUB_PATH + - name: Create Build Environment run: cmake -E make_directory ${{runner.workspace}}/build - name: Configure CMake shell: bash working-directory: ${{runner.workspace}}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ${{matrix.cmake-args}} + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache ${{matrix.cmake-args}} - name: Build working-directory: ${{runner.workspace}}/build diff --git a/.github/workflows/micropython-badger2040.yml b/.github/workflows/micropython-badger2040.yml index ad9186e6..ff469c40 100644 --- a/.github/workflows/micropython-badger2040.yml +++ b/.github/workflows/micropython-badger2040.yml @@ -92,9 +92,18 @@ jobs: - name: Install Compiler & CCache if: runner.os == 'Linux' run: | - sudo apt update && sudo apt install ccache gcc-arm-none-eabi + sudo apt update && sudo apt install ccache python3 -m pip install pillow + - name: Install ARM Toolchain + if: runner.os == 'Linux' + working-directory: ${{runner.workspace}} + run: | + wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 + tar xf gcc-*.tar.bz2 + cd gcc*/bin + pwd >> $GITHUB_PATH + - name: Configure MicroPython shell: bash working-directory: micropython/ports/rp2 diff --git a/.github/workflows/micropython-with-blinka.yml b/.github/workflows/micropython-with-blinka.yml index 1a74049f..0250061e 100644 --- a/.github/workflows/micropython-with-blinka.yml +++ b/.github/workflows/micropython-with-blinka.yml @@ -24,7 +24,7 @@ jobs: name: Linux cache-key: linux cmake-args: '-DPICO_SDK_PATH=$GITHUB_WORKSPACE/pico-sdk' - apt-packages: clang-tidy gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib + apt-packages: ccache runs-on: ${{matrix.os}} @@ -82,6 +82,15 @@ jobs: run: | sudo apt update && sudo apt install ${{matrix.apt-packages}} + - name: Install ARM Toolchain + if: runner.os == 'Linux' + working-directory: ${{runner.workspace}} + run: | + wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 + tar xf gcc-*.tar.bz2 + cd gcc*/bin + pwd >> $GITHUB_PATH + - name: Fetch base MicroPython submodules shell: bash working-directory: micropython diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index c94c05ba..949347b6 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -92,7 +92,16 @@ jobs: - name: Install Compiler & CCache if: runner.os == 'Linux' run: | - sudo apt update && sudo apt install ccache gcc-arm-none-eabi + sudo apt update && sudo apt install ccache + + - name: Install ARM Toolchain + if: runner.os == 'Linux' + working-directory: ${{runner.workspace}} + run: | + wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 + tar xf gcc-*.tar.bz2 + cd gcc*/bin + pwd >> $GITHUB_PATH - uses: actions/checkout@v2 with: From dece2aac85d760b3a0998e0ce9b594a275ccbe91 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Fri, 11 Mar 2022 12:20:27 +0000 Subject: [PATCH 12/12] CI: More complete Python linting --- .github/workflows/python.yml | 35 ++- .../hershey_font_converter/convert.py | 221 +++++++++--------- .../badger2040/image_converter/convert.py | 12 +- .../badger2040/image_converter/data_to_py.py | 5 +- 4 files changed, 134 insertions(+), 139 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index a2792aa3..58fbbb40 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -6,30 +6,25 @@ on: jobs: build: - name: ${{matrix.name}} - strategy: - matrix: - include: - - os: ubuntu-20.04 - name: Linux - cache-key: linux - apt-packages: python3 python3-pip - python-packages: flake8 - - runs-on: ${{matrix.os}} + name: Python Linting + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - # Linux deps - - name: Install deps - if: runner.os == 'Linux' - run: | - sudo apt update && sudo apt install ${{matrix.apt-packages}} - - name: Install Python Deps - run: python3 -m pip install ${{matrix.python-packages}} + run: python3 -m pip install flake8 - - name: Lint + - name: Lint micropython/modules_py shell: bash run: | - python3 -m flake8 --ignore E501 micropython/modules_py micropython/examples \ No newline at end of file + python3 -m flake8 --ignore E501 micropython/modules_py + + - name: Lint micropython/examples + shell: bash + run: | + python3 -m flake8 --ignore E501 micropython/examples + + - name: Lint .py tools in C++ examples + shell: bash + run: | + python3 -m flake8 --ignore E501 examples \ No newline at end of file diff --git a/examples/badger2040/hershey_font_converter/convert.py b/examples/badger2040/hershey_font_converter/convert.py index 51d9f9bf..57df3823 100755 --- a/examples/badger2040/hershey_font_converter/convert.py +++ b/examples/badger2040/hershey_font_converter/convert.py @@ -3,156 +3,157 @@ # converts Hershey fonts into a format easier to consume by the Badger2040 # e-ink badge library - the result can be piped directly into a .hpp file. -import argparse, sys, os, glob +import argparse from pathlib import Path parser = argparse.ArgumentParser( - description='Converts Hershey fonts into the format used by Badger2040.') -parser.add_argument('file', nargs="+", help='input files to convert') + description="Converts Hershey fonts into the format used by Badger2040." +) +parser.add_argument("file", nargs="+", help="input files to convert") + +options = parser.parse_args() -options = None -try: - options = parser.parse_args() -except: - parser.print_help() - sys.exit(0) def convert_font(data): - # parse hershey font data file, the file format contains one record per - # character with the format: - # - # 2761 8MXP[OZPYQZQ[P]N_ - # - # first 5 characters: represent the character id (or a dummy value - # of 12345). if it is a character id then a separate file contains the - # mapping information to convert that into an ascii table entry. if all of - # the ids are 12345 then it seems that the files contain 95 entries that - # start from ascii character 32 (space) in order - # - # next 3 characters: number of vertices (including special left/right - # bounds value) - # - # next 2 characters: represent the "left" and "right" offsets for this - # character, to convert you must subtract 'R' from them. this pair counts - # as the first "vertex" - # - # subsequent pairs of characters: represent each vertex, as before converted - # into numbers by subtracting 'R'. there are vertex count (-1) of these - # - # note! within the vertex data can be extra newline characters which must - # be ignored. + # parse hershey font data file, the file format contains one record per + # character with the format: + # + # 2761 8MXP[OZPYQZQ[P]N_ + # + # first 5 characters: represent the character id (or a dummy value + # of 12345). if it is a character id then a separate file contains the + # mapping information to convert that into an ascii table entry. if all of + # the ids are 12345 then it seems that the files contain 95 entries that + # start from ascii character 32 (space) in order + # + # next 3 characters: number of vertices (including special left/right + # bounds value) + # + # next 2 characters: represent the "left" and "right" offsets for this + # character, to convert you must subtract 'R' from them. this pair counts + # as the first "vertex" + # + # subsequent pairs of characters: represent each vertex, as before converted + # into numbers by subtracting 'R'. there are vertex count (-1) of these + # + # note! within the vertex data can be extra newline characters which must + # be ignored. - vertex_data = [] - char_data = {} + vertex_data = [] + char_data = {} - auto_char_code = 0 + auto_char_code = 0 - # we'll loop, extracting one character per iteration, until all of the - # data is consumed - while(len(data) > 0): - # extract character id - char_id = int(data[0:5]) + # we'll loop, extracting one character per iteration, until all of the + # data is consumed + while len(data) > 0: + char_code = auto_char_code + auto_char_code += 1 - char_code = auto_char_code - auto_char_code += 1 + # extract vertex count + vertex_count = int(data[5:8]) + vertex_count -= 1 # remove one for the bounds data - # extract vertex count - vertex_count = int(data[5:8]) - vertex_count -= 1 # remove one for the bounds data + # extract bounds + left = ord(data[8:9]) - ord("R") + right = ord(data[9:10]) - ord("R") - # extract bounds - left = ord(data[8:9]) - ord("R") - right = ord(data[9:10]) - ord("R") + char_data[char_code] = { + "width": right - left, + "vertex_count": vertex_count, + "first_vertex_offset": len(vertex_data), + } - char_data[char_code] = { - "width": right - left, - "vertex_count": vertex_count, - "first_vertex_offset": len(vertex_data) - } + # work out expected total length of character data + char_data_len = 10 + (vertex_count * 2) - # work out expected total length of character data - char_data_len = 10 + (vertex_count * 2) + # if there are any newlines within this data then remove them before we + # move on the parse the vertices + while data.find("\n", char_data_len) != -1: + data = data.replace("\n", "", 1) - # if there are any newlines within this data then remove them before we - # move on the parse the vertices - while data.find('\n', char_data_len) != -1: - data = data.replace('\n', '', 1) + for i in range(0, vertex_count): + offset = 10 + (i * 2) + if data[offset:offset + 2] == " R": + # pen up for one + x = -128 + y = -128 + else: + x = ord(data[offset + 0:offset + 1]) - ord("R") - left + y = ord(data[offset + 1:offset + 2]) - ord("R") - for i in range(0, vertex_count): - offset = 10 + (i * 2) - if data[offset:offset + 2] == " R": - # pen up for one - x = -128 - y = -128 - else: - x = ord(data[offset + 0:offset + 1]) - ord("R") - left - y = ord(data[offset + 1:offset + 2]) - ord("R") + vertex_data.append(str(x)) + vertex_data.append(str(y)) - vertex_data.append(str(x)) - vertex_data.append(str(y)) + data = data[char_data_len:] - data = data[char_data_len:] + font_name = Path(input_filename).stem - font_name = Path(input_filename).stem - - # create code for all of the vertices - vertex_code = '''\ + # create code for all of the vertices + vertex_code = """\ static const int8_t {font_name}_vertices[{count}] = {{ {vertices} }}; - '''.format(font_name=font_name, count=len(vertex_data), vertices=", ".join(vertex_data)) + """.format( + font_name=font_name, count=len(vertex_data), vertices=", ".join(vertex_data) + ) - # create code for chars and font - # - # struct hershey_font_glyph_t { - # uint32_t width; // character width - # uint32_t vertex_count; // number of vertices - # int8_t *vertices; // vertex data (indices: even = x, odd = y) - # }; - chars = [] - for i in range(0, 95): - if i in char_data: - chars.append( - " {{.width={width}, .vertex_count={vertex_count}, .vertices=&{font_name}_vertices[{offset}]}}".format( - width=char_data[i]["width"], - vertex_count=char_data[i]["vertex_count"], - font_name=font_name, - offset=char_data[i]["first_vertex_offset"] - )) - else: - chars.append(" {.width=0, .vertex_count=0, .vertices=nullptr}") + # create code for chars and font + # + # struct hershey_font_glyph_t { + # uint32_t width; // character width + # uint32_t vertex_count; // number of vertices + # int8_t *vertices; // vertex data (indices: even = x, odd = y) + # }; + chars = [] + for i in range(0, 95): + if i in char_data: + chars.append( + " {{.width={width}, .vertex_count={vertex_count}, .vertices=&{font_name}_vertices[{offset}]}}".format( + width=char_data[i]["width"], + vertex_count=char_data[i]["vertex_count"], + font_name=font_name, + offset=char_data[i]["first_vertex_offset"], + ) + ) + else: + chars.append(" {.width=0, .vertex_count=0, .vertices=nullptr}") - # struct hershey_font_t { - # hershey_font_glyph_t chars[95]; - # }; - font_code = '''\ + # struct hershey_font_t { + # hershey_font_glyph_t chars[95]; + # }; + font_code = """\ static const hershey_font_t {font_name} {{ .chars = {{ {chars} }} }}; - '''.format(font_name=font_name, chars=",\n".join(chars)) + """.format( + font_name=font_name, chars=",\n".join(chars) + ) - print(vertex_code) + print(vertex_code) - print(font_code) + print(font_code) - return """ {{ \"{font_name}\", &{font_name} }}""".format(font_name=font_name) + return """ {{ \"{font_name}\", &{font_name} }}""".format(font_name=font_name) # create map of font name to font structure font_list = [] for input_filename in options.file: - input_file = open(input_filename, mode='r') - data = input_file.read() - input_file.close() + input_file = open(input_filename, mode="r") + data = input_file.read() + input_file.close() - font_list.append(convert_font(data)) + font_list.append(convert_font(data)) -map_code = '''\ +map_code = """\ std::map fonts = {{ {font_list} }}; -'''.format(font_list=",\n".join(font_list)) +""".format( + font_list=",\n".join(font_list) +) -print(map_code) \ No newline at end of file +print(map_code) diff --git a/examples/badger2040/image_converter/convert.py b/examples/badger2040/image_converter/convert.py index 6e793189..d875f78f 100755 --- a/examples/badger2040/image_converter/convert.py +++ b/examples/badger2040/image_converter/convert.py @@ -23,13 +23,13 @@ options = parser.parse_args() def convert_image(img): if options.resize: - img = img.resize((296, 128)) # resize + img = img.resize((296, 128)) # resize try: - enhancer = ImageEnhance.Contrast(img) - img = enhancer.enhance(2.0) + enhancer = ImageEnhance.Contrast(img) + img = enhancer.enhance(2.0) except ValueError: - pass - img = img.convert("1") # convert to black and white + pass + img = img.convert("1") # convert to black and white return img @@ -68,5 +68,3 @@ static const uint8_t {image_name}[{count}] = {{ '''.format(image_name=image_name, count=len(output_data), byte_data=", ".join(str(b) for b in output_data)) print(image_code) - - diff --git a/examples/badger2040/image_converter/data_to_py.py b/examples/badger2040/image_converter/data_to_py.py index da604909..e5515f13 100644 --- a/examples/badger2040/image_converter/data_to_py.py +++ b/examples/badger2040/image_converter/data_to_py.py @@ -85,9 +85,10 @@ STR02 = """_mvdata = memoryview(_data) def data(): return _mvdata - + """ + def write_func(stream, name, arg): stream.write('def {}():\n return {}\n\n'.format(name, arg)) @@ -123,6 +124,7 @@ def quit(msg): print(msg) sys.exit(1) + DESC = """data_to_py.py Utility to convert an arbitrary binary file to Python source. Sample usage: @@ -137,7 +139,6 @@ if __name__ == "__main__": parser.add_argument('outfile', type=str, help='Path and name of output file. Must have .py extension.') - args = parser.parse_args() if not os.path.isfile(args.infile):