mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 13:12:37 -05:00
imx233: enhance button driver adc handling
The current driver is limited to checking if the adc value equals another one with a hardcoded margin. This commit changes two aspects of that: - the margin can be changed globally using IMX233_BUTTON_LRADC_MARGIN and can also be overriden per button using the new LRADC_EX macro - the lradc logic gained two comparison modes to check if the source value is greater (or lower) than a threshold. Change-Id: If1614451dafeae818a96e6f23a84e6731331ba03
This commit is contained in:
parent
030a9da0d7
commit
9fe854e782
3 changed files with 80 additions and 22 deletions
|
|
@ -42,6 +42,11 @@ static int hold_idx = -1; /* index of hold button in map */
|
|||
static int jack_idx = -1; /* index of jack detect in map */
|
||||
#endif
|
||||
|
||||
/* LRADC margin for buttons */
|
||||
#ifndef IMX233_BUTTON_LRADC_MARGIN
|
||||
#define IMX233_BUTTON_LRADC_MARGIN 30
|
||||
#endif
|
||||
|
||||
/* shortcut of button map */
|
||||
#define MAP imx233_button_map
|
||||
|
||||
|
|
@ -89,7 +94,21 @@ static bool imx233_button_read_cooked(int idx)
|
|||
int rel = MAP[idx].u.lradc.relative;
|
||||
if(rel != -1)
|
||||
raw = (raw * MAP[rel].u.lradc.value) / imx233_button_read_raw(rel);
|
||||
res = abs(raw - MAP[idx].u.lradc.value) <= 30;
|
||||
switch(MAP[idx].u.lradc.op)
|
||||
{
|
||||
case IMX233_BUTTON_EQ:
|
||||
res = abs(raw - MAP[idx].u.lradc.value) <= MAP[idx].u.lradc.margin;
|
||||
break;
|
||||
case IMX233_BUTTON_GT:
|
||||
res = raw > MAP[idx].u.lradc.value;
|
||||
break;
|
||||
case IMX233_BUTTON_LT:
|
||||
res = raw < MAP[idx].u.lradc.value;
|
||||
break;
|
||||
default:
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(MAP[idx].periph == IMX233_BUTTON_PSWITCH)
|
||||
{
|
||||
|
|
@ -214,6 +233,9 @@ void imx233_button_init(void)
|
|||
}
|
||||
else if(MAP[i].periph == IMX233_BUTTON_LRADC)
|
||||
{
|
||||
/* use default value for margin */
|
||||
if(MAP[i].u.lradc.margin == 0)
|
||||
MAP[i].u.lradc.margin = IMX233_BUTTON_LRADC_MARGIN;
|
||||
int src = MAP[i].u.lradc.src;
|
||||
/* if channel was already acquired, there is nothing to do */
|
||||
if(src_mask & (1 << src))
|
||||
|
|
@ -258,4 +280,4 @@ void imx233_button_init(void)
|
|||
/* otherwise we need to regularly poll for other buttons */
|
||||
else
|
||||
tick_add_task(do_round);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue