diff --git a/Makefile b/Makefile index 7041161..faf90f8 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ obj-m += sharp.o +sharp-objs += main.o params_iface.o export KROOT=/lib/modules/$(shell uname -r)/build diff --git a/sharp.c b/main.c similarity index 98% rename from sharp.c rename to main.c index 32bd5d1..3a5e24d 100644 --- a/sharp.c +++ b/main.c @@ -29,6 +29,8 @@ #include #include +#include "params_iface.h" + #define GPIO_DISP 22 #define GPIO_SCS 8 #define GPIO_VCOM 23 @@ -148,11 +150,16 @@ static size_t sharp_memory_gray8_to_mono_tagged(u8 *buf, int width, int height, for (b1 = 0; b1 < 8; b1++) { // Change at what gray level the mono pixel is active here - if (buf[(line * width) + b8 + b1] >= 32) { + if (buf[(line * width) + b8 + b1] >= g_param_mono_cutoff) { d |= 0b10000000 >> b1; } } + // Apply inversion + if (g_param_mono_invert) { + d = ~d; + } + // Without the line number and trailer tags, each destination // mono line would have a length `width / 8`. However, we are // inserting the line number at the beginning of the line and diff --git a/params_iface.c b/params_iface.c new file mode 100644 index 0000000..681ada9 --- /dev/null +++ b/params_iface.c @@ -0,0 +1,32 @@ +#include +#include +#include + +#include "params_iface.h" + +int g_param_mono_cutoff = 32; +int g_param_mono_invert = 0; + +static int set_param_u8(const char *val, const struct kernel_param *kp) +{ + int rc, result; + + // Parse string value + if ((rc = kstrtoint(val, 10, &result)) || (result < 0) || (result > 0xff)) { + return -EINVAL; + } + + return param_set_int(val, kp); +} + +static const struct kernel_param_ops u8_param_ops = { + .set = set_param_u8, + .get = param_get_int, +}; + +module_param_cb(mono_cutoff, &u8_param_ops, &g_param_mono_cutoff, 0660); +MODULE_PARM_DESC(mono_cutoff, + "Greyscale value from 0-255 after which a mono pixel will be activated"); + +module_param_cb(mono_invert, &u8_param_ops, &g_param_mono_invert, 0660); +MODULE_PARM_DESC(mono_invert, "0 for no inversion, 1 for inversion"); diff --git a/params_iface.h b/params_iface.h new file mode 100644 index 0000000..c379174 --- /dev/null +++ b/params_iface.h @@ -0,0 +1,7 @@ +#ifndef PARAMS_IFACE_H_ +#define PARAMS_IFACE_H_ + +extern int g_param_mono_cutoff; +extern int g_param_mono_invert; + +#endif