Skip to content

Commit 1f3bb4c

Browse files
committed
Integrates esp32-camera as submodule and build option
Adds esp32-camera as a git submodule and build dependency, streamlines include path usage, and introduces camera model as a configurable build argument. Simplifies CMake logic for esp32-camera detection and improves build.sh usability.
1 parent a26b1dc commit 1f3bb4c

File tree

8 files changed

+51
-54
lines changed

8 files changed

+51
-54
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#.vscode folder
77
.vscode/
88

9+
# Build
10+
/build/
11+
912
# User-specific files
1013
*.rsuser
1114
*.suo

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "esp32-camera"]
2+
path = esp32-camera
3+
url = https://github.com/cnadler86/esp32-camera.git

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
# This allows the IDF component manager to process idf_component.yml
33
# The actual MicroPython module is built via micropython.cmake
44

5-
idf_component_register()
5+
idf_component_register(
6+
REQUIRES esp32-camera
7+
)

build.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,40 @@ set -e
55
IDF_PATH_DEFAULT="$HOME/esp/esp-idf"
66
MICROPYTHON_PATH=""
77
IDF_PATH="$IDF_PATH_DEFAULT"
8-
BOARD=""
8+
BOARD="ESP32_GENERIC_S3"
99
BOARD_VARIANT=""
10+
CAMERA_MODEL=""
1011
BUILD_DIR="build-mp_camera"
1112

1213
# Parse arguments
1314
usage() {
14-
echo "Usage: $0 -m <micropython_path> [-i <idf_path>] [-b <board>] [-v <board_variant>]"
15+
echo "Usage: $0 -m <micropython_path> [-i <idf_path>] [-b <board>] [-v <board_variant>] [-c <camera_model>]"
1516
echo ""
1617
echo "Options:"
1718
echo " -m <path> Path to MicroPython directory (required)"
1819
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 " -b <board> Board name (optional, e.g. ESP32_GENERIC_S3, default: $BOARD)"
2021
echo " -v <variant> Board variant (optional, e.g. SPIRAM_OCT)"
22+
echo " -c <model> Camera model (optional, e.g. FREENOVE_ESP32S3_CAM)"
2123
echo " -h Show this help message"
2224
echo ""
2325
echo "Examples:"
2426
echo " $0 -m ~/privat/micropython"
2527
echo " $0 -m ~/privat/micropython -i ~/esp/esp-idf"
2628
echo " $0 -m ~/privat/micropython -b ESP32_GENERIC_S3"
2729
echo " $0 -m ~/privat/micropython -b ESP32_GENERIC_S3 -v SPIRAM_OCT"
30+
echo " $0 -m ~/privat/micropython -b ESP32_GENERIC_S3 -c FREENOVE_ESP32S3_CAM"
2831
exit 1
2932
}
3033

3134
# Parse command line options
32-
while getopts "m:i:b:v:h" opt; do
35+
while getopts "m:i:b:v:c:h" opt; do
3336
case $opt in
3437
m) MICROPYTHON_PATH="$OPTARG" ;;
3538
i) IDF_PATH="$OPTARG" ;;
3639
b) BOARD="$OPTARG" ;;
3740
v) BOARD_VARIANT="$OPTARG" ;;
41+
c) CAMERA_MODEL="$OPTARG" ;;
3842
h) usage ;;
3943
*) usage ;;
4044
esac
@@ -69,18 +73,22 @@ IDF_PATH=$(realpath "$IDF_PATH")
6973
MODULE_PATH=$(dirname "$(realpath "$0")")
7074

7175
echo "=========================================="
72-
echo "Building MicroPython with IR Learn Module"
76+
echo "Building MicroPython with Camera Module"
7377
echo "=========================================="
7478
echo "MicroPython path: $MICROPYTHON_PATH"
7579
echo "ESP-IDF path: $IDF_PATH"
7680
echo "Module path: $MODULE_PATH"
7781
if [ -n "$BOARD" ]; then
7882
echo "Board: $BOARD"
83+
BUILD_DIR="${BUILD_DIR}-${BOARD}"
7984
if [ -n "$BOARD_VARIANT" ]; then
8085
echo "Board variant: $BOARD_VARIANT"
81-
BUILD_DIR="build-${BOARD_VARIANT}"
86+
BUILD_DIR="${BUILD_DIR}_${BOARD_VARIANT}"
8287
fi
8388
fi
89+
if [ -n "$CAMERA_MODEL" ]; then
90+
echo "Camera model: $CAMERA_MODEL"
91+
fi
8492
echo "Build directory: $BUILD_DIR"
8593
echo "=========================================="
8694
echo ""
@@ -103,6 +111,10 @@ if [ -n "$BOARD_VARIANT" ]; then
103111
IDF_CMD="$IDF_CMD -D MICROPY_BOARD_VARIANT=$BOARD_VARIANT"
104112
fi
105113

114+
if [ -n "$CAMERA_MODEL" ]; then
115+
IDF_CMD="$IDF_CMD -D MICROPY_CAMERA_MODEL=$CAMERA_MODEL"
116+
fi
117+
106118
IDF_CMD="$IDF_CMD -D USER_C_MODULES=$MODULE_PATH/micropython.cmake"
107119
IDF_CMD="$IDF_CMD -D EXTRA_COMPONENT_DIRS=$MODULE_PATH"
108120
IDF_CMD="$IDF_CMD build"
@@ -129,4 +141,8 @@ python "$MICROPYTHON_PATH/ports/esp32/makeimg.py" \
129141
echo ""
130142
echo "Build completed successfully!"
131143
echo "Firmware files in: $MICROPYTHON_PATH/ports/esp32/$BUILD_DIR"
132-
echo "=========================================="
144+
echo "=========================================="
145+
146+
# Clean up build directory
147+
cd "$MODULE_PATH"
148+
rm -rf build

