Skip to content

Commit e8f2701

Browse files
committed
update file structure (improve) and cmake to better handle deps
1 parent b31fef7 commit e8f2701

File tree

6 files changed

+114
-101
lines changed

6 files changed

+114
-101
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# IDF component wrapper for micropython-camera-API user module
2+
# This allows the IDF component manager to process idf_component.yml
3+
# The actual MicroPython module is built via micropython.cmake
4+
5+
idf_component_register()

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,21 +258,19 @@ To build the project, follow these instructions:
258258

259259
- [ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/v5.2.3/esp32/get-started/index.html): I used version 5.2.3, but it might work with other versions (see notes).
260260
- Clone the micropython repo and this repo in a folder, e.g. "MyESPCam". MicroPython version 1.24 or higher is required (at least commit 92484d8).
261-
- You will have to add the ESP32-Camera driver from my fork. To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main_esp32s3/idf_component.yml):
261+
- You will have to add the ESP32-Camera driver. To do this, add the following to the respective idf_component.yml file (e.g. in micropython/ports/esp32/main/idf_component.yml):
262262

263263
```yml
264264
espressif/esp32-camera:
265265
git: https://github.com/cnadler86/esp32-camera.git
266266
```
267267
268-
Alternatively, you can clone the <https://github.com/cnadler86/esp32-camera> repository inside the esp-idf/components folder instead of altering the idf_component.yml file.
269-
270268
### Add camera configurations to your board (optional, but recommended)
271269
272270
#### Supported camera models
273271
274272
This project supports various boards with camera interface out of the box. You typically only need to add a single line to your board config file ("mpconfigboard.h).
275-
Example (don't forget to add the empty line at the bottom):
273+
Example:
276274
277275
```c
278276
#define MICROPY_CAMERA_MODEL_WROVER_KIT 1
@@ -345,9 +343,9 @@ To build the project, you could do it the following way:
345343
```bash
346344
. <path2esp-idf>/esp-idf/export.sh
347345
cd MyESPCam/micropython/ports/esp32
348-
make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD=<Your-Board> clean
349-
make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD=<Your-Board> submodules
350-
make USER_C_MODULES=../../../../micropython-camera-API/src/micropython.cmake BOARD=<Your-Board> all
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
351349
```
352350

353351
Micropython and camera-api folders are at the same level. Note that you need those extra "/../"s while been inside the esp32 port folder.

idf_component.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## IDF Component Manager Manifest File
2+
dependencies:
3+
espressif/esp32-camera:
4+
git: https://github.com/cnadler86/esp32-camera.git
5+
espressif/esp_new_jpeg: "^1.0.0"
6+
idf:
7+
version: ">=5.2.0"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Include the board's default manifest.
22
include("$(PORT_DIR)/boards/manifest.py")
33
# Add custom driver
4-
module("acamera.py")
4+
module("src/acamera.py")

micropython.cmake

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
include(${MICROPY_DIR}/py/py.cmake)
2+
3+
set(MICROPY_FROZEN_MANIFEST ${CMAKE_CURRENT_LIST_DIR}/manifest.py)
4+
5+
add_library(usermod_mp_camera INTERFACE)
6+
7+
target_sources(usermod_mp_camera INTERFACE
8+
${CMAKE_CURRENT_LIST_DIR}/src/modcamera.c
9+
${CMAKE_CURRENT_LIST_DIR}/src/modcamera_api.c
10+
)
11+
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()
22+
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()
54+
55+
# Check if MP_JPEG_DIR is set or if mp_jpeg directory exists two levels up
56+
if(DEFINED MP_JPEG_DIR AND EXISTS "${MP_JPEG_DIR}")
57+
message(STATUS "Using user-defined MP_JPEG_DIR: ${MP_JPEG_DIR}")
58+
set(MP_JPEG_SRC "${MP_JPEG_DIR}/micropython.cmake")
59+
elseif(EXISTS "${CMAKE_CURRENT_LIST_DIR}/../mp_jpeg")
60+
message(STATUS "Found mp_jpeg directory at same level as the camera module")
61+
set(MP_JPEG_SRC "${CMAKE_CURRENT_LIST_DIR}/../mp_jpeg/micropython.cmake")
62+
endif()
63+
64+
# Include mp_jpeg module if found
65+
if(DEFINED MP_JPEG_SRC AND EXISTS "${MP_JPEG_SRC}")
66+
include(${MP_JPEG_SRC})
67+
message(STATUS "Included mp_jpeg module from: ${MP_JPEG_SRC}")
68+
else()
69+
message(STATUS "mp_jpeg module not found - camera module will build without JPEG support")
70+
endif()
71+
72+
# Define MICROPY_CAMERA_MODEL if specified
73+
if (MICROPY_CAMERA_MODEL)
74+
message(STATUS "Using user-defined camera model: ${MICROPY_CAMERA_MODEL}")
75+
target_compile_definitions(usermod_mp_camera INTERFACE
76+
MICROPY_CAMERA_MODEL_${MICROPY_CAMERA_MODEL}=1
77+
)
78+
endif()
79+
80+
# Define MP_CAMERA_DRIVER_VERSION if specified
81+
if (MP_CAMERA_DRIVER_VERSION)
82+
target_compile_definitions(usermod_mp_camera INTERFACE
83+
MP_CAMERA_DRIVER_VERSION=\"${MP_CAMERA_DRIVER_VERSION}\"
84+
)
85+
endif()
86+
87+
# Camera module strings are not suitable for compression and cause size increase
88+
target_compile_definitions(usermod_mp_camera INTERFACE
89+
MICROPY_ROM_TEXT_COMPRESSION=0
90+
)
91+
92+
# Link the camera module with the main usermod target
93+
target_link_libraries(usermod INTERFACE usermod_mp_camera)
94+
95+
# Gather target properties for MicroPython build system
96+
micropy_gather_target_properties(usermod_mp_camera)

src/micropython.cmake

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

0 commit comments

Comments
 (0)