Skip to content

Commit

Permalink
(Continued)
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed May 22, 2024
1 parent a821198 commit d2876d9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 140 deletions.
114 changes: 5 additions & 109 deletions src/hal/hisi/v4_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ typedef struct {

// [vi_dev]
v4_vi_dev videv;

// [vi_chn]
v4_vi_chn vichn;
} v4_config_impl;

extern v4_config_impl v4_config;
Expand Down Expand Up @@ -296,115 +293,12 @@ static enum ConfigError v4_parse_config_videv(
if (err != CONFIG_OK)
return err;

for (char i = 0; i < 4; i++)
device->adChn[i] = -1;
device->wdrCacheLine = v4_config.isp.capt.width;

return CONFIG_OK;
}

static enum ConfigError v4_parse_config_vichn(
struct IniConfig *ini, const char *section, v4_vi_chn *channel) {
enum ConfigError err;
{
const char *possible_values[] = {
"PIXEL_FORMAT_RGB_444",
"PIXEL_FORMAT_RGB_555",
"PIXEL_FORMAT_RGB_565",
"PIXEL_FORMAT_RGB_888",
"PIXEL_FORMAT_BGR_444",
"PIXEL_FORMAT_BGR_555",
"PIXEL_FORMAT_BGR_565",
"PIXEL_FORMAT_BGR_888",
"PIXEL_FORMAT_ARGB_1555",
"PIXEL_FORMAT_ARGB_444",
"PIXEL_FORMAT_ARGB_8565",
"PIXEL_FORMAT_ARGB_8888",
"PIXEL_FORMAT_ARGB_2BPP",
"PIXEL_FORMAT_ABGR_1555",
"PIXEL_FORMAT_ABGR_444",
"PIXEL_FORMAT_ABGR_8565",
"PIXEL_FORMAT_ABGR_8888",
"PIXEL_FORMAT_RGB_BAYER_8BPP",
"PIXEL_FORMAT_RGB_BAYER_10BPP",
"PIXEL_FORMAT_RGB_BAYER_12BPP",
"PIXEL_FORMAT_RGB_BAYER_14BPP",
"PIXEL_FORMAT_RGB_BAYER_16BPP",
"PIXEL_FORMAT_YUV_PLANAR_422",
"PIXEL_FORMAT_YUV_PLANAR_420",
"PIXEL_FORMAT_YUV_PLANAR_444",
"PIXEL_FORMAT_YUV_SEMIPLANAR_422",
"PIXEL_FORMAT_YUV_SEMIPLANAR_420",
"PIXEL_FORMAT_YUV_SEMIPLANAR_444",
"PIXEL_FORMAT_YUV_SEMIPLANAR_422",
"PIXEL_FORMAT_YUV_SEMIPLANAR_420",
"PIXEL_FORMAT_YUV_SEMIPLANAR_444",
"PIXEL_FORMAT_YUYV_PACKAGE_422",
"PIXEL_FORMAT_YVYU_PACKAGE_422",
"PIXEL_FORMAT_UYVY_PACKAGE_422",
"PIXEL_FORMAT_VYUY_PACKAGE_422",
"PIXEL_FORMAT_YYUV_PACKAGE_422",
"PIXEL_FORMAT_YYVU_PACKAGE_422",
"PIXEL_FORMAT_UVYY_PACKAGE_422",
"PIXEL_FORMAT_VUTT_PACKAGE_422",
"PIXEL_FORMAT_VY1UY0_PACKAGE_422",
"PIXEL_FORMAT_YUV_400",
"PIXEL_FORMAT_UV_420",
"PIXEL_FORMAT_BGR_PLANAR_888",
"PIXEL_FORMAT_HSV_888",
"PIXEL_FORMAT_HSV_PLANAR_888",
"PIXEL_FORMAT_LAB_888",
"PIXEL_FORMAT_LAB_PLANAR_888",
"PIXEL_FORMAT_SBC1",
"PIXEL_FORMAT_SBC2",
"PIXEL_FORMAT_SBC2_PLANAR",
"PIXEL_FORMAT_SBC3_PLANAR",
"PIXEL_FORMAT_S16C1",
"PIXEL_FORMAT_U8C1",
"PIXEL_FORMAT_U16C1",
"PIXEL_FORMAT_S32C1",
"PIXEL_FORMAT_U32C1",
"PIXEL_FORMAT_U64C1",
"PIXEL_FORMAT_S64C1"};
const int count = sizeof(possible_values) / sizeof(const char *);
err = parse_enum(
ini, section, "pixformat", (void*)&channel->pixFmt,
possible_values, count, 0);
if (err != CONFIG_OK)
channel->pixFmt = V4_PIXFMT_YUV422SP;
}
{
const char *possible_values[] = {
"COMPRESS_MODE_NONE", "COMPRESS_MODE_SEG", "COMPRESS_MODE_TILE",
"COMPRESS_MODE_LINE", "COMPRESS_MODE_FRAME"};
const int count = sizeof(possible_values) / sizeof(const char *);
err = parse_enum(
ini, section, "compressmode", (void*)&channel->compress,
possible_values, count, 0);
if (err != CONFIG_OK)
return err;
}
err = parse_int(
ini, section, "srcframeRate", INT_MIN, INT_MAX, &channel->srcFps);
if (err != CONFIG_OK)
return err;
err = parse_int(
ini, section, "framerate", INT_MIN, INT_MAX, &channel->dstFps);
if (err != CONFIG_OK)
return err;
return CONFIG_OK;
}

