IDF版本是5.0
已经sc2336: Stream=1
然后初始化csi_ctrl之后
怎么获取到buffer呢
- #include <esp_cache.h>
- #include "esp_heap_caps.h"
- #include "string.h"
- #include "esp_ldo_regulator.h"
- #include "esp_cam_ctlr.h"
- #include "esp_cam_ctlr_csi.h"
- #include "esp_sccb_intf.h"
- #include "esp_sccb_i2c.h"
- #include "esp_cam_sensor.h"
- #include "sc2336.h"
- #define MIPI_SCCB_SDA_IO 7
- #define MIPI_SCCB_SCL_IO 8
- #define CSI_LDO_UNIT_ID 3
- #define CSI_LDO_CFG_VOL_MV 2500
- static bool csi_video_on_get_new_trans(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data) {
- printf("csi_on_get_new_trans \n");
- esp_cam_ctlr_trans_t csi_trans = *(esp_cam_ctlr_trans_t *)user_data;
- trans->buffer = csi_trans.buffer;
- trans->buflen = csi_trans.buflen;
- return false;
- }
- static bool csi_video_on_trans_finished(esp_cam_ctlr_handle_t handle, esp_cam_ctlr_trans_t *trans, void *user_data) {
- printf("csi_video_on_trans_finished \n");
- return false;
- }
- void app_main(void) {
- //---------------BUFFER Init------------------//
- size_t frame_buffer_size = 1920 * 1080 * 10 / 8;
- void *frame_buffer = heap_caps_malloc(frame_buffer_size, MALLOC_CAP_8BIT | MALLOC_CAP_SPIRAM | MALLOC_CAP_CACHE_ALIGNED);
- esp_cam_ctlr_trans_t csi_trans = {};
- csi_trans.buffer = frame_buffer;
- csi_trans.buflen = frame_buffer_size;
- //---------------LDO Init------------------//
- esp_ldo_channel_handle_t ldo_mipi_phy = NULL;
- esp_ldo_channel_config_t ldo_mipi_phy_config = {
- .chan_id = CSI_LDO_UNIT_ID,
- .voltage_mv = CSI_LDO_CFG_VOL_MV,
- };
- ESP_ERROR_CHECK(esp_ldo_acquire_channel(&ldo_mipi_phy_config, &ldo_mipi_phy));
- //---------------I2C Init------------------//
- i2c_master_bus_config_t i2c_bus_conf = {
- .clk_source = I2C_CLK_SRC_DEFAULT,
- .sda_io_num = MIPI_SCCB_SDA_IO,
- .scl_io_num = MIPI_SCCB_SCL_IO,
- .i2c_port = I2C_NUM_0,
- .flags.enable_internal_pullup = true,
- };
- i2c_master_bus_handle_t bus_handle = NULL;
- ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_conf, &bus_handle));
- //---------------SCCB Init------------------//
- esp_sccb_io_handle_t sc2336_io_handle = NULL;
- sccb_i2c_config_t i2c_config = {
- .scl_speed_hz = 400 * 1000,
- .device_address = SC2336_SCCB_ADDR,
- .dev_addr_length = I2C_ADDR_BIT_LEN_7,
- };
- ESP_ERROR_CHECK(sccb_new_i2c_io(bus_handle, &i2c_config, &sc2336_io_handle));
- //---------------SENSOR Init------------------//
- esp_cam_sensor_config_t cam_config = {
- .sccb_handle = sc2336_io_handle,
- .reset_pin = -1,
- .pwdn_pin = -1,
- .xclk_pin = -1,
- .sensor_port = ESP_CAM_SENSOR_MIPI_CSI,
- };
- esp_cam_sensor_device_t *cam = sc2336_detect(&cam_config);
- //---------------FORMAT Init------------------//
- esp_cam_sensor_format_array_t cam_fmt_array = {0};
- esp_cam_sensor_query_format(cam, &cam_fmt_array);
- const esp_cam_sensor_format_t *parray = cam_fmt_array.format_array;
- for (int i = 0; i < cam_fmt_array.count; i++) {
- printf("fmt[%d].name:%s\n", i, parray[i].name);
- }
- esp_cam_sensor_format_t *cam_cur_fmt = NULL;
- for (int i = 0; i < cam_fmt_array.count; i++) {
- if (!strcmp(parray[i].name, "MIPI_2lane_24Minput_RAW10_1920x1080_30fps")) {
- cam_cur_fmt = (esp_cam_sensor_format_t *) & (parray[i].name);
- }
- }
- ESP_ERROR_CHECK(esp_cam_sensor_set_format(cam, (const esp_cam_sensor_format_t *) cam_cur_fmt));
- //---------------START Init------------------//
- int enable_flag = 1;
- ESP_ERROR_CHECK(esp_cam_sensor_ioctl(cam, ESP_CAM_SENSOR_IOC_S_STREAM, &enable_flag));
- //---------------CSI Init------------------//
- esp_cam_ctlr_csi_config_t csi_config = {
- .ctlr_id = 0,
- .clk_src = MIPI_CSI_PHY_CLK_SRC_DEFAULT,
- .byte_swap_en = false,
- .queue_items = 1,
- .h_res = 1920,
- .v_res = 1080,
- .data_lane_num = 2,
- .input_data_color_type = CAM_CTLR_COLOR_RAW10,
- .output_data_color_type = CAM_CTLR_COLOR_RAW10,
- .lane_bit_rate_mbps = 594,
- .bk_buffer_dis = false,
- };
- esp_cam_ctlr_handle_t cam_handle = NULL;
- ESP_ERROR_CHECK(esp_cam_new_csi_ctlr(&csi_config, &cam_handle));
- esp_cam_ctlr_evt_cbs_t cam_ctrl_cbs = {
- .on_get_new_trans = csi_video_on_get_new_trans,
- .on_trans_finished = csi_video_on_trans_finished
- };
- ESP_ERROR_CHECK(esp_cam_ctlr_register_event_callbacks(cam_handle, &cam_ctrl_cbs, &csi_trans));
- ESP_ERROR_CHECK(esp_cam_ctlr_enable(cam_handle));
- memset(frame_buffer, 0xFF, frame_buffer_size);
- esp_cache_msync((void *)frame_buffer, frame_buffer_size, ESP_CACHE_MSYNC_FLAG_DIR_C2M);
- ESP_ERROR_CHECK(esp_cam_ctlr_start(cam_handle));
- while (1) {
- ESP_ERROR_CHECK(esp_cam_ctlr_receive(cam_handle, &csi_trans, ESP_CAM_CTLR_MAX_DELAY));
- printf("HERE? \n")l
- }
- }