Skip to content

Commit

Permalink
koreader PocketBook port
Browse files Browse the repository at this point in the history
  • Loading branch information
chrox committed Jan 12, 2015
1 parent b3fe41b commit 3ffa5dc
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 9 deletions.
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ libs: \

$(OUTPUT_DIR)/libs/libkoreader-input.so: input.c \
$(POPEN_NOSHELL_LIB)
$(CC) $(DYNLIB_CFLAGS) \
-o $@ $< $(POPEN_NOSHELL_LIB)
$(CC) $(DYNLIB_CFLAGS) $(if $(POCKETBOOK),-DPOCKETBOOK,) \
-o $@ $^ $(if $(POCKETBOOK),-linkview,) \

$(OUTPUT_DIR)/libs/libkoreader-lfs.so: \
$(if $(or $(ANDROID),$(WIN32)),$(LUAJIT_LIB),) \
Expand Down Expand Up @@ -458,7 +458,7 @@ $(CZMQ_LIB): $(ZMQ_LIB)
# patch: add _DEFAULT_SOURCE define for glibc starting at version 2.20
-cd $(CZMQ_DIR) && patch -N -p1 < ../czmq_default_source_define.patch
-$(MAKE) -j$(PROCESSORS) -C $(CZMQ_DIR)/build --silent uninstall
$(MAKE) -j$(PROCESSORS) -C $(CZMQ_DIR)/build --silent install
-$(MAKE) -j$(PROCESSORS) -C $(CZMQ_DIR)/build --silent install
-cd $(CZMQ_DIR) && patch -R -p1 < ../zbeacon.patch
-cd $(CZMQ_DIR) && patch -R -p1 < ../czmq_default_source_define.patch
cp -fL $(CZMQ_DIR)/build/$(if $(WIN32),bin,lib)/$(notdir $(CZMQ_LIB)) $@
Expand All @@ -480,7 +480,7 @@ $(FILEMQ_LIB): $(ZMQ_LIB) $(CZMQ_LIB) $(OPENSSL_LIB)
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool && \
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
-$(MAKE) -j$(PROCESSORS) -C $(FILEMQ_DIR)/build --silent uninstall
$(MAKE) -j$(PROCESSORS) -C $(FILEMQ_DIR)/build --silent install
-$(MAKE) -j$(PROCESSORS) -C $(FILEMQ_DIR)/build --silent install
cp -fL $(FILEMQ_DIR)/build/$(if $(WIN32),bin,lib)/$(notdir $(FILEMQ_LIB)) $@

$(ZYRE_LIB): $(ZMQ_LIB) $(CZMQ_LIB)
Expand All @@ -500,7 +500,7 @@ $(ZYRE_LIB): $(ZMQ_LIB) $(CZMQ_LIB)
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool && \
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool
-$(MAKE) -j$(PROCESSORS) -C $(ZYRE_DIR)/build --silent uninstall
$(MAKE) -j$(PROCESSORS) -C $(ZYRE_DIR)/build --silent install
-$(MAKE) -j$(PROCESSORS) -C $(ZYRE_DIR)/build --silent install
cp -fL $(ZYRE_DIR)/build/$(if $(WIN32),bin,lib)/$(notdir $(ZYRE_LIB)) $@

# ===========================================================================
Expand All @@ -513,6 +513,14 @@ android-toolchain:
$(NDK)/build/tools/make-standalone-toolchain.sh --platform=android-9 \
--install-dir=$(ANDROID_TOOLCHAIN)

# ===========================================================================
# helper target for creating standalone pocket toolchain from
# pocketbook-free SDK: https://github.com/pocketbook-free/SDK_481

pocketbook-toolchain:
cd toolchain && \
git clone https://github.com/pocketbook-free/SDK_481 pocketbook-toolchain

# ===========================================================================
# helper target for initializing third-party code

Expand Down
11 changes: 11 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ endif
# android toolchain
ANDROID_TOOLCHAIN=toolchain/android-toolchain

# pocketbook toolchain
POCKETBOOK_TOOLCHAIN=toolchain/pocketbook-toolchain

# if TARGET is not defined we will build an emulator on current machine
ifdef TARGET
export EMULATE_READER=
Expand All @@ -38,6 +41,10 @@ else ifeq ($(TARGET), android)
else ifeq ($(TARGET), win32)
CHOST?=i686-w64-mingw32
export WIN32=1
else ifeq ($(TARGET), pocketbook)
CHOST?=arm-obreey-linux-gnueabi
export POCKETBOOK=1
export SYSROOT=$(CURDIR)/$(POCKETBOOK_TOOLCHAIN)/arm-obreey-linux-gnueabi/sysroot
endif

# unknown device
Expand Down Expand Up @@ -137,6 +144,10 @@ else ifeq ($(TARGET), kindle)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS)
else ifeq ($(TARGET), pocketbook)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
COMPAT_CFLAGS:=$(UBUNTU_COMPAT_CFLAGS) -std=gnu99 --sysroot $(SYSROOT)
else ifeq ($(TARGET), kindle5)
ARM_ARCH:=$(ARMV7_A8_ARCH)
ARM_ARCH+=-mfloat-abi=softfp
Expand Down
9 changes: 9 additions & 0 deletions ffi/framebuffer_linux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function framebuffer:init()
end
-- classic eink framebuffer driver has grayscale values inverted (i.e. 0xF = black, 0 = white)
self.bb:invert()
-- pocketbook 840 seems have no finfo.id
elseif string.byte(ffi.string(finfo.id, 16), 1, 1) == 0 then
if vinfo.bits_per_pixel == 16 then
self.bb = BB.new(vinfo.xres, vinfo.yres, BB.TYPE_BBRGB16, self.data, finfo.line_length)
elseif vinfo.bits_per_pixel == 8 then
self.bb = BB.new(vinfo.xres, vinfo.yres, BB.TYPE_BB8, self.data, finfo.line_length)
else
error("unknown bpp value for the mxc eink driver")
end
else
error("framebuffer model not supported");
end
Expand Down
35 changes: 34 additions & 1 deletion ffi/framebuffer_mxcfb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ end
--[[ refresh functions ]]--
-- Kindle's MXCFB_SEND_UPDATE == 0x4048462e | Kobo's MXCFB_SEND_UPDATE == 0x4044462e
-- Kindle's MXCFB_SEND_UPDATE == 0x4048462e
-- Kobo's MXCFB_SEND_UPDATE == 0x4044462e
-- Pocketbook's MXCFB_SEND_UPDATE == 0x4040462e
local function mxc_update(fb, refarea, refreshtype, waveform_mode, wait, x, y, w, h)
local bb = fb.full_bb or fb.bb
w, x = BB.checkBounds(w or bb:getWidth(), x or 0, 0, bb:getWidth(), 0xFFFF)
Expand Down Expand Up @@ -239,6 +241,14 @@ local function refresh_kobo(fb, refreshtype, waveform_mode, wait, x, y, w, h)
return mxc_update(fb, refarea, refreshtype, waveform_mode, wait, x, y, w, h)
end
local function refresh_pocketbook(fb, refreshtype, waveform_mode, wait, x, y, w, h)
local refarea = ffi.new("struct mxcfb_update_data[1]")
-- TEMP_USE_AMBIENT
refarea[0].temp = 0x1000
return mxc_update(fb, refarea, refreshtype, waveform_mode, wait, x, y, w, h)
end
--[[ framebuffer API ]]--
function framebuffer:refreshPartialImp(x, y, w, h)
Expand Down Expand Up @@ -363,6 +373,29 @@ function framebuffer:init()
self.wait_for_marker_partial = false
self.wait_for_marker_fast = false
end
elseif self.device:isPocketBook() then
require("ffi/mxcfb_pocketbook_h")
self.mech_refresh = refresh_pocketbook
self.mech_wait_update_complete = kindle_pearl_mxc_wait_for_update_complete
self.mech_wait_update_submission = kindle_mxc_wait_for_update_submission
self.update_mode_partial = ffi.C.UPDATE_MODE_PARTIAL
self.update_mode_full = ffi.C.UPDATE_MODE_FULL
self.update_mode_fast = ffi.C.UPDATE_MODE_PARTIAL
self.update_mode_ui = ffi.C.UPDATE_MODE_PARTIAL
self.waveform_fast = ffi.C.WAVEFORM_MODE_A2
self.waveform_ui = ffi.C.WAVEFORM_MODE_GC16
self.waveform_full = ffi.C.WAVEFORM_MODE_GC16
if self.device.model == "PocketBook" then
self.waveform_partial = ffi.C.WAVEFORM_MODE_GC16
self.wait_for_marker_full = true
self.wait_for_marker_partial = false
self.wait_for_marker_fast = false
self.wait_for_marker_ui = false
end
else
error("unknown device type")
end
Expand Down
60 changes: 60 additions & 0 deletions ffi/mxcfb_pocketbook_h.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
local ffi = require("ffi")