static enum ConfigError v4_parse_config_isp(
struct IniConfig *ini, const char *section, v4_isp_dev *isp) {
enum ConfigError err;
parse_int(ini, "isp_image", "isp_x", 0, INT_MAX, &isp->capt.x);

parse_int(ini, "isp_image", "isp_y", 0, INT_MAX, &isp->capt.y);

parse_int(ini, "isp_image", "isp_w", 0, INT_MAX, &isp->capt.width);

parse_int(ini, "isp_image", "isp_h", 0, INT_MAX, &isp->capt.height);

int value;
err = parse_int(
Expand Down Expand Up @@ -537,14 +431,14 @@ static enum ConfigError v4_parse_sensor_config(char *path, v4_config_impl *confi
if (err != CONFIG_OK)
goto RET_ERR;

// [vi_chn]
v4_parse_config_vichn(&ini, "vi_chn", &config->vichn);

// [vi_dev]
err = v4_parse_config_videv(&ini, "vi_dev", &config->videv);
if (err != CONFIG_OK)
goto RET_ERR;

for (char i = 0; i < 4; i++)
config->videv.adChn[i] = -1;

// Fallbacks for default sensor configuration files
if (!config->isp.size.width)
config->isp.size.width = config->isp.capt.width;
Expand All @@ -561,6 +455,8 @@ static enum ConfigError v4_parse_sensor_config(char *path, v4_config_impl *confi
if (!config->videv.bayerSize.height)
config->videv.bayerSize.height = config->isp.capt.height;

config->videv.wdrCacheLine = v4_config.isp.capt.width;

if (!config->isp.wdr)
config->isp.wdr = config->mode;

Expand Down
75 changes: 49 additions & 26 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "v4_hal.h"

v4_isp_alg v4_ae_lib = { .libName = "ae_lib" };
v4_isp_alg v4_ae_lib = { .id = 0, .libName = "ae_lib" };
v4_aud_impl v4_aud;
v4_isp_alg v4_awb_lib = { .libName = "awb_lib" };
v4_isp_alg v4_awb_lib = { .id = 0, .libName = "awb_lib" };
v4_config_impl v4_config;
v4_isp_impl v4_isp;
v4_isp_drv_impl v4_isp_drv;
Expand Down Expand Up @@ -167,7 +167,7 @@ void *v4_image_thread(void)
fprintf(stderr, "[v4_isp] Shutting down ISP thread...\n");
}

int v4_pipeline_create(char mirror, char flip)
int v4_pipeline_create(void)
{
int ret;

Expand Down Expand Up @@ -290,10 +290,11 @@ int v4_region_setbitmap(int handle, hal_bitmap *bitmap)

int v4_sensor_config(void) {
v4_snr_dev config;
memset(&config, 0, sizeof(config));
config.device = 0;
config.input = v4_config.input_mode;
config.dataRate2X = 0;
config.rect = v4_config.isp.capt;
config.rect.width = v4_config.isp.capt.width;
config.rect.height = v4_config.isp.capt.height;

if (config.input == V4_SNR_INPUT_MIPI)
memcpy(&config.mipi, &v4_config.mipi, sizeof(v4_snr_mipi));
Expand Down Expand Up @@ -323,8 +324,6 @@ int v4_sensor_config(void) {
if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_DEV, v4_snr_dev), &config) && close(fd))
V4_ERROR("Configuring imaging device has failed!\n");

usleep(10000);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_MIPI, unsigned int), &config.device);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_SENS, unsigned int), &config.device);
Expand Down Expand Up @@ -764,11 +763,11 @@ int v4_system_calculate_block(short width, short height, v4_common_pixfmt pixFmt

unsigned int bufSize = CEILING_2_POWER(width, alignWidth) *
CEILING_2_POWER(height, alignWidth) *
(pixFmt == V4_PIXFMT_YUV422SP ? 2 : 1.5);
(pixFmt == V4_PIXFMT_YVU422SP ? 2 : 1.5);
unsigned int headSize = 16 * height;
if (pixFmt == V4_PIXFMT_YUV422SP || pixFmt >= V4_PIXFMT_RGB_BAYER_8BPP)
if (pixFmt == V4_PIXFMT_YVU422SP || pixFmt >= V4_PIXFMT_RGB_BAYER_8BPP)
headSize *= 2;
else if (pixFmt == V4_PIXFMT_YUV420SP)
else if (pixFmt == V4_PIXFMT_YVU420SP)
headSize *= 3;
headSize >>= 1;
return bufSize + headSize;
Expand All @@ -789,7 +788,7 @@ void v4_system_deinit(void)
v4_sensor_deinit();
}

