Compare commits

...

29 commits

Author SHA1 Message Date
Dan Halbert
1eabcf46cc CI only for ESP-IDF v5.3 and later 2024-09-27 22:06:20 -04:00
Dan Halbert
046076ca0e use new I2C driver only for ESP-IDF v5.3 and later 2024-09-27 22:03:18 -04:00
Dan Halbert
66c1eff410 fix Write16 bugs; remove unused code 2024-09-27 19:35:23 -04:00
Dan Halbert
bb2ba48e41 register/deregister SCCB I2C device on each read/write 2024-09-24 20:38:50 -04:00
Dan Halbert
7d2126a87c Force new I2C driver; workaround v5.3 instead of v5.4 2024-09-23 20:03:24 -04:00
Dan Halbert
90c1541e2c Merge remote-tracking branch 'espressif/master' into merge-2.0.12-to-circuitpython 2024-09-21 15:49:21 -04:00
Scott Shawcroft
d529ebdffb
Merge pull request #8 from tannewt/update_esp_camera_bae46be
Update esp camera bae46be
2024-03-25 13:47:47 -07:00
Scott Shawcroft
9abb23ed43
Merge remote-tracking branch 'espressif/master' into HEAD 2024-03-22 16:19:14 -07:00
Scott Shawcroft
8f3f2cc8cf
Merge pull request #7 from tannewt/merge_esp_camera
Merge esp camera upstream
2023-09-21 10:01:35 -07:00
Scott Shawcroft
e8d500e948
Merge remote-tracking branch 'origin/master' into circuitpython 2023-09-20 14:34:14 -07:00
75035312ed
Merge pull request #6 from adafruit/solarize
Add solarize effect
2023-08-02 10:19:24 -05:00
2758089a06
Add solarize effect
register 0x5003 bit 0 is solarize. needs a change in the pycamera app too.
2023-08-02 08:00:30 -05:00
Scott Shawcroft
68432607d5
Merge pull request #5 from adafruit/faster-probe
Faster probe
2023-08-01 13:14:03 -07:00
2cd2a6d69f
sccb: lower timeout when probing for camera
1000ms is too long. let's try 50ms.
2023-07-26 12:51:06 -05:00
2710e44802
sccb: don't perform an i2c bus scan 2023-07-26 12:50:38 -05:00
Dan Halbert
4ff7f348d0
Merge pull request #4 from deshipu/circuitpython
Make xclk pin optional
2022-12-16 13:43:13 -05:00
Radomir Dopieralski
d117548c22 Make xclk pin optional
Some camera modules come with a crystal oscillator that already provides
the main clock, and they don't have the xclk/mclk pin. We don't need to
initialize the PWM pin then.

(cherry picked from commit 896cb707dd)
2022-12-16 17:13:45 +01:00
Dan Halbert
7e51ff74b9
Merge pull request #2 from MicroDev1/master
Merge upstream updates
2022-09-20 12:15:45 -04:00
microDev
80b5754456
merge upstream updates 2022-09-17 16:10:32 +05:30
Dan Halbert
54c3f61c86
Merge pull request #1 from adafruit/safe-disable_out_clock
don't reset LEDC channel if it wasn't used by camera
2022-09-13 12:49:34 -04:00
Dan Halbert
7613e49686 don't reset LEDC channel if it wasn't used by camera 2022-09-12 21:11:26 -04:00
Jeff Epler
28804391c0 Fix timeout-get accidental recursion 2022-08-01 09:10:35 -05:00
Jeff Epler
524ba7e0d2 Ensure function declarations are prototypes
(this hid a bug)
2022-08-01 09:10:16 -05:00
Jeff Epler
86627584ef Make sure core pinning is not wrong
there's probably a way to do this in kconfig but I don't know it
2022-08-01 09:10:00 -05:00
Jeff Epler
a12beb9bdb wip 2022-07-29 14:23:37 -05:00
Jeff Epler
476bdc8ec6 use new name 2022-07-29 14:19:49 -05:00
Jeff Epler
2c75c07b44 Fix up sccb driver 2022-07-29 14:19:40 -05:00
Jeff Epler
0018898510 Rename to "sscb" for consistency, but support old name via union 2022-07-29 14:19:22 -05:00
Jeff Epler
6c31a4dccd Allow specifying the i2c port to use for sccb
To do this, put NO_PIN (-1) in `pin_sccb_sda` and set `sccb_i2c_port`.
2022-07-28 12:10:55 -05:00
12 changed files with 161 additions and 189 deletions

