Skip to content

Commit

Permalink
Minor cleanup after #17
Browse files Browse the repository at this point in the history
  • Loading branch information
NiLuJe committed Oct 18, 2018
1 parent ff2fc4c commit f07f337
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 50 deletions.
24 changes: 16 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ifdef LEGACY
endif
# Toggle Bq Cervantes support
ifdef CERVANTES
EXTRA_CPPFLAGS+=-DFBINK_FOR_CERVANTES
EXTRA_CPPFLAGS+=-DFBINK_FOR_CERVANTES
endif
# Toggle generic Linux support
ifdef LINUX
Expand All @@ -144,12 +144,16 @@ endif
FBINK_VERSION=$(shell git describe)
ifdef KINDLE
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Kindle"'
else ifdef KOBO
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Kobo"'
else ifdef CERVANTES
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Cervantes"'
else ifdef LINUX
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Linux"'
else
ifdef CERVANTES
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Cervantes"'
else
ifdef LINUX
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Linux"'
else
LIB_CFLAGS+=-DFBINK_VERSION='"$(FBINK_VERSION) for Kobo"'
endif
endif
endif

# NOTE: Always use as-needed to avoid unecessary DT_NEEDED entries :)
Expand Down Expand Up @@ -189,7 +193,11 @@ else
EXTRA_CPPFLAGS+=-DFBINK_WITH_IMAGE
# Connect button scanning is Kobo specific
ifndef KINDLE
EXTRA_CPPFLAGS+=-DFBINK_WITH_BUTTON_SCAN
ifndef CERVANTES
ifndef LINUX
EXTRA_CPPFLAGS+=-DFBINK_WITH_BUTTON_SCAN
endif
endif
endif
endif

Expand Down
18 changes: 11 additions & 7 deletions fbink.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ static long int
}

// Handle the various eInk update API quirks for the full range of HW we support...
#if defined (FBINK_FOR_KINDLE)
#if defined(FBINK_FOR_KINDLE)
// Legacy Kindle devices ([K2<->K4])
static int
refresh_legacy(int fbfd, const struct mxcfb_rect region, bool is_flashing)
Expand Down Expand Up @@ -1140,10 +1140,14 @@ static int

return EXIT_SUCCESS;
}
#elif defined (FBINK_FOR_CERVANTES)
#elif defined(FBINK_FOR_CERVANTES)
// Legacy Cervantes devices (2013)
static int
refresh_cervantes(int fbfd, const struct mxcfb_rect region, uint32_t waveform_mode, uint32_t update_mode, uint32_t marker)
refresh_cervantes(int fbfd,
const struct mxcfb_rect region,
uint32_t waveform_mode,
uint32_t update_mode,
uint32_t marker)
{
struct mxcfb_update_data update = {
.update_region = region,
Expand Down Expand Up @@ -1195,10 +1199,10 @@ static int
// New cervantes devices (2013+)
static int
refresh_cervantes_new(int fbfd,
const struct mxcfb_rect region,
uint32_t waveform_mode,
uint32_t update_mode,
uint32_t marker)
const struct mxcfb_rect region,
uint32_t waveform_mode,
uint32_t update_mode,
uint32_t marker)
{
struct mxcfb_update_data_org update = {
.update_region = region,
Expand Down
46 changes: 24 additions & 22 deletions fbink_device_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "fbink_device_id.h"

#if defined (FBINK_FOR_KINDLE)
#if defined(FBINK_FOR_KINDLE)
// NOTE: This is adapted from KindleTool,
// c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/kindle_tool.h#L189
static bool
Expand Down Expand Up @@ -202,7 +202,7 @@ static void
}
}
}
#elif defined (FBINK_FOR_CERVANTES)
#elif defined(FBINK_FOR_CERVANTES)
// read pcb id from HWCONFIG for bq/fnac devices, adapted from OKreader's kobo_hwconfig:
// https://github.com/lgeek/okreader/blob/master/src/kobo_hwconfig/kobo_hwconfig.c
static void
Expand All @@ -212,38 +212,40 @@ static void
if (!fp) {
fprintf(stderr, "[FBInk] Couldn't read from %s (not running on a Cervantes?)!\n", HWCONFIG_DEVICE);
} else {
int ret;
int ret;
hwconfig config;

ret = fseek(fp, HWCONFIG_OFFSET, SEEK_SET);
if (ret != 0)
{
fprintf(stderr, "[FBInk] Failed to seek to position 0x%p in %s\n", (void*) HWCONFIG_OFFSET, HWCONFIG_DEVICE);
if (ret != 0) {
fprintf(stderr,
"[FBInk] Failed to seek to position 0x%p in %s\n",
(void*) HWCONFIG_OFFSET,
HWCONFIG_DEVICE);
exit(EXIT_FAILURE);
}

ret = (int) fread(&config, sizeof(config), 1, fp);
if (ret != 1)
{
if (ret != 1) {
fprintf(stderr, "[FBInk] Failed to read the HWCONFIG entry in %s\n", HWCONFIG_DEVICE);
exit(EXIT_FAILURE);
}

if (strncmp(config.magic, HWCONFIG_MAGIC, strlen(HWCONFIG_MAGIC)) != 0)
{
fprintf(stderr, "[FBInk] Input file %s does not appear to contain a HWCONFIG entry\n", HWCONFIG_DEVICE);
if (strncmp(config.magic, HWCONFIG_MAGIC, strlen(HWCONFIG_MAGIC)) != 0) {
fprintf(stderr,
"[FBInk] Input file %s does not appear to contain a HWCONFIG entry\n",
HWCONFIG_DEVICE);
exit(EXIT_FAILURE);
}

// supported devices,
// from https://github.com/bq/cervantes/blob/master/bqHAL/Devices/mx508/src/DeviceInfoMx508.cpp#L33-L37
switch(config.pcb_id) {
case 22: // BQ Cervantes Touch - Fnac Touch (2012-2013)
case 23: // BQ Cervantes TouchLight - Fnac Touch Plus (2012-2013)
case 33: // BQ Cervantes 2013 - Fnac Touch Light (2013)
// supported devices,
// from https://github.com/bq/cervantes/blob/master/bqHAL/Devices/mx508/src/DeviceInfoMx508.cpp#L33-L37
switch (config.pcb_id) {
case 22: // BQ Cervantes Touch - Fnac Touch (2012-2013)
case 23: // BQ Cervantes TouchLight - Fnac Touch Plus (2012-2013)
case 33: // BQ Cervantes 2013 - Fnac Touch Light (2013)
break;
case 51: // BQ Cervantes 3 - Fnac Touch Light 2 (2016)
case 68: // BQ Cervantes 4
case 51: // BQ Cervantes 3 - Fnac Touch Light 2 (2016)
case 68: // BQ Cervantes 4
device_quirks->isCervantesNew = true;
break;
default:
Expand Down Expand Up @@ -326,10 +328,10 @@ static void
static void
identify_device(FBInkDeviceQuirks* device_quirks)
{
#if defined (FBINK_FOR_KINDLE)
#if defined(FBINK_FOR_KINDLE)
identify_kindle(device_quirks);
#elif defined (FBINK_FOR_CERVANTES)
identify_cervantes(device_quirks);
#elif defined(FBINK_FOR_CERVANTES)
identify_cervantes(device_quirks);
#else
identify_kobo(device_quirks);
#endif
Expand Down
13 changes: 7 additions & 6 deletions fbink_device_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
#include "fbink.h"
#include "fbink_internal.h"

#ifdef FBINK_FOR_KINDLE
#if defined(FBINK_FOR_KINDLE)
# define KINDLE_SERIAL_NO_LENGTH 16

static bool is_kindle_device(uint32_t, FBInkDeviceQuirks*);
static bool is_kindle_device_new(uint32_t, FBInkDeviceQuirks*);
static uint32_t from_base(char*, uint8_t);
static void identify_kindle(FBInkDeviceQuirks*);
#elif defined (FBINK_FOR_CERVANTES)
#define HWCONFIG_DEVICE "/dev/mmcblk0"
#define HWCONFIG_OFFSET (1024 * 512)
#define HWCONFIG_MAGIC "HW CONFIG "
typedef struct __attribute__ ((__packed__)) {
#elif defined(FBINK_FOR_CERVANTES)
# define HWCONFIG_DEVICE "/dev/mmcblk0"
# define HWCONFIG_OFFSET (1024 * 512)
# define HWCONFIG_MAGIC "HW CONFIG "
typedef struct __attribute__((__packed__))
{
char magic[10];
char version[5];
uint8_t size;
Expand Down
16 changes: 9 additions & 7 deletions fbink_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
# endif
// Connect button scanning is Kobo specific
# ifndef FBINK_FOR_KINDLE
# ifndef FBINK_WITH_BUTTON_SCAN
# define FBINK_WITH_BUTTON_SCAN
# ifndef FBINK_FOR_CERVANTES
# ifndef FBINK_WITH_BUTTON_SCAN
# define FBINK_WITH_BUTTON_SCAN
# endif
# endif
# endif
#endif
Expand Down Expand Up @@ -84,12 +86,12 @@
#include "utf8/utf8.h"

// NOTE: We always neeed one of those, because we rely on mxcfb_rect in a number of places
#if defined (FBINK_FOR_KINDLE)
#if defined(FBINK_FOR_KINDLE)
# include "eink/mxcfb-kindle.h"
// Legacy einkfb driver
# include "eink/einkfb.h"
#elif defined (FBINK_FOR_CERVANTES)
# include "eink/mxcfb-cervantes.h"
#elif defined(FBINK_FOR_CERVANTES)
# include "eink/mxcfb-cervantes.h"
#else
# include "eink/mxcfb-kobo.h"
#endif
Expand Down Expand Up @@ -291,11 +293,11 @@ static struct mxcfb_rect draw(const char*,
const FBInkConfig*);

static long int jiffies_to_ms(long int);
#if defined (FBINK_FOR_KINDLE)
#if defined(FBINK_FOR_KINDLE)
static int refresh_legacy(int, const struct mxcfb_rect, bool);
static int refresh_kindle(int, const struct mxcfb_rect, uint32_t, uint32_t, uint32_t);
static int refresh_kindle_koa2(int, const struct mxcfb_rect, uint32_t, uint32_t, uint32_t);
#elif defined (FBINK_FOR_CERVANTES)
#elif defined(FBINK_FOR_CERVANTES)
static int refresh_cervantes(int, const struct mxcfb_rect, uint32_t, uint32_t, uint32_t);
static int refresh_cervantes_new(int, const struct mxcfb_rect, uint32_t, uint32_t, uint32_t);
#else
Expand Down

0 comments on commit f07f337

Please sign in to comment.