S3C2440 is displayed on LCD through v4l2 acquisition

Publisher:CrystalRoseLatest update time:2016-06-12 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
S3C2440 is displayed on LCD through v4l2 acquisition
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include 
#include 
#include 
#include 

 

#define COLS 320
#define ROWS 240
#define V4L2_DEV_NODE "/dev/video13"
#define FB_DEV_NODE "/dev/fb0"

#define CLEAR(x) memset(&(x),0,sizeof(x))

typedef struct v4l2_format   V_FORMAT;
typedef struct fb_var_screeninfo F_VINFO;

struct fb_var_screeninfo fb_var;
struct fb_fix_screeninfo fb_fix;
char * fb_base_addr = NULL;

static void show_rgb565_img(void *scr, __u16 *data_buf)
{ 

	__u16 x, y;
	__u16 *fb_buf = (__u16 *)scr;
	fb_buf += (320);

	for (y = 0; y < ROWS; y++) {
		for (x = 0; x < COLS; x++) { 
			fb_buf[x] = *data_buf++ ;
		}
		fb_buf += 320;
	}
}

int main(void)
{

	int v4l2_fd = -1;
	int fb_fd = -1;
	int n=0;
	__u8 *fb_buf;
	__u8 *buf;
	__u32 screensize;
 
 	//unsigned int width = 0;
	//unsigned int height = 0;
	//unsigned int bpp = 0;

	V_FORMAT fmt;
	enum v4l2_buf_type type;
	type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	printf("Start Main \n");
	printf("Before openning video \n");
 
	v4l2_fd = open(V4L2_DEV_NODE, O_RDWR | O_NONBLOCK, 0);
 
	if (v4l2_fd < 0) {
		printf(" open video ERR\n");
		return 0;
	}
	printf("Before openning FB \n");
 
	fb_fd = open(FB_DEV_NODE, O_RDWR);
	if (fb_fd < 0) {
		printf("error open fb_fd\n");
		exit(1);
	}

	/* Get fixed screen information */
	if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_fix)) {
		printf("Error reading fb fixed information.\n");
		exit(1);
	}

	/* Get variable screen information 	*/
	if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_var)) {
		printf("Error reading fb variable information.\n");
		exit(1);
	}
 
	screensize = fb_var.xres * fb_var.yres * fb_var.bits_per_pixel / 8;
	//screensize = 480 * 272 * 16 / 8;
 
	fb_buf = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0);

	if ((int)fb_buf == -1) {
		printf("Error: failed to map framebuffer device to memory.\n");
		close(fb_fd);
		return -1;
	}

	CLEAR (fmt);
	fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	fmt.fmt.pix.width = 320;
	fmt.fmt.pix.height = 240;
	//fmt.fmt.pix.depth = 16;
	fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB565;
	//printf("VIDIOC_S_FMT is %x\n",VIDIOC_S_FMT);

	if ((ioctl(v4l2_fd, VIDIOC_S_FMT, &fmt)) < 0) {
		printf("Error: failed to set video format.\n");
		return 0;
	}

	buf = malloc(320 * 240 * 3); 
	//printf("VIDIOC_STREAMON is %x\n",VIDIOC_STREAMON);
 
	if ((ioctl(v4l2_fd, VIDIOC_STREAMON, &type)) < 0) {
		printf("error ioctl streamon\n");
		return 0;
	}

	printf("start to get pic %d\n",(int)fmt.fmt.pix.sizeimage);
	while(1) {
		n=read(v4l2_fd, buf, 320*240*2);
		printf("display %d\n",n);
		show_rgb565_img(fb_buf,buf);
	}
}
 
Keywords:S3C2440 Reference address:S3C2440 is displayed on LCD through v4l2 acquisition

Previous article:How to use STM32's on-chip Flash to store Chinese character library
Next article:Mini2440 NRF24L01 wireless module driver

Recommended ReadingLatest update time:2024-11-16 16:44

Based on 51 MCU + DHT11 temperature and humidity module + ESP8266 module + upload oneNET APP display + LCD1602 display
basic introduction Recently, I made a device based on 51 MCU (STC89C52) + DHT11 temperature and humidity module + ESP8266 module + upload to oneNET APP display + LCD1602 display. The 51 MCU collects the temperature and humidity of the DHT11 module, uploads the temperature and humidity to the oneNET platform through th
[Microcontroller]
Based on 51 MCU + DHT11 temperature and humidity module + ESP8266 module + upload oneNET APP display + LCD1602 display
s3c2440 bare metal - memory controller 4 - SDRAM programming implementation
Configuring the Memory Controller - SDRAM Programming Configuration The 2440 memory controller has a total of 13 registers. BANK0--BANK5 only need to set two registers: BWSCON and BANKCONx (x is 0 to 5); when BANK6 and BANK7 are connected to external SDRAM, in addition to BWSCON and BANKCONx (x is 6 and 7)
[Microcontroller]
Linux 2.6.32 porting to arm9 (s3c2440) platform 2 -- Kconfig and Makefile (2) Linux
There is a Kconfig and Makefile in each directory of the Linux kernel source tree. The Kconfigs distributed to each directory constitute a distributed kernel configuration database. Each Kconfig describes the kernel configuration menu related to the source document of the directory to which it belongs. When executing
[Microcontroller]
S3C2440 Bare Metal Practice 1 Creating an Initial Project
I haven't played with S3C2440 for several years. From single-chip microcomputers to embedded systems, I remember that this was one of the earliest chips I used when I got started with embedded systems. S3C2440 has MMU and can run operating systems such as WinCE/Linux. It is suitable for embedded development. It alwa
[Microcontroller]
Design of Embedded IPv6 Firewall Based on S3C2440 Processor
1 Introduction Among the numerous network security facilities, firewalls are effective and important network security devices. They screen and shield network communications to prevent unauthorized access to and from computer networks. Firewalls are a security barrier between trusted networks and untrusted networks.
[Microcontroller]
Design of Embedded IPv6 Firewall Based on S3C2440 Processor
Design of LCD display driver IP based on NiosII in SOPC
introduction The NioslI embedded processor is a SOPC solution proposed by Altera. It is a 32-bit embedded processor that users can configure and build at will. Combined with rich peripherals, it can quickly and flexibly build a powerful SOPC system. Altera provides some general IP cores, allowing users to easil
[Embedded]
Design of LCD display driver IP based on NiosII in SOPC
Design of ultra-low power LCD display circuit module
   LCD display module: LCD liquid crystal display is an extremely low power display device with small operating current, light weight, low power consumption, long life, clear and beautiful writing. It is widely used in portable instruments and higher-end instruments for low-power applications. Pin 1: VSS is the ground
[Power Management]
Design of ultra-low power LCD display circuit module
S3C2440 Clock Architecture and Programming
If the CPU is the brain of the computer and the current is the blood of the computer, then the clock is the heart of the computer. The clock frequency determines the speed of the processor's calculations. Each of its "beats" drives the processor to continuously execute commands. The difference is that the heart rate o
[Microcontroller]
S3C2440 Clock Architecture and Programming
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号