diff options
author | Amaury Pouly <amaury.pouly@gmail.com> | 2016-05-02 21:21:44 +0100 |
---|---|---|
committer | Amaury Pouly <amaury.pouly@gmail.com> | 2016-05-28 17:09:19 +0200 |
commit | 9fe854e7825fd25a3cd5c6dd02c449b77d236d41 (patch) | |
tree | 1ddf6711c2083af4ecda8e0b7355df9b4bf5e8ef /firmware/target/arm/imx233/button-imx233.c | |
parent | 030a9da0d7963200d3e9c687f5ac72e802a48da4 (diff) | |
download | rockbox-9fe854e7825fd25a3cd5c6dd02c449b77d236d41.tar.gz rockbox-9fe854e7825fd25a3cd5c6dd02c449b77d236d41.zip |
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
Diffstat (limited to 'firmware/target/arm/imx233/button-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/button-imx233.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/firmware/target/arm/imx233/button-imx233.c b/firmware/target/arm/imx233/button-imx233.c index 4ebba41ad3..a77d3d76c9 100644 --- a/firmware/target/arm/imx233/button-imx233.c +++ b/firmware/target/arm/imx233/button-imx233.c @@ -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); -}
\ No newline at end of file +} |