View Single Post
Old 11-21-2009, 10:29 PM   #1
sanek_vi
Junior Member
sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.sanek_vi can self-interpret dreams as they happen.
 
Posts: 1
Karma: 20654
Join Date: Nov 2009
Device: Kindle DX
Drawing to the e-ink screen

Hello.
I have a code I would like to share with the community. It draws a rectangle on the e-ink screen. To execute:

1. Cross-compile the code and upload it to Kindle (usbnet assumed)
Code:
$ arm-none-linux-gnueabi-gcc -o hello-kindle hello.c
$ cat hello-kindle | ssh root@192.168.2.2 "cat - > /var/tmp/root/hello-arm"
2. Execute the code on the kindle
Code:
[root@kindle root]# /usr/sbin/eips  -c
[root@kindle root]# ./hello-arm 
Size: 824 x 1200
[root@kindle root]# echo 2 > /proc/eink_fb/update_display

The code is below. Comments/Questions are welcomed.
Code:
#include <stdio.h>
// Read in header files
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <unistd.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
/*
ACCELEROMETER=/proc/accelerometer   (cat works, tail -f doesnt)                            
/dev/input/event0 - keyboard
/dev/input/event1 - pointer
*/

#define putpixel(_x, _y, _c) 						\
	if ((_x) & 01) {						\
		data[((_y)*width + (_x)) >> 1] &= 0xF0;			\
		data[((_y)*width + (_x)) >> 1] |= (_c & 0x0F);		\
	} else {							\
		data[((_y)*width + (_x)) >> 1] &= 0x0F;			\
		data[((_y)*width + (_x)) >> 1] |= ((_c & 0x0F) << 4);	\
	}

int main(int argc, char** argv) {
	int width = 0;
	int height = 0;
	int row, column, i, j;

	// open framebuffer device and read out info
	int fd = open("/dev/fb0", O_RDWR);
                                                                  
	struct fb_var_screeninfo screeninfo;
	ioctl(fd, FBIOGET_VSCREENINFO, &screeninfo);
                                                                  
	// determine size
	width = screeninfo.xres;
	height = screeninfo.yres;

	printf("Size: %d x %d\n", width, height);
                                                                  
	// embed framebuffer into memory
                                                                  
	unsigned char *data = (unsigned char*)
		mmap(0, width * height / 2,
			PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
                                                                  
	// Clear memory (4 bpp)
	memset(data, 0, width * height / 2);

	// Draw a box
	for (i = 100; i <= 200; ++i) {
		putpixel(300, i, 0xF);
		putpixel(400, i, 0xF);
		putpixel(i+200, 100, 0xF);
		putpixel(i+200, 200, 0xF);
	}
                                                                 
	// mask framebuffer out of memory
	munmap(data, width * height / 2);
}
sanek_vi is offline   Reply With Quote