2012-05-19 14:09:46 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 by Amaury Pouly
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "system.h"
|
2016-05-30 15:24:38 +00:00
|
|
|
#include "tick.h"
|
2014-02-22 19:36:27 +00:00
|
|
|
#include "button-imx233.h"
|
2016-05-30 15:24:38 +00:00
|
|
|
#include "mpr121-zenxfi3.h"
|
2012-05-19 14:09:46 +00:00
|
|
|
|
2014-02-22 19:36:27 +00:00
|
|
|
#define I_VDDIO 0 /* index in the table */
|
|
|
|
|
|
|
|
struct imx233_button_map_t imx233_button_map[] =
|
|
|
|
{
|
|
|
|
[I_VDDIO] = IMX233_BUTTON_(VDDIO, VDDIO(3640), "vddio"), /* we need VDDIO for relative */
|
2016-05-28 14:40:04 +00:00
|
|
|
IMX233_BUTTON_(HOLD, GPIO(0, 4), "hold", INVERTED),
|
2014-02-22 19:36:27 +00:00
|
|
|
IMX233_BUTTON(VOL_DOWN, GPIO(2, 7), "vol_down", INVERTED),
|
|
|
|
IMX233_BUTTON(VOL_UP, GPIO(2, 8), "vol_up", INVERTED),
|
2016-05-28 14:40:04 +00:00
|
|
|
IMX233_BUTTON_(JACK, LRADC_EX(5, GT, 2000, I_VDDIO, 0), "jack"),
|
2014-02-22 19:36:27 +00:00
|
|
|
IMX233_BUTTON(POWER, PSWITCH(1), "power"),
|
|
|
|
IMX233_BUTTON_(END, END(), "")
|
|
|
|
};
|
|
|
|
|
2016-05-30 15:24:38 +00:00
|
|
|
/* MPR121 configuration, mostly extracted from OF */
|
|
|
|
static struct mpr121_config_t mpr121_config =
|
2012-05-19 14:09:46 +00:00
|
|
|
{
|
|
|
|
.ele =
|
|
|
|
{
|
|
|
|
[0] = {.tth = 5, .rth = 4 },
|
|
|
|
[1] = {.tth = 5, .rth = 4 },
|
|
|
|
[2] = {.tth = 5, .rth = 4 },
|
|
|
|
[3] = {.tth = 5, .rth = 4 },
|
|
|
|
[4] = {.tth = 4, .rth = 3 },
|
|
|
|
[5] = {.tth = 4, .rth = 3 },
|
|
|
|
[6] = {.tth = 5, .rth = 4 },
|
|
|
|
[7] = {.tth = 5, .rth = 4 },
|
|
|
|
[8] = {.gpio = ELE_GPIO_OUTPUT_OPEN_LED },
|
|
|
|
},
|
|
|
|
.filters =
|
|
|
|
{
|
|
|
|
.ele =
|
|
|
|
{
|
|
|
|
.rising = {.mhd = 1, .nhd = 1, .ncl = 1, .fdl = 1 },
|
|
|
|
.falling = {.mhd = 1, .nhd = 1, .ncl = 0xff, .fdl = 2 },
|
|
|
|
}
|
|
|
|
},
|
|
|
|
.autoconf =
|
|
|
|
{
|
|
|
|
.en = true, .ren = true, .retry = RETRY_NEVER,
|
|
|
|
.usl = 0xc4, .lsl = 0x7f, .tl = 0xb0
|
|
|
|
},
|
|
|
|
.ele_en = ELE_EN0_x(7),
|
|
|
|
.cal_lock = CL_TRACK
|
|
|
|
};
|
|
|
|
|
|
|
|
/* B0P18 is #IRQ line of the touchpad */
|
|
|
|
void button_init_device(void)
|
|
|
|
{
|
2016-05-30 15:24:38 +00:00
|
|
|
mpr121_init();
|
|
|
|
mpr121_set_config(&mpr121_config);
|
2014-02-22 19:36:27 +00:00
|
|
|
/* generic part */
|
|
|
|
imx233_button_init();
|
2012-05-19 14:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int button_read_device(void)
|
|
|
|
{
|
|
|
|
/* since sliding hold will usually trigger power, ignore power button
|
|
|
|
* for one second after hold is released */
|
|
|
|
static int power_ignore_counter = 0;
|
|
|
|
static bool old_hold;
|
|
|
|
bool hold = button_hold();
|
|
|
|
if(hold != old_hold)
|
|
|
|
{
|
|
|
|
old_hold = hold;
|
|
|
|
if(!hold)
|
|
|
|
power_ignore_counter = HZ;
|
|
|
|
}
|
2016-05-30 15:24:38 +00:00
|
|
|
/* interpret touchpad status */
|
|
|
|
unsigned status = mpr121_get_touch_status();
|
|
|
|
unsigned touchpad_btns = 0;
|
|
|
|
/* ELE3: up
|
|
|
|
* ELE4: back
|
|
|
|
* ELE5: menu
|
|
|
|
* ELE6: down
|
|
|
|
* ELE7: play */
|
|
|
|
if(status & 0x8) touchpad_btns |= BUTTON_UP;
|
|
|
|
if(status & 0x10) touchpad_btns |= BUTTON_BACK;
|
|
|
|
if(status & 0x20) touchpad_btns |= BUTTON_MENU;
|
|
|
|
if(status & 0x40) touchpad_btns |= BUTTON_DOWN;
|
|
|
|
if(status & 0x80) touchpad_btns |= BUTTON_PLAY;
|
|
|
|
/* feed it to generic code */
|
2014-02-22 19:36:27 +00:00
|
|
|
int res = imx233_button_read(touchpad_btns);
|
2014-03-22 15:03:12 +00:00
|
|
|
if(power_ignore_counter > 0)
|
|
|
|
{
|
2012-05-19 14:09:46 +00:00
|
|
|
power_ignore_counter--;
|
2014-03-22 15:03:12 +00:00
|
|
|
res &= ~BUTTON_POWER;
|
|
|
|
}
|
2014-02-22 20:22:45 +00:00
|
|
|
return res;
|
2012-05-19 14:09:46 +00:00
|
|
|
}
|