diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bd35672a7d..35eb6dd6c4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,11 +11,8 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - idf_ver: ["release-v4.1", "release-v4.2", "release-v4.3"] + idf_ver: ["release-v4.3"] idf_target: ["esp32", "esp32s2"] - exclude: - - idf_ver: "release-v4.1" - idf_target: esp32s2 # ESP32S2 support started with version 4.2 container: espressif/idf:${{ matrix.idf_ver }} steps: - uses: actions/checkout@v1 @@ -25,7 +22,7 @@ jobs: env: IDF_TARGET: ${{ matrix.idf_target }} shell: bash - working-directory: examples + working-directory: examples/camera_example run: | . ${IDF_PATH}/export.sh idf.py build @@ -48,7 +45,7 @@ jobs: env: IDF_TARGET: ${{ matrix.idf_target }} shell: bash - working-directory: examples + working-directory: examples/camera_example run: | . ${IDF_PATH}/export.sh export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function" diff --git a/CMakeLists.txt b/CMakeLists.txt index 65e46aef60..a3c60fdfd6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}") # set conversion sources -set(COMPONENT_SRCS +set(srcs conversions/yuv.c conversions/to_jpg.cpp conversions/to_bmp.c @@ -10,11 +10,11 @@ set(COMPONENT_SRCS conversions/esp_jpg_decode.c ) -set(COMPONENT_PRIV_INCLUDEDIRS +set(priv_include_dirs conversions/private_include ) -set(COMPONENT_ADD_INCLUDEDIRS +set(include_dirs driver/include conversions/include ) @@ -23,7 +23,7 @@ set(COMPONENT_REQUIRES driver) # set driver sources only for supported platforms if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3") - list(APPEND COMPONENT_SRCS + list(APPEND srcs driver/esp_camera.c driver/cam_hal.c driver/sccb.c @@ -44,42 +44,42 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST sensors/sc031gs.c ) - list(APPEND COMPONENT_PRIV_INCLUDEDIRS + list(APPEND priv_include_dirs driver/private_include sensors/private_include target/private_include ) if(IDF_TARGET STREQUAL "esp32") - list(APPEND COMPONENT_SRCS + list(APPEND srcs target/xclk.c target/esp32/ll_cam.c ) endif() if(IDF_TARGET STREQUAL "esp32s2") - list(APPEND COMPONENT_SRCS + list(APPEND srcs target/xclk.c target/esp32s2/ll_cam.c target/tjpgd.c ) - list(APPEND COMPONENT_PRIV_INCLUDEDIRS + list(APPEND priv_include_dirs target/esp32s2/private_include ) endif() if(IDF_TARGET STREQUAL "esp32s3") - list(APPEND COMPONENT_SRCS + list(APPEND srcs target/esp32s3/ll_cam.c ) endif() - set(COMPONENT_PRIV_REQUIRES freertos nvs_flash) + set(priv_requires freertos nvs_flash) set(min_version_for_esp_timer "4.2") if (idf_version VERSION_GREATER_EQUAL min_version_for_esp_timer) - list(APPEND COMPONENT_PRIV_REQUIRES esp_timer) + list(APPEND priv_requires esp_timer) endif() endif() @@ -87,12 +87,18 @@ endif() # CONFIG_ESP_ROM_HAS_JPEG_DECODE is available from IDF v4.4 but # previous IDF supported chips already support JPEG decoder, hence okay to use this if(idf_version VERSION_GREATER_EQUAL "4.4" AND NOT CONFIG_ESP_ROM_HAS_JPEG_DECODE) - list(APPEND COMPONENT_SRCS + list(APPEND srcs target/tjpgd.c ) - list(APPEND COMPONENT_PRIV_INCLUDEDIRS + list(APPEND priv_include_dirs target/jpeg_include/ ) endif() -register_component() +idf_component_register( + SRCS ${srcs} + INCLUDE_DIRS ${include_dirs} + PRIV_INCLUDE_DIRS ${priv_include_dirs} + REQUIRES driver # due to include of driver/gpio.h in esp_camera.h + PRIV_REQUIRES ${priv_requires} +) diff --git a/README.md b/README.md index 316a1d90bb..092f893f8a 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,25 @@ This repository hosts ESP32 series Soc compatible driver for image sensors. Addi ## Installation Instructions -### Using esp-idf +### Using with ESP-IDF -- Clone or download and extract the repository to the components folder of your ESP-IDF project +- Add a dependency on `espressif/esp32-camera` component: + ```bash + idf.py add-dependency "espressif/esp32-camera" + ``` + (or add it manually in idf_component.yml of your project) - Enable PSRAM in `menuconfig` (also set Flash and PSRAM frequiencies to 80MHz) - Include `esp_camera.h` in your code -### Using PlatformIO +These instructions also work for PlatformIO, if you are using `framework=espidf`. + +### Using with Arduino + +#### Arduino IDE + +If you are using the arduino-esp32 core in Arduino IDE, no installation is needed! You can use esp32-camera right away. + +#### PlatformIO The easy way -- on the `env` section of `platformio.ini`, add the following: @@ -68,41 +80,15 @@ Enable PSRAM on `menuconfig` or type it direclty on `sdkconfig`. Check the [offi CONFIG_ESP32_SPIRAM_SUPPORT=y ``` -***Arduino*** The easy-way (content above) only seems to work if you're using `framework=arduino` which seems to take a bunch of the guesswork out (thanks Arduino!) but also suck up a lot more memory and flash, almost crippling the performance. If you plan to use the `framework=espidf` then read the sections below carefully!! - -## Platform.io lib/submodule (for framework=espidf) +## Examples -It's probably easier to just skip the platform.io library registry version and link the git repo as a submodule. (i.e. using code outside the platform.io library management). In this example we will install this as a submodule inside the platform.io $project/lib folder: -``` -cd $project\lib -git submodule add -b master https://github.com/espressif/esp32-camera.git -``` +This component comes with a basic example illustrating how to get frames from the camera. You can try out the example using the following command: -Then in `platformio.ini` file ``` -build_flags = - -I../lib/esp32-camera +idf.py create-project-from-example "espressif/esp32-camera:camera_example" ``` -After that `#include "esp_camera.h"` statement will be available. Now the module is included, and you're hopefully back to the same place as the easy-Arduino way. - -**Warning about platform.io/espidf and fresh (not initialized) git repos** -There is a sharp-edge on you'll discover in the platform.io build process (in espidf v3.3 & 4.0.1) where a project which has only had `git init` but nothing committed will crash platform.io build process with highly non-useful output. The cause is due to lack of a version (making you think you did something wrong, when you didn't at all) - the output is horribly non-descript. Solution: the devs want you to create a file called version.txt with a number in it, or simply commit any file to the projects git repo and use git. This happens because platform.io build process tries to be too clever and determine the build version number from the git repo - it's a sharp edge you'll only encounter if you're experimenting on a new project with no commits .. like wtf is my camera not working let's try a 'clean project'?! -## Platform.io Kconfig -Kconfig is used by the platform.io menuconfig (accessed by running: `pio run -t menuconfig`) to interactively manage the various #ifdef statements throughout the espidf and supporting libraries (i.e. this repo: esp32-camera and arduino-esp32.git). The menuconfig process generates the `sdkconfig` file which is ultimately used behind the scenes by espidf compile+build process. - -**Make sure to append or symlink** [this `Kconfig`](./Kconfig) content into the `Kconfig` of your project. - -You symlink (or copy) the included Kconfig into your platform.io projects src directory. The file should be named `Kconfig.projbuild` in your projects src\ directory or you could also add the library path to a CMakefile.txt and hope the `Kconfig` (or `Kconfig.projbuild`) gets discovered by the menuconfig process, though this unpredictable for me. - -The unpredictable wonky behavior in platform.io build process around Kconfig naming (Kconfig vs. Kconfig.projbuild) occurs between espidf versions 3.3 and 4.0 - but if you don't see "Camera configuration" in your `pio run -t menuconfig` then there is no point trying to test camera code (it may compile, but it probably won't work!) and it seems the platform.io devs (when they built their wrapper around the espidf menuconfig) didn't implement it properly. You've probably already figured out you can't use the espidf build tools since the files are in totally different locations and also different versions with sometimes different syntax. This is one of those times you might consider changing the `platformio.ini` from `platform=espressif32` to `platform=https://github.com/platformio/platform-espressif32.git#develop` to get a more recent version of the espidf 4.0 tools. - -However with a bit of patience and experimenting you'll figure the Kconfig out. Once Kconfig (or Kconfig.projbuild) is working then you will be able to choose the configurations according to your setup or the camera libraries will be compiled. Although you might also need to delete your .pio/build directory before the options appear .. again, the `pio run -t menuconfig` doens't always notice the new Kconfig files! - -If you miss-skip-ignore this critical step the camera module will compile but camera logic inside the library will be 'empty' because the Kconfig sets the proper #ifdef statements during the build process to initialize the selected cameras. It's very not optional! - - -## Examples +This command will download the example into `camera_example` directory. It comes already pre-configured with the correct settings in menuconfig. ### Initialization diff --git a/component.mk b/component.mk deleted file mode 100755 index 8db15eb883..0000000000 --- a/component.mk +++ /dev/null @@ -1,4 +0,0 @@ -COMPONENT_ADD_INCLUDEDIRS := driver/include conversions/include -COMPONENT_PRIV_INCLUDEDIRS := driver/private_include conversions/private_include sensors/private_include target/private_include -COMPONENT_SRCDIRS := driver conversions sensors target target/esp32 -CXXFLAGS += -fno-rtti diff --git a/examples/Makefile b/examples/Makefile deleted file mode 100644 index f06df0ecc9..0000000000 --- a/examples/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# -# This is a project Makefile. It is assumed the directory this Makefile resides in is a -# project subdirectory. -# - -PROJECT_NAME := camera_example - -EXTRA_COMPONENT_DIRS := ../ - -include $(IDF_PATH)/make/project.mk - diff --git a/examples/CMakeLists.txt b/examples/camera_example/CMakeLists.txt similarity index 67% rename from examples/CMakeLists.txt rename to examples/camera_example/CMakeLists.txt index 0a03968845..c44adc7b70 100644 --- a/examples/CMakeLists.txt +++ b/examples/camera_example/CMakeLists.txt @@ -2,8 +2,6 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.5) -set(EXTRA_COMPONENT_DIRS "../") - -add_compile_options(-fdiagnostics-color=always) +set(COMPONENTS main) include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(camera_example) \ No newline at end of file +project(camera_example) diff --git a/examples/camera_example/main/CMakeLists.txt b/examples/camera_example/main/CMakeLists.txt new file mode 100644 index 0000000000..0811eaadb5 --- /dev/null +++ b/examples/camera_example/main/CMakeLists.txt @@ -0,0 +1,3 @@ +idf_component_register(SRCS take_picture.c + PRIV_INCLUDE_DIRS . + PRIV_REQUIRES nvs_flash) diff --git a/examples/camera_example/main/idf_component.yml b/examples/camera_example/main/idf_component.yml new file mode 100644 index 0000000000..efa9638bc0 --- /dev/null +++ b/examples/camera_example/main/idf_component.yml @@ -0,0 +1,5 @@ +dependencies: + espressif/esp32-camera: + version: "*" + override_path: "../../../" + diff --git a/examples/main/take_picture.c b/examples/camera_example/main/take_picture.c similarity index 100% rename from examples/main/take_picture.c rename to examples/camera_example/main/take_picture.c diff --git a/examples/sdkconfig.defaults b/examples/camera_example/sdkconfig.defaults similarity index 100% rename from examples/sdkconfig.defaults rename to examples/camera_example/sdkconfig.defaults diff --git a/examples/main/CMakeLists.txt b/examples/main/CMakeLists.txt deleted file mode 100644 index 1735fb184b..0000000000 --- a/examples/main/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -set(COMPONENT_SRCS take_picture.c) -set(COMPONENT_ADD_INCLUDEDIRS .) -register_component() \ No newline at end of file diff --git a/examples/main/component.mk b/examples/main/component.mk deleted file mode 100644 index 0b9d7585e7..0000000000 --- a/examples/main/component.mk +++ /dev/null @@ -1,5 +0,0 @@ -# -# "main" pseudo-component makefile. -# -# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) - diff --git a/idf_component.yml b/idf_component.yml index 2b98f8d06c..d51d3691b7 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,2 +1,5 @@ description: ESP32 compatible driver for OV2640, OV3660, OV5640, OV7670 and OV7725 image sensors. url: https://github.com/espressif/esp32-camera +issues: https://github.com/espressif/esp32-camera/issues +documentation: https://github.com/espressif/esp32-camera/tree/main/README.md +repository: https://github.com/espressif/esp32-camera.git