View file

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "latest"]
idf_ver: ["release-v5.3", "latest"]
idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3"]
container: espressif/idf:${{ matrix.idf_ver }}
steps:

View file

@ -84,7 +84,8 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
# include the SCCB I2C driver
# this uses either the legacy I2C API or the newwer version from IDF v5.4
# as this features a method to obtain the I2C driver from a port number
if (idf_version VERSION_GREATER_EQUAL "5.4")
# CIRCUITPY-CHANGE: Use new driver for 5.3 or greater.
if (idf_version VERSION_GREATER_EQUAL "5.3")
list(APPEND srcs driver/sccb-ng.c)
else()
list(APPEND srcs driver/sccb.c)
@ -93,7 +94,7 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
endif()
# CONFIG_ESP_ROM_HAS_JPEG_DECODE is available from IDF v4.4 but
# previous IDF supported chips already support JPEG decoder, hence okay to use this
# previous IDF supported chips already support JPEG decoder, hence okay qto use this
if(idf_version VERSION_GREATER_EQUAL "4.4" AND NOT CONFIG_ESP_ROM_HAS_JPEG_DECODE)
list(APPEND srcs
target/tjpgd.c

View file

@ -409,6 +409,9 @@ esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint
#if CONFIG_CAMERA_CORE0
xTaskCreatePinnedToCore(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle, 0);
#elif CONFIG_CAMERA_CORE1
#if CONFIG_FREERTOS_UNICORE
#error "Cannot pin to core 1 on unicore"
#endif
xTaskCreatePinnedToCore(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle, 1);
#else
xTaskCreate(cam_task, "cam_task", CAM_TASK_STACK, NULL, configMAX_PRIORITIES - 2, &cam_obj->task_handle);
@ -534,3 +537,10 @@ void cam_give_all(void) {
cam_obj->frames[x].en = 1;
}
}
bool cam_avail(void)
{
camera_fb_t *dma_buffer = NULL;
BaseType_t result = xQueuePeek(cam_obj->frame_buffer_queue, (void *)&dma_buffer, 0);
return result != pdFALSE;
}

View file

