From 905abf8d7bda836dc82c5c9f136687636cf07a9b Mon Sep 17 00:00:00 2001 From: Vikram Date: Fri, 31 Mar 2023 21:33:40 +0530 Subject: [PATCH 1/2] Extend s/w jpeg decoder functions for chips missing rom tjpgd Also, disabled camera_init and capture from example for chips not supporting camera Signed-off-by: Vikram --- CMakeLists.txt | 13 ++++- conversions/esp_jpg_decode.c | 8 ++- driver/esp_camera.c | 2 +- driver/include/esp_camera.h | 18 ++++--- examples/main/take_picture.c | 13 +++-- target/jpeg_include/tjpgd.h | 99 ++++++++++++++++++++++++++++++++++++ target/{esp32s2 => }/tjpgd.c | 0 7 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 target/jpeg_include/tjpgd.h rename target/{esp32s2 => }/tjpgd.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a9267ba9a..65e46aef60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,7 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST list(APPEND COMPONENT_SRCS target/xclk.c target/esp32s2/ll_cam.c - target/esp32s2/tjpgd.c + target/tjpgd.c ) list(APPEND COMPONENT_PRIV_INCLUDEDIRS @@ -84,4 +84,15 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST 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 + target/tjpgd.c + ) + list(APPEND COMPONENT_PRIV_INCLUDEDIRS + target/jpeg_include/ + ) +endif() + register_component() diff --git a/conversions/esp_jpg_decode.c b/conversions/esp_jpg_decode.c index 52833a733d..168325baf5 100644 --- a/conversions/esp_jpg_decode.c +++ b/conversions/esp_jpg_decode.c @@ -17,16 +17,14 @@ #if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+ #if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4 #include "esp32/rom/tjpgd.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "tjpgd.h" #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/rom/tjpgd.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/tjpgd.h" -#elif CONFIG_IDF_TARGET_ESP32H2 -#include "esp32h2/rom/tjpgd.h" +#elif CONFIG_ESP_ROM_HAS_JPEG_DECODE // available since IDF 4.4 +#include "rom/tjpgd.h" // latest IDFs have `rom/` includes available #else -#error Target CONFIG_IDF_TARGET is not supported +#include "tjpgd.h" // using software decoder #endif #else // ESP32 Before IDF 4.0 #include "rom/tjpgd.h" diff --git a/driver/esp_camera.c b/driver/esp_camera.c index 47407a0154..4b7e906a57 100644 --- a/driver/esp_camera.c +++ b/driver/esp_camera.c @@ -245,7 +245,7 @@ static esp_err_t camera_probe(const camera_config_t *config, camera_model_t *out ESP_LOGD(TAG, "Doing SW reset of sensor"); vTaskDelay(10 / portTICK_PERIOD_MS); - + return s_state->sensor.reset(&s_state->sensor); err : CAMERA_DISABLE_OUT_CLOCK(); diff --git a/driver/include/esp_camera.h b/driver/include/esp_camera.h index 2a25a56287..ce031c88d4 100755 --- a/driver/include/esp_camera.h +++ b/driver/include/esp_camera.h @@ -72,6 +72,12 @@ #include "sys/time.h" #include "sdkconfig.h" +/** + * @brief define for if chip supports camera + */ +#define ESP_CAMERA_SUPPORTED (CONFIG_IDF_TARGET_ESP32 | CONFIG_IDF_TARGET_ESP32S3 | \ + CONFIG_IDF_TARGET_ESP32S2) + #ifdef __cplusplus extern "C" { #endif @@ -85,7 +91,7 @@ typedef enum { } camera_grab_mode_t; /** - * @brief Camera frame buffer location + * @brief Camera frame buffer location */ typedef enum { CAMERA_FB_IN_PSRAM, /*!< Frame buffer is placed in external PSRAM */ @@ -99,7 +105,7 @@ typedef enum { typedef enum { CONV_DISABLE, RGB565_TO_YUV422, - + YUV422_TO_RGB565, YUV422_TO_YUV420 } camera_conv_mode_t; @@ -219,15 +225,15 @@ sensor_t * esp_camera_sensor_get(void); /** * @brief Save camera settings to non-volatile-storage (NVS) - * - * @param key A unique nvs key name for the camera settings + * + * @param key A unique nvs key name for the camera settings */ esp_err_t esp_camera_save_to_nvs(const char *key); /** * @brief Load camera settings from non-volatile-storage (NVS) - * - * @param key A unique nvs key name for the camera settings + * + * @param key A unique nvs key name for the camera settings */ esp_err_t esp_camera_load_from_nvs(const char *key); diff --git a/examples/main/take_picture.c b/examples/main/take_picture.c index 41abf66e65..3a243d2554 100644 --- a/examples/main/take_picture.c +++ b/examples/main/take_picture.c @@ -10,7 +10,7 @@ /** * 2. Kconfig setup - * + * * If you have a Kconfig file, copy the content from * https://github.com/espressif/esp32-camera/blob/master/Kconfig into it. * In case you haven't, copy and paste this Kconfig file inside the src directory. @@ -20,9 +20,9 @@ /** * 3. Enable PSRAM on sdkconfig: - * + * * CONFIG_ESP32_SPIRAM_SUPPORT=y - * + * * More info on * https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/kconfig.html#config-esp32-spiram-support */ @@ -95,6 +95,7 @@ static const char *TAG = "example:take_picture"; +#if ESP_CAMERA_SUPPORTED static camera_config_t camera_config = { .pin_pwdn = CAM_PIN_PWDN, .pin_reset = CAM_PIN_RESET, @@ -139,9 +140,11 @@ static esp_err_t init_camera(void) return ESP_OK; } +#endif void app_main(void) { +#if ESP_CAMERA_SUPPORTED if(ESP_OK != init_camera()) { return; } @@ -157,4 +160,8 @@ void app_main(void) vTaskDelay(5000 / portTICK_RATE_MS); } +#else + ESP_LOGE(TAG, "Camera support is not available for this chip"); + return; +#endif } diff --git a/target/jpeg_include/tjpgd.h b/target/jpeg_include/tjpgd.h new file mode 100644 index 0000000000..31fbc97cce --- /dev/null +++ b/target/jpeg_include/tjpgd.h @@ -0,0 +1,99 @@ +/*----------------------------------------------------------------------------/ +/ TJpgDec - Tiny JPEG Decompressor include file (C)ChaN, 2012 +/----------------------------------------------------------------------------*/ +#ifndef _TJPGDEC +#define _TJPGDEC +/*---------------------------------------------------------------------------*/ +/* System Configurations */ + +#define JD_SZBUF 512 /* Size of stream input buffer */ +#define JD_FORMAT 0 /* Output pixel format 0:RGB888 (3 BYTE/pix), 1:RGB565 (1 WORD/pix) */ +#define JD_USE_SCALE 1 /* Use descaling feature for output */ +#define JD_TBLCLIP 1 /* Use table for saturation (might be a bit faster but increases 1K bytes of code size) */ + +/*---------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/* These types must be 16-bit, 32-bit or larger integer */ +typedef int INT; +typedef unsigned int UINT; + +/* These types must be 8-bit integer */ +typedef char CHAR; +typedef unsigned char UCHAR; +typedef unsigned char BYTE; + +/* These types must be 16-bit integer */ +typedef short SHORT; +typedef unsigned short USHORT; +typedef unsigned short WORD; +typedef unsigned short WCHAR; + +/* These types must be 32-bit integer */ +typedef long LONG; +typedef unsigned long ULONG; +typedef unsigned long DWORD; + + +/* Error code */ +typedef enum { + JDR_OK = 0, /* 0: Succeeded */ + JDR_INTR, /* 1: Interrupted by output function */ + JDR_INP, /* 2: Device error or wrong termination of input stream */ + JDR_MEM1, /* 3: Insufficient memory pool for the image */ + JDR_MEM2, /* 4: Insufficient stream input buffer */ + JDR_PAR, /* 5: Parameter error */ + JDR_FMT1, /* 6: Data format error (may be damaged data) */ + JDR_FMT2, /* 7: Right format but not supported */ + JDR_FMT3 /* 8: Not supported JPEG standard */ +} JRESULT; + + + +/* Rectangular structure */ +typedef struct { + WORD left, right, top, bottom; +} JRECT; + + + +/* Decompressor object structure */ +typedef struct JDEC JDEC; +struct JDEC { + UINT dctr; /* Number of bytes available in the input buffer */ + BYTE* dptr; /* Current data read ptr */ + BYTE* inbuf; /* Bit stream input buffer */ + BYTE dmsk; /* Current bit in the current read byte */ + BYTE scale; /* Output scaling ratio */ + BYTE msx, msy; /* MCU size in unit of block (width, height) */ + BYTE qtid[3]; /* Quantization table ID of each component */ + SHORT dcv[3]; /* Previous DC element of each component */ + WORD nrst; /* Restart inverval */ + UINT width, height; /* Size of the input image (pixel) */ + BYTE* huffbits[2][2]; /* Huffman bit distribution tables [id][dcac] */ + WORD* huffcode[2][2]; /* Huffman code word tables [id][dcac] */ + BYTE* huffdata[2][2]; /* Huffman decoded data tables [id][dcac] */ + LONG* qttbl[4]; /* Dequaitizer tables [id] */ + void* workbuf; /* Working buffer for IDCT and RGB output */ + BYTE* mcubuf; /* Working buffer for the MCU */ + void* pool; /* Pointer to available memory pool */ + UINT sz_pool; /* Size of momory pool (bytes available) */ + UINT (*infunc)(JDEC*, BYTE*, UINT);/* Pointer to jpeg stream input function */ + void* device; /* Pointer to I/O device identifiler for the session */ +}; + + + +/* TJpgDec API functions */ +JRESULT jd_prepare (JDEC*, UINT(*)(JDEC*,BYTE*,UINT), void*, UINT, void*); +JRESULT jd_decomp (JDEC*, UINT(*)(JDEC*,void*,JRECT*), BYTE); + + +#ifdef __cplusplus +} +#endif + +#endif /* _TJPGDEC */ diff --git a/target/esp32s2/tjpgd.c b/target/tjpgd.c similarity index 100% rename from target/esp32s2/tjpgd.c rename to target/tjpgd.c From b93a1d76621b542283190b3104cb222793e94df9 Mon Sep 17 00:00:00 2001 From: Vikram Date: Mon, 24 Apr 2023 18:43:01 +0530 Subject: [PATCH 2/2] Extend CI build support for C3 and C2 Signed-off-by: Vikram --- .github/workflows/build.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2859a73d62..bd35672a7d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,10 @@ jobs: strategy: matrix: idf_ver: ["release-v4.4", "release-v5.0", "release-v5.1", "latest"] - idf_target: ["esp32", "esp32s2", "esp32s3"] + idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3"] + exclude: + - idf_ver: "release-v4.4" + idf_target: esp32c2 # ESP32C2 support started with version 5.0 container: espressif/idf:${{ matrix.idf_ver }} steps: - uses: actions/checkout@v1