Created
January 24, 2014 13:09
-
-
Save nullnilaki/8596916 to your computer and use it in GitHub Desktop.
fb_mmap_code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include <sys/mman.h> | |
#include <sys/ioctl.h> | |
#include <dev/wscons/wsconsio.h> | |
#include <dev/wscons/wsksymdef.h> | |
int | |
main(int argc, char **argv) | |
{ | |
int fd; | |
struct wsdisplay_fbinfo vinfo; | |
int orig_mode; | |
int mode; | |
int wstype; | |
unsigned int line_length; | |
unsigned char *fb; | |
if ((fd = open( "/dev/ttyE0", O_RDWR)) < 0) { | |
fprintf(stderr, "Failed to open /dev/ttyE0\n") ; | |
return 1; | |
} | |
ioctl(STDIN_FILENO, WSDISPLAYIO_GMODE, &orig_mode) ; | |
mode = WSDISPLAYIO_MODE_MAPPED ; | |
if (ioctl(STDIN_FILENO, WSDISPLAYIO_SMODE, &mode) == -1) { | |
fprintf(stderr, "WSDISPLAYIO_SMODE failed.\n"); | |
return 1; | |
} | |
if (ioctl(fd , WSDISPLAYIO_GINFO , &vinfo) == -1) { | |
fprintf(stderr, "WSDISPLAYIO_GINFO failed.\n"); | |
goto error; | |
} | |
if (ioctl(fd , WSDISPLAYIO_GTYPE , &wstype) == -1) { | |
fprintf(stderr, "WSDISPLAYIO_GTYPE failed.\n"); | |
goto error; | |
} | |
if (ioctl(fd , WSDISPLAYIO_LINEBYTES , &line_length) == -1) { | |
fprintf(stderr, "WSDISPLAYIO_LINEBYTES failed.\n"); | |
goto error; | |
} | |
if ((fb = mmap( NULL, line_length * vinfo.height, | |
PROT_WRITE|PROT_READ, MAP_SHARED, fd , (off_t)0)) == MAP_FAILED) { | |
fprintf(stderr, "mmap failed.\n"); | |
goto error; | |
} | |
fprintf(stderr, "width %d line length %d height %d depth %d mmap %p wstype %d\n" , | |
vinfo.width , line_length , vinfo.height , vinfo.depth , fb , wstype); | |
memset(fb, 0xff, line_length * vinfo.height); | |
sleep(2); | |
ioctl(STDIN_FILENO, WSDISPLAYIO_SMODE, &orig_mode); | |
return 0; | |
error: | |
ioctl(STDIN_FILENO, WSDISPLAYIO_SMODE, &orig_mode); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment