You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
8.3 KiB

  1. # Porting
  2. This page aims to provide guidance on how to port KOReader to other platforms.
  3. There are mainly two modules that you need to take care of: input and output.
  4. After you finish these two, KOReader should have no problem running on your platform.
  5. Feel free to open issues in our issue tracker if you need further help on this topic :)
  6. ## Output Module
  7. ### Current mxcfb eInk devices
  8. KOReader uses the Linux framebuffer to control eInk devices, so the output module for mxcfb (i.e., those based on Freescale/NXP hardware) devices is [`base/ffi/framebuffer_mxcfb.lua`](
  9. Most common bitdepths are supported, although no devices should actually be using anything other than 8bpp, 16bpp and 32bpp.
  10. For 8bpp, we assume the grayscale palette is NOT inverted.
  11. At 32bpp, we generally assume the pixel format is BGRA, and we honor Alpha, despite it being effectively ignored by the display (see Kobos).
  12. At 16bpp, we assume the pixel format is RGB565.
  13. For obvious performance reasons, we prefer 8bpp, and we will attempt to enforce that on devices which are not natively running at that depth (i.e., [on Kobos](
  14. As explained below, the same considerations should be kept in mind regarding the effective 16c palette of eInk screens.
  15. When we're in control of the data, we attempt to always use "perfect" in-palette colors (c.f., the [COLOR constants]( in the BlitBuffer module).
  16. Otherwise, when there'd be signficiant gain in doing so (i.e., when displaying mainly image content), we attempt to make use of [dithering](, ideally [offloaded to the hardware]( when supported.
  17. The actual framebuffer content is then refreshed (i.e., displayed) via device-specific ioctls, making the best effort in using device-specific capabilities, whether that be [optimized waveform modes](, hardware dithering or [hardware inversion](
  18. The platform-specific Lua FFI modules for using the mxcfb driver are generated from the [kernel header files]( using [ffi-cdecl]( `ffi-cdecl` operates on [C files]( which specify what to export.
  19. To use `ffi-cdecl` first you need to build the gcc plugin for the platform toolchain, e.g.:
  20. ```
  21. cd ffi-cdecl
  22. make clean
  23. PATH=$HOME/x-tools/arm-remarkable-linux-gnueabihf/bin/:$PATH make CHOST=arm-remarkable-linux-gnueabihf CROSS_DIR=$HOME/x-tools/arm-remarkable-linux-gnueabihf/
  24. ```
  25. Then you can (re)generate the [ffi lua files](, e.g.
  26. ```
  27. PATH=$HOME/x-tools/arm-remarkable-linux-gnueabihf/bin/:$PATH ./ffi-cdecl arm-remarkable-linux-gnueabihf-gcc ../koreader/base/ffi-cdecl/mxcfb_remarkable_decl.c ../koreader/base/ffi/mxcfb_remarkable_h.lua
  28. ```
  29. ### Legacy einkfb eInk devices
  30. KOReader uses the Linux framebuffer to control eInk devices, so the output module for legacy einkfb devices is [`base/ffi/framebuffer_einkfb.lua`](
  31. Following are the framebuffers that `framebuffer_einkfb.lua` currently supports:
  32. * 4bpp framebuffer (palette is always inverted)
  33. * 16c 8bpp framebuffer (inverted grayscale palette)
  34. For 4bpp framebuffers, it means every pixel is represented with 4 bits, so we have 2 pixels in 1 byte.
  35. That also effectively limits the palette to 16 colors.
  36. The inverted part means that every pixel's color value is flipped (`^ 0xFF`).
  37. For example, two pixels `0x00` and `0xF0` will be flipped to `0xFF` and `0x0F`, before being packed to accomodate the framebuffer's pixel format (here, [into a single byte](
  38. For 8bpp framebuffers, it means each pixel is instead stored in 1 byte, making addressing much simpler.
  39. The effective color palette of the display is still limited to 16 shades of gray: it will do a decimating quantization pass on its own on refresh.
  40. So, while a black pixel will indeed be `0x00`, any color value < `0x11` (the next effective shade of gray in the [palette]( will be displayed as pure black, too.
  41. If the palette is expected to be inverted, then all the bits are flipped in the same way as done on a 4bpp framebuffer.
  42. In practice, [this is always the case](
  43. The actual framebuffer content is then refreshed (i.e., displayed) via device-specific ioctls.
  44. ## Blitter Module
  45. All the intermediary buffers are handled in a pixel format that matches the output module in use as closely as possible.
  46. The magic happens in [`base/ffi/blitbuffer.lua`](, with some help from the [LinuxFB]( frontend to the output modules.
  47. Note that on most devices, a [C version]( is used instead for more consistent performance.
  48. Which version is more easily readable to a newcomer is up for debate, so, don't hesitate to cross-reference ;).
  49. Feature-parity should be complete, with the exception of 4bpp support in the C version.
  50. If you need a bit of guidance, you can also take a look at [FBInk](, and/or ping [@NiLuJe]( on gitter.
  51. ## Input Module
  52. We have an [`input.c`]( module in [koreader-base][kb-framework] that reads input events from Linux's input system and passes it on to the Lua frontend.
  53. Basically, you don't need to change that module because it should support most of the events.
  54. For this part, the file you have to hack on is [`koreader/frontend/ui/input.lua`](
  55. Firstly, you need to tell which input device to open on KOReader start. All the input devices are opened in `Input:init()` function.
  56. Next, you might need to define `Input:eventAdjustHook()` function in `Input:init()` method.
  57. We use this hook function to translate events into a format that KOReader understands.
  58. You can look at the KindleTouch initialization code for a real-world example.
  59. For some Kobo devices (Mini, Touch, Glo and Aura HD) the function `Input:eventAdjustHook()` was skipped and the functions `Input:init()` and `Input:handleTypeBTouchEv()` were changed to accomodate for the single touch protocol.
  60. For the Kobo Aura (and others with the same kernel quirks) with multitouch support, an extra function `Input:handlePhoenixTouchEv()` was added.
  61. Linux supports two kinds of Multi-touch protocols:
  62. * <>
  63. Currently, KOReader supports gesture detection of protocol B, so if your device sends out protocol A, you need to make a variant of function `Input:handleTouchEv()` (like `Input:handleTypeBTouchEv()` and `Input:handlePhoenixTouchEv()`) and simulate protocol B.
  64. You are also welcome to send a PR that adds protocol A support to KOReader.
  65. More information on Linux's input system:
  66. * <>
  67. * <>
  68. [kb-framework]:
  69. <!-- kate: indent-mode cstyle; indent-width 4; replace-tabs on; remove-trailing-spaces none; -->