Skip to content

Commit 7472fc7

Browse files
committed
Improve error handling for setting pixel format
1 parent 4467667 commit 7472fc7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

driver/esp_camera.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,28 @@ esp_err_t esp_camera_init(const camera_config_t *config)
305305
frame_size = camera_sensor[camera_model].max_size;
306306
}
307307

308+
s_state->sensor.pixformat = pix_format;
309+
ESP_LOGD(TAG, "Setting pixel format to %d", pix_format);
310+
if (s_state->sensor.set_pixformat(&s_state->sensor, pix_format)) {
311+
ESP_LOGE(TAG, "Failed to set pixel format");
312+
err = ESP_ERR_CAMERA_FAILED_TO_SET_PIXEL_FORMAT;
313+
goto fail;
314+
}
315+
308316
err = cam_config(config, frame_size, s_state->sensor.id.PID);
309317
if (err != ESP_OK) {
310318
ESP_LOGE(TAG, "Camera config failed with error 0x%x", err);
311319
goto fail;
312320
}
313321

314322
s_state->sensor.status.framesize = frame_size;
315-
s_state->sensor.pixformat = pix_format;
316-
317323
ESP_LOGD(TAG, "Setting frame size to %dx%d", resolution[frame_size].width, resolution[frame_size].height);
318324
if (s_state->sensor.set_framesize(&s_state->sensor, frame_size) != 0) {
319325
ESP_LOGE(TAG, "Failed to set frame size");
320326
err = ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE;
321327
goto fail;
322328
}
323-
s_state->sensor.set_pixformat(&s_state->sensor, pix_format);
329+
324330
#if CONFIG_CAMERA_CONVERTER_ENABLED
325331
if(config->conv_mode) {
326332
s_state->sensor.pixformat = get_output_data_format(config->conv_mode); // If conversion enabled, change the out data format by conversion mode

driver/include/esp_camera.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,11 @@ typedef struct {
170170
} camera_fb_t;
171171

172172
#define ESP_ERR_CAMERA_BASE 0x20000
173-
#define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
174-
#define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
175-
#define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 3)
176-
#define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 4)
173+
#define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
174+
#define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
175+
#define ESP_ERR_CAMERA_FAILED_TO_SET_PIXEL_FORMAT (ESP_ERR_CAMERA_BASE + 3)
176+
#define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 4)
177+
#define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 5)
177178

178179
/**
179180
* @brief Initialize the camera driver

0 commit comments

Comments
 (0)