Commit 765db0a3 authored by 吴智聪(John Wu)'s avatar 吴智聪(John Wu)

clean up neuros_ir and neuros_ir_blaster code

parent 67fc7be9
......@@ -61,7 +61,8 @@
#define IR_RETRY_COUNT 3
#define FACTORY_TEST_DELAY 6
struct irrtc_device {
struct irrtc_device
{
int key;
};
static struct irrtc_device device;
......@@ -71,18 +72,18 @@ static wait_queue_head_t poll_queue;
static char *devname = "neuros_ir";
static struct input_dev *ir_input_dev;
static int factory_test=0;
static int osd_key=0;
static int is_learning=0;
static int factory_test = 0;
static int osd_key = 0;
static int is_learning = 0;
#if USE_WORKQUEUE
#define KEYBUF_SIZE 2
static int keybuf[KEYBUF_SIZE];
static int roffset=0;
static int woffset=0;
static int numOfKeys=0;
static int roffset = 0;
static int woffset = 0;
static int numOfKeys = 0;
#else
static int keyin=0;
static int keyin = 0;
#endif
static void irrtc_report_key(int ir_key);
......@@ -105,7 +106,7 @@ EXPORT_SYMBOL(unlock_data_protect);
static void set_factory_test(int value)
{
factory_test=value;
factory_test = value;
}
EXPORT_SYMBOL(set_factory_test);
......@@ -117,13 +118,13 @@ EXPORT_SYMBOL(get_osd_key);
static void set_osd_key(int value)
{
osd_key=value;
osd_key = value;
}
EXPORT_SYMBOL(set_osd_key);
static void set_is_learning(int value)
{
is_learning=value;
is_learning = value;
}
EXPORT_SYMBOL(set_is_learning);
......@@ -140,7 +141,7 @@ static int read_keybuf(void)
{
numOfKeys--;
key = keybuf[roffset];
if(++roffset >= KEYBUF_SIZE) roffset = 0;
if (++roffset >= KEYBUF_SIZE) roffset = 0;
}
up(&keybuf_sem);
......@@ -158,14 +159,14 @@ static void write_keybuf(int key)
// Display some more sober debug message on key presses but don't bother with key releases.
if (key != 0x00) printk("{IR:key:%02x}\n", key);
if(++numOfKeys > KEYBUF_SIZE)
if (++numOfKeys > KEYBUF_SIZE)
{
numOfKeys = KEYBUF_SIZE;
if(++roffset >= KEYBUF_SIZE) roffset = 0;
if (++roffset >= KEYBUF_SIZE) roffset = 0;
}
keybuf[woffset]=key;
if(++woffset >= KEYBUF_SIZE) woffset = 0;
keybuf[woffset] = key;
if (++woffset >= KEYBUF_SIZE) woffset = 0;
up(&keybuf_sem);
}
......@@ -224,7 +225,7 @@ static irqreturn_t handle_irrtc_irqs(int irq, void * dev_id)
set_factory_test(0);
}
#else
keyin=1;
keyin = 1;
#endif
return IRQ_HANDLED;
}
......@@ -273,31 +274,34 @@ static ssize_t irrtc_read(struct file *filp, char __user *buff, size_t count, lo
key = read_keybuf();
dbg("key=%d\n", key);
if (key!=-1) //none key
r=copy_to_user(buff, &key, sizeof(int));
if (key != -1) //none key
r = copy_to_user(buff, &key, sizeof(int));
else
count=0;
count = 0;
#else
if (-EINTR == down_interruptible(&keybuf_sem))
return 0;
if (count > KEYBUF_SIZE * sizeof(int)) {
if (count > KEYBUF_SIZE * sizeof(int))
{
if (roffset <= woffset)
count = (woffset - roffset) * sizeof(int);
else
count = (KEYBUF_SIZE - (roffset - woffset + 1)) * sizeof(int);
}
if (count == 0) {
if (count == 0)
{
printk("buffer empty\n");
goto out;
}
if (roffset < woffset)
r=copy_to_user(buff, keybuf + roffset, count);
else {
r=copy_to_user(buff, &keybuf[roffset], (KEYBUF_SIZE - roffset + 1) * sizeof(int));
r=copy_to_user(buff + (KEYBUF_SIZE - roffset + 1) * sizeof(int), keybuf, woffset * sizeof(int));
r = copy_to_user(buff, keybuf + roffset, count);
else
{
r = copy_to_user(buff, &keybuf[roffset], (KEYBUF_SIZE - roffset + 1) * sizeof(int));
r = copy_to_user(buff + (KEYBUF_SIZE - roffset + 1) * sizeof(int), keybuf, woffset * sizeof(int));
}
out:
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment