Framebuffer programming 2 (in a simple program)

Source: Internet
Author: User

1. Development Platform sc6410, compiler Arm-Linux-GCC 4.3

The source code is as follows:

# Include <fcntl. h>
# Include <sys/IOCTL. h>
# Include <sys/types. h>
# Include <sys/STAT. h>
# Include <sys/Mman. h>
# Include <unistd. h>
# Include <string. h>
# Include <stdlib. h>
# Include <stdio. h>
# Include <string. h>
# Include <Linux/types. h>
# Include <Linux/FB. h>
# Include <Linux/videodev2.h>

Int main (INT argc, char * argv [])
{
Int fbfd = 0;
Struct fb_var_screeninfo vinfo;
Struct fb_fix_screeninfo finfo;
Long int screensize = 0;
Char * FBP = NULL;
Int x = 0, y = 0;
Long int location = 0;
Int sav = 0;

// Open framebuffer Device
Fbfd = open ("/dev/fb0", o_rdwr );
If (! Fbfd ){
Printf ("error: cannot open the framebuffer device! \ N ");
Exit (1 );
}
Printf ("Well you open the framebuffer sucessful! \ N ");
// Get the Fixed Screen Information
If (IOCTL (fbfd, fbioget_fscreeninfo, & finfo )){
Printf ("error reading fixed information \ n ");
Exit (2 );
}
// Get the variable screen information
If (IOCTL (fbfd, fbioget_vscreeninfo, & vinfo )){
Printf ("error reading variable information \ n ");
Exit (3 );
}
// Show these information
Printf ("vinfo. xres = % d \ n", vinfo. xres );
Printf ("vinfo. yres = % d \ n", vinfo. yres );
Printf ("vinfo. bit_per_bits = % d \ n", vinfo. bits_per_pixel );
Printf ("vinfo. xoffset = % d \ n", vinfo. xoffset );
Printf ("vinfo. yoffset = % d \ n", vinfo. yoffset );
Printf ("finfo. line_length = % d \ n", finfo. line_length );
Screensize = vinfo. xres * vinfo. yres * vinfo. bits_per_pixel/8;

// Map the device to memory
FBP = (char *) MMAP (0, screensize, prot_read | prot_write, map_shared, fbfd, 0 );
If (INT) FBP =-1 ){
Printf ("error: failed to map framebuffer device to memory \ n ");
Exit (4 );
}
Memset (FBP, 0, screensize );
// Plot the screen the color for black
For (x = 0; x <vinfo. xres; X ++)
For (y = 0; y <vinfo. yres; y ++ ){
Location = (x + vinfo. xoffset) * (vinfo. bits_per_pixel/8) + (Y + vinfo. yoffset) * finfo. line_length;
* (FBP + location) = 0xff;
* (FBP + location + 1) = 0x00;
}
Sleep (10 );
// Release the memory
Munmap (FBP, screensize );
Close (fbfd );
Return 0;
}

The result of compilation and download to the Development Board is (and the display screen of your development board turns blue ):

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.