Skip to content

Commit

Permalink
Pocketbook: Add support for waveform presets. (#1218)
Browse files Browse the repository at this point in the history
Ship "slow, but always work" baseline, that can be
bumped from UI up to a level that still works.
  • Loading branch information
ezdiy committed Oct 15, 2020
1 parent 9080efe commit 136ae92
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
15 changes: 10 additions & 5 deletions ffi-cdecl/include/mxcfb-pb.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,22 @@ struct mxcfb_rect {
#define EPDC_WFTYPE_GC16 2
#define EPDC_WFTYPE_GC4 3
#define EPDC_WFTYPE_A2 4
#define EPDC_WFTYPE_GL16 5
#define EPDC_WFTYPE_GL16 5 // On B288 this is very fast, but flickers, interferes with HWROT.
#define EPDC_WFTYPE_A2IN 6
#define EPDC_WFTYPE_A2OUT 7
#define EPDC_WFTYPE_DU4 8
#define EPDC_WFTYPE_AA 9
#define EPDC_WFTYPE_AAD 10
#define EPDC_WFTYPE_GC16HQ 15
#define EPDC_WFTYPE_DU4 8 // not B288
#define EPDC_WFTYPE_AA 9 // not B288
#define EPDC_WFTYPE_AAD 10 // not B288
#define EPDC_WFTYPE_GS16 14 // B288 only. More aggressive than GC16, less than GL16.
#define EPDC_WFTYPE_GC16HQ 15 // not B288
// NOTE: Alias that to our usual constant names...
#define WAVEFORM_MODE_INIT EPDC_WFTYPE_INIT
#define WAVEFORM_MODE_DU EPDC_WFTYPE_DU
#define WAVEFORM_MODE_GC16 EPDC_WFTYPE_GC16
#define WAVEFORM_MODE_GC4 EPDC_WFTYPE_GC4
#define WAVEFORM_MODE_A2 EPDC_WFTYPE_A2
#define WAVEFORM_MODE_GL16 EPDC_WFTYPE_GL16
#define WAVEFORM_MODE_GS16 EPDC_WFTYPE_GS16
#define WAVEFORM_MODE_A2IN EPDC_WFTYPE_A2IN
#define WAVEFORM_MODE_A2OUT EPDC_WFTYPE_A2OUT
#define WAVEFORM_MODE_DU4 EPDC_WFTYPE_DU4
Expand Down Expand Up @@ -246,6 +248,9 @@ struct mxcfb_csc_matrix {
// >_<".
// c.f., https://github.com/koreader/koreader-base/pull/1188 & https://github.com/koreader/koreader/pull/6669

// This only probes whether EPDC is busy, we use this to detect B288.
#define EPDC_GET_UPDATE_STATE _IOR('F', 0x55, __u32)

#define MXCFB_SET_PWRDOWN_DELAY _IOW('F', 0x30, int32_t)
#define MXCFB_GET_PWRDOWN_DELAY _IOR('F', 0x31, int32_t)
#define MXCFB_SET_UPDATE_SCHEME _IOW('F', 0x32, __u32)
Expand Down
3 changes: 3 additions & 0 deletions ffi-cdecl/mxcfb_pb_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cdecl_const(EPDC_WFTYPE_GC16)
cdecl_const(EPDC_WFTYPE_GC4)
cdecl_const(EPDC_WFTYPE_A2)
cdecl_const(EPDC_WFTYPE_GL16)
cdecl_const(EPDC_WFTYPE_GS16)
cdecl_const(EPDC_WFTYPE_A2IN)
cdecl_const(EPDC_WFTYPE_A2OUT)
cdecl_const(EPDC_WFTYPE_DU4)
Expand All @@ -31,6 +32,7 @@ cdecl_const(WAVEFORM_MODE_GC16)
cdecl_const(WAVEFORM_MODE_GC4)
cdecl_const(WAVEFORM_MODE_A2)
cdecl_const(WAVEFORM_MODE_GL16)
cdecl_const(WAVEFORM_MODE_GS16)
cdecl_const(WAVEFORM_MODE_A2IN)
cdecl_const(WAVEFORM_MODE_A2OUT)
cdecl_const(WAVEFORM_MODE_DU4)
Expand Down Expand Up @@ -61,3 +63,4 @@ cdecl_struct(mxcfb_update_marker_data)

cdecl_const(MXCFB_SEND_UPDATE)
cdecl_const(MXCFB_WAIT_FOR_UPDATE_COMPLETE_PB)
cdecl_const(EPDC_GET_UPDATE_STATE)
8 changes: 8 additions & 0 deletions ffi/framebuffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ local fb = {
default = nil, -- if not nil, use this as default rotation value (this one is canonical, not HW)
every_paint = false, -- true if HW mode should be enforced for every paint batch
},]]
-- User-selectable WF aggressiveness.
-- Lower level is the slowest and most conservative, increasing values trade speed for glitches and ghosting.
wf_level = 0,
wf_level_max = 0, -- Maximum supported value for wf_level.
}

