Skip to content

Commit 4f7bb95

Browse files
committed
Improve error handling for setting pixel format
1 parent b817e9b commit 4f7bb95

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
@@ -327,22 +327,28 @@ esp_err_t esp_camera_init(const camera_config_t *config)
327327
frame_size = camera_sensor[camera_model].max_size;
328328
}
329329

330+
s_state->sensor.pixformat = pix_format;
331+
ESP_LOGD(TAG, "Setting pixel format to %d", pix_format);
332+
if (s_state->sensor.set_pixformat(&s_state->sensor, pix_format)) {
333+
ESP_LOGE(TAG, "Failed to set pixel format");
334+
err = ESP_ERR_CAMERA_FAILED_TO_SET_PIXEL_FORMAT;
335+
goto fail;
336+
}
337+
330338
err = cam_config(config, frame_size, s_state->sensor.id.PID);
331339
if (err != ESP_OK) {
332340
ESP_LOGE(TAG, "Camera config failed with error 0x%x", err);
333341
goto fail;
334342
}
335343

336344
s_state->sensor.status.framesize = frame_size;
337-
s_state->sensor.pixformat = pix_format;
338-
339345
ESP_LOGD(TAG, "Setting frame size to %dx%d", resolution[frame_size].width, resolution[frame_size].height);
340346
if (s_state->sensor.set_framesize(&s_state->sensor, frame_size) != 0) {
341347
ESP_LOGE(TAG, "Failed to set frame size");
342348
err = ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE;
343349
goto fail;
344350
}
345-
s_state->sensor.set_pixformat(&s_state->sensor, pix_format);
351+
346352
#if CONFIG_CAMERA_CONVERTER_ENABLED
347353
if(config->conv_mode) {
348354
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)