Skip to content

Commit

Permalink
Merge pull request #45 from Seeed-Studio/perf
Browse files Browse the repository at this point in the history
Resolution and Key Loss Fixes
  • Loading branch information
LynnL4 authored Jan 15, 2024
2 parents c421591 + e4f7afb commit dd1bcdc
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 47 deletions.
6 changes: 3 additions & 3 deletions core/data/el_data_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ class Storage {
return value;
auto kv = utility::el_make_storage_kv(key, value);
[[maybe_unused]] bool is_ok = get(kv);
EL_ASSERT(is_ok);
// EL_ASSERT(is_ok);

return value;
}

template <typename KVType> Storage& operator>>(KVType&& kv) {
[[maybe_unused]] bool is_ok = get(std::forward<KVType>(kv));
EL_ASSERT(is_ok);
// EL_ASSERT(is_ok);

return *this;
}
Expand All @@ -307,7 +307,7 @@ class Storage {

template <typename KVType> Storage& operator<<(KVType&& kv) {
bool is_ok __attribute__((unused)) = emplace(std::forward<KVType>(kv));
EL_ASSERT(is_ok);
// EL_ASSERT(is_ok);

return *this;
}
Expand Down
4 changes: 2 additions & 2 deletions porting/himax/we2/boards/grove_vision_ai_we2/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@


#define PRODUCT_NAME_PREFIX "grove_vision_ai"
#define PRODUCT_NAME_SUFFIX "we2"
#define PRODUCT_NAME_SUFFIX "v2"
#define DEVICE_NAME (PRODUCT_NAME_PREFIX "_" PRODUCT_NAME_SUFFIX)
#define PORT_DEVICE_NAME "Grove Vision AI (WE2)"
#define PORT_DEVICE_NAME "Grove Vision AI (V2)"


#ifdef __cplusplus
Expand Down
96 changes: 96 additions & 0 deletions porting/himax/we2/drivers/OV5647_mipi_2lane_1296x972.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{HX_CIS_I2C_Action_W, 0x3000, 0x0f},
{HX_CIS_I2C_Action_W, 0x3001, 0xff},
{HX_CIS_I2C_Action_W, 0x3002, 0xe4},
{HX_CIS_I2C_Action_S, 0x0040, 0x00}, //delay 64ms
{HX_CIS_I2C_Action_W, 0x0100, 0x00},
{HX_CIS_I2C_Action_W, 0x0103, 0x01},
{HX_CIS_I2C_Action_W, 0x3034, 0x1a},
{HX_CIS_I2C_Action_W, 0x3035, 0x21},
{HX_CIS_I2C_Action_W, 0x3036, 0x62},
{HX_CIS_I2C_Action_W, 0x303c, 0x11},
{HX_CIS_I2C_Action_W, 0x3106, 0xf5},
{HX_CIS_I2C_Action_W, 0x3827, 0xec},
{HX_CIS_I2C_Action_W, 0x370c, 0x03},
{HX_CIS_I2C_Action_W, 0x3612, 0x59},
{HX_CIS_I2C_Action_W, 0x3618, 0x00},
{HX_CIS_I2C_Action_W, 0x5000, 0x06},
{HX_CIS_I2C_Action_W, 0x5002, 0x41},
{HX_CIS_I2C_Action_W, 0x5003, 0x08},
{HX_CIS_I2C_Action_W, 0x5a00, 0x08},
{HX_CIS_I2C_Action_W, 0x3000, 0x00},
{HX_CIS_I2C_Action_W, 0x3001, 0x00},
{HX_CIS_I2C_Action_W, 0x3002, 0x00},
{HX_CIS_I2C_Action_W, 0x3016, 0x08},
{HX_CIS_I2C_Action_W, 0x3017, 0xe0},
{HX_CIS_I2C_Action_W, 0x3018, 0x44},
{HX_CIS_I2C_Action_W, 0x301c, 0xf8},
{HX_CIS_I2C_Action_W, 0x301d, 0xf0},
{HX_CIS_I2C_Action_W, 0x3a18, 0x00},
{HX_CIS_I2C_Action_W, 0x3a19, 0xf8},
{HX_CIS_I2C_Action_W, 0x3c01, 0x80},
{HX_CIS_I2C_Action_W, 0x3b07, 0x0c},
{HX_CIS_I2C_Action_W, 0x3800, 0x00},
{HX_CIS_I2C_Action_W, 0x3801, 0x00},
{HX_CIS_I2C_Action_W, 0x3802, 0x00},
{HX_CIS_I2C_Action_W, 0x3803, 0x00},
{HX_CIS_I2C_Action_W, 0x3804, 0x0a},
{HX_CIS_I2C_Action_W, 0x3805, 0x3f},
{HX_CIS_I2C_Action_W, 0x3806, 0x07},
{HX_CIS_I2C_Action_W, 0x3807, 0xa3},
{HX_CIS_I2C_Action_W, 0x3808, 0x05},
{HX_CIS_I2C_Action_W, 0x3809, 0x10},
{HX_CIS_I2C_Action_W, 0x380a, 0x03},
{HX_CIS_I2C_Action_W, 0x380b, 0xcc},
{HX_CIS_I2C_Action_W, 0x380c, 0x07},
{HX_CIS_I2C_Action_W, 0x380d, 0x68},
{HX_CIS_I2C_Action_W, 0x3811, 0x0c},
{HX_CIS_I2C_Action_W, 0x3813, 0x06},
{HX_CIS_I2C_Action_W, 0x3814, 0x31},
{HX_CIS_I2C_Action_W, 0x3815, 0x31},
{HX_CIS_I2C_Action_W, 0x3630, 0x2e},
{HX_CIS_I2C_Action_W, 0x3632, 0xe2},
{HX_CIS_I2C_Action_W, 0x3633, 0x23},
{HX_CIS_I2C_Action_W, 0x3634, 0x44},
{HX_CIS_I2C_Action_W, 0x3636, 0x06},
{HX_CIS_I2C_Action_W, 0x3620, 0x64},
{HX_CIS_I2C_Action_W, 0x3621, 0xe0},
{HX_CIS_I2C_Action_W, 0x3600, 0x37},
{HX_CIS_I2C_Action_W, 0x3704, 0xa0},
{HX_CIS_I2C_Action_W, 0x3703, 0x5a},
{HX_CIS_I2C_Action_W, 0x3715, 0x78},
{HX_CIS_I2C_Action_W, 0x3717, 0x01},
{HX_CIS_I2C_Action_W, 0x3731, 0x02},
{HX_CIS_I2C_Action_W, 0x370b, 0x60},
{HX_CIS_I2C_Action_W, 0x3705, 0x1a},
{HX_CIS_I2C_Action_W, 0x3f05, 0x02},
{HX_CIS_I2C_Action_W, 0x3f06, 0x10},
{HX_CIS_I2C_Action_W, 0x3f01, 0x0a},
{HX_CIS_I2C_Action_W, 0x3a08, 0x01},
{HX_CIS_I2C_Action_W, 0x3a09, 0x28},
{HX_CIS_I2C_Action_W, 0x3a0a, 0x00},
{HX_CIS_I2C_Action_W, 0x3a0b, 0xf6},
{HX_CIS_I2C_Action_W, 0x3a0d, 0x08},
{HX_CIS_I2C_Action_W, 0x3a0e, 0x06},
{HX_CIS_I2C_Action_W, 0x3a0f, 0x58},
{HX_CIS_I2C_Action_W, 0x3a10, 0x50},
{HX_CIS_I2C_Action_W, 0x3a1b, 0x58},
{HX_CIS_I2C_Action_W, 0x3a1e, 0x50},
{HX_CIS_I2C_Action_W, 0x3a11, 0x60},
{HX_CIS_I2C_Action_W, 0x3a1f, 0x28},
{HX_CIS_I2C_Action_W, 0x4001, 0x02},
{HX_CIS_I2C_Action_W, 0x4004, 0x04},
{HX_CIS_I2C_Action_W, 0x4000, 0x09},
{HX_CIS_I2C_Action_W, 0x4837, 0x16},
{HX_CIS_I2C_Action_W, 0x4800, 0x24},
{HX_CIS_I2C_Action_W, 0x3503, 0x00},
{HX_CIS_I2C_Action_W, 0x3820, 0x41},
{HX_CIS_I2C_Action_W, 0x3821, 0x07},
{HX_CIS_I2C_Action_W, 0x350a, 0x00},
{HX_CIS_I2C_Action_W, 0x350b, 0x10},
{HX_CIS_I2C_Action_W, 0x3500, 0x00},
{HX_CIS_I2C_Action_W, 0x3501, 0x1a},
{HX_CIS_I2C_Action_W, 0x3502, 0xf0},
{HX_CIS_I2C_Action_W, 0x3212, 0xa0},
{HX_CIS_I2C_Action_W, 0x4800, OV5647_MIPI_CTRL_OFF},
{HX_CIS_I2C_Action_W, 0x4202, 0x0F},
{HX_CIS_I2C_Action_W, 0x0100, 0x01},
103 changes: 67 additions & 36 deletions porting/himax/we2/drivers/drv_ov5647.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include "drv_ov5647.h"

static HX_CIS_SensorSetting_t OV5647_init_setting[] = {
#include "OV5647_mipi_2lane_640x480.i"
#if (OV5647_MIPI_MODE == OV5647_MIPI_640X480)
#include "OV5647_mipi_2lane_640x480.i"
#elif (OV5647_MIPI_MODE == OV5647_MIPI_2592X1944)
#include "OV5647_mipi_2lane_2592x1944.i"
#elif (OV5647_MIPI_MODE == OV5647_MIPI_1296X972)
#include "OV5647_mipi_2lane_1296x972.i"
#endif

};

static HX_CIS_SensorSetting_t OV5647_stream_on[] = {
Expand Down Expand Up @@ -34,6 +41,16 @@ el_res_t _drv_ov5647_fit_res(uint16_t width, uint16_t height) {
res.width = 160;
res.height = 120;
}
// if (width > 480 || height > 320) {
// res.width = 960;
// res.height = 540;
// } else if (width > 240 || height > 160) {
// res.width = 480;
// res.height = 270;
// } else {
// res.width = 240;
// res.height = 135;
// }
EL_LOGD("fit width: %d height: %d", res.width, res.height);

return res;
Expand All @@ -47,7 +64,7 @@ void drv_ov5647_cb(SENSORDPLIB_STATUS_E event) {
_frame_count++;
break;
default:
EL_LOGD("Unkonw event");
el_printf("Unkonw event:%d", event);

break;
}
Expand All @@ -63,8 +80,8 @@ void set_mipi_csirx_enable() {
uint32_t bitrate_1lane = OV5647_MIPI_CLOCK_FEQ * 2;
uint32_t mipi_lnno = OV5647_MIPI_LANE_CNT;
uint32_t pixel_dpp = OV5647_MIPI_DPP;
uint32_t line_length = OV5647_MAX_WIDTH;
uint32_t frame_length = OV5647_MAX_HEIGHT;
uint32_t line_length = OV5647_SENSOR_WIDTH;
uint32_t frame_length = OV5647_SENSOR_HEIGHT;
uint32_t byte_clk = bitrate_1lane / 8;
uint32_t continuousout = OV5647_MIPITX_CNTCLK_EN;
uint32_t deskew_en = 0;
Expand Down Expand Up @@ -256,25 +273,22 @@ el_err_code_t drv_ov5647_init(uint16_t width, uint16_t height) {
_jpeg.size = width * height / 4;

// DMA
if (!_jpegsize_baseaddr)
_jpegsize_baseaddr = (uint32_t)el_aligned_malloc_once(32, 64);
if (!_jpegsize_baseaddr) _jpegsize_baseaddr = (uint32_t)el_aligned_malloc_once(32, 64);
if (_jpegsize_baseaddr == 0) {
ret = EL_ENOMEM;
goto err;
}

{
size_t bs = (((623 + (size_t)(res.width / 16) * (size_t)(res.height / 16) * 128 + 35) >> 2) << 2);
if (!_wdma1_baseaddr)
_wdma1_baseaddr = (uint32_t)el_aligned_malloc_once(32, bs); // JPEG
size_t bs = (((623 + (size_t)(res.width / 16) * (size_t)(res.height / 16) * 128 + 35) >> 2) << 2);
if (!_wdma1_baseaddr) _wdma1_baseaddr = (uint32_t)el_aligned_malloc_once(32, bs); // JPEG
}
if (_wdma1_baseaddr == 0) {
ret = EL_ENOMEM;
goto err;
}
_wdma2_baseaddr = _wdma1_baseaddr;
if (!_wdma3_baseaddr)
_wdma3_baseaddr = (uint32_t)el_aligned_malloc_once(32, res.width * res.height * 3 / 2);
if (!_wdma3_baseaddr) _wdma3_baseaddr = (uint32_t)el_aligned_malloc_once(32, res.width * res.height * 3 / 2);
if (_wdma3_baseaddr == 0) {
ret = EL_ENOMEM;
goto err;
Expand All @@ -291,28 +305,44 @@ el_err_code_t drv_ov5647_init(uint16_t width, uint16_t height) {

sensordplib_set_xDMA_baseaddrbyapp(_wdma1_baseaddr, _wdma2_baseaddr, _wdma3_baseaddr);
sensordplib_set_jpegfilesize_addrbyapp(_jpegsize_baseaddr);
// datapath init
if (OV5647_MAX_WIDTH / res.width == 3) {
sensordplib_set_sensorctrl_inp(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_MAX_WIDTH,
OV5647_MAX_HEIGHT,
INP_SUBSAMPLE_8TO2);
EL_LOGD("subsample: 4x");
} else if (OV5647_MAX_WIDTH / res.width == 2) {
sensordplib_set_sensorctrl_inp(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_MAX_WIDTH,
OV5647_MAX_HEIGHT,
INP_SUBSAMPLE_4TO2);
EL_LOGD("subsample: 2x");
} else {
sensordplib_set_sensorctrl_inp(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_MAX_WIDTH,
OV5647_MAX_HEIGHT,
INP_SUBSAMPLE_DISABLE);
EL_LOGD("subsample: 1x");

crop.start_x = 0;
crop.start_y = 0;
crop.last_x = 0;
crop.last_y = 0;


switch (res.width) {
case 640:
sensordplib_set_sensorctrl_inp_wi_crop_bin(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_SENSOR_WIDTH,
OV5647_SENSOR_HEIGHT,
OV5647_SUB_SAMPLE,
crop,
INP_BINNING_DISABLE);
break;
case 320:
sensordplib_set_sensorctrl_inp_wi_crop_bin(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_SENSOR_WIDTH,
OV5647_SENSOR_HEIGHT,
OV5647_SUB_SAMPLE,
crop,
INP_BINNING_4TO2_B);
break;
case 160:
sensordplib_set_sensorctrl_inp_wi_crop_bin(SENSORDPLIB_SENSOR_OV5647,
SENSORDPLIB_STREAM_NONEAOS,
OV5647_SENSOR_WIDTH,
OV5647_SENSOR_HEIGHT,
OV5647_SUB_SAMPLE,
crop,
INP_BINNING_8TO2_B);
break;

default:
break;
}

//HW5x5 Cfg
Expand Down Expand Up @@ -386,7 +416,7 @@ el_err_code_t drv_ov5647_deinit() {
}
set_mipi_csirx_disable();
// power off
hx_drv_sensorctrl_set_xSleep(0);
hx_drv_sensorctrl_set_xSleep(1);
return EL_OK;
}

Expand All @@ -402,8 +432,8 @@ el_err_code_t drv_ov5647_capture(uint32_t timeout) {
return EL_OK;
}

el_err_code_t drv_ov5647_capture_stop(){
_frame_ready = false;
el_err_code_t drv_ov5647_capture_stop() {
_frame_ready = false;
sensordplib_retrigger_capture();

return EL_OK;
Expand All @@ -426,5 +456,6 @@ el_img_t drv_ov5647_get_jpeg() {
hx_drv_jpeg_get_MemAddrByFrameNo(frame_no, _wdma2_baseaddr, &_jpeg.data);
_jpeg.size = mem_val == reg_val ? mem_val : reg_val;
hx_InvalidateDCache_by_Addr((volatile void*)_jpeg.data, _jpeg.size);
EL_LOGD("JPEG size: %d", _jpeg.size);
return _jpeg;
}
27 changes: 24 additions & 3 deletions porting/himax/we2/drivers/drv_ov5647.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,30 @@
#endif
#endif

#define DEAULT_XHSUTDOWN_PIN AON_GPIO2
#define OV5647_MAX_WIDTH 640
#define OV5647_MAX_HEIGHT 480
#define DEAULT_XHSUTDOWN_PIN AON_GPIO2

#define OV5647_MIPI_640X480 0
#define OV5647_MIPI_2592X1944 1
#define OV5647_MIPI_1296X972 2

#define OV5647_MIPI_MODE OV5647_MIPI_1296X972

#if (OV5647_MIPI_MODE == OV5647_MIPI_640X480)
#define OV5647_SENSOR_WIDTH 640
#define OV5647_SENSOR_HEIGHT 480
#define OV5647_SUB_SAMPLE INP_SUBSAMPLE_DISABLE
#elif (OV5647_MIPI_MODE == OV5647_MIPI_2592X1944)
#define OV5647_SENSOR_WIDTH 2592
#define OV5647_SENSOR_HEIGHT 1944
#define OV5647_SUB_SAMPLE INP_SUBSAMPLE_8TO2
#elif (OV5647_MIPI_MODE == OV5647_MIPI_1296X972)
#define OV5647_SENSOR_WIDTH 1296
#define OV5647_SENSOR_HEIGHT 972
#define OV5647_SUB_SAMPLE INP_SUBSAMPLE_4TO2

#else
#error "OV5647_MIPI_MODE not defined"
#endif

#define OV5647_SENSOR_I2CID (0x36)
#define OV5647_MIPI_CLOCK_FEQ (220) //MHz
Expand Down
2 changes: 1 addition & 1 deletion porting/himax/we2/el_config_porting.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#define CONFIG_EL_DEBUG 3
#define CONFIG_EL_HAS_FREERTOS_SUPPORT 1
#define SSCMA_REPL_EXECUTOR_PRIO 2
#define CONFIG_SSCMA_TENSOR_ARENA_SIZE (1200 * 1024)
#define CONFIG_SSCMA_TENSOR_ARENA_SIZE (800 * 1024)

#define CONFIG_EL_TFLITE
#define CONFIG_EL_TFLITE_OP_SOFTMAX
Expand Down
10 changes: 8 additions & 2 deletions porting/himax/we2/el_flash_we2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ static int _el_flash_db_erase(long offset, size_t size) {
}

int ret = -1;
if (hx_lib_spi_eeprom_erase_sector(USE_DW_SPI_MST_Q, addr, FLASH_SECTOR) == E_OK) [[likely]]
ret = 0;
for (size_t i = addr; i < size; i += 4096) {
if(i < _el_flash_db_partition_begin)
continue;
if(i >= _el_flash_db_partition_end)
break;
if (hx_lib_spi_eeprom_erase_sector(USE_DW_SPI_MST_Q, i, FLASH_SECTOR) == E_OK) [[likely]]
ret = 0;
}

if (hx_lib_spi_eeprom_enable_XIP(USE_DW_SPI_MST_Q, true, FLASH_QUAD, true) == E_OK) [[likely]]
_el_xip_enabled = true;
Expand Down

0 comments on commit dd1bcdc

Please sign in to comment.