实现功能:GPIO键值及其状态在另一个模块响应
gpio_keys.c
#include
#ifdef DEBUG
#define dbg_printk(fmt, args...) \
printk(TAG " %s;%d " fmt , __FUNCTION__, __LINE__, ## args);
#else
#define dbg_printk(fmt, args...)
#endif
static RAW_NOTIFIER_HEAD(KEY_NOTIFIER);
int register_key_notifier(struct notifier_block *nb)
{
return raw_notifier_chain_register(&KEY_NOTIFIER, nb);
}
EXPORT_SYMBOL(register_key_notifier);
int unregister_key_notifier(struct notifier_block *nb)
{
return raw_notifier_chain_unregister(&KEY_NOTIFIER, nb);
}
EXPORT_SYMBOL(unregister_key_notifier);
static int key_notifier_call_chain(unsigned long val, void *v)
{
return raw_notifier_call_chain(&KEY_NOTIFIER, val, v);
}
gpio key_down:
key_notifier_call_chain(button->code,"down");
gpio_key_up:
key_notifier_call_chain(0,"up");
xxx.c
#include
extern int register_key_notifier(struct notifier_block *nb);
extern int unregister_key_notifier(struct notifier_block *nb);
static void key_state_response(struct notifier_block *, unsigned long , void *);
static struct notifier_block key_detect_notifier =
{
.notifier_call = key_state_response,
};
void key_state_response(struct notifier_block *key_block, unsigned long keyval, void *v)
{
if(keyval == KEY_POWER)
{
printk("key power %s\n",v);
}
else if(keyval == KEY_VOLUMEUP)
{
printk("key volumeup %s\n",v);
}
else if(keyval == KEY_VOLUMEDOWN)
{
printk("key volumedown %s\n",v);
}
else
{
printk("key %s\n",v);
}
}
register_key_notifier(&key_detect_notifier);
unregister_key_notifier(&key_detect_notifier);
阅读(784) | 评论(0) | 转发(0) |