Skip to content

Commit c5f249c

Browse files
committed
Add build script, i2c objects and try newest icropython with latest idf in pipeline
1 parent 3892f22 commit c5f249c

File tree

4 files changed

+178
-32
lines changed

4 files changed

+178
-32
lines changed

.github/workflows/ESP32.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,6 @@ jobs:
5353
sudo apt-get update
5454
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
5555
56-
# Download and set up ESP-IDF (if not cached)
57-
- name: Set up ESP-IDF
58-
id: export-idf
59-
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
60-
run: |
61-
cd ~
62-
git clone --depth 1 --branch v5.4.2 https://github.com/espressif/esp-idf.git
63-
# git clone --depth 1 --branch ${{ env.IDF_VER }} https://github.com/espressif/esp-idf.git
64-
git -C esp-idf submodule update --init --recursive --filter=tree:0
65-
cd esp-idf
66-
./install.sh all
67-
source ./export.sh
68-
6956
# Clone the latest MicroPython release (if not cached)
7057
- name: Clone MicroPython latest release
7158
id: clone-micropython
@@ -75,7 +62,8 @@ jobs:
7562
cd ~/esp-idf/
7663
source ./export.sh
7764
cd ~
78-
git clone --depth 1 --branch ${{ env.MPY_RELEASE }} https://github.com/micropython/micropython.git
65+
# git clone --depth 1 --branch ${{ env.MPY_RELEASE }} https://github.com/micropython/micropython.git
66+
git clone --depth 1 https://github.com/micropython/micropython.git
7967
cd micropython
8068
# git submodule update --init --depth 1
8169
cd mpy-cross
@@ -84,6 +72,19 @@ jobs:
8472
echo "Micropython setup successfully"
8573
source ~/micropython/tools/ci.sh && echo "IDF_VER=$IDF_VER" >> $GITHUB_ENV
8674
75+
# Download and set up ESP-IDF (if not cached)
76+
- name: Set up ESP-IDF
77+
id: export-idf
78+
if: steps.cache_esp_idf.outputs.cache-hit != 'true'
79+
run: |
80+
cd ~
81+
# git clone --depth 1 --branch v5.5.1 https://github.com/espressif/esp-idf.git
82+
git clone --depth 1 --branch ${{ env.IDF_VER }} https://github.com/espressif/esp-idf.git
83+
git -C esp-idf submodule update --init --recursive --filter=tree:0
84+
cd esp-idf
85+
./install.sh all
86+
source ./export.sh
87+
8788
# Dynamically create jobs for each board
8889
build:
8990
needs: setup-environment

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,17 +338,13 @@ If you also want to include the [mp_jpeg module](https://github.com/cnadler86/mp
338338

339339
### Build the API
340340

341-
To build the project, you could do it the following way:
341+
To build the project, just use the buils script with the path to your micropython folder:
342342

343343
```bash
344-
. <path2esp-idf>/esp-idf/export.sh
345-
cd MyESPCam/micropython/ports/esp32
346-
make USER_C_MODULES=../../../../micropython-camera-API/micropython.cmake BOARD=<Your-Board> clean
347-
make USER_C_MODULES=../../../../micropython-camera-API/micropython.cmake BOARD=<Your-Board> submodules
348-
make USER_C_MODULES=../../../../micropython-camera-API/micropython.cmake BOARD=<Your-Board> all
344+
./build.sh -m path/to/micropython -b ESP32_GENERIC_S3
349345
```
350346

351-
Micropython and camera-api folders are at the same level. Note that you need those extra "/../"s while been inside the esp32 port folder.
347+
Use `./build.sh -h` to see all available options.
352348
If you experience problems, visit [MicroPython external C modules](https://docs.micropython.org/en/latest/develop/cmodules.html).
353349

354350
## Notes

build.sh

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Default values
5+
IDF_PATH_DEFAULT="$HOME/esp/esp-idf"
6+
MICROPYTHON_PATH=""
7+
IDF_PATH="$IDF_PATH_DEFAULT"
8+
BOARD=""
9+
BOARD_VARIANT=""
10+
BUILD_DIR="build-mp_camera"
11+
12+
# Parse arguments
13+
usage() {
14+
echo "Usage: $0 -m <micropython_path> [-i <idf_path>] [-b <board>] [-v <board_variant>]"
15+
echo ""
16+
echo "Options:"
17+
echo " -m <path> Path to MicroPython directory (required)"
18+
echo " -i <path> Path to ESP-IDF directory (optional, default: $IDF_PATH_DEFAULT)"
19+
echo " -b <board> Board name (optional, e.g. ESP32_GENERIC_S3)"
20+
echo " -v <variant> Board variant (optional, e.g. SPIRAM_OCT)"
21+
echo " -h Show this help message"
22+
echo ""
23+
echo "Examples:"
24+
echo " $0 -m ~/privat/micropython"
25+
echo " $0 -m ~/privat/micropython -i ~/esp/esp-idf"
26+
echo " $0 -m ~/privat/micropython -b ESP32_GENERIC_S3"
27+
echo " $0 -m ~/privat/micropython -b ESP32_GENERIC_S3 -v SPIRAM_OCT"
28+
exit 1
29+
}
30+
31+
# Parse command line options
32+
while getopts "m:i:b:v:h" opt; do
33+
case $opt in
34+
m) MICROPYTHON_PATH="$OPTARG" ;;
35+
i) IDF_PATH="$OPTARG" ;;
36+
b) BOARD="$OPTARG" ;;
37+
v) BOARD_VARIANT="$OPTARG" ;;
38+
h) usage ;;
39+
*) usage ;;
40+
esac
41+
done
42+
43+
# Check required arguments
44+
if [ -z "$MICROPYTHON_PATH" ]; then
45+
echo "Error: MicroPython path is required (-m option)"
46+
echo ""
47+
usage
48+
fi
49+
50+
# Validate paths
51+
if [ ! -d "$MICROPYTHON_PATH" ]; then
52+
echo "Error: MicroPython directory not found: $MICROPYTHON_PATH"
53+
exit 1
54+
fi
55+
56+
if [ ! -d "$IDF_PATH" ]; then
57+
echo "Error: ESP-IDF directory not found: $IDF_PATH"
58+
exit 1
59+
fi
60+
61+
if [ ! -f "$IDF_PATH/export.sh" ]; then
62+
echo "Error: ESP-IDF export.sh not found in: $IDF_PATH"
63+
exit 1
64+
fi
65+
66+
# Get absolute paths
67+
MICROPYTHON_PATH=$(realpath "$MICROPYTHON_PATH")
68+
IDF_PATH=$(realpath "$IDF_PATH")
69+
MODULE_PATH=$(dirname "$(realpath "$0")")
70+
71+
echo "=========================================="
72+
echo "Building MicroPython with IR Learn Module"
73+
echo "=========================================="
74+
echo "MicroPython path: $MICROPYTHON_PATH"
75+
echo "ESP-IDF path: $IDF_PATH"
76+
echo "Module path: $MODULE_PATH"
77+
if [ -n "$BOARD" ]; then
78+
echo "Board: $BOARD"
79+
if [ -n "$BOARD_VARIANT" ]; then
80+
echo "Board variant: $BOARD_VARIANT"
81+
BUILD_DIR="build-${BOARD_VARIANT}"
82+
fi
83+
fi
84+
echo "Build directory: $BUILD_DIR"
85+
echo "=========================================="
86+
echo ""
87+
88+
# Source ESP-IDF environment
89+
echo "Setting up ESP-IDF environment..."
90+
source "$IDF_PATH/export.sh"
91+
92+
# Change to MicroPython ESP32 port directory
93+
cd "$MICROPYTHON_PATH/ports/esp32"
94+
95+
# Build idf.py command with optional parameters
96+
IDF_CMD="idf.py -B $BUILD_DIR"
97+
98+
if [ -n "$BOARD" ]; then
99+
IDF_CMD="$IDF_CMD -D MICROPY_BOARD=$BOARD"
100+
fi
101+
102+
if [ -n "$BOARD_VARIANT" ]; then
103+
IDF_CMD="$IDF_CMD -D MICROPY_BOARD_VARIANT=$BOARD_VARIANT"
104+
fi
105+
106+
IDF_CMD="$IDF_CMD -D USER_C_MODULES=$MODULE_PATH/micropython.cmake"
107+
IDF_CMD="$IDF_CMD -D EXTRA_COMPONENT_DIRS=$MODULE_PATH"
108+
IDF_CMD="$IDF_CMD build"
109+
110+
# Build MicroPython with IR Learn module
111+
echo ""
112+
echo "Building MicroPython..."
113+
echo "Command: $IDF_CMD"
114+
eval $IDF_CMD
115+
116+
# Create firmware images
117+
echo ""
118+
echo "Creating firmware images..."
119+
cd "$BUILD_DIR"
120+
121+
python "$MICROPYTHON_PATH/ports/esp32/makeimg.py" \
122+
sdkconfig \
123+
bootloader/bootloader.bin \
124+
partition_table/partition-table.bin \
125+
micropython.bin \
126+
firmware.bin \
127+
micropython.uf2
128+
129+
echo ""
130+
echo "Build completed successfully!"
131+
echo "Firmware files in: $MICROPYTHON_PATH/ports/esp32/$BUILD_DIR"
132+
echo "=========================================="

