From a2436761942c4737ad139b66ca463e272a878039 Mon Sep 17 00:00:00 2001 From: Ozan Durgut Date: Sat, 5 Sep 2026 12:26:44 +0200 Subject: [PATCH] chore: remove dead code and unused config Cleanup around the dead code that I am aware so long but did not have a time to fix them all. This commit removes: - device/camera/esp32_ov2640_old.cpp (whole file, superseded) - arch/arm/cm7_common.c and arch/arm/cm7_fft.c (comment-only stubs; functionality moved to dwt_timer.c / cmsis_fft.c) - core/image.h: GMMStats typedef (never instantiated) - imgproc/filter.h: SepFilter2DContext struct (never instantiated) - imgproc/filter.c: commented-out dead wrapper() function, and unused STRONG/WEAK macros (Canny hardcodes the literals instead) - imgproc/fft.c: multiply() function (not declared in fft.h, no callers) - imgproc/segmentation.c: GMMComponent struct, GMM_COMPONENTS macro, and gaussian_prob() (none called by grabCutLite or anything else) - device/serial/stm32_uart.c: UART_CMD_CAPTURE/UART_CMD_SEND macros (code uses local "STR"/"STW" arrays instead), and the tx_flag/rx_flag globals plus their writes in the HAL UART callbacks (write-only, never read; also removes an uninitialized-tx_flag bug since only rx_flag was zero-initialized) - board/stm32f7/configs.h: LCD_FRAME_BUFFER and CAMERA_FRAME_BUFFER defines (never read; display code uses FRAME_BUFFER) - embedDIP_configs.h: derived EMBED_DIP_HAS_CAMERA/EMBED_DIP_HAS_DISPLAY macros and ENABLE_UART_LOGGING defines (all board sections; never consumed anywhere) - CMakeLists.txt: EMBEDDIP_BUILD_DOCS and EMBEDDIP_ENABLE_UART_LOGGING options, plus the associated ENABLE_UART_LOGGING compile definition (neither option was consumed elsewhere in the build) Signed-off-by: Ozan Durgut --- CMakeLists.txt | 3 - arch/arm/cm7_common.c | 34 ----- arch/arm/cm7_fft.c | 46 ------- board/stm32f7/configs.h | 3 - core/image.h | 10 -- device/camera/esp32_ov2640_old.cpp | 212 ----------------------------- device/serial/stm32_uart.c | 6 - embedDIP_configs.h | 17 --- imgproc/fft.c | 55 -------- imgproc/filter.c | 44 ------ imgproc/filter.h | 13 -- imgproc/segmentation.c | 13 -- 12 files changed, 456 deletions(-) delete mode 100644 arch/arm/cm7_common.c delete mode 100644 arch/arm/cm7_fft.c delete mode 100644 device/camera/esp32_ov2640_old.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b87ac32..4c0daed 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,11 +24,9 @@ set_property(CACHE EMBEDDIP_ARCH PROPERTY STRINGS "ARM" "XTENSA") set(EMBEDDIP_CPU "" CACHE STRING "CPU variant (required): CORTEX_M7, LX6, LX7") set_property(CACHE EMBEDDIP_CPU PROPERTY STRINGS "CORTEX_M7" "LX6" "LX7") -option(EMBEDDIP_ENABLE_UART_LOGGING "Enable UART logging" ON) option(EMBEDDIP_ENABLE_IMAGE_PROCESSING "Enable image processing modules" ON) option(EMBEDDIP_ENABLE_CAMERA_INPUT "Enable camera input interfaces" ON) option(EMBEDDIP_ENABLE_DISPLAY_OUTPUT "Enable display output interfaces" ON) -option(EMBEDDIP_BUILD_DOCS "Build documentation with Doxygen" OFF) if(EMBEDDIP_TARGET_BOARD STREQUAL "") message(FATAL_ERROR "EMBEDDIP_TARGET_BOARD is required. Supported values: STM32F7, ESP32") @@ -186,7 +184,6 @@ target_compile_definitions(embedDIP PUBLIC USE_EMBED_DIP ${EMBEDDIP_BOARD_DEFINES} ${EMBEDDIP_ARCH_DEFINES} - $<$:ENABLE_UART_LOGGING=1> $<$:ENABLE_IMAGE_PROCESSING=1> $<$:ENABLE_CAMERA_INPUT=1> $<$:ENABLE_DISPLAY_OUTPUT=1> diff --git a/arch/arm/cm7_common.c b/arch/arm/cm7_common.c deleted file mode 100644 index dd6238c..0000000 --- a/arch/arm/cm7_common.c +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2025 EmbedDIP - -#include - -#if defined(EMBED_DIP_ARCH_ARM) && defined(EMBED_DIP_CPU_CORTEX_M7) - - #include "core/image.h" - - #include - #include - - #include "stm32f7xx_hal.h" - #include - #include - - #define DWT_LAR_KEY 0xC5ACCE55 - -void tic() -{ - // Unlock access to DWT - DWT->LAR = DWT_LAR_KEY; - CoreDebug->DEMCR |= 0x01000000; - DWT->CYCCNT = 0; // reset the counter - DWT->CTRL |= 0x00000001; // enable the counter -} - -uint32_t toc() -{ - DWT->CTRL &= 0xFFFFFFFE; // disable the counter - return DWT->CYCCNT; // Return elapsed cycles -} - -#endif diff --git a/arch/arm/cm7_fft.c b/arch/arm/cm7_fft.c deleted file mode 100644 index d8e58dd..0000000 --- a/arch/arm/cm7_fft.c +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2025 EmbedDIP - -#include - -#if defined(EMBED_DIP_ARCH_ARM) && defined(EMBED_DIP_CPU_CORTEX_M7) - - #include "arm_const_structs.h" - #include "arm_math.h" - #include - -embeddip_status_t embeddip_fft_backend_init(int n) -{ - if (n != 256) { - return EMBEDDIP_ERROR_INVALID_SIZE; - } - return EMBEDDIP_OK; -} - -embeddip_status_t embeddip_fft_backend_forward_1d(float *data, int n) -{ - if (!data) { - return EMBEDDIP_ERROR_NULL_PTR; - } - if (n != 256) { - return EMBEDDIP_ERROR_INVALID_SIZE; - } - - arm_cfft_f32(&arm_cfft_sR_f32_len256, data, 0, 1); - return EMBEDDIP_OK; -} - -embeddip_status_t embeddip_fft_backend_inverse_1d(float *data, int n) -{ - if (!data) { - return EMBEDDIP_ERROR_NULL_PTR; - } - if (n != 256) { - return EMBEDDIP_ERROR_INVALID_SIZE; - } - - arm_cfft_f32(&arm_cfft_sR_f32_len256, data, 1, 1); - return EMBEDDIP_OK; -} - -#endif diff --git a/board/stm32f7/configs.h b/board/stm32f7/configs.h index 96cc29b..4a0337b 100755 --- a/board/stm32f7/configs.h +++ b/board/stm32f7/configs.h @@ -2,6 +2,3 @@ // Copyright (c) 2025 EmbedDIP #define FRAME_BUFFER 0xC0000000 -#define LCD_FRAME_BUFFER 0xC0000000 /* LCD Frame buffer of size 800x480 in ARGB8888 */ -// #define CAMERA_FRAME_BUFFER 0xC0177000 -#define CAMERA_FRAME_BUFFER 0xC0000000 diff --git a/core/image.h b/core/image.h index 6500a8a..141a0f7 100755 --- a/core/image.h +++ b/core/image.h @@ -261,16 +261,6 @@ typedef enum { MORPH_ELLIPSE = 2 /**< Elliptical structuring element */ } MorphShape; -/** - * @struct GMMStats - * @brief Simple Gaussian mixture model statistics (per channel). - */ -typedef struct { - float mean[3]; /**< Per-channel mean (RGB) */ - float var[3]; /**< Per-channel variance (diagonal covariance) */ - int count; /**< Number of samples accumulated */ -} GMMStats; - /** * @struct channels_t * @brief Floating-point image channel storage (up to 6 channels). diff --git a/device/camera/esp32_ov2640_old.cpp b/device/camera/esp32_ov2640_old.cpp deleted file mode 100644 index 7fe8e12..0000000 --- a/device/camera/esp32_ov2640_old.cpp +++ /dev/null @@ -1,212 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright (c) 2025 EmbedDIP - -#include - -// This is an alternative OV2640 implementation. Use esp32_ov2640.cpp instead. -// To enable this implementation, define DEVICE_OV2640_ALT in your project. -#if defined(DEVICE_OV2640_ALT) - - #include "device/camera/camera.h" - - #include - - #include "Arduino.h" - #include "esp32-hal-ledc.h" - #include "esp_camera.h" - #include - #include - #include - #include - - #define CAMERA_MODEL_ESP_EYE // Has PSRAM - #define PWDN_GPIO_NUM -1 - #define RESET_GPIO_NUM -1 - #define XCLK_GPIO_NUM 4 - #define SIOD_GPIO_NUM 18 - #define SIOC_GPIO_NUM 23 - - #define Y9_GPIO_NUM 36 - #define Y8_GPIO_NUM 37 - #define Y7_GPIO_NUM 38 - #define Y6_GPIO_NUM 39 - #define Y5_GPIO_NUM 35 - #define Y4_GPIO_NUM 14 - #define Y3_GPIO_NUM 13 - #define Y2_GPIO_NUM 34 - #define VSYNC_GPIO_NUM 5 - #define HREF_GPIO_NUM 27 - #define PCLK_GPIO_NUM 25 - - #define LED_GPIO_NUM 22 -void setupLedFlash() -{ - #if defined(LED_GPIO_NUM) - ledcAttach(LED_GPIO_NUM, 5000, 8); - #else - log_i("LED flash is disabled -> LED_GPIO_NUM undefined"); - #endif -} -int camera_init(ImageResolution resolution, ImageFormat format) -{ - Serial.println("[INFO] Starting camera initialization..."); - - camera_config_t config; - config.ledc_channel = LEDC_CHANNEL_0; - config.ledc_timer = LEDC_TIMER_0; - config.pin_d0 = Y2_GPIO_NUM; - config.pin_d1 = Y3_GPIO_NUM; - config.pin_d2 = Y4_GPIO_NUM; - config.pin_d3 = Y5_GPIO_NUM; - config.pin_d4 = Y6_GPIO_NUM; - config.pin_d5 = Y7_GPIO_NUM; - config.pin_d6 = Y8_GPIO_NUM; - config.pin_d7 = Y9_GPIO_NUM; - config.pin_xclk = XCLK_GPIO_NUM; - config.pin_pclk = PCLK_GPIO_NUM; - config.pin_vsync = VSYNC_GPIO_NUM; - config.pin_href = HREF_GPIO_NUM; - config.pin_sccb_sda = SIOD_GPIO_NUM; - config.pin_sccb_scl = SIOC_GPIO_NUM; - config.pin_pwdn = PWDN_GPIO_NUM; - config.pin_reset = RESET_GPIO_NUM; - config.xclk_freq_hz = 10000000; - config.frame_size = (framesize_t)resolution; - config.pixel_format = (format == IMAGE_FORMAT_RGB565) ? PIXFORMAT_RGB565 : PIXFORMAT_GRAYSCALE; - config.grab_mode = CAMERA_GRAB_WHEN_EMPTY; - config.fb_location = CAMERA_FB_IN_PSRAM; - config.jpeg_quality = 12; - config.fb_count = 1; - - // Serial.println("[INFO] Camera pins and default config set."); - - if (config.pixel_format == PIXFORMAT_JPEG) { - Serial.println("[INFO] JPEG mode detected."); - if (psramFound()) { - config.jpeg_quality = 10; - config.fb_count = 2; - config.grab_mode = CAMERA_GRAB_LATEST; - // Serial.println("[INFO] PSRAM detected. Using higher quality JPEG and double - // buffers."); - } else { - config.frame_size = (framesize_t)resolution; - config.fb_location = CAMERA_FB_IN_DRAM; - // Serial.println("[WARN] PSRAM not found. Lowering resolution and using DRAM."); - } - } else { - config.frame_size = (framesize_t)resolution; - #if CONFIG_IDF_TARGET_ESP32S3 - config.fb_count = 2; - #endif - // Serial.println("[INFO] Non-JPEG mode. Using QQVGA and double buffer (if ESP32S3)."); - } - - #if defined(CAMERA_MODEL_ESP_EYE) - pinMode(13, INPUT_PULLUP); - pinMode(14, INPUT_PULLUP); - // Serial.println("[INFO] Pull-up enabled on ESP-EYE buttons."); - #endif - - esp_err_t err = esp_camera_init(&config); - if (err != ESP_OK) { - Serial.printf("[ERROR] Camera init failed with error 0x%x\n", err); - return -1; - } - // Serial.println("[INFO] Camera initialized successfully."); - - sensor_t *s = esp_camera_sensor_get(); - if (s->id.PID == OV3660_PID) { - // Serial.println("[INFO] Detected sensor OV3660. Applying default tuning..."); - s->set_vflip(s, 1); - s->set_brightness(s, 1); - s->set_saturation(s, -2); - } - - if (config.pixel_format == PIXFORMAT_JPEG) { - // Serial.println("[INFO] Setting JPEG frame size to QVGA."); - s->set_framesize(s, FRAMESIZE_QVGA); - } - - #if defined(CAMERA_MODEL_M5STACK_WIDE) || defined(CAMERA_MODEL_M5STACK_ESP32CAM) - s->set_vflip(s, 1); - s->set_hmirror(s, 1); - // Serial.println("[INFO] M5STACK: Flipping and mirroring image."); - #endif - - #if defined(CAMERA_MODEL_ESP32S3_EYE) - s->set_vflip(s, 1); - // Serial.println("[INFO] ESP32S3_EYE: Applying vertical flip."); - #endif - - #if defined(LED_GPIO_NUM) - setupLedFlash(); - // Serial.println("[INFO] LED Flash setup completed."); - #endif - - // Serial.println("[INFO] Camera setup completed."); - return 0; -} - -int camera_capture(captureMode mode, Image *inImg) -{ - // Serial.println("[INFO] Capturing image from camera..."); - - camera_fb_t *fb = esp_camera_fb_get(); - if (!fb) { - // Serial.println("[ERROR] Failed to get frame buffer from camera."); - return -1; - } - - // Serial.printf("[INFO] Frame captured. Resolution: %dx%d, Format: %d, Size: %d bytes\n", - // fb->width, fb->height, fb->format, fb->len); - - if (inImg == NULL || inImg->pixels == NULL) { - // Serial.println("[ERROR] Output image buffer is NULL."); - esp_camera_fb_return(fb); - return -2; - } - - if (fb->width != inImg->width || fb->height != inImg->height) { - // Serial.printf("[ERROR] Size mismatch! Expected: %dx%d, Got: %dx%d\n", inImg->width, - // inImg->height, fb->width, fb->height); - esp_camera_fb_return(fb); - return -3; - } - - if (fb->format != PIXFORMAT_GRAYSCALE) { - // Serial.printf("[ERROR] Pixel format mismatch. Expected GRAYSCALE (1), got: %d\n", - // fb->format); - esp_camera_fb_return(fb); - return -4; - } - - memcpy(inImg->pixels, fb->buf, fb->len); - // Serial.printf("[INFO] Image copied to buffer. %d bytes written.\n", fb->len); - - esp_camera_fb_return(fb); - // Serial.println("[INFO] Frame buffer returned to camera driver."); - - return 0; -} - -int camera_stop(void) -{ - return 0; -} -int camera_setRes(ImageResolution resolution) -{ - sensor_t *s = esp_camera_sensor_get(); - if (!s) - return -1; - - s->set_framesize(s, (framesize_t)resolution); - - return 0; -} - -camera_t esp32_ov2640 = {.init = camera_init, - .capture = camera_capture, - .stop = camera_stop, - .setRes = camera_setRes}; - -#endif diff --git a/device/serial/stm32_uart.c b/device/serial/stm32_uart.c index 3896db9..168d63b 100644 --- a/device/serial/stm32_uart.c +++ b/device/serial/stm32_uart.c @@ -42,21 +42,15 @@ static int serial_flush(void) } #define UART_BLOCK_SIZE_MAX 65535 - #define UART_CMD_CAPTURE "STR" - #define UART_CMD_SEND "STW" - -volatile bool tx_flag, rx_flag = false; void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { (void)huart; - tx_flag = true; } void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { (void)huart; - rx_flag = true; } static int serial_capture(Image *img) diff --git a/embedDIP_configs.h b/embedDIP_configs.h index abe3373..b44cb92 100755 --- a/embedDIP_configs.h +++ b/embedDIP_configs.h @@ -129,9 +129,6 @@ #define STM32F7xx 1 #endif - #ifndef ENABLE_UART_LOGGING - #define ENABLE_UART_LOGGING 1 - #endif #ifndef ENABLE_IMAGE_PROCESSING #define ENABLE_IMAGE_PROCESSING 1 #endif @@ -158,9 +155,6 @@ #define ARDUINO_ARCH_ESP32 1 #endif - #ifndef ENABLE_UART_LOGGING - #define ENABLE_UART_LOGGING 1 - #endif #ifndef ENABLE_IMAGE_PROCESSING #define ENABLE_IMAGE_PROCESSING 1 #endif @@ -186,17 +180,6 @@ * @brief Non-user-editable convenience macros computed from the config. * @{ */ -#if (ENABLE_CAMERA_INPUT) - #define EMBED_DIP_HAS_CAMERA 1 -#else - #define EMBED_DIP_HAS_CAMERA 0 -#endif - -#if (ENABLE_DISPLAY_OUTPUT) - #define EMBED_DIP_HAS_DISPLAY 1 -#else - #define EMBED_DIP_HAS_DISPLAY 0 -#endif /** @} */ /* end of embedDIP_cfg_derived */ #endif /* EMBED_DIP_CONFIGS_H */ diff --git a/imgproc/fft.c b/imgproc/fft.c index 7498e59..1f5d220 100644 --- a/imgproc/fft.c +++ b/imgproc/fft.c @@ -339,61 +339,6 @@ embeddip_status_t polarToCart(const Image *mag_img, const Image *phase_img, Imag return EMBEDDIP_OK; } -embeddip_status_t multiply(const Image *img1, const Image *img2, Image *outImg) -{ - if (!img1 || !img2 || !outImg) - return EMBEDDIP_ERROR_NULL_PTR; - - if (img1->width != img2->width || img1->height != img2->height) - return EMBEDDIP_ERROR_INVALID_SIZE; - - if (isChalsEmpty(outImg)) { - embeddip_status_t status = createChals(outImg, 1); - if (status != EMBEDDIP_OK) - return status; - outImg->is_chals = 1; - } - - float *in1 = NULL; - float *in2 = NULL; - const uint8_t *pix1 = NULL; - const uint8_t *pix2 = NULL; - - if (img1->log == IMAGE_DATA_CH0) { - in1 = img1->chals ? img1->chals->ch[0] : NULL; - } else if (img1->log == IMAGE_DATA_COMPLEX) { - in1 = img1->chals ? img1->chals->ch[1] : NULL; - } else if (img1->log == IMAGE_DATA_PIXELS) { - pix1 = (const uint8_t *)img1->pixels; - } else { - return EMBEDDIP_ERROR_INVALID_ARG; - } - - if (img2->log == IMAGE_DATA_CH0) { - in2 = img2->chals ? img2->chals->ch[0] : NULL; - } else if (img2->log == IMAGE_DATA_COMPLEX) { - in2 = img2->chals ? img2->chals->ch[1] : NULL; - } else if (img2->log == IMAGE_DATA_PIXELS) { - pix2 = (const uint8_t *)img2->pixels; - } else { - return EMBEDDIP_ERROR_INVALID_ARG; - } - - if ((!in1 && !pix1) || (!in2 && !pix2) || !outImg->chals || !outImg->chals->ch[0]) - return EMBEDDIP_ERROR_NULL_PTR; - - float *out = outImg->chals->ch[0]; - int size = img1->width * img1->height; - for (int i = 0; i < size; ++i) { - float v1 = in1 ? in1[i] : (float)pix1[i]; - float v2 = in2 ? in2[i] : (float)pix2[i]; - out[i] = v1 * v2; - } - - outImg->log = IMAGE_DATA_CH0; - return EMBEDDIP_OK; -} - embeddip_status_t difference(const Image *src1, const Image *src2, Image *dst) { if (!src1 || !src2 || !dst) diff --git a/imgproc/filter.c b/imgproc/filter.c index a53278f..42d5702 100755 --- a/imgproc/filter.c +++ b/imgproc/filter.c @@ -317,47 +317,6 @@ embeddip_status_t sepfilter2D(Image *src, return EMBEDDIP_OK; } -/* -void wrapper(ImageOpFunc func, Image *src, Image *dst, void *context) -{ - assert(func && src && dst); - assert(src->format == dst->format); - - // Ensure channels are allocated for input - if (!src->is_chals) - { - src->chals = (channels_t *)memory_alloc(sizeof(channels_t)); - src->is_chals = true; - for (int i = 0; i < 4; ++i) - src->chals->ch[i] = NULL; - } - - // Ensure channels are allocated for output - if (!dst->is_chals) - { - dst->chals = (channels_t *)memory_alloc(sizeof(channels_t)F); - dst->is_chals = true; - for (int i = 0; i < 4; ++i) - dst->chals->ch[i] = NULL; - } - - // Dispatch per format - if (src->format == IMAGE_FORMAT_GRAYSCALE) - { - func(src, dst, 0, context); // l channel - } - else if (src->format == IMAGE_FORMAT_RGB888) - { - for (int ch = 1; ch <= 3; ++ch) // r=1, g=2, b=3 - func(src, dst, ch, context); - } - else - { - assert(false && "Unsupported format in wrapper"); - } -} - */ - /** * @brief Applies a min filter (non-linear) to the image using a square window. * @@ -1100,9 +1059,6 @@ void nonMaximumSuppression(const Image *magImg, const Image *phaseImg, Image *ds dst->log = IMAGE_DATA_CH0; } -#define STRONG 255 -#define WEAK 50 - /** * @brief Apply double thresholding to classify strong/weak edges. * Writes to float ch0 (values: 0.0f, weakVal, strongVal). diff --git a/imgproc/filter.h b/imgproc/filter.h index 671cc42..1749d2e 100755 --- a/imgproc/filter.h +++ b/imgproc/filter.h @@ -25,19 +25,6 @@ typedef struct { int chal; ///< Reserved channel field (internal use) } Filter2DContext; -/** - * @brief Context for separable 2D convolution. - * - * Stores independent horizontal and vertical 1D kernels. - */ -typedef struct { - int sizeX; ///< Horizontal kernel size - const float *kernelX; ///< Horizontal kernel coefficients - int sizeY; ///< Vertical kernel size - const float *kernelY; ///< Vertical kernel coefficients - float delta; ///< Offset added after convolution -} SepFilter2DContext; - /** * @brief Applies 2D filter to a single channel (internal helper function). * @param src Pointer to the input image diff --git a/imgproc/segmentation.c b/imgproc/segmentation.c index 570fd7c..251f6e2 100644 --- a/imgproc/segmentation.c +++ b/imgproc/segmentation.c @@ -934,21 +934,8 @@ embeddip_status_t colorRegionGrowing(const Image *inImg, #define FOREGROUND 255 #define BACKGROUND 0 -#define GMM_COMPONENTS 2 #define MAX_ITER_GRABCUT 5 -typedef struct { - float weight; - float mean; - float variance; -} GMMComponent; - -static float gaussian_prob(float x, float mean, float var) -{ - float diff = x - mean; - return (1.0f / sqrtf(2.0f * M_PI * var)) * expf(-(diff * diff) / (2.0f * var)); -} - /** * @brief Performs a simplified GrabCut-inspired segmentation on a grayscale image using a * rectangular ROI.