@ -163,12 +163,15 @@ static esp_err_t camera_probe(const camera_config_t *config, camera_model_t *out
CAMERA_ENABLE_OUT_CLOCK(config);
}
if (config->pin_sccb_sda != -1) {
ESP_LOGD(TAG, "Initializing SCCB");
ret = SCCB_Init(config->pin_sccb_sda, config->pin_sccb_scl);
} else {
// CIRCUITPY-CHANGE: use passed-in handle; never initialize with pins
// if (config->pin_sccb_sda != -1) {
// ESP_LOGD(TAG, "Initializing SCCB");
// ret = SCCB_Init(config->pin_sccb_sda, config->pin_sccb_scl);
// } else {
{
ESP_LOGD(TAG, "Using existing I2C port");
ret = SCCB_Use_Port(config->sccb_i2c_port);
// CIRCUITPY-CHANGE: pass in bus handle.
ret = SCCB_Use_Handle(config->sccb_i2c_master_bus_handle);
}
if(ret != ESP_OK) {
@ -356,14 +359,25 @@ esp_err_t esp_camera_deinit()
return ret;
}
#define FB_GET_TIMEOUT (4000 / portTICK_PERIOD_MS)
#define FB_GET_TIMEOUT (4000)
camera_fb_t *esp_camera_fb_get()
bool esp_camera_fb_available() {
if (s_state == NULL) {
return false;
}
return cam_avail();
}
camera_fb_t *esp_camera_fb_get(void)
{
return esp_camera_fb_get_timeout(FB_GET_TIMEOUT);
}
camera_fb_t *esp_camera_fb_get_timeout(int timeout) {
if (s_state == NULL) {
return NULL;
}
camera_fb_t *fb = cam_take(FB_GET_TIMEOUT);
camera_fb_t *fb = cam_take(timeout / portTICK_PERIOD_MS);
//set the frame properties
if (fb) {
fb->width = resolution[s_state->sensor.status.framesize].width;
@ -483,4 +497,3 @@ void esp_camera_return_all(void) {
}
cam_give_all();
}

View file

@ -72,6 +72,9 @@
#include "sys/time.h"
#include "sdkconfig.h"
// CIRCUITPY-CHANGE. Remove after updating to ESP-IDF v5.4.
#include "driver/i2c_types.h"
/**
* @brief define for if chip supports camera
*/
@ -154,7 +157,9 @@ typedef struct {
camera_conv_mode_t conv_mode; /*!< RGB<->YUV Conversion mode */
#endif
int sccb_i2c_port; /*!< If pin_sccb_sda is -1, use the already configured I2C bus by number */
// CIRCUITPY-CHANGE: use handle instead of port, because it's owned by CircuitPython
// int sccb_i2c_port; /*!< If pin_sccb_sda is -1, use the already configured I2C bus by number */
i2c_master_bus_handle_t sccb_i2c_master_bus_handle;
} camera_config_t;
/**
@ -202,6 +207,13 @@ esp_err_t esp_camera_init(const camera_config_t* config);
*/
esp_err_t esp_camera_deinit(void);
/**
* @brief Obtain pointer to a frame buffer, with timeout.
*
* @return pointer to the frame buffer, or NULL if no frame was obtained within the timeout
*/
camera_fb_t* esp_camera_fb_get_timeout(int timeout_ms);
/**
* @brief Obtain pointer to a frame buffer.
*
@ -209,6 +221,13 @@ esp_err_t esp_camera_deinit(void);
*/
camera_fb_t* esp_camera_fb_get(void);
/**
* @brief Check whether a framebuffer is avaiable without blocking
*
* @return true if available, false otherwise
*/
bool esp_camera_fb_available(void);
/**
* @brief Return the frame buffer to be reused again.
*
@ -248,4 +267,3 @@ void esp_camera_return_all(void);
#endif
#include "img_converters.h"

View file

@ -51,6 +51,8 @@ void cam_stop(void);
void cam_start(void);
bool cam_avail(void);
camera_fb_t *cam_take(TickType_t timeout);
void cam_give(camera_fb_t *dma_buffer);

View file

@ -9,8 +9,11 @@
#ifndef __SCCB_H__
#define __SCCB_H__
#include <stdint.h>
// CIRCUITPY-CHANGE: need i2c_master_bus_handle_t
#include "driver/i2c_types.h"
int SCCB_Init(int pin_sda, int pin_scl);
int SCCB_Use_Port(int sccb_i2c_port);
// CIRCUITPY-CHANGE: pass handle instead of port
int SCCB_Use_Handle(i2c_master_bus_handle_t handle);
int SCCB_Deinit(void);
uint8_t SCCB_Probe(void);
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg);

View file

@ -23,7 +23,8 @@ static const char *TAG = "sccb-ng";
#define LITTLETOBIG(x) ((x << 8) | (x >> 8))
#include "esp_private/i2c_platform.h"
// CIRCUITPY-CHANGE: not available until ESP-IDF v5.4, and not needed
// #include "esp_private/i2c_platform.h"
#include "driver/i2c_master.h"
#include "driver/i2c_types.h"
@ -34,173 +35,68 @@ static const char *TAG = "sccb-ng";
#define TIMEOUT_MS 1000 /*!< I2C timeout duration */
#define SCCB_FREQ CONFIG_SCCB_CLK_FREQ /*!< I2C master frequency */
#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave */
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
#define ACK_VAL 0x0 /*!< I2C ack value */
#define NACK_VAL 0x1 /*!< I2C nack value */
#if CONFIG_SCCB_HARDWARE_I2C_PORT1
const int SCCB_I2C_PORT_DEFAULT = 1;
#else
const int SCCB_I2C_PORT_DEFAULT = 0;
#endif
#define MAX_DEVICES UINT8_MAX-1
// CIRCUITPY-CHANGE: device handles are registered and dregistered on each read and write, so they are not
// remembered.
/*
The legacy I2C driver used addresses to differentiate between devices, whereas the new driver uses
i2c_master_dev_handle_t structs which are registed to the bus.
To avoid re-writing all camera dependant code, we simply translate the devices address to the corresponding
device_handle. This keeps all interfaces to the drivers identical.
To perform this conversion the following local struct is used.
*/
typedef struct
// CIRCUITPY-CHANGE: remember the passed-in bus handle insted of the port.
// The I2C bus handle is owned and managed by CircuitPython.
static i2c_master_bus_handle_t sccb_i2c_master_bus_handle;
static esp_err_t register_device(uint8_t device_addr, i2c_master_dev_handle_t *dev_handle)
{
i2c_master_dev_handle_t dev_handle;
uint16_t address;
} device_t;
i2c_device_config_t dev_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = device_addr,
.scl_speed_hz = SCCB_FREQ,
};
static device_t devices[MAX_DEVICES];
static uint8_t device_count = 0;
static int sccb_i2c_port;
static bool sccb_owns_i2c_port;
i2c_master_dev_handle_t *get_handle_from_address(uint8_t slv_addr)
{
for (uint8_t i = 0; i < device_count; i++)
{
if (slv_addr == devices[i].address)
{
return &(devices[i].dev_handle);
}
esp_err_t ret = i2c_master_bus_add_device(sccb_i2c_master_bus_handle, &dev_config, dev_handle);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "register_device failed bus_handle:%p, slv_addr: 0x%02x, ret:%d", sccb_i2c_master_bus_handle, device_addr, ret);
}
ESP_LOGE(TAG, "Device with address %02x not found", slv_addr);
return NULL;
return ret;
}
static esp_err_t deregister_device(i2c_master_dev_handle_t dev_handle)
{
esp_err_t ret = i2c_master_bus_rm_device(dev_handle);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "deregister_device failed ret:%d", ret);
}
return ret;
}
int SCCB_Install_Device(uint8_t slv_addr)
{
esp_err_t ret;
i2c_master_bus_handle_t bus_handle;
if (device_count > MAX_DEVICES)
{
ESP_LOGE(TAG, "cannot add more than %d devices", MAX_DEVICES);
return ESP_FAIL;
}
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
return ret;
}
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = slv_addr, // not yet set
.scl_speed_hz = SCCB_FREQ,
};
ret = i2c_master_bus_add_device(bus_handle, &dev_cfg, &(devices[device_count].dev_handle));
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to install SCCB I2C device: %s", esp_err_to_name(ret));
return -1;
}
devices[device_count].address = slv_addr;
device_count++;
// CIRCUITPY-CHANGE: don't install device: each read or write will do that temporarily,
return 0;
}
int SCCB_Init(int pin_sda, int pin_scl)
{
ESP_LOGI(TAG, "pin_sda %d pin_scl %d", pin_sda, pin_scl);
// i2c_config_t conf;
esp_err_t ret;
sccb_i2c_port = SCCB_I2C_PORT_DEFAULT;
sccb_owns_i2c_port = true;
ESP_LOGI(TAG, "sccb_i2c_port=%d", sccb_i2c_port);
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = SCCB_I2C_PORT_DEFAULT,
.scl_io_num = pin_scl,
.sda_io_num = pin_sda,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = 1};
i2c_master_bus_handle_t bus_handle;
ret = i2c_new_master_bus(&i2c_mst_config, &bus_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to install SCCB I2C master bus on port %d: %s", sccb_i2c_port, esp_err_to_name(ret));
return ret;
}
return ESP_OK;
// CIRCUITPY-CHANGE: initialization via pins not available; do not use
return ESP_FAIL;
}
int SCCB_Use_Port(int i2c_num)
{ // sccb use an already initialized I2C port
if (sccb_owns_i2c_port)
{
SCCB_Deinit();
}
if (i2c_num < 0 || i2c_num > I2C_NUM_MAX)
{
return ESP_ERR_INVALID_ARG;
}
sccb_i2c_port = i2c_num;
// CIRCUITPY-CHANGE: pass in handle instead of port, because handle is owned by CircuitPython
int SCCB_Use_Handle(i2c_master_bus_handle_t handle)
{
sccb_i2c_master_bus_handle = handle;
return ESP_OK;
}
int SCCB_Deinit(void)
{
esp_err_t ret;
for (uint8_t i = 0; i < device_count; i++)
{
ret = i2c_master_bus_rm_device(devices[i].dev_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to remove SCCB I2C Device");
return ret;
}
devices[i].dev_handle = NULL;
devices[i].address = 0;
}
device_count = 0;
if (!sccb_owns_i2c_port)
{
return ESP_OK;
}
sccb_owns_i2c_port = false;
i2c_master_bus_handle_t bus_handle;
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
return ret;
}
ret = i2c_del_master_bus(bus_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to get delete SCCB I2C Master Bus at port %d", sccb_i2c_port);
return ret;
}
// CIRCUITPY-CHANGE: don't install device: each read or write will do that temporarily,
return ESP_OK;
}
@ -208,14 +104,7 @@ uint8_t SCCB_Probe(void)
{
uint8_t slave_addr = 0x0;
esp_err_t ret;
i2c_master_bus_handle_t bus_handle;
ret = i2c_master_get_bus_handle(sccb_i2c_port, &bus_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "failed to get SCCB I2C Bus handle for port %d", sccb_i2c_port);
return ret;
}
// CIRCUITPY-CHANGE: already have handle
for (size_t i = 0; i < CAMERA_MODEL_MAX; i++)
{
@ -225,7 +114,8 @@ uint8_t SCCB_Probe(void)
}
slave_addr = camera_sensor[i].sccb_addr;
ret = i2c_master_probe(bus_handle, slave_addr, TIMEOUT_MS);
// CIRCUITPY-CHANGE: use saved handle
ret = i2c_master_probe(sccb_i2c_master_bus_handle, slave_addr, TIMEOUT_MS);
if (ret == ESP_OK)
{
@ -241,14 +131,19 @@ uint8_t SCCB_Probe(void)
uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
// CIRCUITPY-CHANGE: register device only while in use
uint8_t tx_buffer[1];
uint8_t rx_buffer[1];
tx_buffer[0] = reg;
esp_err_t ret = i2c_master_transmit_receive(dev_handle, tx_buffer, 1, rx_buffer, 1, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit_receive(dev_handle, tx_buffer, 1, rx_buffer, 1, TIMEOUT_MS);
deregister_device(dev_handle);
if (ret != ESP_OK)
{
@ -260,13 +155,18 @@ uint8_t SCCB_Read(uint8_t slv_addr, uint8_t reg)
int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
// CIRCUITPY-CHANGE: register device only while in use
uint8_t tx_buffer[2];
tx_buffer[0] = reg;
tx_buffer[1] = data;
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 2, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit(dev_handle, tx_buffer, 2, TIMEOUT_MS);
deregister_device(dev_handle);
if (ret != ESP_OK)
{
@ -278,14 +178,19 @@ int SCCB_Write(uint8_t slv_addr, uint8_t reg, uint8_t data)
uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
// CIRCUITPY-CHANGE: register device only while in use
uint8_t rx_buffer[1];
uint16_t reg_htons = LITTLETOBIG(reg);
uint8_t *reg_u8 = (uint8_t *)&reg_htons;
esp_err_t ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 1, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 1, TIMEOUT_MS);
deregister_device(dev_handle);
if (ret != ESP_OK)
{
@ -297,16 +202,19 @@ uint8_t SCCB_Read16(uint8_t slv_addr, uint16_t reg)
int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
uint16_t reg_htons = LITTLETOBIG(reg);
// CIRCUITPY-CHANGE: register device only while in use
uint8_t tx_buffer[3];
tx_buffer[0] = reg_htons >> 8;
tx_buffer[1] = reg_htons & 0x00ff;
tx_buffer[0] = reg >> 8;
tx_buffer[1] = reg & 0x00ff;
tx_buffer[2] = data;
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 3, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit(dev_handle, tx_buffer, 3, TIMEOUT_MS);
deregister_device(dev_handle);
if (ret != ESP_OK)
{
@ -317,14 +225,19 @@ int SCCB_Write16(uint8_t slv_addr, uint16_t reg, uint8_t data)
uint16_t SCCB_Read_Addr16_Val16(uint8_t slv_addr, uint16_t reg)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
// CIRCUITPY-CHANGE: register device only while in use
uint8_t rx_buffer[2];
uint16_t reg_htons = LITTLETOBIG(reg);
uint8_t *reg_u8 = (uint8_t *)&reg_htons;
esp_err_t ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 2, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit_receive(dev_handle, reg_u8, 2, rx_buffer, 2, TIMEOUT_MS);
deregister_device(dev_handle);
uint16_t data = ((uint16_t)rx_buffer[0] << 8) | (uint16_t)rx_buffer[1];
if (ret != ESP_OK)
@ -337,22 +250,24 @@ uint16_t SCCB_Read_Addr16_Val16(uint8_t slv_addr, uint16_t reg)
int SCCB_Write_Addr16_Val16(uint8_t slv_addr, uint16_t reg, uint16_t data)
{
i2c_master_dev_handle_t dev_handle = *(get_handle_from_address(slv_addr));
uint16_t reg_htons = LITTLETOBIG(reg);
// CIRCUITPY-CHANGE: register device only while in use
uint8_t tx_buffer[4];
tx_buffer[0] = reg_htons >> 8;
tx_buffer[1] = reg_htons & 0x00ff;
tx_buffer[0] = reg >> 8;
tx_buffer[1] = reg & 0x00ff;
tx_buffer[2] = data >> 8;
tx_buffer[3] = data & 0x00ff;
esp_err_t ret = i2c_master_transmit(dev_handle, tx_buffer, 4, TIMEOUT_MS);
esp_err_t ret;
i2c_master_dev_handle_t dev_handle;
register_device(slv_addr, &dev_handle);
ret = i2c_master_transmit(dev_handle, tx_buffer, 4, TIMEOUT_MS);
deregister_device(dev_handle);
if (ret != ESP_OK)
{
ESP_LOGE(TAG, "W [%04x]=%02x fail\n", reg, data);
}
return ret == ESP_OK ? 0 : -1;
return 0;
}

View file

@ -18,9 +18,11 @@
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#else
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
#include "esp_log.h"
static const char* TAG = "sccb";
#endif
#include "esp_check.h"
#define LITTLETOBIG(x) ((x<<8)|(x>>8))
@ -49,7 +51,7 @@ static bool sccb_owns_i2c_port;
int SCCB_Init(int pin_sda, int pin_scl)
{
ESP_LOGI(TAG, "pin_sda %d pin_scl %d", pin_sda, pin_scl);
ESP_LOGI(TAG, "yolo pin_sda %d pin_scl %d", pin_sda, pin_scl);
i2c_config_t conf;
esp_err_t ret;
@ -106,7 +108,7 @@ uint8_t SCCB_Probe(void)
i2c_master_start(cmd);
i2c_master_write_byte(cmd, ( slave_addr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 1000 / portTICK_RATE_MS);
esp_err_t ret = i2c_master_cmd_begin(sccb_i2c_port, cmd, 50 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if( ret == ESP_OK) {
return slave_addr;

View file

@ -24,6 +24,8 @@
static const char *TAG = "ov5640";
#endif
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
//#define REG_DEBUG_ON
static int read_reg(uint8_t slv_addr, const uint16_t reg){
@ -790,7 +792,7 @@ static int set_awb_gain_dsp(sensor_t *sensor, int enable)
static int set_special_effect(sensor_t *sensor, int effect)
{
int ret=0;
if (effect < 0 || effect > 6) {
if (effect < 0 || effect >= ARRAY_SIZE(sensor_special_effects)) {
return -1;
}

View file

@ -248,7 +248,7 @@ static const DRAM_ATTR uint8_t sensor_saturation_levels[9][11] = {
{0x1d, 0x60, 0x03, 0x11, 0xa8, 0xb9, 0xaf, 0x96, 0x19, 0x01, 0x98},//+4
};
static const DRAM_ATTR uint8_t sensor_special_effects[7][4] = {
static const DRAM_ATTR uint8_t sensor_special_effects[][4] = {
{0x06, 0x40, 0x2c, 0x08},//Normal
{0x46, 0x40, 0x28, 0x08},//Negative
{0x1e, 0x80, 0x80, 0x08},//Grayscale
@ -256,6 +256,7 @@ static const DRAM_ATTR uint8_t sensor_special_effects[7][4] = {
{0x1e, 0x60, 0x60, 0x08},//Green Tint
{0x1e, 0xa0, 0x40, 0x08},//Blue Tint
{0x1e, 0x40, 0xa0, 0x08},//Sepia
{0x06, 0x40, 0x2c, 0x09},//Solarize
};
static const DRAM_ATTR uint16_t sensor_regs_gamma0[][2] = {

View file

@ -40,6 +40,11 @@ esp_err_t xclk_timer_conf(int ledc_timer, int xclk_freq_hz)
esp_err_t camera_enable_out_clock(const camera_config_t* config)
{
if (config->ledc_channel == NO_CAMERA_LEDC_CHANNEL) {
g_ledc_channel = NO_CAMERA_LEDC_CHANNEL;
return ESP_OK;
}
esp_err_t err = xclk_timer_conf(config->ledc_timer, config->xclk_freq_hz);
if (err != ESP_OK) {
ESP_LOGE(TAG, "ledc_timer_config failed, rc=%x", err);