src/modcamera_api.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@
4242
#include "hal/i2c_ll.h"
4343
#endif
4444

45+
// Get the I2C port from the I2C object. This will be deleted in the future
46+
// Structure matches machine_hw_i2c_obj_t from machine_i2c.c
47+
#if MICROPY_HW_ESP_NEW_I2C_DRIVER && CONFIG_SCCB_HARDWARE_I2C_DRIVER_NEW
48+
typedef struct _machine_hw_i2c_obj_t {
49+
mp_obj_base_t base;
50+
i2c_master_bus_handle_t bus_handle;
51+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
52+
i2c_master_dev_handle_t dev_handle;
53+
#endif
54+
uint8_t port : 8;
55+
gpio_num_t scl : 8;
56+
gpio_num_t sda : 8;
57+
uint32_t freq;
58+
uint32_t timeout_us;
59+
} machine_hw_i2c_obj_t;
60+
#elif CONFIG_SCCB_HARDWARE_I2C_DRIVER_LEGACY
61+
typedef struct _machine_hw_i2c_obj_t {
62+
mp_obj_base_t base;
63+
i2c_port_t port : 8;
64+
gpio_num_t scl : 8;
65+
gpio_num_t sda : 8;
66+
uint32_t freq;
67+
uint32_t timeout_us;
68+
} machine_hw_i2c_obj_t;
69+
#else
70+
#error "Unsupported I2C driver configuration for casmera module"
71+
#endif
72+
4573
typedef struct mp_camera_obj_t mp_camera_obj;
4674
const mp_obj_type_t camera_type;
4775

@@ -133,17 +161,6 @@ static mp_obj_t mp_camera_make_new(const mp_obj_type_t *type, size_t n_args, siz
133161
mp_raise_TypeError(MP_ERROR_TEXT("i2c must be a machine.I2C object"));
134162
}
135163

136-
// Get the I2C port from the I2C object
137-
// Structure matches machine_hw_i2c_obj_t from machine_i2c.c
138-
typedef struct _machine_hw_i2c_obj_t {
139-
mp_obj_base_t base;
140-
i2c_port_t port : 8;
141-
gpio_num_t scl : 8;
142-
gpio_num_t sda : 8;
143-
uint32_t freq;
144-
uint32_t timeout_us;
145-
} machine_hw_i2c_obj_t;
146-
147164
machine_hw_i2c_obj_t *i2c = (machine_hw_i2c_obj_t *)MP_OBJ_TO_PTR(i2c_obj);
148165
i2c_port = (int8_t)i2c->port;
149166
sda_pin = i2c->sda;

0 commit comments

Comments
 (0)