ffi.cdef[[
struct mxcfb_rect {
unsigned int top;
unsigned int left;
unsigned int width;
unsigned int height;
};
struct mxcfb_alt_buffer_data {
unsigned int phys_addr;
unsigned int width;
unsigned int height;
struct mxcfb_rect alt_update_region;
};
struct mxcfb_update_data {
struct mxcfb_rect update_region;
unsigned int waveform_mode;
unsigned int update_mode;
unsigned int update_marker;
int temp;
unsigned int flags;
struct mxcfb_alt_buffer_data alt_buffer_data;
};
struct mxcfb_update_marker_data {
unsigned int update_marker;
unsigned int collision_test;
};
static const int UPDATE_MODE_PARTIAL = 0;
static const int UPDATE_MODE_FULL = 1;
static const int WAVEFORM_MODE_INIT = 0;
static const int WAVEFORM_MODE_DU = 1;
static const int WAVEFORM_MODE_GC16 = 2;
static const int WAVEFORM_MODE_GC4 = 3;
static const int WAVEFORM_MODE_A2 = 4;
static const int WAVEFORM_MODE_GL16 = 5;
static const int WAVEFORM_MODE_A2IN = 6;
static const int WAVEFORM_MODE_A2OUT = 7;
static const int WAVEFORM_MODE_GL4 = 10;
static const int WAVEFORM_MODE_GL16_INV = 11;
static const int WAVEFORM_MODE_AUTO = 257;
static const int TEMP_USE_AMBIENT = 4096;
static const int TEMP_USE_PAPYRUS = 4097;
static const int TEMP_USE_AUTO = 4097;
static const int EPDC_FLAG_ENABLE_INVERSION = 1;
static const int EPDC_FLAG_FORCE_MONOCHROME = 2;
static const int EPDC_FLAG_USE_CMAP = 4;
static const int EPDC_FLAG_USE_ALT_BUFFER = 256;
static const int EPDC_FLAG_TEST_COLLISION = 512;
static const int EPDC_FLAG_GROUP_UPDATE = 1024;
static const int EPDC_FLAG_FORCE_Y2 = 2048;
static const int EPDC_FLAG_USE_REAGLD = 4096;
static const int EPDC_FLAG_USE_DITHERING_Y1 = 8192;
static const int EPDC_FLAG_USE_DITHERING_Y2 = 16384;
static const int EPDC_FLAG_USE_DITHERING_Y4 = 32768;
static const int MXCFB_SEND_UPDATE = 1077954094;
static const int MXCFB_WAIT_FOR_UPDATE_COMPLETE = 3221767727;
static const int MXCFB_WAIT_FOR_UPDATE_COMPLETE_PEARL = 1074021935;
static const int MXCFB_WAIT_FOR_UPDATE_SUBMISSION = 1074021943;
]]
71 changes: 68 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/

#include "popen-noshell/popen_noshell.h"

#ifdef POCKETBOOK
#include "inkview.h"
#endif

#include <err.h>
#include <stdio.h>
#include <signal.h>
Expand Down Expand Up @@ -62,14 +67,75 @@ int findFreeFdSlot() {
return -1;
}

#ifdef POCKETBOOK
int is_in_touch = 0;
static inline void genEmuEvent(int fd, int type, int code, int value) {
struct input_event input;

input.type = type;
input.code = code;
input.value = value;

gettimeofday(&input.time, NULL);
if(write(fd, &input, sizeof(struct input_event)) == -1) {
printf("Failed to generate emu event.\n");
}

return;
}

int pb_event_handler(int type, int par1, int par2) {
//printf("ev:%d %d %d\n", type, par1, par2);
//fflush(stdout);
if (type == EVT_POINTERDOWN) {
is_in_touch = 1;
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_TRACKING_ID, 0);
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_POSITION_X, par1);
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_POSITION_Y, par2);
} else if (type == EVT_MTSYNC) {
genEmuEvent(inputfds[0], EV_SYN, SYN_REPORT, 0);
} else if (type == EVT_POINTERMOVE) {
if (is_in_touch) {
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_POSITION_X, par1);
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_POSITION_Y, par2);
}
} else if (type == EVT_POINTERUP) {
is_in_touch = 0;
genEmuEvent(inputfds[0], EV_ABS, ABS_MT_TRACKING_ID, -1);
}
return 0;
}
#endif

static int openInputDevice(lua_State *L) {
const char* inputdevice = luaL_checkstring(L, 1);
#ifdef POCKETBOOK
int inkview_events = luaL_checkint(L, 2);
#endif
int fd;
int childpid;
fd = findFreeFdSlot();
if(fd == -1) {
return luaL_error(L, "no free slot for new input device <%s>", inputdevice);
}

#ifdef POCKETBOOK
if(inkview_events == 1) {
if ((childpid = fork()) == -1) {
return luaL_error(L, "cannot fork() emu event listener");
}
if(childpid == 0) {
/* we only use inputfds[0] in emu mode, because we only have one
* fake device so far. */
inputfds[0] = open(inputdevice, O_RDWR | O_NONBLOCK);
if (inputfds < 0) {
return luaL_error(L, "error opening input device <%s>: %d", inputdevice, errno);
}
InkViewMain(pb_event_handler);
}
}
#endif

if(!strcmp("fake_events", inputdevice)) {
/* special case: the power slider */
int pipefd[2];
Expand Down Expand Up @@ -192,9 +258,6 @@ static int fakeTapInput(lua_State *L) {
int inputfd = -1;
struct input_event ev;
inputfd = open(inputdevice, O_WRONLY | O_NDELAY);
if (inputfd == NULL) {
return luaL_error(L, "cannot open input device <%s>", inputdevice);
}
if(inputfd != -1) {
gettimeofday(&ev.time, NULL);
ev.type = 3;
Expand Down Expand Up @@ -246,6 +309,8 @@ static int fakeTapInput(lua_State *L) {
ev.code = 0;
ev.value = 0;
write(inputfd, &ev, sizeof(ev));
} else {
return luaL_error(L, "cannot open input device <%s>", inputdevice);
}
ioctl(inputfd, EVIOCGRAB, 0);
close(inputfd);
Expand Down

0 comments on commit 3ffa5dc

Please sign in to comment.