平台:ubuntu虚拟机 ZYNQ7035

1.vivado编辑BD文件,设置两个IIC接口

2.设备树搭建,应用petalinux调用hdf直接生成

 在Ubuntu虚拟机内搭建工程
source /opt/pkg/petalinux/2018.3/settings.shpetalinux-create -t project --template zynq -n cam2hdmi   //创建文件夹
//将生成的hdf文件放到文件夹下
cd cam2hdmi //进入到 petalinux 工程目录下
petalinux-config --get-hw-description
//--进入系统配置
petalinux-config -c kernel  //配置内核
petalinux-config -c rootfs   //配置根文件  配置密码
petalinux-build   //编译工程
//没有外部设备以上基本不用更改
petalinux-package --boot --fsbl --fpga --u-boot --force    //生成boot.bin文件

将boot.bin image.ub文件拷贝到SD卡,启动文件制作完成。
系统启动可以通过串口看到:

3.在线调试

因为配置时调用PS端以太网,选用linux TCF agent在线调试方法。
直接在SDK内编译函数实现功能。
主函数:I2C0_FILE_NAME 具体位置,例如我的:/dev/i2c-0

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>#include "VDMA.h"
#include "i2c.h"
#include"camera_reg.h"int main(){iic_init(I2C0_FILE_NAME);iic_init(I2C1_FILE_NAME);
}

linux下操作IIC写入函数:

#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include "types.h"
#include "i2c.h"
#include "camera_reg.h"int iic_init(char* iic_path){Xuint8 fd;
///reset cam1 configfd = iic_open(iic_path);//fd = iic_open(I2C0_FILE_NAME);if (fd<0 ){printf("open faild");}IicWrite(fd,0x3017, 0x00);ov5640_init_rgb(fd);iic_close(fd);return 0;
}int iic_open(char* iic_path)
{int file = 0;// Open a connection to the I2C userspace control file.if ((file = open(iic_path, O_RDWR)) < 0) {perror("Unable to open i2c control file");exit(-1);}return file;
}void iic_close(int file)
{close(file);
}int IicWrite(Xuint8 file, Xuint16 addr,Xuint8 value)
{unsigned char outbuf[3];struct i2c_rdwr_ioctl_data packets;struct i2c_msg messages[1];messages[0].addr = CAM_OV5640; //器件地址messages[0].flags  = 0; //0 write 1 readmessages[0].len       = sizeof(outbuf);messages[0].buf       = outbuf;outbuf[0] = addr >>8;   //因为该器件寄存器地址为16位outbuf[1] = addr;outbuf[2] = value;/* Transfer the i2c packets to the kernel and verify it worked */packets.msgs  = messages;packets.nmsgs = 1;if(ioctl(file, I2C_RDWR, &packets) < 0) {perror("Unable to send data");return -1;}usleep(2000);return 0;
}

摄像头配置参数:参考米联客代码


