Skip to content

Commit

Permalink
WDR VC channel count is different between V4 and V4A
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Sep 13, 2024
1 parent 4d1adc6 commit fa91a56
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 27 deletions.
99 changes: 72 additions & 27 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,42 +463,87 @@ int v4_region_setbitmap(int handle, hal_bitmap *bitmap)

int v4_sensor_config(void) {
int fd;
v4_snr_dev config;
memset(&config, 0, sizeof(config));
config.device = 0;
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)
memcpy(&config.lvds, &v4_config.lvds, sizeof(v4_snr_lvds));
char v4a_device = 0;
if (EQUALS(chip, "Hi3516AV300") ||
EQUALS(chip, "Hi3516DV300") ||
EQUALS(chip, "Hi3516CV500"))
v4a_device = 1;

if (v4a_device) {
v4a_snr_dev config;
memset(&config, 0, sizeof(config));
config.device = 0;
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)
memcpy(&config.lvds, &v4_config.lvds, sizeof(v4_snr_lvds));

if (!access(v4_snr_endp, F_OK))
fd = open(v4_snr_endp, O_RDWR);
else fd = open("/dev/mipi", O_RDWR);
if (fd < 0)
HAL_ERROR("v4_snr", "Opening imaging device has failed!\n");

int laneMode = 0;
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode);

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

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

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

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, v4a_snr_dev), &config))
HAL_ERROR("v4_snr", "Configuring imaging device has failed!\n");

if (!access(v4_snr_endp, F_OK))
fd = open(v4_snr_endp, O_RDWR);
else fd = open("/dev/mipi", O_RDWR);
if (fd < 0)
HAL_ERROR("v4_snr", "Opening imaging device has failed!\n");
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_MIPI, unsigned int), &config.device);

int laneMode = 0;
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode);
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_SENS, unsigned int), &config.device);

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device);
close(fd);
} else {
v4_snr_dev config;
memset(&config, 0, sizeof(config));
config.device = 0;
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)
memcpy(&config.lvds, &v4_config.lvds, sizeof(v4_snr_lvds));

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_MIPI, unsigned int), &config.device);
if (!access(v4_snr_endp, F_OK))
fd = open(v4_snr_endp, O_RDWR);
else fd = open("/dev/mipi", O_RDWR);
if (fd < 0)
HAL_ERROR("v4_snr", "Opening imaging device has failed!\n");

ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_SENS, unsigned int), &config.device);
int laneMode = 0;
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode);

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))
HAL_ERROR("v4_snr", "Configuring imaging device has failed!\n");
ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKON_MIPI, unsigned int), &config.device);

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_RST_MIPI, unsigned int), &config.device);

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

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))
HAL_ERROR("v4_snr", "Configuring imaging device has failed!\n");

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);

close(fd);
}

return EXIT_SUCCESS;
}
Expand Down
2 changes: 2 additions & 0 deletions src/hal/hisi/v4_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "v4_vi.h"
#include "v4_vpss.h"

#include "../support.h"

#include <fcntl.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
Expand Down
37 changes: 37 additions & 0 deletions src/hal/hisi/v4_snr.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ typedef struct {
unsigned short syncCode[V4_SNR_LVDS_LANE_NUM * V4_SNR_WDR_VC_NUM * 4];
} v4_snr_lvds;

typedef struct {
v4_common_prec prec;
v4_snr_lwdr wdr;
int syncSavOn;
v4_snr_lvsync vsync;
v4_snr_fid fid;
int dataBeOn;
int syncBeOn;
// Value -1 signifies a lane is disabled
short laneId[V4_SNR_LVDS_LANE_NUM];
/* Each lane has two virtual channel, each has four params
If syncSavOn is false: SOF, EOF, SOL, EOL
If syncSavOn is true: invalid sav, invalid eav, valid sav, valid eav */
unsigned short syncCode[V4_SNR_LVDS_LANE_NUM * V4A_SNR_WDR_VC_NUM * 4];
} v4a_snr_lvds;

typedef struct {
v4_common_prec prec;
v4_snr_mwdr mode;
Expand All @@ -112,6 +128,16 @@ typedef struct {
};
} v4_snr_mipi;

typedef struct {
v4_common_prec prec;
v4_snr_mwdr mode;
// Value -1 signifies a lane is disabled
short laneId[V4_SNR_MIPI_LANE_NUM];
union {
short wdrVcType[V4A_SNR_WDR_VC_NUM];
};
} v4a_snr_mipi;

typedef struct {
unsigned int device;
v4_snr_input input;
Expand All @@ -123,6 +149,17 @@ typedef struct {
};
} v4_snr_dev;

typedef struct {
unsigned int device;
v4_snr_input input;
int dataRate2X;
v4_common_rect rect;
union {
v4a_snr_mipi mipi;
v4a_snr_lvds lvds;
};
} v4a_snr_dev;

typedef union {
signed char i2c;
struct {
Expand Down

0 comments on commit fa91a56

Please sign in to comment.