Skip to content

Commit 79bb644

Browse files
authored
Develop (cnadler86#3)
Adds Workflow capabilities for automatic builds for generic boards. Fixes cnadler86#2. Draft for gather precompiled firmware over Workflow.
1 parent 38f3a1f commit 79bb644

File tree

6 files changed

+194
-167
lines changed

6 files changed

+194
-167
lines changed

.github/ESP32.yaml

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/ESP32.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Build MicroPython Camera for ESP32 Boards
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
pull_request:
7+
branches:
8+
- master
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
setup-environment:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
# Get the latest MicroPython release
19+
- name: Get MicroPython latest release
20+
run: |
21+
MPY_RELEASE=$(curl --silent "https://api.github.com/repos/micropython/micropython/releases/latest" | jq -r .tag_name)
22+
echo "MPY_RELEASE=${MPY_RELEASE}" >> $GITHUB_ENV
23+
24+
# Cache ESP-IDF dependencies and MicroPython
25+
- name: Cache ESP-IDF and MicroPython
26+
id: cache_esp_idf
27+
uses: actions/cache@v4
28+
with:
29+
lookup-only: true
30+
path: |
31+
~/esp-idf/
32+
~/.espressif/
33+
!~/.espressif/dist/
34+
~/.cache/pip/
35+
~/micropython/
36+
key: mpy-${{ env.MPY_RELEASE }}
37+
restore-keys: mpy-
38+
39+
# Install ESP-IDF dependencies (if not cached)
40+
- name: Install dependencies
41+
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
42+
run: |
43+
sudo apt-get update
44+
sudo apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0
45+
46+
# Clone the latest MicroPython release (if not cached)
47+
- name: Clone MicroPython latest release
48+
id: clone-micropython
49+
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
50+
run: |
51+
echo "Cloning MicroPython release: $MPY_RELEASE"
52+
cd ~
53+
git clone --depth 1 --branch ${{ env.MPY_RELEASE }} https://github.com/micropython/micropython.git
54+
cd micropython
55+
git submodule update --init --depth 1
56+
cd mpy-cross
57+
make
58+
cd ~/micropython/ports/esp32
59+
make submodules
60+
echo "Micropython setup successfully"
61+
source ~/micropython/tools/ci.sh && echo "IDF_VER=$IDF_VER" >> $GITHUB_ENV
62+
63+
# Download and set up ESP-IDF (if not cached)
64+
- name: Set up ESP-IDF
65+
id: export-idf
66+
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
67+
run: |
68+
cd ~
69+
git clone --depth 1 --branch release/v5.2 https://github.com/espressif/esp-idf.git
70+
# git clone --depth 1 --branch ${{ env.IDF_VER }} https://github.com/espressif/esp-idf.git
71+
git -C esp-idf submodule update --init --recursive --filter=tree:0
72+
cd esp-idf
73+
./install.sh all
74+
cd components
75+
git clone https://github.com/espressif/esp32-camera
76+
cd ~/esp-idf/
77+
source ./export.sh
78+
79+
# Dynamically create jobs for each board
80+
build:
81+
needs: setup-environment
82+
runs-on: ubuntu-24.04
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
board:
87+
- ESP32_GENERIC-SPIRAM
88+
- ESP32_GENERIC_S2
89+
- ESP32_GENERIC_S3
90+
- ESP32_GENERIC_S3-SPIRAM_OCT
91+
- ESP32_GENERIC_S3-FLASH_4M
92+
93+
steps:
94+
# Get the latest MicroPython release
95+
- name: Get MicroPython latest release
96+
run: |
97+
MPY_RELEASE=$(curl --silent "https://api.github.com/repos/micropython/micropython/releases/latest" | jq -r .tag_name)
98+
echo "MPY_RELEASE=${MPY_RELEASE}" >> $GITHUB_ENV
99+
100+
# Cache ESP-IDF dependencies and MicroPython
101+
- name: Cache ESP-IDF and MicroPython
102+
uses: actions/cache@v4
103+
with:
104+
path: |
105+
~/esp-idf/
106+
~/.espressif/
107+
!~/.espressif/dist/
108+
~/.cache/pip/
109+
~/micropython/
110+
key: mpy-${{ env.MPY_RELEASE }}
111+
restore-keys: mpy-
112+
113+
- name: Checkout repository
114+
uses: actions/checkout@v4
115+
116+
- name: Install ESP-IDF dependencies
117+
run: |
118+
sudo apt-get update
119+
sudo apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 build-essential pkg-config
120+
121+
# Build MicroPython for each board
122+
- name: Build MicroPython
123+
run: |
124+
cd ~/micropython/ports/esp32
125+
source ~/esp-idf/export.sh
126+
127+
# Check if a variant is defined and adjust the make command
128+
IFS='-' read -r BOARD_NAME BOARD_VARIANT <<< "${{ matrix.board }}"
129+
if [ -n "${BOARD_VARIANT}" ]; then
130+
make USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake BOARD=$BOARD_NAME BOARD_VARIANT=$BOARD_VARIANT all
131+
else
132+
make USER_C_MODULES=${{ github.workspace }}/src/micropython.cmake BOARD=$BOARD_NAME all
133+
fi
134+
mv ~/micropython/ports/esp32/build-${{ matrix.board }}/firmware.bin ~/${{ matrix.board }}.bin
135+
136+
- name: Upload firmware artifact
137+
uses: actions/upload-artifact@v4
138+
with:
139+
name: firmware-${{ matrix.board }}
140+
path: ~/${{ matrix.board }}.bin
141+
retention-days: 1

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ This project aims to support cameras in different ports in micropython, starting
33
At the moment, this is a micropython user module, but it might get in the micropython repo in the future.
44
The API is stable, but it might change without previous anounce.
55

6-
## Setup build environment
6+
## Precomiled FW (the easy way)
7+
If you are not familiar with building a custom firmware, you can go to the actions tab and start the build workflow by yourself. Then, you can download one if the generic FWs that suits your board.
8+
9+
## Setup build environment (the DIY way)
710
To build the project, follow the following instructions:
811
- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.2/esp32/get-started/index.html): I used version 5.2.2, but it might work with other versions.
912
- Clone the micropython repo and this repo in a folder, e.g. "MyESPCam". I used the actual micropython master branch (between v1.23 and before 1.24).
@@ -12,7 +15,7 @@ To build the project, follow the following instructions:
1215
espressif/esp32-camera:
1316
git: https://github.com/espressif/esp32-camera
1417
```
15-
Note: Im am trying to figure out a more elegant way to do this.
18+
You can also clone the https://github.com/espressif/esp32-camera repository inside the esp-idf/components folder instead of altering the idf_component.yml file.
1619

1720
## Add camera configurations to your board (Optional, but recomended)
1821
To make things easier, add the following lines to your board config-file "mpconfigboard.h" with the respective pins and camera parameters. Otherwise you will need to pass all parameters during construction.

src/micropython.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ target_sources(usermod_mp_camera INTERFACE
55
)
66
target_include_directories(usermod_mp_camera INTERFACE
77
${CMAKE_CURRENT_LIST_DIR}
8+
${IDF_PATH}/components/esp32-camera/driver/include
9+
${IDF_PATH}/components/esp32-camera/driver/private_include
10+
${IDF_PATH}/components/esp32-camera/conversions/include
11+
${IDF_PATH}/components/esp32-camera/conversions/private_include
12+
${IDF_PATH}/components/esp32-camera/sensors/private_include
813
)
914
target_compile_definitions(usermod_mp_camera INTERFACE)
1015
target_link_libraries(usermod INTERFACE usermod_mp_camera)

src/modcamera.h

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,51 +43,22 @@
4343
#include "esp_camera.h"
4444
#include "sensor.h"
4545

46-
#ifndef MICROPY_CAMERA_PIN_PWDN
47-
#define MICROPY_CAMERA_PIN_PWDN 32
48-
#endif
49-
50-
#ifndef MICROPY_CAMERA_PIN_RESET
51-
#define MICROPY_CAMERA_PIN_RESET -1
52-
#endif
53-
54-
#ifndef MICROPY_CAMERA_PIN_SIOD
55-
#define MICROPY_CAMERA_PIN_SIOD 26
56-
#endif
57-
58-
#ifndef MICROPY_CAMERA_PIN_SIOC
59-
#define MICROPY_CAMERA_PIN_SIOC 27
46+
#if defined(MICROPY_CAMERA_PIN_SIOD) && defined(MICROPY_CAMERA_PIN_SIOC) && defined(MICROPY_CAMERA_PIN_D0) && defined(MICROPY_CAMERA_PIN_D1) && defined(MICROPY_CAMERA_PIN_D2) && \
47+
defined(MICROPY_CAMERA_PIN_D3) && defined(MICROPY_CAMERA_PIN_D4) && defined(MICROPY_CAMERA_PIN_D5) && defined(MICROPY_CAMERA_PIN_D6) && defined(MICROPY_CAMERA_PIN_D7) && \
48+
defined(MICROPY_CAMERA_PIN_PCLK) && defined(MICROPY_CAMERA_PIN_VSYNC) && defined(MICROPY_CAMERA_PIN_HREF) && defined(MICROPY_CAMERA_PIN_XCLK)
49+
#define MICROPY_CAMERA_ALL_REQ_PINS_DEFINED (1)
6050
#endif
6151

62-
#ifndef MICROPY_CAMERA_PIN_D0
63-
#define MICROPY_CAMERA_PIN_D0 5
64-
#define MICROPY_CAMERA_PIN_D1 18
65-
#define MICROPY_CAMERA_PIN_D2 19
66-
#define MICROPY_CAMERA_PIN_D3 21
67-
#define MICROPY_CAMERA_PIN_D4 36
68-
#define MICROPY_CAMERA_PIN_D5 39
69-
#define MICROPY_CAMERA_PIN_D6 34
70-
#define MICROPY_CAMERA_PIN_D7 35
71-
#endif
72-
73-
#ifndef MICROPY_CAMERA_PIN_VSYNC
74-
#define MICROPY_CAMERA_PIN_VSYNC 25
75-
#endif
76-
77-
#ifndef MICROPY_CAMERA_PIN_HREF
78-
#define MICROPY_CAMERA_PIN_HREF 23
79-
#endif
80-
81-
#ifndef MICROPY_CAMERA_PIN_PCLK
82-
#define MICROPY_CAMERA_PIN_PCLK 22
52+
#ifndef MICROPY_CAMERA_PIN_PWDN
53+
#define MICROPY_CAMERA_PIN_PWDN (-1)
8354
#endif
8455

85-
#ifndef MICROPY_CAMERA_PIN_XCLK
86-
#define MICROPY_CAMERA_PIN_XCLK 0
56+
#ifndef MICROPY_CAMERA_PIN_RESET
57+
#define MICROPY_CAMERA_PIN_RESET (-1)
8758
#endif
8859

8960
#ifndef MICROPY_CAMERA_XCLK_FREQ
90-
#define MICROPY_CAMERA_XCLK_FREQ 10
61+
#define MICROPY_CAMERA_XCLK_FREQ (10)
9162
#endif
9263

9364
#ifndef MICROPY_CAMERA_DEFAULT_FRAME_SIZE
@@ -103,11 +74,11 @@
10374
#endif
10475

10576
#ifndef MICROPY_CAMERA_FB_COUNT
106-
#define MICROPY_CAMERA_FB_COUNT 1
77+
#define MICROPY_CAMERA_FB_COUNT (1)
10778
#endif
10879

10980
#ifndef MICROPY_CAMERA_JPEG_QUALITY
110-
#define MICROPY_CAMERA_JPEG_QUALITY 15
81+
#define MICROPY_CAMERA_JPEG_QUALITY (15)
11182
#endif
11283

11384
//Supported Camera sensors

0 commit comments

Comments
 (0)