===================== headset.h =====================
/*
* Copyright (C) 2012 Spreadtrum Communications Inc.
* filename: headset.h
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __HEADSET_H__
#define __HEADSET_H__
enum {
BIT_HEADSET_OUT = 0,
BIT_HEADSET_MIC = (1 << 0),
BIT_HEADSET_NO_MIC = (1 << 1),
};
struct _headset_gpio {
int active_low;
int gpio;
int irq;
unsigned int irq_type_active;
unsigned int irq_type_inactive;
int debounce;
int debounce_sw;
int holded;
int active;
int irq_enabled;
const char *desc;
struct _headset *parent;
unsigned int timeout_ms;
struct hrtimer timer;
enum hrtimer_restart (*callback)(int active, struct _headset_gpio *hgp);
};
struct _headset {
struct switch_dev sdev;
struct input_dev *input;
struct _headset_gpio detect;
struct _headset_gpio button;
int headphone;
};
#endif
===================== headset.c =====================
/*
* Copyright (C) 2012 Spreadtrum Communications Inc.
* filename: headset.c
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/delay.h>
#include <linux/switch.h>
#include <linux/input.h>
#include <mach/gpio.h>
#include "headset.h"
#include <mach/board.h>
#define HEADSET_WITH_EIC
#ifdef HEADSET_WITH_EIC
#include <mach/eic.h>
#define HEADSET_DETECT_GPIO EIC_ID_13
#define HEADSET_BUTTON_GPIO EIC_ID_12
#define headset_gpio_init(gpio, desc) { }
#define headset_gpio_free(gpio) { }
#define headset_gpio2irq_free(irq, args) \
sprd_free_eic_irq(irq)
#define headset_gpio2irq(gpio) \
sprd_alloc_eic_irq(gpio)
#define headset_gpio_set_irq_type(irq, type) \
set_irq_type(irq, type)
#define headset_gpio_get_value(gpio) \

这篇博客详细介绍了在Linux环境下,针对展讯8810平台如何实现耳机插入检测和耳机上的按键识别的驱动程序。包括`headset.h`和`headset.c`两个文件,涉及GPIO、中断处理、定时器等技术,用于识别耳机插入状态和按键事件。
最低0.47元/天 解锁文章
3195





