Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/espressif/bindings/espcamera/Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void check_for_deinit(espcamera_camera_obj_t *self) {
static mp_obj_t espcamera_camera_frame_available_get(const mp_obj_t self_in) {
espcamera_camera_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
return mp_obj_new_bool(esp_camera_fb_available());
return mp_obj_new_bool(common_hal_espcamera_camera_available(self));
}
static MP_DEFINE_CONST_FUN_OBJ_1(espcamera_camera_frame_available_get_obj, espcamera_camera_frame_available_get);

Expand Down
14 changes: 14 additions & 0 deletions ports/espressif/common-hal/busio/I2C.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "py/runtime.h"

#include "driver/gpio.h"
#include "soc/soc_caps.h"

#include "bindings/espidf/__init__.h"
#include "shared-bindings/microcontroller/__init__.h"
Expand Down Expand Up @@ -88,6 +89,19 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self,
}
CHECK_ESP_RESULT(result);

// Record which port the auto-selected bus landed on. There is no public accessor to map
// a bus handle back to its port, so match the handle against each initialized port.
// Other code (e.g. espcamera) needs the port number to reuse this same bus rather than
// create a second master bus on the same pins.
self->port = -1;
for (i2c_port_num_t port = 0; port < (int)SOC_HP_I2C_NUM; port++) {
i2c_master_bus_handle_t bus_handle;
if (i2c_master_get_bus_handle(port, &bus_handle) == ESP_OK && bus_handle == self->handle) {
self->port = port;
break;
}
}

self->xSemaphore = xSemaphoreCreateMutex();
if (self->xSemaphore == NULL) {
i2c_del_master_bus(self->handle);
Expand Down
1 change: 1 addition & 0 deletions ports/espressif/common-hal/busio/I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef struct {
size_t timeout_ms;
size_t frequency;
i2c_master_bus_handle_t handle;
i2c_port_num_t port;
SemaphoreHandle_t xSemaphore;
bool has_lock;
} busio_i2c_obj_t;
9 changes: 6 additions & 3 deletions ports/espressif/common-hal/espcamera/Camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ void common_hal_espcamera_camera_construct(
self->camera_config.pin_reset = reset_pin ? common_hal_mcu_pin_number(reset_pin) : NO_PIN;
self->camera_config.pin_xclk = external_clock_pin ? common_hal_mcu_pin_number(external_clock_pin) : NO_PIN;

self->camera_config.pin_sccb_sda = common_hal_mcu_pin_number(i2c->sda_pin);
self->camera_config.pin_sccb_scl = common_hal_mcu_pin_number(i2c->scl_pin);
// Reuse the I2C bus that CircuitPython already created on these pins instead of letting
// esp32-camera create a second master bus on the same pins, which doesn't work.
self->camera_config.pin_sccb_sda = -1;
self->camera_config.pin_sccb_scl = -1;
self->camera_config.sccb_i2c_port = i2c->port;

self->camera_config.pin_d7 = data_pins[7];
self->camera_config.pin_d6 = data_pins[6];
Expand Down Expand Up @@ -154,7 +157,7 @@ bool common_hal_espcamera_camera_deinited(espcamera_camera_obj_t *self) {
}

bool common_hal_espcamera_camera_available(espcamera_camera_obj_t *self) {
return esp_camera_fb_available();
return esp_camera_available_frames();
}

camera_fb_t *common_hal_espcamera_camera_take(espcamera_camera_obj_t *self, int timeout_ms) {
Expand Down
Loading