Skip to content

Commit a70c047

Browse files
committed
Remove dependency on OpenCV fork
Fixes #31
1 parent 90f87dc commit a70c047

File tree

5 files changed

+95
-2
lines changed

5 files changed

+95
-2
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "src/opencv/opencv"]
22
path = src/opencv/opencv
3-
url = https://github.com/sfe-SparkFro/opencv.git
3+
url = https://github.com/opencv/opencv.git
44
[submodule "src/ulab"]
55
path = src/ulab
66
url = https://github.com/v923z/micropython-ulab.git
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2019 BayLibre SAS
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_
8+
#define ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_
9+
10+
/*
11+
* Some gcc versions and/or configurations as found in the Zephyr SDK
12+
* (questionably) define __INT32_TYPE__ and derivatives as a long int
13+
* which makes the printf format checker to complain about long vs int
14+
* mismatch when %u is given a uint32_t argument, and uint32_t pointers not
15+
* being compatible with int pointers. Let's redefine them to follow
16+
* common expectations and usage.
17+
*/
18+
19+
#if __SIZEOF_INT__ != 4
20+
#error "unexpected int width"
21+
#endif
22+
23+
#undef __INT32_TYPE__
24+
#undef __UINT32_TYPE__
25+
#undef __INT_FAST32_TYPE__
26+
#undef __UINT_FAST32_TYPE__
27+
#undef __INT_LEAST32_TYPE__
28+
#undef __UINT_LEAST32_TYPE__
29+
#undef __INT64_TYPE__
30+
#undef __UINT64_TYPE__
31+
#undef __INT_FAST64_TYPE__
32+
#undef __UINT_FAST64_TYPE__
33+
#undef __INT_LEAST64_TYPE__
34+
#undef __UINT_LEAST64_TYPE__
35+
36+
#define __INT32_TYPE__ int
37+
#define __UINT32_TYPE__ unsigned int
38+
#define __INT_FAST32_TYPE__ __INT32_TYPE__
39+
#define __UINT_FAST32_TYPE__ __UINT32_TYPE__
40+
#define __INT_LEAST32_TYPE__ __INT32_TYPE__
41+
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
42+
#define __INT64_TYPE__ long long int
43+
#define __UINT64_TYPE__ unsigned long long int
44+
#define __INT_FAST64_TYPE__ __INT64_TYPE__
45+
#define __UINT_FAST64_TYPE__ __UINT64_TYPE__
46+
#define __INT_LEAST64_TYPE__ __INT64_TYPE__
47+
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
48+
49+
/*
50+
* The confusion also exists with __INTPTR_TYPE__ which is either an int
51+
* (even when __INT32_TYPE__ is a long int) or a long int. Let's redefine
52+
* it to a long int to get some uniformity. Doing so also makes it compatible
53+
* with LP64 (64-bit) targets where a long is always 64-bit wide.
54+
*/
55+
56+
#if __SIZEOF_POINTER__ != __SIZEOF_LONG__
57+
#error "unexpected size difference between pointers and long ints"
58+
#endif
59+
60+
#undef __INTPTR_TYPE__
61+
#undef __UINTPTR_TYPE__
62+
#define __INTPTR_TYPE__ long int
63+
#define __UINTPTR_TYPE__ long unsigned int
64+
65+
/*
66+
* Re-define the INTN_C(value) integer constant expression macros to match the
67+
* integer types re-defined above.
68+
*/
69+
70+
#undef __INT32_C
71+
#undef __UINT32_C
72+
#undef __INT64_C
73+
#undef __UINT64_C
74+
#define __INT32_C(c) c
75+
#define __UINT32_C(c) c ## U
76+
#define __INT64_C(c) c ## LL
77+
#define __UINT64_C(c) c ## ULL
78+
79+
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_STDINT_H_ */

src/opencv/platforms/rp2350.toolchain.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ include("${CMAKE_CURRENT_LIST_DIR}/common.cmake")
1212
# Set RP2350 specific settings
1313
set(OPENCV_DISABLE_THREAD_SUPPORT ON)
1414

15+
# Add compiler flag -D_M_CEE
16+
# set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -D_M_CEE")
17+
# set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -D_M_CEE")
18+
1519
# Fix for https://github.com/raspberrypi/pico-sdk/issues/2505
1620
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -DOPENCV_INCLUDE_PORT_FILE=\\\"${CMAKE_CURRENT_LIST_DIR}/include/rp2350_unsafe_cv_xadd.h\\\"")
1721
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -DOPENCV_INCLUDE_PORT_FILE=\\\"${CMAKE_CURRENT_LIST_DIR}/include/rp2350_unsafe_cv_xadd.h\\\"")
22+
23+
# Fix for https://github.com/sparkfun/micropython-opencv/issues/31
24+
# Source: https://docs.zephyrproject.org/4.0.0/doxygen/html/zephyr__stdint_8h_source.html
25+
set(CMAKE_C_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -imacros ${CMAKE_CURRENT_LIST_DIR}/include/zephyr_stdint.h")
26+
set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} -imacros ${CMAKE_CURRENT_LIST_DIR}/include/zephyr_stdint.h")

src/opencv_upy.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ target_link_libraries(usermod INTERFACE "-Wl,--wrap,malloc")
5050
target_link_libraries(usermod INTERFACE "-Wl,--wrap,free")
5151
target_link_libraries(usermod INTERFACE "-Wl,--wrap,calloc")
5252
target_link_libraries(usermod INTERFACE "-Wl,--wrap,realloc")
53+
54+
# __NEWLIB__ is not defined for some reason, which causes a conflicting
55+
# definition of uint here:
56+
# https://github.com/opencv/opencv/blob/9cdd525bc59b34a3db8f6db905216c5398ca93d6/modules/core/include/opencv2/core/hal/interface.h#L35-L39
57+
target_compile_definitions(usermod INTERFACE -D__NEWLIB__)

0 commit comments

Comments
 (0)