Skip to content

Commit 5936a22

Browse files
authored
Fix SPIRAM checks and allow conversion APIs to be built for all platforms (#397)
Signed-off-by: Vikram <[email protected]>
1 parent e7f843b commit 5936a22

File tree

5 files changed

+42
-42
lines changed

5 files changed

+42
-42
lines changed

CMakeLists.txt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
# set conversion sources
2+
set(COMPONENT_SRCS
3+
conversions/yuv.c
4+
conversions/to_jpg.cpp
5+
conversions/to_bmp.c
6+
conversions/jpge.cpp
7+
conversions/esp_jpg_decode.c
8+
)
9+
10+
set(COMPONENT_PRIV_INCLUDEDIRS
11+
conversions/private_include
12+
)
13+
14+
set(COMPONENT_ADD_INCLUDEDIRS
15+
driver/include
16+
conversions/include
17+
)
18+
19+
# set driver sources only for supported platforms
120
if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3")
2-
set(COMPONENT_SRCS
21+
list(APPEND COMPONENT_SRCS
322
driver/esp_camera.c
423
driver/cam_hal.c
524
driver/sccb.c
@@ -16,22 +35,11 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
1635
sensors/bf3005.c
1736
sensors/bf20a6.c
1837
sensors/sc030iot.c
19-
conversions/yuv.c
20-
conversions/to_jpg.cpp
21-
conversions/to_bmp.c
22-
conversions/jpge.cpp
23-
conversions/esp_jpg_decode.c
2438
)
2539

26-
set(COMPONENT_ADD_INCLUDEDIRS
27-
driver/include
28-
conversions/include
29-
)
30-
31-
set(COMPONENT_PRIV_INCLUDEDIRS
40+
list(APPEND COMPONENT_PRIV_INCLUDEDIRS
3241
driver/private_include
3342
sensors/private_include
34-
conversions/private_include
3543
target/private_include
3644
)
3745

@@ -70,5 +78,6 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
7078
message(WARNING "ESP-IDF version detected: '${idf_version}'.")
7179
endif()
7280

73-
register_component()
7481
endif()
82+
83+
register_component()

conversions/esp_jpg_decode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
#include "tjpgd.h"
2222
#elif CONFIG_IDF_TARGET_ESP32S3
2323
#include "esp32s3/rom/tjpgd.h"
24+
#elif CONFIG_IDF_TARGET_ESP32C3
25+
#include "esp32c3/rom/tjpgd.h"
26+
#elif CONFIG_IDF_TARGET_ESP32H2
27+
#include "esp32h2/rom/tjpgd.h"
2428
#else
2529
#error Target CONFIG_IDF_TARGET is not supported
2630
#endif

conversions/jpge.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ namespace jpge {
2929
if(b){
3030
return b;
3131
}
32+
// check if SPIRAM is enabled and allocate on SPIRAM if allocatable
33+
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
3234
return heap_caps_malloc(nSize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
35+
#else
36+
return NULL;
37+
#endif
3338
}
3439
static inline void jpge_free(void *p) { free(p); }
3540

conversions/to_bmp.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@
2121
#include "esp_jpg_decode.h"
2222

2323
#include "esp_system.h"
24-
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
25-
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
26-
#include "esp32/spiram.h"
27-
#elif CONFIG_IDF_TARGET_ESP32S2
28-
#include "esp32s2/spiram.h"
29-
#elif CONFIG_IDF_TARGET_ESP32S3
30-
#include "esp32s3/spiram.h"
31-
#else
32-
#error Target CONFIG_IDF_TARGET is not supported
33-
#endif
34-
#else // ESP32 Before IDF 4.0
35-
#include "esp_spiram.h"
36-
#endif
3724

3825
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
3926
#include "esp32-hal-log.h"
@@ -72,7 +59,12 @@ typedef struct {
7259

7360
static void *_malloc(size_t size)
7461
{
62+
// check if SPIRAM is enabled and allocate on SPIRAM if allocatable
63+
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
7564
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
65+
#endif
66+
// try allocating in internal memory
67+
return malloc(size);
7668
}
7769

7870
//output buffer and image width

conversions/to_jpg.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,6 @@
2121
#include "jpge.h"
2222
#include "yuv.h"
2323

24-
#include "esp_system.h"
25-
#if ESP_IDF_VERSION_MAJOR >= 4 // IDF 4+
26-
#if CONFIG_IDF_TARGET_ESP32 // ESP32/PICO-D4
27-
#include "esp32/spiram.h"
28-
#elif CONFIG_IDF_TARGET_ESP32S2
29-
#include "esp32s2/spiram.h"
30-
#elif CONFIG_IDF_TARGET_ESP32S3
31-
#include "esp32s3/spiram.h"
32-
#else
33-
#error Target CONFIG_IDF_TARGET is not supported
34-
#endif
35-
#else // ESP32 Before IDF 4.0
36-
#include "esp_spiram.h"
37-
#endif
38-
3924
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
4025
#include "esp32-hal-log.h"
4126
#define TAG ""
@@ -50,7 +35,12 @@ static void *_malloc(size_t size)
5035
if(res) {
5136
return res;
5237
}
38+
39+
// check if SPIRAM is enabled and is allocatable
40+
#if (CONFIG_SPIRAM_SUPPORT && (CONFIG_SPIRAM_USE_CAPS_ALLOC || CONFIG_SPIRAM_USE_MALLOC))
5341
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
42+
#endif
43+
return NULL;
5444
}
5545

5646
static IRAM_ATTR void convert_line_format(uint8_t * src, pixformat_t format, uint8_t * dst, size_t width, size_t in_channels, size_t line)

0 commit comments

Comments
 (0)