Compare commits
4 Commits
f0f671c6fb
...
4f8931f193
Author | SHA1 | Date | |
---|---|---|---|
4f8931f193 | |||
2b070b173a | |||
13d25c6866 | |||
1e4ba2c739 |
@ -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))
|
||||
|
@ -6,6 +6,9 @@
|
||||
#include <linux/of_device.h>
|
||||
#include <linux/serdev.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
// #define ENABLE_DEBUG ENABLE_DEBUG
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Markus Koch");
|
||||
@ -22,18 +25,86 @@ static struct of_device_id lw35ioc_dt_ids[] = {
|
||||
};
|
||||
MODULE_DEVICE_TABLE(of, lw35ioc_dt_ids);
|
||||
|
||||
/* Only used for initialization, not for actualy keycode mapping */
|
||||
static int keycode_map[] = {
|
||||
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
|
||||
KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
|
||||
KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y, KEY_Z,
|
||||
KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9,
|
||||
KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, KEY_F6, KEY_F7, KEY_F8, KEY_F9,
|
||||
KEY_F10, KEY_F11, KEY_F12,
|
||||
KEY_UP, KEY_DOWN, KEY_RIGHT, KEY_LEFT, KEY_PAGEUP, KEY_PAGEDOWN,
|
||||
KEY_102ND, KEY_INSERT, KEY_HOME, KEY_END, KEY_PRINT,
|
||||
KEY_CAPSLOCK, KEY_LEFTCTRL, KEY_LEFTSHIFT, KEY_LEFTALT, KEY_TAB,
|
||||
KEY_MINUS, KEY_COMMA, KEY_SEMICOLON, KEY_RIGHTBRACE, KEY_LEFTBRACE,
|
||||
KEY_GRAVE, KEY_SPACE, KEY_EQUAL, KEY_DOT, KEY_SLASH, KEY_APOSTROPHE,
|
||||
KEY_BACKSLASH,
|
||||
KEY_DELETE, KEY_ESC, KEY_ENTER, KEY_BACKSPACE,
|
||||
KEY_SYSRQ
|
||||
};
|
||||
|
||||
enum lw35ioc_state {SYNC, TYPE, KEYBOARD, PRINTER};
|
||||
|
||||
struct lw35ioc_packet {
|
||||
enum lw35ioc_state state;
|
||||
};
|
||||
|
||||
struct lw35ioc_priv {
|
||||
struct serdev_device *serdev;
|
||||
struct input_dev *input_dev;
|
||||
|
||||
// USER VARS HERE
|
||||
struct lw35ioc_packet packet;
|
||||
};
|
||||
|
||||
static int lw35ioc_receive_buf(struct serdev_device *serdev,
|
||||
const unsigned char *data,
|
||||
size_t count)
|
||||
const unsigned char *data,
|
||||
size_t count)
|
||||
{
|
||||
dev_info(&serdev->dev, "RX: %c\n", data[0]);
|
||||
return 1; // TODO: return proper value
|
||||
struct lw35ioc_priv *priv = serdev_device_get_drvdata(serdev);
|
||||
unsigned char c;
|
||||
int ev;
|
||||
int i;
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
dev_info(&serdev->dev, "IRQ.\n");
|
||||
#endif
|
||||
for (i = 0; i < count; ++i) {
|
||||
c = data[i];
|
||||
#ifdef ENABLE_DEBUG
|
||||
dev_info(&serdev->dev, " RX [%d]: %02x\n", priv->packet.state, c);
|
||||
#endif
|
||||
switch (priv->packet.state) {
|
||||
case SYNC:
|
||||
if (c == 0xFF)
|
||||
priv->packet.state = TYPE;
|
||||
break;
|
||||
case TYPE:
|
||||
if (c == 0x55)
|
||||
priv->packet.state = KEYBOARD;
|
||||
else if (c == 0xAA)
|
||||
priv->packet.state = PRINTER;
|
||||
else
|
||||
priv->packet.state = SYNC;
|
||||
break;
|
||||
case KEYBOARD:
|
||||
if (c > 127) {
|
||||
c -= 128;
|
||||
ev = 1;
|
||||
} else {
|
||||
ev = 0;
|
||||
}
|
||||
input_report_key(priv->input_dev, c, ev);
|
||||
input_sync(priv->input_dev);
|
||||
priv->packet.state = SYNC;
|
||||
break;
|
||||
case PRINTER:
|
||||
dev_info(&serdev->dev, "Printer not yet implemented.\n");
|
||||
priv->packet.state = SYNC;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
static void lw35ioc_write_wakeup(struct serdev_device *serdev)
|
||||
@ -51,39 +122,70 @@ static int lw35ioc_probe(struct serdev_device *serdev)
|
||||
{
|
||||
struct lw35ioc_priv *priv = NULL;
|
||||
int ret;
|
||||
int i;
|
||||
u32 speed = 9600;
|
||||
struct input_dev *input_dev;
|
||||
|
||||
printk(KERN_INFO "lw35ioc: probe\n");
|
||||
|
||||
priv = devm_kzalloc(&serdev->dev,
|
||||
sizeof(struct lw35ioc_priv),
|
||||
GFP_KERNEL);
|
||||
if (!priv)
|
||||
return -ENOMEM;
|
||||
priv = devm_kzalloc(&serdev->dev,
|
||||
sizeof(struct lw35ioc_priv),
|
||||
GFP_KERNEL);
|
||||
if (!priv) {
|
||||
printk(KERN_ERR "lw35ioc: Not enough memory.\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
priv->serdev = serdev;
|
||||
priv->packet.state = SYNC;
|
||||
serdev_device_set_drvdata(serdev, priv);
|
||||
serdev_device_set_client_ops(serdev, &lw35ioc_serdev_ops);
|
||||
|
||||
input_dev = devm_input_allocate_device(&serdev->dev);
|
||||
if (!input_dev) {
|
||||
dev_err(&serdev->dev, "Unable to allocate input device.\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
priv->input_dev = input_dev;
|
||||
input_dev->name = "lw35ioc";
|
||||
input_dev->phys = "lw35ioc/input1";
|
||||
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
|
||||
__set_bit(EV_KEY, input_dev->evbit);
|
||||
__set_bit(EV_REP, input_dev->evbit);
|
||||
for (i = 0; i < ARRAY_SIZE(keycode_map); i++)
|
||||
__set_bit(keycode_map[i], input_dev->keybit);
|
||||
ret = input_register_device(input_dev);
|
||||
if (ret) {
|
||||
dev_err(&serdev->dev, "Unable to register input device.\n");
|
||||
goto fail0;
|
||||
}
|
||||
|
||||
ret = serdev_device_open(serdev);
|
||||
if (ret) {
|
||||
dev_err(&serdev->dev, "Unable to open device.\n");
|
||||
goto fail0;
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
speed = serdev_device_set_baudrate(serdev, speed);
|
||||
dev_info(&serdev->dev, "Using baudrate: %u\n", speed);
|
||||
|
||||
dev_info(&serdev->dev, "Loaded driver\n");
|
||||
dev_info(&serdev->dev, "Loaded driver.\n");
|
||||
|
||||
return 0;
|
||||
|
||||
fail1:
|
||||
input_unregister_device(input_dev);
|
||||
fail0:
|
||||
devm_kfree(&serdev->dev, input_dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void lw35ioc_remove(struct serdev_device *serdev)
|
||||
{
|
||||
struct lw35ioc_priv *priv = serdev_device_get_drvdata(serdev);
|
||||
|
||||
serdev_device_close(priv->serdev);
|
||||
input_unregister_device(priv->input_dev);
|
||||
|
||||
dev_info(&serdev->dev, "remove\n");
|
||||
return;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@
|
||||
#define KEY_COMPOSE 127
|
||||
|
||||
#define SKEY_FN 255
|
||||
#define KEYCODE_FN 127
|
||||
// #define KEYCODE_FN 127
|
||||
|
||||
/*
|
||||
* Special keys:
|
||||
@ -196,23 +196,35 @@ uint8_t matrix_state_last_vector[9] = {0xFF, 0xFF, 0xFF, 0xFF,
|
||||
|
||||
uint8_t fn_active = 0;
|
||||
|
||||
void uart_putc(char c)
|
||||
{
|
||||
while (!(UCSRA & (1 << UDRE)));
|
||||
UDR = c;
|
||||
}
|
||||
|
||||
void process_key_event(uint8_t col, uint8_t row, uint8_t state)
|
||||
{
|
||||
char c;
|
||||
uint8_t keycode;
|
||||
int event = 0;
|
||||
|
||||
keycode = keycode_translation_matrix[fn_active][col][row];
|
||||
|
||||
if (keycode == SKEY_FN) {
|
||||
fn_active = state;
|
||||
#ifdef KEYCODE_FN
|
||||
while (!(UCSRA & (1 << UDRE)));
|
||||
UDR = KEYCODE_FN | (state << 7);
|
||||
c = KEYCODE_FN | (state << 7);
|
||||
event = 1;
|
||||
#endif
|
||||
} else {
|
||||
c = keycode | (state << 7);
|
||||
while (!(UCSRA & (1 << UDRE)));
|
||||
UDR = c;
|
||||
event = 1;
|
||||
}
|
||||
|
||||
if (event) {
|
||||
uart_putc(0xFF);
|
||||
uart_putc(0x55);
|
||||
uart_putc(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user