📄 vcodec_sdk.c
字号:
/*****************************************************************************************************************************************
File Name: vcodec_SDK.c
Author: Xue, Zhenwu
Date: October, 19th, 2007
Revision: 1.0
Description: SDK of video codec for the yth project.
******************************************************************************************************************************************/
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <linux/ioctl.h>
#include <asm-arm/ioctl.h>
#include <sys/ioctl.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/config.h>
#include <linux/slab.h>
#include <linux/errno.h>
#define VDECODER_WADDR 0x4A
#define VDECODER_RADDR 0x4B
#define VENCODER_WADDR 0x88
static int I2C; /*Device ID of the I2C bus*/
int init_I2C(); /*Initialize the I2C bus*/
int write_7113(unsigned char address, unsigned char value); /*Write a value into SAA7113H's register*/
unsigned char read_7113(unsigned char address); /*Read SAA7113H's register*/
int write_7121(unsigned char address, unsigned char value); /*Write a value into SAA7121's register*/
unsigned char read_7121(unsigned char address); /*Read SAA7121's register*/
int release_I2C(); /*Release the I2C bus*/
/*********************************************************************************************************************************
Function: init_I2C
Description: open the i2c device
**********************************************************************************************************************************/
int init_I2C(){
I2C = open("/dev/i2c/0", O_RDWR);
if(I2C<0){
printf("Error: Unable to open I2C device!\n");
return -1;
}else{
return 0;
}
}
/************************************************************************************************************************************
Function: write_7113
Description: Write a value into SAA7113H's register
************************************************************************************************************************************/
int write_7113(unsigned char address, unsigned char value){
unsigned char buf[2];
int ret;
unsigned char vv;
int i;
int count = 0;
while(count<=20){
buf[0] = address;
buf[1] = value;
ioctl(I2C, I2C_TENBIT, 0);
ioctl(I2C, I2C_SLAVE_FORCE, VDECODER_WADDR>>1);
ret=write(I2C, buf, 2);
while((ret=write(I2C, buf, 2))<2);
printf("Info: Write %d bytes into SAA7113 at 0x%02X.\n", ret, address);
vv = read_7113(address);
if(vv==value){
break;
}
i = 1000;
while(i--);
count++;
}
if(vv!=value){
printf("Error when writing SAA7113 at 0x%02X!\n", address);
}
return ret;
}
/*************************************************************************************************************************************
Function: read_7113
Description: Read SAA7113H's register
**************************************************************************************************************************************/
unsigned char read_7113(unsigned char address){
unsigned char buf[2];
int ret;
buf[0] = address;
ret = ioctl(I2C, I2C_TENBIT, 0);
ret = ioctl(I2C, I2C_SLAVE_FORCE, VDECODER_RADDR>>1);
ret = write(I2C, &address, 1);
while((ret = write(I2C, &address, 1))<1);
ret = read(I2C, &buf[1], 1);
while((ret = read(I2C, &buf[1], 1))<1);
return buf[1];
}
/************************************************************************************************************************************
Function: write_7121
Description: Write a value into SAA7121's register
************************************************************************************************************************************/
int write_7121(unsigned char address, unsigned char value){
unsigned char buf[2];
int ret;
buf[0] = address;
buf[1] = value;
ioctl(I2C, I2C_TENBIT, 0);
ioctl(I2C, I2C_SLAVE_FORCE, VENCODER_WADDR>>1);
ret = write(I2C, buf, 2);
while((ret = write(I2C, buf, 2))<2);
//printf("Info: Write %d bytes into SAA7121 at 0x%02X.\n", ret, address);
return 0;
}
/*************************************************************************************************************************************
Function: read_7121
Description: Read SAA7121's register
**************************************************************************************************************************************/
unsigned char read_7121(unsigned char address){
unsigned char buf[2];
int ret;
buf[0] = address;
ret = ioctl(I2C, I2C_TENBIT, 0);
ret = ioctl(I2C, I2C_SLAVE_FORCE, VENCODER_WADDR>>1);
ret = write(I2C, &address, 1);
if(ret<0){
printf("Error when sending SAA7121's register address!\n");
}
ret = read(I2C, &buf[1], 1);
if(ret<0){
printf("Error when reading SAA7121!\n");
}
return buf[1];
}
/************************************************************************************************************************************
Function: release_I2C
Description: release the I2C device
************************************************************************************************************************************/
int release_I2C(){
close(I2C);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -