Skip to content

Commit 50b2e40

Browse files
committed
ports/espressif/common-hal/espcamera/Camera.c: check for unspecified pins
1 parent eff544c commit 50b2e40

File tree

3 files changed

+13
-13
lines changed
  • ports/espressif

3 files changed

+13
-13
lines changed

ports/espressif/boards/adafruit_esp32s3_camera/board.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "esp_log.h"
1818
#include "esp_err.h"
19-
#include "driver/i2c.h"
2019

2120

2221
#define DELAY 0x80

ports/espressif/boards/seeed_xiao_esp32_s3_sense/board.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
//
55
// SPDX-License-Identifier: MIT
66

7-
#include "supervisor/board.h"
87
#include "mpconfigboard.h"
9-
#include "esp_log.h"
10-
#include "esp_err.h"
11-
#include "driver/i2c.h"
128

139
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/espressif/common-hal/espcamera/Camera.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
#ifndef CONFIG_PM_ENABLE
2727
#define CONFIG_PM_ENABLE 0
2828
#endif
29-
#include "esp-idf/components/driver/i2c/i2c_private.h"
29+
30+
// i2c_private.h uses `#if` with some macros that may be undefined and taken as 0.
31+
#pragma GCC diagnostic push
32+
#pragma GCC diagnostic ignored "-Wundef"
33+
#include "esp-idf/components/esp_driver_i2c/i2c_private.h"
34+
#pragma GCC diagnostic pop
3035

3136
#include "esp-camera/driver/private_include/cam_hal.h"
3237

@@ -90,13 +95,12 @@ void common_hal_espcamera_camera_construct(
9095

9196
self->i2c = i2c;
9297

93-
self->camera_config.pin_pwdn = common_hal_mcu_pin_number(powerdown_pin);
94-
self->camera_config.pin_reset = common_hal_mcu_pin_number(reset_pin);
95-
self->camera_config.pin_xclk = common_hal_mcu_pin_number(external_clock_pin);
98+
// These pins might be NULL because they were not specified.
99+
self->camera_config.pin_pwdn = powerdown_pin ? common_hal_mcu_pin_number(powerdown_pin) : NO_PIN;
100+
self->camera_config.pin_reset = reset_pin ? common_hal_mcu_pin_number(reset_pin) : NO_PIN;
101+
self->camera_config.pin_xclk = external_clock_pin ? common_hal_mcu_pin_number(external_clock_pin) : NO_PIN;
96102

97-
self->camera_config.pin_sccb_sda = NO_PIN;
98-
self->camera_config.pin_sccb_scl = NO_PIN;
99-
/* sccb i2c port set below */
103+
self->camera_config.sccb_i2c_master_bus_handle = self->i2c->handle;
100104

101105
self->camera_config.pin_d7 = data_pins[7];
102106
self->camera_config.pin_d6 = data_pins[6];
@@ -119,7 +123,7 @@ void common_hal_espcamera_camera_construct(
119123
self->camera_config.fb_count = framebuffer_count;
120124
self->camera_config.grab_mode = grab_mode;
121125

122-
self->camera_config.sccb_i2c_port = self->i2c->handle->base->port_num;
126+
123127

124128
i2c_lock(self);
125129
esp_err_t result = esp_camera_init(&self->camera_config);
@@ -135,6 +139,7 @@ extern void common_hal_espcamera_camera_deinit(espcamera_camera_obj_t *self) {
135139

136140
common_hal_pwmio_pwmout_deinit(&self->pwm);
137141

142+
// Does nothing if pin is NO_PIN (-1).
138143
reset_pin_number(self->camera_config.pin_pwdn);
139144
reset_pin_number(self->camera_config.pin_reset);
140145
reset_pin_number(self->camera_config.pin_xclk);

0 commit comments

Comments
 (0)