int v4_system_init(char *snrConfig)
int v4_system_init(char *snrConfig, char mirror, char flip)
{
int ret;

Expand All @@ -813,14 +812,14 @@ int v4_system_init(char *snrConfig)
{
v4_vb_pool pool;
unsigned long long vencSize = v4_system_calculate_block(
v4_config.vichn.size.width, v4_config.vichn.size.height,
v4_config.vichn.pixFmt, alignWidth);
v4_config.isp.size.width, v4_config.isp.size.height,
V4_PIXFMT_YVU420SP, alignWidth);

memset(&pool, 0, sizeof(pool));
pool.count = 2;
pool.comm[0].blockSize = v4_vb_virawbuffer(v4_config.vichn.size.width,
v4_config.vichn.size.height, V4_PIXFMT_YUV420SP,
v4_config.vichn.compress, alignWidth);
pool.comm[0].blockSize = v4_vb_virawbuffer(v4_config.isp.size.width,
v4_config.isp.size.height, V4_PIXFMT_RGB_BAYER_8BPP + v4_config.mipi.prec,
V4_COMPR_NONE, alignWidth);
pool.comm[0].blockCnt = 3;
pool.comm[1].blockSize = vencSize;
pool.comm[1].blockCnt = 2;
Expand Down Expand Up @@ -860,31 +859,55 @@ int v4_system_init(char *snrConfig)

{
v4_vi_pipe pipe;
memset(&pipe, 0, sizeof(pipe));
pipe.pixFmt = v4_config.vichn.pixFmt;
pipe.compress = v4_config.vichn.compress;
pipe.bypass = 0;
pipe.yuvSkipOn = 0;
pipe.ispBypassOn = 0;
pipe.maxSize.width = 0;
pipe.maxSize.height = 0;
pipe.pixFmt = V4_PIXFMT_RGB_BAYER_8BPP + v4_config.mipi.prec;
pipe.compress = V4_COMPR_NONE;
pipe.prec = v4_config.mipi.prec;
pipe.srcFps = -1;
pipe.dstFps = -1;
pipe.nRedOn = 0;
pipe.nRed.pixFmt = V4_PIXFMT_YVU420SP;
pipe.nRed.prec = V4_PREC_8BPP;
pipe.nRed.srcRfrOrChn0 = 0;
pipe.nRed.compress = V4_COMPR_NONE;
pipe.sharpenOn = 0;
pipe.srcFps = 25;
pipe.dstFps = 25;
pipe.discProPic = 0;
if (ret = v4_vi.fnCreatePipe(_v4_vi_pipe, &pipe))
printf("ret: %#x\n", ret);//return ret;
return ret;
}
if (ret = v4_vi.fnStartPipe(_v4_vi_pipe))
return ret;

if (ret = v4_vi.fnSetChannelConfig(_v4_isp_chn, &v4_config.vichn))
return ret;
{
v4_vi_chn channel;
channel.size = v4_config.isp.size;
channel.pixFmt = V4_PIXFMT_RGB_BAYER_8BPP + v4_config.mipi.prec;
channel.dynRange = V4_HDR_SDR8;
channel.videoFmt = 0;
channel.compress = V4_COMPR_NONE;
channel.mirror = mirror;
channel.flip = flip;
channel.depth = 0;
channel.srcFps = -1;
channel.dstFps = -1;
if (ret = v4_vi.fnSetChannelConfig(_v4_isp_chn, &channel))
return ret;
}
if (ret = v4_vi.fnEnableChannel(_v4_isp_chn))
return ret;

if (ret = v4_isp_drv.obj->pfnRegisterCallback(_v4_isp_dev, &v4_ae_lib, &v4_awb_lib))
return ret;
{
v4_isp_bus bus;
bus.i2c = 0;
if (ret = v4_isp_drv.obj->pfnSetBusInfo(_v4_isp_dev, bus))
return ret;
}
if (ret = v4_isp_drv.obj->pfnRegisterCallback(_v4_isp_dev, &v4_ae_lib, &v4_awb_lib))
return ret;

if (ret = v4_isp.fnRegisterAE(_v4_isp_dev, &v4_ae_lib))
return ret;
Expand Down
4 changes: 2 additions & 2 deletions src/hal/hisi/v4_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int v4_channel_unbind(char index);

void *v4_image_thread(void);

int v4_pipeline_create(char mirror, char flip);
int v4_pipeline_create(void);
void v4_pipeline_destroy(void);

int v4_region_create(char handle, hal_rect rect);
Expand All @@ -58,4 +58,4 @@ void *v4_video_thread(void);
int v4_system_calculate_block(short width, short height, v4_common_pixfmt pixFmt,
unsigned int alignWidth);
void v4_system_deinit(void);
int v4_system_init(char *snrConfig);
int v4_system_init(char *snrConfig, char mirror, char flip);
6 changes: 3 additions & 3 deletions src/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ int start_sdk() {
case HAL_PLATFORM_I6C: ret = i6c_system_init(); break;
case HAL_PLATFORM_I6F: ret = i6f_system_init(); break;
case HAL_PLATFORM_V4: ret = v4_system_init(
app_config.sensor_config); break;
app_config.sensor_config, app_config.mirror,
app_config.flip); break;
}
if (ret) {
fprintf(stderr, "System initialization failed with %#x!\n%s\n",
Expand Down Expand Up @@ -227,8 +228,7 @@ int start_sdk() {
height, framerate); break;
case HAL_PLATFORM_I6F: ret = i6f_pipeline_create(0, width,
height, framerate); break;
case HAL_PLATFORM_V4: ret = v4_pipeline_create(app_config.mirror,
app_config.flip); break;
case HAL_PLATFORM_V4: ret = v4_pipeline_create(); break;
}
if (ret) {
fprintf(stderr, "Pipeline creation failed with %#x!\n%s\n",
Expand Down

0 comments on commit d2876d9

Please sign in to comment.