#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/videodev.h>
#include <linux/fb.h>
#include <linux/i2c-algo-faraday.h>
#include "xc3028_control.h"
#include "xc3028_channelmaps.h"
#include "xc3028_scodes.h"
#include "xc3028_firmwares.h"
#define XCEIVE_XC3028_SUBADDR_FREQ_ERROR 0x0001
#define XCEIVE_XC3028_SUBADDR_LOCK 0x0002
#define XCEIVE_XC3028_SUBADDR_VERSION 0x0004
#define XCEIVE_XC3028_SUBADDR_PRODUCT_ID 0x0008
#define XCEIVE_XC3028_SUBADDR_HSYNC_FREQ 0x0010
#define XCEIVE_XC3028_SUBADDR_FRAME_LINES 0x0020
#define XCEIVE_XC3028_SUBADDR_QUALITY 0x0040
#define XCEIVE_XC3028_SUBADDR_ADC_ENVELOPE 0x0100
#define TUNER_ID_WRITE 0xc2
#define TUNER_ID_READ 0xc3
int tv_fd=-1;
int gpid =-1;
/* *************************************************************** */
/* GLOBAL VARIABLES */
/* *************************************************************** */
XC3028_TV_MODE XC3028_current_tv_mode = {0,0,0};
XC3028_CHANNEL_MAP *XC3028_current_channel_map_ptr = 0;
XC3028_CHANNEL XC3028_current_channel = {{' ',' ',' ',' '}, 0, 0};
//static int area_addr = &XC3028_channel_map_taiwan_analog_cable;
static int mode_addr = &XC3028_tv_mode_m_n_ntsc_pal_mts_lcd_nogd;
static int channel_init = 1,freq_offset = 0;
struct i2c_faraday_msg i2c_ap ;
int xc3028_send_i2c_data(unsigned char *bytes_to_send, int nb_bytes_to_send);
int xc3028_read_i2c_data(unsigned char *bytes_received, int nb_bytes_to_receive);
int xc3028_reset();
int xc3028_wait(int wait_ms);
#define TV_Reset 1
#define TV_IR 2
/* *************************************************************** */
/* *************************************************************** */
/* */
/* CODE PROVIDED BY XCEIVE */
/* */
/* *************************************************************** */
/* *************************************************************** */
int xc3028_load_i2c_sequence(XC3028_I2C_SEQUENCE i2c_sequence)
{
int i,nbytes_to_send,pos,result;
unsigned int length, index;
unsigned char buf[XC3028_MAX_I2C_WRITE_LENGTH];
index=0;
while ((i2c_sequence.sequence[index]!=0xFF) || (i2c_sequence.sequence[index+1]!=0xFF)) {
length = i2c_sequence.sequence[index]*256 + i2c_sequence.sequence[index+1];
if (length==0x0000) {
//this is in fact a RESET command
result = xc3028_reset();
index+=2;
if (result!=XC3028_RESULT_SUCCESS)
return result;
} else if (length & 0x8000) {
//this is in fact a WAIT command
result = xc3028_wait(length & 0x7FFF);
index+=2;
if (result!=XC3028_RESULT_SUCCESS)
return result;
} else {
//send i2c data whilst ensuring individual transactions do
//not exceed XC3028_MAX_I2C_WRITE_LENGTH bytes
index+=2;
buf[0] = i2c_sequence.sequence[index];
pos = 1;
while (pos < length) {
if ( (length-pos) > XC3028_MAX_I2C_WRITE_LENGTH-1) {
nbytes_to_send = XC3028_MAX_I2C_WRITE_LENGTH;
} else {
nbytes_to_send = (length-pos+1);
}
for (i=1;i<nbytes_to_send;i++) {
buf[i] = i2c_sequence.sequence[index+pos+i-1];
}
result = xc3028_send_i2c_data(buf, nbytes_to_send);
if (result!=XC3028_RESULT_SUCCESS)
return result;
pos += nbytes_to_send-1;
}
index+=length;
}
}
return XC3028_RESULT_SUCCESS;
}
int xc3028_get_reg(unsigned short int subaddr, unsigned short int *data)
{
unsigned char buf[2];
int result;
printf("xc3028_get_reg\n");
buf[0]=(subaddr>>8) & 0xFF;
buf[1]=subaddr & 0xFF;
result = xc3028_send_i2c_data(buf, 2);
if (result!=XC3028_RESULT_SUCCESS)
return result;
result = xc3028_read_i2c_data(buf, 2);
if (result!=XC3028_RESULT_SUCCESS)
return result;
(*data) = buf[0];
(*data) = ((*data) << 8) + buf[1];
return XC3028_RESULT_SUCCESS;
}
int xc3028_initialize(XC3028_TV_MODE* new_tv_mode_ptr, XC3028_CHANNEL_MAP* new_channel_map_ptr)
{
int result;
int base_firmware_changed = (new_tv_mode_ptr->base_firmware_ptr != XC3028_current_tv_mode.base_firmware_ptr);
int std_firmware_changed = (new_tv_mode_ptr->std_firmware_ptr != XC3028_current_tv_mode.std_firmware_ptr);
// if base firmware has changed, then do hardware reset and reload base
// firmware file
if (base_firmware_changed) {
result = xc3028_reset();
if (result!=XC3028_RESULT_SUCCESS)
return result;
printf("load base firmware...\n");
result = xc3028_load_i2c_sequence(*(new_tv_mode_ptr->base_firmware_ptr));
if (result!=XC3028_RESULT_SUCCESS)
return result;
}
// if base firmware has changed -or- standard-specific firmware has
// changed then reload standard-specific firmware file
if (base_firmware_changed || std_firmware_changed) {
printf("load std firmware...\n");
result = xc3028_load_i2c_sequence(*(new_tv_mode_ptr->std_firmware_ptr));
if (result!=XC3028_RESULT_SUCCESS)
{
printf("load std firmware fail\n");
return result;
}
}
XC3028_current_tv_mode = *new_tv_mode_ptr;
XC3028_current_channel_map_ptr = new_channel_map_ptr;
// if base firmware has changed -or- standard-specific firmware has
// changed then re-write RF channel
//justin
/*
if (base_firmware_changed || std_firmware_changed) {
//do not return error if channel is incorrect...
xc3028_set_channel(XC3028_current_channel);
}
*/
return XC3028_RESULT_SUCCESS;
}
int xc3028_shutdown()
{
//unsigned char buf[4] = {0x00, 0x08, 0x00, 0x00};
unsigned char buf[4] = {0x80, 0x08, 0x00, 0x00}; //modified for firmware v2.2
printf("xc3028_shutdown\n");
xc3028_send_i2c_data(buf, 4); //no ack check
//reset current firmware pointers to force firmware reload
//during subsequent call to xc3028_initialize()
XC3028_current_tv_mode.base_firmware_ptr=0;
XC3028_current_tv_mode.std_firmware_ptr=0;
return 0;
}
/*
int xc3028_set_frequency(double frequency_in_mhz)
{
unsigned int frequency_code;
int result;
XC3028_CHANNEL new_channel;
if (XC3028_current_channel_map_ptr == 0)
return XC3028_RESULT_NO_CHANNELMAP_SPECIFIED;
if ((frequency_in_mhz>1023) || (frequency_in_mhz<1))
return XC3028_RESULT_OUT_OF_RANGE;
//frequency_code = (unsigned int)floor(frequency_in_mhz/0.015625);justin
new_channel.frequency = frequency_code;
new_channel.dcode = 0xFF;
return xc3028_set_channel(new_channel);
}
*/
int xc3028_send_scode(unsigned char dcode)
{
unsigned char buf[4];
int result;
//buf[0] = 0x20;
buf[0] = 0xA0; // modified for firmware v2.2
buf[1] = 0x00;
buf[2] = 0x00;
buf[3] = 0x00;
if (XC3028_current_tv_mode.scode_table_ptr==0) {
return XC3028_RESULT_SUCCESS;
}
result = xc3028_send_i2c_data(buf, 4);
if (result!=XC3028_RESULT_SUCCESS)
return result;
result = xc3028_send_i2c_data((*(XC3028_current_tv_mode.scode_table_ptr))[dcode], 12);
if (result!=XC3028_RESULT_SUCCESS)
return result;
buf[0] = 0x00;
buf[1] = 0x8C;
result = xc3028_send_i2c_data(buf, 2);
if (result!=XC3028_RESULT_SUCCESS)
return result;
return XC3028_RESULT_SUCCESS;
}
int xc3028_set_channel(XC3028_CHANNEL new_channel)
{
int i,result;
unsigned int frequency;
ahui35
- 粉丝: 0
- 资源: 1
最新资源
- 信捷XC PLC与力士乐VFC-x610变频器通讯程序原创可直接用于生产的程序,程序带注释,并附送触摸屏程序,有接线方式和设置,通讯地址说明等 程序采用轮询,可靠稳定 器件:信捷XC3的PLC,博世
- CMIP6 变量详细表格
- KF2EDGK系列5.08接线端子,带3D封装
- 信捷XC PLC与3台力士乐VFC-x610变频器通讯通讯 原创可直接用于生产的程序,程序带注释,并附送触摸屏程序,有接线方式和设置,通讯地址说明等 程序采用轮询,可靠稳定 器件:信捷XC3的PLC
- org.xmind.ui.mindmap-3.6.1.jar
- 16台搅拌机定时控制程序16台搅拌机定时控制,使用三菱FX系列PLC,威伦通触摸屏,具备完善的控制功能
- 微网双层优化模型matlab 采用yalmip编写三个微网的分层优化模型,考虑电价的负荷响应,综合配电网运营商收益和用户购电成本,程序运行稳定
- rv1126交叉编译工具链gcc-arm-8.3-2019.02-x86-64-arm-linux-gnueabihf.tar.xz和安装步骤
- 1960-2023年世界各国国民总收入数据
- 风储深度调峰模型matlab 考虑风储的调峰模型,采用cplex作为求解器,实现不同主体出力优化控制,程序运行稳定,有参考资料,
- 计算机系统安全性与性能评估:IOMMU在Linux环境下的性能研究及其优化策略
- 电动汽车蒙特卡洛分析matlab 通过matlab程序编写电动汽车蒙特卡洛模型,得到汽车行驶里程的概率分布曲线和充电功率曲线,程序运行可靠,有参考资料
- 考虑交通流量的电动汽车充电站规划matlab 程序采用matlab编制,采用粒子群算法,结合交通网络流量,得到最终充电站规划方案,程序运行可靠
- rustdesk-1.3.6-x86-64.msi
- 电动汽车优化模型matlab 狼群算法
- 你还在为伺服驱动器 FPGA架构苦恼吗,本方案FPGA代码实现电流环 速度环 位置环 SVPWM 坐标变 测速 分频 滤波器等,程序方便移植不同的平台,具有很高的研究价值
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