void ov5640_init_rgb(Xuint8 file)
{IicWrite(file,0x3103, 0x11); // system clock from pad, bit[1]IicWrite(file,0x3008, 0x82); // software reset, bit[7]// delay 5msIicWrite(file,0x3008, 0x42); // software power down, bit[6]IicWrite(file,0x3103, 0x03); // system clock from PLL, bit[1]IicWrite(file,0x3017, 0xff); // FREX, Vsync, HREF, PCLK, D[9:6] output enableIicWrite(file,0x3018, 0xff); // D[5:0], GPIO[1:0] output enableIicWrite(file,0x3034, 0x1a); // MIPI 10-bitIicWrite(file,0x3037, 0x13); // PLL root divider, bit[4], PLL pre-divider, bit[3:0]IicWrite(file,0x3108, 0x01); // PCLK root divider, bit[5:4], SCLK2x root divider, bit[3:2]// SCLK root divider, bit[1:0]IicWrite(file,0x3630, 0x36);IicWrite(file,0x3631, 0x0e);IicWrite(file,0x3632, 0xe2);IicWrite(file,0x3633, 0x12);IicWrite(file,0x3621, 0xe0);IicWrite(file,0x3704, 0xa0);IicWrite(file,0x3703, 0x5a);IicWrite(file,0x3715, 0x78);IicWrite(file,0x3717, 0x01);IicWrite(file,0x370b, 0x60);IicWrite(file,0x3705, 0x1a);IicWrite(file,0x3905, 0x02);IicWrite(file,0x3906, 0x10);IicWrite(file,0x3901, 0x0a);IicWrite(file,0x3731, 0x12);IicWrite(file,0x3600, 0x08); // VCM controlIicWrite(file,0x3601, 0x33); // VCM controlIicWrite(file,0x302d, 0x60); // system controlIicWrite(file,0x3620, 0x52);IicWrite(file,0x371b, 0x20);IicWrite(file,0x471c, 0x50);IicWrite(file,0x3a13, 0x43); // pre-gain = 1.047xIicWrite(file,0x3a18, 0x00); // gain ceilingIicWrite(file,0x3a19, 0xf8); // gain ceiling = 15.5xIicWrite(file,0x3635, 0x13);IicWrite(file,0x3636, 0x03);IicWrite(file,0x3634, 0x40);IicWrite(file,0x3622, 0x01);// 50/60Hz detection 50/60Hz 灯光条纹过滤IicWrite(file,0x3c01, 0x34); // Band auto, bit[7]IicWrite(file,0x3c04, 0x28); // threshold low sumIicWrite(file,0x3c05, 0x98); // threshold high sumIicWrite(file,0x3c06, 0x00); // light meter 1 threshold[15:8]IicWrite(file,0x3c07, 0x08); // light meter 1 threshold[7:0]IicWrite(file,0x3c08, 0x00); // light meter 2 threshold[15:8]IicWrite(file,0x3c09, 0x1c); // light meter 2 threshold[7:0]IicWrite(file,0x3c0a, 0x9c); // sample number[15:8]IicWrite(file,0x3c0b, 0x40); // sample number[7:0]IicWrite(file,0x3810, 0x00); // Timing Hoffset[11:8]IicWrite(file,0x3811, 0x10); // Timing Hoffset[7:0]IicWrite(file,0x3812, 0x00); // Timing Voffset[10:8]IicWrite(file,0x3708, 0x64);IicWrite(file,0x4001, 0x02); // BLC start from line 2IicWrite(file,0x4005, 0x1a); // BLC always updateIicWrite(file,0x3000, 0x00); // enable blocksIicWrite(file,0x3004, 0xff); // enable clocksIicWrite(file,0x300e, 0x58); // MIPI power down, DVP enableIicWrite(file,0x302e, 0x00);IicWrite(file,0x4300, 0x61); // YUV 422, YUYVIicWrite(file,0x501f, 0x01); // YUV 422IicWrite(file,0x440e, 0x00);IicWrite(file,0x5000, 0xa7); // Lenc on, raw gamma on, BPC on, WPC on, CIP on// AEC target 自动曝光控制IicWrite(file,0x3a0f, 0x30); // stable range in highIicWrite(file,0x3a10, 0x28); // stable range in lowIicWrite(file,0x3a1b, 0x30); // stable range out highIicWrite(file,0x3a1e, 0x26); // stable range out lowIicWrite(file,0x3a11, 0x60); // fast zone highIicWrite(file,0x3a1f, 0x14); // fast zone low// Lens correction for ? 镜头补偿IicWrite(file,0x5800, 0x23);IicWrite(file,0x5801, 0x14);IicWrite(file,0x5802, 0x0f);IicWrite(file,0x5803, 0x0f);IicWrite(file,0x5804, 0x12);IicWrite(file,0x5805, 0x26);IicWrite(file,0x5806, 0x0c);IicWrite(file,0x5807, 0x08);IicWrite(file,0x5808, 0x05);IicWrite(file,0x5809, 0x05);IicWrite(file,0x580a, 0x08);IicWrite(file,0x580b, 0x0d);IicWrite(file,0x580c, 0x08);IicWrite(file,0x580d, 0x03);IicWrite(file,0x580e, 0x00);IicWrite(file,0x580f, 0x00);IicWrite(file,0x5810, 0x03);IicWrite(file,0x5811, 0x09);IicWrite(file,0x5812, 0x07);IicWrite(file,0x5813, 0x03);IicWrite(file,0x5814, 0x00);IicWrite(file,0x5815, 0x01);IicWrite(file,0x5816, 0x03);IicWrite(file,0x5817, 0x08);IicWrite(file,0x5818, 0x0d);IicWrite(file,0x5819, 0x08);IicWrite(file,0x581a, 0x05);IicWrite(file,0x581b, 0x06);IicWrite(file,0x581c, 0x08);IicWrite(file,0x581d, 0x0e);IicWrite(file,0x581e, 0x29);IicWrite(file,0x581f, 0x17);IicWrite(file,0x5820, 0x11);IicWrite(file,0x5821, 0x11);IicWrite(file,0x5822, 0x15);IicWrite(file,0x5823, 0x28);IicWrite(file,0x5824, 0x46);IicWrite(file,0x5825, 0x26);IicWrite(file,0x5826, 0x08);IicWrite(file,0x5827, 0x26);IicWrite(file,0x5828, 0x64);IicWrite(file,0x5829, 0x26);IicWrite(file,0x582a, 0x24);IicWrite(file,0x582b, 0x22);IicWrite(file,0x582c, 0x24);IicWrite(file,0x582d, 0x24);IicWrite(file,0x582e, 0x06);IicWrite(file,0x582f, 0x22);IicWrite(file,0x5830, 0x40);IicWrite(file,0x5831, 0x42);IicWrite(file,0x5832, 0x24);IicWrite(file,0x5833, 0x26);IicWrite(file,0x5834, 0x24);IicWrite(file,0x5835, 0x22);IicWrite(file,0x5836, 0x22);IicWrite(file,0x5837, 0x26);IicWrite(file,0x5838, 0x44);IicWrite(file,0x5839, 0x24);IicWrite(file,0x583a, 0x26);IicWrite(file,0x583b, 0x28);IicWrite(file,0x583c, 0x42);IicWrite(file,0x583d, 0xce); // lenc BR offset// AWB 自动白平衡/*IicWrite(file,0x5180, 0xff); // AWB B blockIicWrite(file,0x5181, 0xf2); // AWB controlIicWrite(file,0x5182, 0x00); // [7:4] max local counter, [3:0] max fast counterIicWrite(file,0x5183, 0x14); // AWB advancedIicWrite(file,0x5184, 0x25);IicWrite(file,0x5185, 0x24);IicWrite(file,0x5186, 0x09);IicWrite(file,0x5187, 0x09);IicWrite(file,0x5188, 0x09);IicWrite(file,0x5189, 0x75);IicWrite(file,0x518a, 0x54);IicWrite(file,0x518b, 0xe0);IicWrite(file,0x518c, 0xb2);IicWrite(file,0x518d, 0x42);IicWrite(file,0x518e, 0x3d);IicWrite(file,0x518f, 0x56);IicWrite(file,0x5190, 0x46);IicWrite(file,0x5191, 0xf8); // AWB top limitIicWrite(file,0x5192, 0x04); // AWB bottom limitIicWrite(file,0x5193, 0x70); // red limitIicWrite(file,0x5194, 0xf0); // green limitIicWrite(file,0x5195, 0xf0); // blue limitIicWrite(file,0x5196, 0x03); // AWB controlIicWrite(file,0x5197, 0x01); // local limitIicWrite(file,0x5198, 0x04);IicWrite(file,0x5199, 0x12);IicWrite(file,0x519a, 0x04);IicWrite(file,0x519b, 0x00);IicWrite(file,0x519c, 0x06);IicWrite(file,0x519d, 0x82);IicWrite(file,0x519e, 0x38); // AWB control*/IicWrite(file,0x5180, 0xff); // AWB B blockIicWrite(file,0x5181, 0x58); // AWB controlIicWrite(file,0x5182, 0x11); // [7:4] max local counter, [3:0] max fast counterIicWrite(file,0x5183, 0x90); // AWB advancedIicWrite(file,0x5184, 0x25);IicWrite(file,0x5185, 0x24);IicWrite(file,0x5186, 0x09);IicWrite(file,0x5187, 0x09);IicWrite(file,0x5188, 0x09);IicWrite(file,0x5189, 0x75);IicWrite(file,0x518a, 0x54);IicWrite(file,0x518b, 0xe0);IicWrite(file,0x518c, 0xb2);IicWrite(file,0x518d, 0x42);IicWrite(file,0x518e, 0x3d);IicWrite(file,0x518f, 0x56);IicWrite(file,0x5190, 0x46);IicWrite(file,0x5191, 0xff); // AWB top limitIicWrite(file,0x5192, 0x00); // AWB bottom limitIicWrite(file,0x5193, 0xf0); // red limitIicWrite(file,0x5194, 0xf0); // green limitIicWrite(file,0x5195, 0xf0); // blue limitIicWrite(file,0x5196, 0x03); // AWB controlIicWrite(file,0x5197, 0x02); // local limitIicWrite(file,0x5198, 0x04);IicWrite(file,0x5199, 0x12);IicWrite(file,0x519a, 0x04);IicWrite(file,0x519b, 0x00);IicWrite(file,0x519c, 0x06);IicWrite(file,0x519d, 0x82);IicWrite(file,0x519e, 0x00); // AWB control// Gamma 伽玛曲线IicWrite(file,0x5480, 0x01); // Gamma bias plus on, bit[0]IicWrite(file,0x5481, 0x08);IicWrite(file,0x5482, 0x14);IicWrite(file,0x5483, 0x28);IicWrite(file,0x5484, 0x51);IicWrite(file,0x5485, 0x65);IicWrite(file,0x5486, 0x71);IicWrite(file,0x5487, 0x7d);IicWrite(file,0x5488, 0x87);IicWrite(file,0x5489, 0x91);IicWrite(file,0x548a, 0x9a);IicWrite(file,0x548b, 0xaa);IicWrite(file,0x548c, 0xb8);IicWrite(file,0x548d, 0xcd);IicWrite(file,0x548e, 0xdd);IicWrite(file,0x548f, 0xea);IicWrite(file,0x5490, 0x1d);// color matrix 色彩矩阵IicWrite(file,0x5381, 0x1e); // CMX1 for YIicWrite(file,0x5382, 0x5b); // CMX2 for YIicWrite(file,0x5383, 0x08); // CMX3 for YIicWrite(file,0x5384, 0x0a); // CMX4 for UIicWrite(file,0x5385, 0x7e); // CMX5 for UIicWrite(file,0x5386, 0x88); // CMX6 for UIicWrite(file,0x5387, 0x7c); // CMX7 for VIicWrite(file,0x5388, 0x6c); // CMX8 for VIicWrite(file,0x5389, 0x10); // CMX9 for VIicWrite(file,0x538a, 0x01); // sign[9]IicWrite(file,0x538b, 0x98); // sign[8:1]// UV adjust UV色彩饱和度调整IicWrite(file,0x5580, 0x06); // saturation on, bit[1]IicWrite(file,0x5583, 0x40);IicWrite(file,0x5584, 0x10);IicWrite(file,0x5589, 0x10);IicWrite(file,0x558a, 0x00);IicWrite(file,0x558b, 0xf8);IicWrite(file,0x501d, 0x40); // enable manual offset of contrast// CIP 锐化和降噪IicWrite(file,0x5300, 0x08); // CIP sharpen MT threshold 1IicWrite(file,0x5301, 0x30); // CIP sharpen MT threshold 2IicWrite(file,0x5302, 0x10); // CIP sharpen MT offset 1IicWrite(file,0x5303, 0x00); // CIP sharpen MT offset 2IicWrite(file,0x5304, 0x08); // CIP DNS threshold 1IicWrite(file,0x5305, 0x30); // CIP DNS threshold 2IicWrite(file,0x5306, 0x08); // CIP DNS offset 1IicWrite(file,0x5307, 0x16); // CIP DNS offset 2IicWrite(file,0x5309, 0x08); // CIP sharpen TH threshold 1IicWrite(file,0x530a, 0x30); // CIP sharpen TH threshold 2IicWrite(file,0x530b, 0x04); // CIP sharpen TH offset 1IicWrite(file,0x530c, 0x06); // CIP sharpen TH offset 2IicWrite(file,0x5025, 0x00);IicWrite(file,0x3008, 0x02); // wake up from standby, bit[6]// YUV VGA 30fps, night mode 5fps// Input Clock = 24Mhz, PCLK = 56MHzIicWrite(file,0x3035, 0x11); // PLLIicWrite(file,0x3036, 0x46); // PLLIicWrite(file,0x3c07, 0x08); // light meter 1 threshold [7:0]IicWrite(file,0x3820, 0x40); // Sensor flip off, ISP flip onIicWrite(file,0x3821, 0x07); // Sensor mirror on, ISP mirror on, H binning onIicWrite(file,0x3814, 0x31); // X INCIicWrite(file,0x3815, 0x31); // Y INCIicWrite(file,0x3800, 0x00); // HSIicWrite(file,0x3801, 0x00); // HSIicWrite(file,0x3802, 0x00); // VSIicWrite(file,0x3803, 0x04); // VSIicWrite(file,0x3804, 0x0a); // HW (HE)IicWrite(file,0x3805, 0x3f); // HW (HE)IicWrite(file,0x3806, 0x07); // VH (VE)IicWrite(file,0x3807, 0x9b); // VH (VE)IicWrite(file,0x3808, 0x02); // DVPHOIicWrite(file,0x3809, 0x80); // DVPHOIicWrite(file,0x380a, 0x01); // DVPVOIicWrite(file,0x380b, 0xe0); // DVPVOIicWrite(file,0x380c, 0x07); // HTSIicWrite(file,0x380d, 0x68); // HTSIicWrite(file,0x380e, 0x03); // VTSIicWrite(file,0x380f, 0xd8); // VTSIicWrite(file,0x3813, 0x06); // Timing VoffsetIicWrite(file,0x3618, 0x00);IicWrite(file,0x3612, 0x29);IicWrite(file,0x3709, 0x52);IicWrite(file,0x370c, 0x03);IicWrite(file,0x3a02, 0x17); // 60Hz max exposure, night mode 5fpsIicWrite(file,0x3a03, 0x10); // 60Hz max exposureIicWrite(file,0x3a14, 0x17); // 50Hz max exposure, night mode 5fpsIicWrite(file,0x3a15, 0x10); // 50Hz max exposureIicWrite(file,0x4004, 0x02); // BLC 2 linesIicWrite(file,0x3002, 0x1c); // reset JFIFO, SFIFO, JPEGIicWrite(file,0x3006, 0xc3); // disable clock of JPEG2x, JPEGIicWrite(file,0x4713, 0x03); // JPEG mode 3IicWrite(file,0x4407, 0x04); // Quantization scaleIicWrite(file,0x460b, 0x35);IicWrite(file,0x460c, 0x22);IicWrite(file,0x4837, 0x22); // DVP CLK dividerIicWrite(file,0x3824, 0x02); // DVP CLK dividerIicWrite(file,0x5001, 0xa3); // SDE on, scale on, UV average off, color matrix on, AWB onIicWrite(file,0x3503, 0x00); // AEC/AGC on
}

ZYNQ linux环境下PS I2C配置OV5640相关推荐

  1. linux 环境下安装和配置mysql数据库以及远程登录

      上一篇文章写了linux 环境下配置python虚拟环境, 本篇文章我们来看看如何在linux环境下配置 mysql, 并实现远程数据库登录.    安装 //root 下安装,为了方便操作我全部 ...

  2. Linux环境下nginx安装配置--淘宝Tengine

    文章目录 前言 一.tengine是什么? 二.使用步骤 1.下载地址 2.解压 3.依赖安装 4.安装nginx 5.编译 6.启动 7.设置为系统服务 7.服务启动.停止.重启 总结 前言 随着公 ...

  3. linux环境下ps命令行,Linux下ps命令详解

    下ps命令详解Linux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待)2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号)3. 不可中断(收到信号不唤醒和不可运行, 进程必须 ...

  4. linux环境下ps命令行,Linux下ps命令详解 Linux下ps命令的详细使用方法

    Linux下ps命令详解 Linux上进程有5种状态:1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运 ...

  5. Linux环境下Redis安装配置步骤

    在LInux下安装Redis的步骤如下: 1.首先下载一个Redis安装包,官网下载地址为:https://redis.io/ 2.在Linux下解压redis: tar -zxvf redis-2. ...

  6. Linux环境下Anaconda3安装配置pytorch

    目录 1 安装anaconda 2 配置conda环境 2.1 一些常用conda命令 2.2 安装pytorch 1 安装anaconda https://blog.csdn.net/tomatt7 ...

  7. 在Linux环境下安装和配置phpmyadmin

    phpmyadmin是一种mysql的图形化管理工具,该工具允许你在web界面上管理你的mysql数据库,不可谓不方便快捷. 此次安装与配置是在centos 6.4系统下,该系统已部署lnmp环境.关 ...

  8. python安装环境配置linux_[Python学习] Linux环境下的Python配置,必备库的安装配置...

    1.默认Python安装情况 一般情况,Linux会预装Python的,版本较低,比如Ubuntu15的系统一般预装的是Python2.7.10. 使用命令:which python可以查看当前的py ...

  9. Linux环境下Redis主从配置

    #在主节点配置成功的情况下配置从节点的步骤: #1.新建一个文件 [root@localhost redis-5.0.14]# mkdir config #2.复制两个从节点的配置文件并重命名 [ro ...

最新文章

  1. 人力资源大数据解决方案
  2. 常用函数式接口之Consumer
  3. linux跟aix时间同步,Linux 与AIX环境下修改时间
  4. 【C语言】如何安装CLion并在CLion中Run一个程序
  5. u-boot移植随笔:关于u-boot引导内核出现“Error: unrecognized/unsupported machine ID (r1 = 0x33f4fee8)”的问题
  6. linux源码包与RPM包的区别
  7. c/c++将字符串中的空格替换成%20
  8. python里字典的基本用法(包括嵌套字典)_Python使用字典的嵌套功能详解 python 嵌套中的字典赋值...
  9. 求多个数最小公倍数的一种变换算法
  10. 控制台中如何将IE11降级
  11. DOS CMD 设置环境变量
  12. android 微信照片,手机微信图片怎么恢复 答案让人难以置信
  13. 第22篇-安卓手机端抓包软件VNET介绍
  14. 吕梁云计算机中心,吕梁云计算中心综合实力全国排第三
  15. WPA和WPA2的区别
  16. PMP49个子过程ITTO总结
  17. 用定制标签库和配置文件实现对JSP页面元素的访问控制
  18. python_音频处理_Windows10_ raise NoBackendError() audioread.exceptions.NoBackendError
  19. iphone震动反馈怎么设置,如何在iPhone上禁用触觉反馈振动 | MOS86
  20. Expert Metalink – Support Tips Tools Resources

热门文章

  1. java计算机毕业设计家装建材网源程序+mysql+系统+lw文档+远程调试
  2. 唐山胃肠病医院教你如何治疗肛肠疾病
  3. 18年秋招-Java后端面试总结与心路历程(非科班小白勉强拿几个互联网offer但是决定转行了)
  4. Qt编写自定义控件66-光晕时钟
  5. 网易企业邮箱HTTPS加密上传配置SSL证书
  6. Proteus: no power supply specified for net VCC in power rail configuration
  7. 《光晕:斯巴达进攻》正式登陆Windows Phone及Windows 8.1平台
  8. 怎么查看手机的信号质量
  9. 使用Nginx搭建反向代理
  10. 数字式电子体温计芯片方案