esp32-camera

Submodule esp32-camera added at b9c5c51

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## IDF Component Manager Manifest File
22
dependencies:
33
espressif/esp32-camera:
4-
git: https://github.com/cnadler86/esp32-camera.git
4+
override_path: esp32-camera
55
espressif/esp_new_jpeg: "^1.0.0"
66
idf:
77
version: ">=5.2.0"

micropython.cmake

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,22 @@ target_sources(usermod_mp_camera INTERFACE
99
${CMAKE_CURRENT_LIST_DIR}/src/modcamera_api.c
1010
)
1111

12-
# Register dependency on esp32-camera component
13-
# The component is managed by IDF component manager via idf_component.yml
14-
# Add include directories directly from managed_components (they exist after Component Manager ran)
15-
# Allow manual override via ESP32_CAMERA_DIR
16-
if(DEFINED ESP32_CAMERA_DIR AND EXISTS "${ESP32_CAMERA_DIR}")
17-
message(STATUS "Using user-defined ESP32_CAMERA_DIR: ${ESP32_CAMERA_DIR}")
18-
set(ESP32_CAMERA_MANAGED_DIR "${ESP32_CAMERA_DIR}")
19-
else()
20-
set(ESP32_CAMERA_MANAGED_DIR "${MICROPY_PORT_DIR}/managed_components/espressif__esp32-camera")
21-
endif()
12+
idf_component_get_property(camera_dir esp32-camera COMPONENT_DIR)
13+
target_include_directories(usermod_mp_camera INTERFACE
14+
${camera_dir}/driver/include
15+
${camera_dir}/driver/private_include
16+
${camera_dir}/sensors/private_include
17+
)
2218

23-
if(EXISTS "${ESP32_CAMERA_MANAGED_DIR}")
24-
# Add standard include directories for esp32-camera
25-
list(APPEND MICROPY_INC_USERMOD
26-
${ESP32_CAMERA_MANAGED_DIR}/driver/include
27-
${ESP32_CAMERA_MANAGED_DIR}/driver/private_include
28-
${ESP32_CAMERA_MANAGED_DIR}/conversions/include
29-
${ESP32_CAMERA_MANAGED_DIR}/conversions/private_include
30-
${ESP32_CAMERA_MANAGED_DIR}/sensors/private_include
31-
)
32-
33-
message(STATUS "Found esp32-camera at: ${ESP32_CAMERA_MANAGED_DIR}")
34-
35-
# Link against the component library when target exists (during actual build)
36-
# The target doesn't exist yet during include(), but will exist during build
37-
if(TARGET espressif__esp32-camera)
38-
idf_component_get_property(esp32_camera_lib espressif__esp32-camera COMPONENT_LIB)
39-
target_link_libraries(usermod_mp_camera INTERFACE ${esp32_camera_lib})
40-
endif()
41-
42-
# Set MP_CAMERA_DRIVER_VERSION if available
43-
if(EXISTS "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml")
44-
file(READ "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml" _camera_component_yml)
45-
string(REGEX MATCH "version: ([0-9]+\\.[0-9]+(\\.[0-9]+)?)" _ ${_camera_component_yml})
46-
if(CMAKE_MATCH_1)
47-
set(MP_CAMERA_DRIVER_VERSION "${CMAKE_MATCH_1}")
48-
message(STATUS "Found esp32-camera version: ${MP_CAMERA_DRIVER_VERSION}")
49-
endif()
50-
endif()
51-
else()
52-
message(WARNING "esp32-camera component not found - component manager should have downloaded it based on idf_component.yml")
53-
endif()
19+
# # Set MP_CAMERA_DRIVER_VERSION if available
20+
# if(EXISTS "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml")
21+
# file(READ "${ESP32_CAMERA_MANAGED_DIR}/idf_component.yml" _camera_component_yml)
22+
# string(REGEX MATCH "version: ([0-9]+\\.[0-9]+(\\.[0-9]+)?)" _ ${_camera_component_yml})
23+
# if(CMAKE_MATCH_1)
24+
# set(MP_CAMERA_DRIVER_VERSION "${CMAKE_MATCH_1}")
25+
# message(STATUS "Found esp32-camera version: ${MP_CAMERA_DRIVER_VERSION}")
26+
# endif()
27+
# endif()
5428

5529
# Check if MP_JPEG_DIR is set or if mp_jpeg directory exists two levels up
5630
if(DEFINED MP_JPEG_DIR AND EXISTS "${MP_JPEG_DIR}")

src/modcamera_api.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
// Get the I2C port from the I2C object. This will be deleted in the future
4646
// 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
47+
#if MICROPY_HW_ESP_NEW_I2C_DRIVER
4848
typedef struct _machine_hw_i2c_obj_t {
4949
mp_obj_base_t base;
5050
i2c_master_bus_handle_t bus_handle;
@@ -57,7 +57,7 @@
5757
uint32_t freq;
5858
uint32_t timeout_us;
5959
} machine_hw_i2c_obj_t;
60-
#elif CONFIG_SCCB_HARDWARE_I2C_DRIVER_LEGACY
60+
#else
6161
typedef struct _machine_hw_i2c_obj_t {
6262
mp_obj_base_t base;
6363
i2c_port_t port : 8;
@@ -66,8 +66,6 @@
6666
uint32_t freq;
6767
uint32_t timeout_us;
6868
} machine_hw_i2c_obj_t;
69-
#else
70-
#error "Unsupported I2C driver configuration for casmera module"
7169
#endif
7270

7371
typedef struct mp_camera_obj_t mp_camera_obj;

0 commit comments

Comments
 (0)