--[[
Expand Down Expand Up @@ -449,6 +453,10 @@ function fb:setupDithering()
end
end

function fb:getWaveformLevel()
return math.min(self.wf_level_max, self.wf_level)
end

function fb:saveCurrentBB()
if self.saved_bb then self.saved_bb:free() end
self.saved_bb = self.bb:copy()
Expand Down
1 change: 1 addition & 0 deletions ffi/framebuffer_linux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function framebuffer:setRotationMode(mode)
self.cur_rotation_mode = mode
self:setHWRotation(mode)
self:reinit()
assert(self.forced_rotation, "reinit/fb hooks shouldn't flip hw rotation flags")
if self.forced_rotation.restore then
self:setHWRotation(self.native_rotation_mode)
end
Expand Down
31 changes: 28 additions & 3 deletions ffi/framebuffer_mxcfb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,13 @@ function framebuffer:refreshFastImp(x, y, w, h, dither)
self:mech_refresh(C.UPDATE_MODE_PARTIAL, self.waveform_fast, x, y, w, h, dither)
end

-- Detect Allwinner boards. Those emulate mxcfb API in a custom driver (poorly).
function framebuffer:isB288(fb)
require("ffi/mxcfb_pocketbook_h")
-- On a real MXC driver, it returns -EINVAL
return C.ioctl(self.fd, C.EPDC_GET_UPDATE_STATE, ffi.new("uint32_t[1]")) == 0
end

function framebuffer:init()
framebuffer.parent.init(self)

Expand Down Expand Up @@ -721,11 +728,29 @@ function framebuffer:init()
self.mech_refresh = refresh_pocketbook
self.mech_wait_update_complete = pocketbook_mxc_wait_for_update_complete

self.waveform_fast = C.WAVEFORM_MODE_DU
self.waveform_ui = C.WAVEFORM_MODE_GL16
self.wf_level_max = 3
local level = self:getWaveformLevel()
-- Level 0 is most conservative.
-- This is what inkview does on all platforms.
-- Slow (>150ms on B288 Carta).
if level == 0 then
self.waveform_fast = C.WAVEFORM_MODE_GC16
self.waveform_partial = C.WAVEFORM_MODE_GC16
elseif level == 1 then
self.waveform_fast = C.WAVEFORM_MODE_DU
self.waveform_partial = C.WAVEFORM_MODE_GC16
elseif level == 2 then
self.waveform_fast = C.WAVEFORM_MODE_DU
self.waveform_partial = self:isB288() and C.WAVEFORM_MODE_GS16 or C.WAVEFORM_MODE_GC16
-- Level 3 is most aggressive.
-- Fast (>80ms on B288 Carta), but flickers and may be buggy.
elseif level == 3 then
self.waveform_fast = C.WAVEFORM_MODE_DU
self.waveform_partial = C.WAVEFORM_MODE_GL16
end
self.waveform_ui = self.waveform_partial
self.waveform_flashui = C.WAVEFORM_MODE_GC16
self.waveform_full = C.WAVEFORM_MODE_GC16
self.waveform_partial = C.WAVEFORM_MODE_GL16
self.waveform_night = C.WAVEFORM_MODE_GC16
self.waveform_flashnight = self.waveform_night
self.night_is_reagl = false
Expand Down
3 changes: 3 additions & 0 deletions ffi/mxcfb_pocketbook_h.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static const int EPDC_WFTYPE_GC16 = 2;
static const int EPDC_WFTYPE_GC4 = 3;
static const int EPDC_WFTYPE_A2 = 4;
static const int EPDC_WFTYPE_GL16 = 5;
static const int EPDC_WFTYPE_GS16 = 14;
static const int EPDC_WFTYPE_A2IN = 6;
static const int EPDC_WFTYPE_A2OUT = 7;
static const int EPDC_WFTYPE_DU4 = 8;
Expand All @@ -23,6 +24,7 @@ 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_GS16 = 14;
static const int WAVEFORM_MODE_A2IN = 6;
static const int WAVEFORM_MODE_A2OUT = 7;
static const int WAVEFORM_MODE_DU4 = 8;
Expand Down Expand Up @@ -68,4 +70,5 @@ struct mxcfb_update_marker_data {
};
static const int MXCFB_SEND_UPDATE = 1077954094;
static const int MXCFB_WAIT_FOR_UPDATE_COMPLETE_PB = 1074021935;
static const int EPDC_GET_UPDATE_STATE = 2147763797;
]]

0 comments on commit 136ae92

Please sign in to comment.