/*
* \file cameratester.c
* \brief
*
* \version 1.0.0
* \date 2012年06月26日
* \author James Deng <csjamesdeng@allwinnertech.com>
*
* Copyright (c) 2012 Allwinner Technology. All Rights Reserved.
*
*/
#include <linux/videodev2.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include "drv_display_sun4i.h"
#include "dragonboard_inc.h"
struct buffer
{
void *start;
size_t length;
};
struct size
{
int width;
int height;
};
typedef enum
{
TVD_UV_SWAP,
TVD_COLOR_SET,
}tvd_param_t;
static int fd;
static int csi_format;
static int fps;
static int req_frame_num;
static struct buffer *buffers = NULL;
static int nbuffers = 0;
static struct size input_size;
static struct size disp_size;
static int disp;
static int layer;
static __disp_layer_info_t layer_para;
static int screen_width;
static int screen_height;
static __disp_pixel_fmt_t disp_format;
static __disp_pixel_mod_t disp_seq;
static __disp_pixel_seq_t disp_mode;
#define DISPLAY
#define LCD_WIDTH 800
#define LCD_HEIGHT 480
int sel = 0;//which screen 0/1
//__disp_video_fb_t video_fb;
#if 0
int disp_init(int w,int h)
{
/*display start*/
//unsigned int h,w;
unsigned int arg[4];
__u32 id = 0;
#if 0
//h= 480;
//w= 640;
if((disp = open("/dev/disp",O_RDWR)) == -1)
{
printf("open file /dev/disp fail. \n");
return 0;
}
arg[0] = 0;
ioctl(disp, DISP_CMD_LCD_ON, (void*)arg);
//layer0
arg[0] = 0;
arg[1] = DISP_LAYER_WORK_MODE_SCALER;
layer = ioctl(disp, DISP_CMD_LAYER_REQUEST, (void*)arg);
if(layer == 0)
{
printf("request layer0 fail\n");
return 0;
}
printf("video layer hdl:%d\n", layer);
layer_para.mode = DISP_LAYER_WORK_MODE_SCALER;
layer_para.pipe = 0;
layer_para.fb.addr[0] = 0;//your Y address,modify this
layer_para.fb.addr[1] = 0; //your C address,modify this
layer_para.fb.addr[2] = 0;
layer_para.fb.size.width = w;
layer_para.fb.size.height = h;
layer_para.fb.mode = disp_mode;///DISP_MOD_INTERLEAVED;//DISP_MOD_NON_MB_PLANAR;//DISP_MOD_NON_MB_PLANAR;//DISP_MOD_NON_MB_UV_COMBINED;
layer_para.fb.format = disp_format;//DISP_FORMAT_YUV420;//DISP_FORMAT_YUV422;//DISP_FORMAT_YUV420;
layer_para.fb.br_swap = 0;
layer_para.fb.seq = disp_seq;//DISP_SEQ_UVUV;//DISP_SEQ_YUYV;//DISP_SEQ_YVYU;//DISP_SEQ_UYVY;//DISP_SEQ_VYUY//DISP_SEQ_UVUV
layer_para.ck_enable = 0;
layer_para.alpha_en = 1;
layer_para.alpha_val = 0xff;
layer_para.src_win.x = 0;
layer_para.src_win.y = 0;
layer_para.src_win.width = w;
layer_para.src_win.height = h;
layer_para.scn_win.x = 0;
layer_para.scn_win.y = 0;
layer_para.scn_win.width = LCD_WIDTH;//800;
layer_para.scn_win.height = LCD_HEIGHT;//480;
arg[0] = sel;
arg[1] = layer;
arg[2] = (__u32)&layer_para;
ioctl(disp,DISP_CMD_LAYER_SET_PARA,(void*)arg);
arg[0] = sel;
arg[1] = layer;
ioctl(disp,DISP_CMD_LAYER_TOP,(void*)arg);
#endif
arg[0] = sel;
arg[1] = layer;
ioctl(disp,DISP_CMD_LAYER_OPEN,(void*)arg);
#if 1
int fb_fd;
unsigned long fb_layer;
void *addr = NULL;
fb_fd = open("/dev/fb0", O_RDWR);
if (ioctl(fb_fd, FBIOGET_LAYER_HDL_0, &fb_layer) == -1) {
printf("get fb layer handel\n");
}
addr = malloc(LCD_WIDTH*LCD_HEIGHT*3);
memset(addr, 0xff, LCD_WIDTH*LCD_HEIGHT*3);
write(fb_fd, addr, LCD_WIDTH*LCD_HEIGHT*3);
//memset(addr, 0x12, 800*480*3);
printf("fb_layer hdl: %ld\n", fb_layer);
close(fb_fd);
arg[0] = 0;
arg[1] = fb_layer;
ioctl(disp, DISP_CMD_LAYER_BOTTOM, (void *)arg);
#endif
}
#endif
int ii=234;
#if 1
static int disp_init(int width, int height)
{
unsigned int args[4];
if ((disp = open("/dev/disp", O_RDWR)) == -1) {
db_error("can't open /dev/disp(%s)\n", strerror(errno));
return -1;
}
args[0] = 0;
screen_width = ioctl(disp, DISP_CMD_SCN_GET_WIDTH, args);
screen_height = ioctl(disp, DISP_CMD_SCN_GET_HEIGHT, args);
args[0] = 0;
args[1] = DISP_LAYER_WORK_MODE_SCALER;
layer = ioctl(disp, DISP_CMD_LAYER_REQUEST, args);
if (layer == 0) {
db_error("request layer failed\n");
return -1;
}
memset(&layer_para, 0, sizeof(__disp_layer_info_t));
layer_para.mode = DISP_LAYER_WORK_MODE_SCALER;
layer_para.pipe = 0;
layer_para.prio = 0;
layer_para.alpha_en = 1;
layer_para.alpha_val = 0xff;
layer_para.ck_enable = 0;
layer_para.src_win.x = 0;
layer_para.src_win.y = 0;
layer_para.src_win.width = width;
layer_para.src_win.height = height;
layer_para.scn_win.x = screen_width >> 1;
layer_para.scn_win.y = 0;
layer_para.scn_win.width = screen_width >> 1;
layer_para.scn_win.height = screen_height >> 1;
layer_para.fb.addr[0] = 324;
layer_para.fb.addr[1] = 875;
layer_para.fb.addr[2] = 456;
layer_para.fb.size.width = width;
layer_para.fb.size.height = height;
layer_para.fb.format = disp_format;
layer_para.fb.seq = disp_seq;
layer_para.fb.mode = disp_mode;
layer_para.fb.br_swap = 0;
args[0] = 0;
args[1] = layer;
args[2] = (__u32)&layer_para;
ioctl(disp, DISP_CMD_LAYER_SET_PARA, args);
args[0] = 0;
args[1] = layer;
ioctl(disp, DISP_CMD_LAYER_TOP, args);
args[0] = 0;
args[1] = layer;
ioctl(disp, DISP_CMD_LAYER_OPEN, args);
return 0;
}
#endif
static int disp_start(void)
{
unsigned int args[4];
args[0] = 0;
args[1] = layer;
return ioctl(disp, DISP_CMD_VIDEO_START, args);
}
static int disp_stop(void)
{
unsigned int args[4];
args[0] = 0;
args[1] = layer;
return ioctl(disp, DISP_CMD_VIDEO_STOP, args);
}
static int disp_quit(void)
{
unsigned int args[4];
args[0] = 0;
args[0] = layer;
ioctl(disp, DISP_CMD_LAYER_CLOSE, args);
ioctl(disp, DISP_CMD_LAYER_RELEASE, args);
return 0;
}
static int disp_set_addr(int width, int height, unsigned int *addr)
{
__disp_video_fb_t fb;
unsigned int args[4];
memset(&fb, 0, sizeof(__disp_video_fb_t));
fb.interlace = 0;
fb.top_field_first = 0;
fb.frame_rate = 25;
fb.addr[0] = *addr;
fb.id = 0;
switch (csi_format) {
case V4L2_PIX_FMT_YUV422P:
case V4L2_PIX_FMT_YUYV:
case V4L2_PIX_FMT_YVYU:
case V4L2_PIX_FMT_UYVY:
case V4L2_PIX_FMT_VYUY:
fb.addr[1] = *addr + width * height;
fb.addr[2] = *addr + width * height * 3 / 2;
break;
case V4L2_PIX_FMT_YUV420:
fb.addr[1] = *addr + width * height;
fb.addr[2] = *addr + width * height * 5 / 4;
break;
case V4L2_PIX_FMT_NV16:
case V4L2_PIX_FMT_NV12:
case V4L2_PIX_FMT_HM12:
fb.addr[1] = *addr + width * height;
fb.addr[2] = layer_para.fb.addr[1];
break;
default:
break;
}
args[0] = 0;
args[1] = layer;
args[2] = (__u32)&fb;
return ioctl(disp, DISP_CMD_VIDEO_SET_FB, args);
}
static int read_frame(void)
{
struct v4l2_buffer buf;
memset(&buf, 0, sizeof(struct v4l2_buffer));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
ioctl(fd, VIDIOC_DQBUF, &buf);
disp_set_addr(disp_size.width, disp_size.height, &buf.m.offset);
ioctl(fd, VIDIOC_QBUF, &buf);
return 1;
}
static int g_aiSupportedFormats[] = {V4L2_PIX_FMT_YUYV, V4L2_PIX_FMT_MJPEG, V4L2_PIX_FMT_RGB565, V4L2_PIX_FMT_NV12};
static int isSupportThisFormat(int iPixelFormat)
{
int i;
for (i = 0; i < sizeof(g_aiSupportedFormats)/sizeof(g_aiSupport
kuangdoushi
- 粉丝: 56
- 资源: 15
最新资源
- 基于springboot扶贫助农系统设计与实现源码(java毕业设计完整源码+LW).zip
- python入门的基础知识
- 功能描述: 本系统由STM32单片机核心板、交流电压电流检测模块、WIFI模块、指示灯组成 1、220V市电经过互感器后产生微弱交流电,经过整流滤波后变为直流,然后通过单片机AD转,然后算出
- python入门指南:环境搭建、基础语法与进阶应用
- 基于spring boot护肤品推荐系统的设计与实现源码(java毕业设计完整源码).zip
- 基于spring boot框架药品购买系统源码(java毕业设计完整源码).zip
- 声音数字化入门:基本概念、过程与应用
- 伺服电机控制工程 伺服电机开发实例 modbus开发源码C# winform位置模式力矩模式 本工程源码编译环境是visual studio (最好采用2013以上版本),编写语言是C# ,winfo
- 电商用户行为数据集.zip
- 基于springboot的交通旅游订票系统源码(java毕业设计完整源码+LW).zip
- 机械设计销钉自动送料压装设备sw2017全套设计资料100%好用.zip
- 机械设计小芯轴自动折弯机sw18可编辑全套设计资料100%好用.zip
- FX5U和je-C伺服通讯案例和学习资料,绝无仅有 物超所值
- 基于Spring Boot的企业员工管理设计与实现源码(java毕业设计完整源码).zip
- python代码入门 (资料备份).zip
- 免费SharedLibrary-C#
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