display: kernel-driver: rework color-to-bw conversion

This commit is contained in:
Markus Koch 2019-11-01 19:51:10 +01:00
parent f0f671c6fb
commit 1e4ba2c739

View File

@ -8,8 +8,7 @@
#include <linux/gpio/consumer.h>
#include <linux/fb.h>
#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))