📄 zc030x_reg.c
字号:
/* Include sensor size */#include "zc030x_cameras.h"/* Include declarations */#include "zc030x_reg.h"/* Reset the chip */int zc030x_reg_reset(struct usb_device *udev){ /* Check arguments */ if (udev == NULL) return REG_Error; /* Debug this */ PDEBUG(3, ">>> REGRESET"); /* Send the reset sequence */ if (zc030x_reg_write(udev, ZR(SystemControl), ZV(Reset)) != REG_OK) return REG_Error; if (zc030x_reg_write(udev, ZR(CMOSSensorSelect), 0x01) != REG_OK) return REG_Error; if (zc030x_reg_write(udev, ZR(SystemOperating), ZV(Start)) != REG_OK) return REG_Error; if (zc030x_reg_write(udev, ZR(VideoControlFunc), ZV(ResetSensor)|ZV(SensorTurnOn)) != REG_OK) return REG_Error; /* Return */ PDEBUG(3, "<<< REGRESET OK"); return REG_OK;}/* Set picture size */int zc030x_reg_setsize(struct usb_zc030x *dev, __u16 width, __u16 height, __u8 mask2){ /* Return type */ int ret = 0; struct usb_device *udev; /* Check arguments */ if (dev == NULL) return REG_Error; udev = dev->udev; if (udev == NULL) return REG_Error; /* Debug this */ PDEBUG(3, ">>> REGSETSIZE"); /* Set the downsampling */ if (width && height && width <= (SensorSizeList[dev->sensor_id].Width * 55) / 100 && height <= (SensorSizeList[dev->sensor_id].Height * 55) / 100) { if (zc030x_reg_write(udev, ZR(ClockSelect), ZV(Downsampled)|mask2) == REG_Error) return REG_Error; ret = ZV(HalfScaleInc); currentheight=SensorSizeList[dev->sensor_id].Height/2; currentwidth=SensorSizeList[dev->sensor_id].Width/2; } else { if (zc030x_reg_write(udev, ZR(ClockSelect), ZV(Fullscale)|mask2) == REG_Error) return REG_Error; ret = ZV(FullScaleInc); currentheight=SensorSizeList[dev->sensor_id].Height; currentwidth=SensorSizeList[dev->sensor_id].Width; } /* Send the size command : width */ if (zc030x_reg_write(udev, ZR(FrameWidthHigh), SensorSizeList[dev->sensor_id].Width >> 8) == REG_Error) return REG_Error; if (zc030x_reg_write(udev, ZR(FrameWidthLow), SensorSizeList[dev->sensor_id].Width & 0xFF) == REG_Error) return REG_Error; /* Send the size command : height */ if (zc030x_reg_write(udev, ZR(FrameHeightHigh), SensorSizeList[dev->sensor_id].Height >> 8) == REG_Error) return REG_Error; if (zc030x_reg_write(udev, ZR(FrameHeightLow), SensorSizeList[dev->sensor_id].Height & 0xFF) == REG_Error) return REG_Error; /* Send the size command : line width */ if (zc030x_reg_write(udev, ZR(WinWidthHigh), SensorSizeList[dev->sensor_id].Width >> 8) == REG_Error) return REG_Error; if (zc030x_reg_write(udev, ZR(WinWidthLow), (SensorSizeList[dev->sensor_id].Width + ret) & 0xFF) == REG_Error) return REG_Error; /* Send the size command : height */ if (zc030x_reg_write(udev, ZR(WinHeightHigh), SensorSizeList[dev->sensor_id].Height >> 8) == REG_Error) return REG_Error; if (zc030x_reg_write(udev, ZR(WinHeightLow), (SensorSizeList[dev->sensor_id].Height + ret) & 0xFF) == REG_Error) return REG_Error; /* Okay, return */ PDEBUG(3, "<<< REGSETSIZE OK [%dx%d]", width, height); return REG_OK;}/* Read a register from the bridge chip */int zc030x_reg_read(struct usb_device *udev, __u16 addr, __u16 value, __u16 length){ /* Return type */ int ret = 0; /* Buffers */ unsigned char buf[4] = {0, 0, 0, 0}; /* Check arguments */ if (udev == NULL) return REG_Error; /* Submit the URB */ ret = usb_control_msg (udev, usb_rcvctrlpipe (udev, 0), 0x00A1, 0xc0, value, addr, buf, length, HZ); /* Check reading */ if (ret < 0) return REG_Error; /* Save the result and return*/ ret = buf[0] | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24); return ret; }/* Write a register on the bridge chip */int zc030x_reg_write(struct usb_device *udev, __u16 addr, __u16 value){ /* Return type */ int ret = 0; /* Buffers */ unsigned char buf[4] = {0, 0, 0, 0}; /* Check arguments */ if (udev == NULL) return REG_Error; /* Submit the URB */ ret = usb_control_msg (udev, usb_sndctrlpipe (udev, 0), 0x00A0, 0x40, value, addr, buf, 0x0000, HZ); /* Check reading */ if (ret < 0) return REG_Error; /* Okay, return */ PDEBUG(6, "Writing at address 0x%04x the value 0x%04x ( 0x0000 })", addr, value); return REG_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -