From 1e4ba2c73953ee8694a590bf789e43faa42209d4 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Fri, 1 Nov 2019 19:51:10 +0100 Subject: [PATCH] display: kernel-driver: rework color-to-bw conversion --- display/kernel-driver/lmg6202ulyt.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/display/kernel-driver/lmg6202ulyt.c b/display/kernel-driver/lmg6202ulyt.c index dfc5453..4d9bd15 100644 --- a/display/kernel-driver/lmg6202ulyt.c +++ b/display/kernel-driver/lmg6202ulyt.c @@ -8,8 +8,7 @@ #include #include -#define BPP 8 // 8 -#define PIX_THRESHOLD 0 +#define BPP 16 #define LMGE_GPIO 100 #define LMGE_OTHER 99 @@ -21,9 +20,9 @@ MODULE_AUTHOR("Markus Koch"); MODULE_DESCRIPTION("lmg6202ulyt display driver"); MODULE_VERSION("0.1"); -static char *testparam = "param"; -module_param(testparam, charp, S_IRUGO); -MODULE_PARM_DESC(testparam, "A test parameter"); +static int pix_threshold = 0; +module_param(pix_threshold, int, 0); +MODULE_PARM_DESC(pix_threshold, "Black / White threshold. 0-255"); static struct of_device_id lmg6202ulyt_dt_ids[] = { { .compatible = "hitachi,lmg6202ulyt", }, @@ -122,7 +121,9 @@ static int lmg6202ulyt_init_fix(struct lmg6202ulyt_priv *priv) else fix->visual = FB_VISUAL_TRUECOLOR; - printk(KERN_INFO "lmg6202ulyt: Using %d bpp.\n", var->bits_per_pixel); + printk(KERN_INFO "lmg6202ulyt: Using %d bpp (%s).\n", + var->bits_per_pixel, + (var->grayscale ? "grayscale" : "truecolor")); return 0; } @@ -209,6 +210,7 @@ void lmg6202ulyt_deferred_io(struct fb_info *info, struct list_head *pagelist) int i; int blk; char __iomem *pixel; + char pixval; int txsz; spi_write(priv->spi, buf, 5); @@ -219,7 +221,13 @@ void lmg6202ulyt_deferred_io(struct fb_info *info, struct list_head *pagelist) buf[0] = 1; for (i = 0; i < BLOCKSIZE * 8; i++) { - if (*pixel > PIX_THRESHOLD) { +#if BPP == 8 + pixval = *(pixel); +#else + pixval = *(pixel + 1); + // TODO: We should have more cases here for higher BPPs +#endif + if (pixval > pix_threshold) { buf[(i / 8) + 1] |= (1 << (7 - (i % 8))); } if (pixel >= info->screen_base + info->screen_size - ((info->var.bits_per_pixel) / 8))