add kindlePaperWhite support for einkfb module

pull/2/merge
Qingping Hou 12 years ago
parent 54b33bd6a7
commit a43d1f7ae2

@ -75,16 +75,17 @@ static int openFrameBuffer(lua_State *L) {
}
/* mmap the framebuffer */
fb->buf->pitch = fb->finfo.line_length;
fb_map_address = mmap(0, fb->finfo.smem_len,
PROT_READ | PROT_WRITE, MAP_SHARED, fb->fd, 0);
if(fb_map_address == MAP_FAILED) {
return luaL_error(L, "cannot mmap framebuffer");
}
if (fb->vinfo.bits_per_pixel != 4) {
/* for 8bpp K4, we create a shadow 4bpp blitbuffer
* K4 uses 16 scale 8bpp framebuffer, so we still cheat it as 4bpp */
fb->buf->pitch = fb->buf->pitch / 2;
if (fb->vinfo.bits_per_pixel == 8) {
/* for 8bpp K4, PaperWhite, we create a shadow 4bpp blitbuffer. These
* models use 16 scale 8bpp framebuffer, so we still cheat it as 4bpp
* */
fb->buf->pitch = fb->finfo.line_length / 2;
fb->buf->data = (uint8_t *)calloc(fb->buf->pitch * fb->vinfo.yres, sizeof(uint8_t));
if (!fb->buf->data) {
@ -92,6 +93,7 @@ static int openFrameBuffer(lua_State *L) {
}
fb->buf->allocated = 1;
/* now setup framebuffer map */
fb->real_buf = (BlitBuffer *)malloc(sizeof(BlitBuffer));
if (!fb->buf->data) {
return luaL_error(L, "failed to allocate memory for framebuffer's blitbuffer!");
@ -102,6 +104,7 @@ static int openFrameBuffer(lua_State *L) {
fb->real_buf->allocated = 0;
fb->real_buf->data = fb_map_address;
} else {
fb->buf->pitch = fb->finfo.line_length;
/* for K2, K3 and DXG, we map framebuffer to fb->buf->data directly */
fb->real_buf = NULL;
fb->buf->data = fb_map_address;
@ -160,43 +163,141 @@ static int closeFrameBuffer(lua_State *L) {
return 0;
}
static int einkUpdate(lua_State *L) {
FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb");
// for Kindle e-ink display
int fxtype = luaL_optint(L, 2, 0);
#ifndef EMULATE_READER
int i = 0, j = 0, h = 0, w = 0, pitch = 0;
uint8_t *fb_buf = NULL;
inline void fbInvert4BppTo8Bpp(FBInfo *fb) {
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
shadow_buf = fb->buf->data;
fb_buf = fb->real_buf->data;
h = fb->buf->h;
w = fb->buf->w;
pitch = fb->buf->pitch;
fb_pitch = fb->real_buf->pitch;
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
for (i = (h-1); i > 0; i--) {
for (j = (w-1)/2; j > 0; j--) {
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2] &= 0xF0;
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
}
}
}
inline void fb4BppTo8Bpp(FBInfo *fb) {
int i = 0, j = 0, h = 0, w = 0, pitch = 0, fb_pitch = 0;
uint8_t *shadow_buf = NULL, *fb_buf = NULL;
shadow_buf = fb->buf->data;
fb_buf = fb->real_buf->data;
/* h is 1024 for PaperWhite */
h = fb->buf->h;
/* w is 758 for PaperWhite */
w = fb->buf->w;
/* pitch is 384 for shadow buffer */
pitch = fb->buf->pitch;
/* pitch is 768 for PaperWhite */
fb_pitch = fb->real_buf->pitch;
/* copy bitmap from 4bpp shadow blitbuffer to framebuffer */
if (fb->vinfo.bits_per_pixel != 4) {
fb_buf = fb->buf->data;
h = fb->buf->h;
w = fb->buf->w;
pitch = fb->buf->pitch;
for (i = (h-1); i > 0; i--) {
for (j = (w-1)/2; j > 0; j--) {
fb->real_buf->data[i*w + j*2] = fb_buf[i*pitch + j];
fb->real_buf->data[i*w + j*2] &= 0xF0;
fb->real_buf->data[i*w + j*2] |= fb_buf[i*pitch + j]>>4 & 0x0F;
fb->real_buf->data[i*w + j*2 + 1] = fb_buf[i*pitch + j];
fb->real_buf->data[i*w + j*2 + 1] &= 0x0F;
fb->real_buf->data[i*w + j*2 + 1] |= fb_buf[i*pitch + j]<<4 & 0xF0;
}
for (i = (h-1); i > 0; i--) {
for (j = (w-1)/2; j > 0; j--) {
fb_buf[i*fb_pitch + j*2] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2] &= 0xF0;
fb_buf[i*fb_pitch + j*2] |= shadow_buf[i*pitch + j]>>4 & 0x0F;
fb_buf[i*fb_pitch + j*2] = ~fb_buf[i*fb_pitch + j*2];
fb_buf[i*fb_pitch + j*2 + 1] = shadow_buf[i*pitch + j];
fb_buf[i*fb_pitch + j*2 + 1] &= 0x0F;
fb_buf[i*fb_pitch + j*2 + 1] |= shadow_buf[i*pitch + j]<<4 & 0xF0;
fb_buf[i*fb_pitch + j*2 + 1] = ~fb_buf[i*fb_pitch + j*2 + 1];
}
}
}
inline void fillUpdateAreaT(update_area_t *myarea, FBInfo *fb, lua_State *L) {
int fxtype = luaL_optint(L, 2, 0);
myarea->x1 = luaL_optint(L, 3, 0);
myarea->y1 = luaL_optint(L, 4, 0);
myarea->x2 = myarea->x1 + luaL_optint(L, 5, fb->vinfo.xres);
myarea->y2 = myarea->y1 + luaL_optint(L, 6, fb->vinfo.yres);
myarea->buffer = NULL;
myarea->which_fx = fxtype ? fx_update_partial : fx_update_full;
}
inline void fillMxcfbUpdateData51(mxcfb_update_data51 *myarea, FBInfo *fb, lua_State *L) {
myarea->update_region.top = luaL_optint(L, 3, 0);
myarea->update_region.left = luaL_optint(L, 4, 0);
myarea->update_region.width = luaL_optint(L, 5, fb->vinfo.xres);
myarea->update_region.height = luaL_optint(L, 6, fb->vinfo.yres);
myarea->waveform_mode = 257;
myarea->update_mode = 0;
myarea->update_marker = 1;
myarea->hist_bw_waveform_mode = 0;
myarea->hist_gray_waveform_mode = 0;
myarea->temp = 0x1001;
myarea->flags = 0;
myarea->alt_buffer_data.virt_addr = NULL;
myarea->alt_buffer_data.phys_addr = NULL;
myarea->alt_buffer_data.width = 0;
myarea->alt_buffer_data.height = 0;
myarea->alt_buffer_data.alt_update_region.top = 0;
myarea->alt_buffer_data.alt_update_region.left = 0;
myarea->alt_buffer_data.alt_update_region.width = 0;
myarea->alt_buffer_data.alt_update_region.height = 0;
}
inline void Kindle3einkUpdate(FBInfo *fb, lua_State *L) {
update_area_t myarea;
fillUpdateAreaT(&myarea, fb, L);
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
}
inline void kindle4einkUpdate(FBInfo *fb, lua_State *L) {
update_area_t myarea;
myarea.x1 = luaL_optint(L, 3, 0);
myarea.y1 = luaL_optint(L, 4, 0);
myarea.x2 = myarea.x1 + luaL_optint(L, 5, fb->vinfo.xres);
myarea.y2 = myarea.y1 + luaL_optint(L, 6, fb->vinfo.yres);
myarea.buffer = NULL;
myarea.which_fx = fxtype ? fx_update_partial : fx_update_full;
fbInvert4BppTo8Bpp(fb);
fillUpdateAreaT(&myarea, fb, L);
ioctl(fb->fd, FBIO_EINK_UPDATE_DISPLAY_AREA, &myarea);
}
inline void kindlePWeinkUpdate(FBInfo *fb, lua_State *L) {
mxcfb_update_data51 myarea;
fb4BppTo8Bpp(fb);
fillMxcfbUpdateData51(&myarea, fb, L);
ioctl(fb->fd, 0x4048462e, &myarea);
}
#endif
static int einkUpdate(lua_State *L) {
FBInfo *fb = (FBInfo*) luaL_checkudata(L, 1, "einkfb");
// for Kindle e-ink display
#ifndef EMULATE_READER
if (fb->vinfo.bits_per_pixel == 8) {
if (fb->buf->h == 1024) {
/* Kindle PaperWhite */
kindlePWeinkUpdate(fb, L);
} else {
/* kindle4 */
kindle4einkUpdate(fb, L);
}
} else {
/* kindle2, 3, DXG */
Kindle3einkUpdate(fb, L);
}
#else
int fxtype = luaL_optint(L, 2, 0);
// for now, we only do fullscreen blits in emulation mode
if (fxtype == 0) {
// simmulate a full screen update in eink screen

@ -27,6 +27,7 @@ struct fb_var_screeninfo {
#else
#include <linux/fb.h>
#include "include/einkfb.h"
#include "include/mxcfb.h"
#endif
#include <lua.h>

Loading…
Cancel
Save