From 2397fedf2a28d3d528e106815a0b169cfc85fd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Wed, 22 May 2024 20:41:44 -0400 Subject: [PATCH] Fixed wrong sized LVDS struct that rendered the MIPI configuration command inoperable --- src/hal/hisi/v4_config.h | 29 ++++++++++++++++------------- src/hal/hisi/v4_hal.c | 38 +++++++++++++++----------------------- src/hal/hisi/v4_snr.h | 12 ++++++++---- src/hal/hisi/v4_vi.h | 12 ++++++------ 4 files changed, 45 insertions(+), 46 deletions(-) diff --git a/src/hal/hisi/v4_config.h b/src/hal/hisi/v4_config.h index 583c821..851b3eb 100644 --- a/src/hal/hisi/v4_config.h +++ b/src/hal/hisi/v4_config.h @@ -402,24 +402,27 @@ static enum ConfigError v4_parse_sensor_config(char *path, v4_config_impl *confi config->input_mode = V4_SNR_INPUT_MIPI; } - if (config->input_mode == V4_VI_INTF_MIPI) { + if (config->input_mode == V4_SNR_INPUT_MIPI) { // [mipi] { - const char *possible_values[] = { - "RAW_DATA_8BIT", "RAW_DATA_10BIT", "RAW_DATA_12BIT", - "RAW_DATA_14BIT", "RAW_DATA_16BIT", "RAW_DATA_YUV420_8BIT_NORMAL", - "RAW_DATA_YUV420_8BIT_LEGACY", "RAW_DATA_YUV422_8BIT"}; - const int count = sizeof(possible_values) / sizeof(const char *); - err = parse_enum( - &ini, "mode", "raw_bitness", (void*)&config->mipi.prec, - possible_values, count, 0); - if (err != CONFIG_OK) - goto RET_ERR; + int rawBitness; + parse_int(&ini, "mode", "raw_bitness", 0, INT_MAX, &rawBitness); + switch (rawBitness) { + case 8: config->mipi.prec = V4_PREC_8BPP; break; + case 10: config->mipi.prec = V4_PREC_10BPP; break; + case 12: config->mipi.prec = V4_PREC_12BPP; break; + case 14: config->mipi.prec = V4_PREC_14BPP; break; + case 16: config->mipi.prec = V4_PREC_16BPP; break; + default: config->mipi.prec = V4_PREC_10BPP; break; + } } - err = parse_array(&ini, "mipi", "lane_id", (int*)&config->mipi.laneId, 8); + int laneId[4]; + err = parse_array(&ini, "mipi", "lane_id", (int*)&laneId, 4); if (err != CONFIG_OK) goto RET_ERR; - } else if (config->input_mode == V4_VI_INTF_LVDS) { + else for (char i = 0; i < 4; i++) + config->mipi.laneId[i] = laneId[i]; + } else if (config->input_mode == V4_SNR_INPUT_LVDS) { // [lvds] err = v4_parse_config_lvds(&ini, "lvds", &config->lvds); if (err != CONFIG_OK) diff --git a/src/hal/hisi/v4_hal.c b/src/hal/hisi/v4_hal.c index f2e7ccb..5867340 100644 --- a/src/hal/hisi/v4_hal.c +++ b/src/hal/hisi/v4_hal.c @@ -215,11 +215,6 @@ void v4_pipeline_destroy(void) v4_vpss.fnStopGroup(grp); v4_vpss.fnDestroyGroup(grp); } - - v4_vi.fnDisableChannel(_v4_vi_chn); - v4_vi.fnDisableDevice(_v4_vi_dev); - - v4_isp.fnExit(_v4_isp_dev); } int v4_region_create(char handle, hal_rect rect) @@ -295,7 +290,6 @@ int v4_sensor_config(void) { config.input = v4_config.input_mode; 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)); else if (config.input == V4_SNR_INPUT_LVDS) @@ -306,24 +300,21 @@ int v4_sensor_config(void) { V4_ERROR("Opening imaging device has failed!\n"); int laneMode = 0; - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode)) - V4_ERROR("Configuring imaging device lane-splitting mode has failed!\n"); - - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device)) - V4_ERROR("Enabling imaging device clocking has failed!\n"); + ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode); - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_MIPI, unsigned int), &config.device)) - V4_ERROR("Resetting imaging device has failed!\n"); + ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device); - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_SENS, unsigned int), &config.device)) - V4_ERROR("Enabling imaging sensor clocking has failed!\n"); + ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_MIPI, unsigned int), &config.device); - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_SENS, unsigned int), &config.device)) - V4_ERROR("Resetting imaging sensor has failed!\n"); + ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_SENS, unsigned int), &config.device); - if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_DEV, v4_snr_dev), &config) && close(fd)) + ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_SENS, unsigned int), &config.device); + + if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_DEV, v4_snr_dev), &config)) 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); @@ -786,7 +777,7 @@ void v4_system_deinit(void) v4_vi.fnStopPipe(_v4_vi_pipe); v4_vi.fnDestroyPipe(_v4_vi_pipe); - v4_vi.fnDisableChannel(_v4_vi_chn); + v4_vi.fnDisableChannel(_v4_vi_pipe, _v4_vi_chn); v4_sensor_deconfig(); @@ -892,8 +883,9 @@ int v4_system_init(char *snrConfig, char mirror, char flip) { v4_vi_chn channel; - channel.size = v4_config.isp.size; - channel.pixFmt = V4_PIXFMT_RGB_BAYER_8BPP + v4_config.mipi.prec; + channel.size.width = v4_config.isp.capt.width; + channel.size.height = v4_config.isp.capt.height; + channel.pixFmt = V4_PIXFMT_YVU420SP; channel.dynRange = V4_HDR_SDR8; channel.videoFmt = 0; channel.compress = V4_COMPR_NONE; @@ -902,10 +894,10 @@ int v4_system_init(char *snrConfig, char mirror, char flip) channel.depth = 0; channel.srcFps = -1; channel.dstFps = -1; - if (ret = v4_vi.fnSetChannelConfig(_v4_vi_chn, &channel)) + if (ret = v4_vi.fnSetChannelConfig(_v4_vi_pipe, _v4_vi_chn, &channel)) return ret; } - if (ret = v4_vi.fnEnableChannel(_v4_vi_chn)) + if (ret = v4_vi.fnEnableChannel(_v4_vi_pipe, _v4_vi_chn)) return ret; { diff --git a/src/hal/hisi/v4_snr.h b/src/hal/hisi/v4_snr.h index adbaebe..e9ffd27 100644 --- a/src/hal/hisi/v4_snr.h +++ b/src/hal/hisi/v4_snr.h @@ -75,19 +75,23 @@ typedef enum { V4_SNR_MWDR_END } v4_snr_mwdr; +typedef struct { + v4_snr_lfid type; + unsigned char outputFil; +} v4_snr_fid; + typedef struct { v4_snr_lvsynct type; unsigned short hBlank1; unsigned short hBlank2; } v4_snr_lvsync; -typedef struct -{ +typedef struct { v4_common_prec prec; v4_snr_lwdr wdr; int syncSavOn; - v4_snr_lvsynct vsync; - v4_snr_lfid fid; + v4_snr_lvsync vsync; + v4_snr_fid fid; int dataBeOn; int syncBeOn; // Value -1 signifies a lane is disabled diff --git a/src/hal/hisi/v4_vi.h b/src/hal/hisi/v4_vi.h index e139985..34bce67 100644 --- a/src/hal/hisi/v4_vi.h +++ b/src/hal/hisi/v4_vi.h @@ -141,9 +141,9 @@ typedef struct { int (*fnEnableDevice)(int device); int (*fnSetDeviceConfig)(int device, v4_vi_dev *config); - int (*fnDisableChannel)(int channel); - int (*fnEnableChannel)(int channel); - int (*fnSetChannelConfig)(int channel, v4_vi_chn *config); + int (*fnDisableChannel)(int pipe, int channel); + int (*fnEnableChannel)(int pipe, int channel); + int (*fnSetChannelConfig)(int pipe, int channel, v4_vi_chn *config); int (*fnBindPipe)(int device, v4_vi_bind *config); int (*fnCreatePipe)(int pipe, v4_vi_pipe *config); @@ -179,19 +179,19 @@ static int v4_vi_load(v4_vi_impl *vi_lib) { return EXIT_FAILURE; } - if (!(vi_lib->fnDisableChannel = (int(*)(int device)) + if (!(vi_lib->fnDisableChannel = (int(*)(int pipe, int device)) dlsym(vi_lib->handle, "HI_MPI_VI_DisableChn"))) { fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_DisableChn!\n"); return EXIT_FAILURE; } - if (!(vi_lib->fnEnableChannel = (int(*)(int device)) + if (!(vi_lib->fnEnableChannel = (int(*)(int pipe, int device)) dlsym(vi_lib->handle, "HI_MPI_VI_EnableChn"))) { fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_EnableChn!\n"); return EXIT_FAILURE; } - if (!(vi_lib->fnSetChannelConfig = (int(*)(int device, v4_vi_chn *config)) + if (!(vi_lib->fnSetChannelConfig = (int(*)(int pipe, int device, v4_vi_chn *config)) dlsym(vi_lib->handle, "HI_MPI_VI_SetChnAttr"))) { fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_SetChnAttr!\n"); return EXIT_FAILURE;