⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 videoin.c

📁 一个视频信号输入的verilog源代码
💻 C
字号:

#include <stdio.h>
#include "videoin.h"
#include "auto32.h"
#include "alt_types.h"
#include "led7segment.h"
#include "demos.h"

void videoinIsr (void* context, alt_u32 id) {
  // reset interrupt bit 
  IOWR_VIDEOIN_MICR(8);
  // is next buffer free?
  if ((videoOwn + 1)%3 != lcdOwn) {
    // update ownership and point to next buffer
    videoOwn = (videoOwn + 1)%3;
    IOWR_VIDEOIN_MFBSTART((unsigned int) buffers[videoOwn]);
  }
  else {
    // re-use current buffer
    IOWR_VIDEOIN_MFBSTART((unsigned int) buffers[videoOwn]);
  }
  // reset done bit and reload frame buffer address
  IOWR_VIDEOIN_MCONTROL(1);
  // set flag
  videoFlags = videoFlags | 0x1;
}

// Disable videoin interrupts and avalon master
void videoInDisable(void) {
  IOWR_VIDEOIN_MINTEN(0x0);
  IOWR_VIDEOIN_MCONTROL(0x0);
};

// Clear interrupt then Enable videoin interrupts and avalon master
void videoInEnable(void) {
  IOWR_VIDEOIN_MICR(8);
  IOWR_VIDEOIN_MINTEN(0x8);
  IOWR_VIDEOIN_MCONTROL(0x1);
};

void videoInClip(int xClipStart, int xClipEnd, int yClipStart, int yClipEnd) {
  videoIn.xClipS = xClipStart;
  videoIn.xClipE = xClipEnd;
  videoIn.yClipS = yClipStart;
  videoIn.yClipE = yClipEnd;
  videoIn.clipWidth = videoIn.xClipE - videoIn.xClipS + 1;
  videoIn.clipHeight = videoIn.yClipE - videoIn.yClipS + 1;
  IOWR_VIDEOIN_XCLIPS(videoIn.xClipS);
  IOWR_VIDEOIN_XCLIPE(videoIn.xClipE);
  IOWR_VIDEOIN_YCLIPS(videoIn.yClipS);
  IOWR_VIDEOIN_YCLIPE(videoIn.yClipE);
  IOWR_VIDEOIN_XLEN(videoIn.xClipE - videoIn.xClipS);
  IOWR_VIDEOIN_YLEN(videoIn.yClipE - videoIn.yClipS);
}

// Set up scaling parameters
int videoInScale(int xScale, int yScale) {
  if ((xScale > 12288) || (xScale < 1365)) {
    xScale = 4096;
    return -1;
  }
  if ((yScale > 12288) || (yScale < 1365)) {
    yScale = 4096;
    return -1;
  }
  videoIn.xScale = xScale;
  videoIn.yScale = yScale;
  int xFactor = 16777216/xScale;
  int yFactor = 16777216/yScale;
  videoIn.xFactor = xFactor;
  videoIn.yFactor = yFactor;
  videoIn.scaledWidth = (videoIn.clipWidth-1)*4096/xFactor + 1;
  videoIn.scaledHeight = (videoIn.clipHeight-1)*4096/yFactor + 1;
  IOWR_VIDEOIN_XSCALE(videoIn.xFactor);
  IOWR_VIDEOIN_YSCALE(videoIn.yFactor);
  return 0;
};

// Set up scaling parameters from desired width
// Width is corrected to ensure it is even and height is calculated
// based on VGA aspect ratio and stretching 
int videoInScale2(int width) {
  if (width > 512) {
    videoIn.scaledWidth = 512;
  } else {
    videoIn.scaledWidth = (width/2)*2;
  }
  videoIn.scaledHeight = (width*480*LCDSTRETCH)/(640*4096);
  videoIn.xFactor = ((videoIn.clipWidth-1)*4096)/(videoIn.scaledWidth - 1);
  videoIn.yFactor = ((videoIn.clipHeight-1)*4096)/(videoIn.scaledHeight - 1);
  videoIn.xScale = 16777216/videoIn.xFactor;
  videoIn.yScale = 16777216/videoIn.yFactor;
  IOWR_VIDEOIN_XSCALE(videoIn.xFactor);
  IOWR_VIDEOIN_YSCALE(videoIn.yFactor);
  return 0;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -