diff options
author | Andrew Ryabinin <ryabinin.a.a@gmail.com> | 2012-03-23 22:09:20 +0400 |
---|---|---|
committer | Andrew Ryabinin <ryabinin.a.a@gmail.com> | 2012-04-19 17:31:13 +0400 |
commit | 8187d8d5d158bef269048694fd6e65d89263cd42 (patch) | |
tree | e96b29053f82f930ccd8be12c0c013b6cf78778f | |
parent | 8361c1d901a86a16f3bfe22593f0314f8cf37249 (diff) |
hm60x: Use binary search in button driver.
Change-Id: I4abca66150c23ffb7cc27c4c5320b8117c27e228
-rw-r--r-- | firmware/target/arm/rk27xx/hm60x/button-hm60x.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/firmware/target/arm/rk27xx/hm60x/button-hm60x.c b/firmware/target/arm/rk27xx/hm60x/button-hm60x.c index eaadaa131c..af31e78133 100644 --- a/firmware/target/arm/rk27xx/hm60x/button-hm60x.c +++ b/firmware/target/arm/rk27xx/hm60x/button-hm60x.c @@ -31,16 +31,26 @@ void button_init_device(void) { int button_read_device(void) { int adc_val = adc_read(ADC_BUTTONS); - if (adc_val < 30) { - return BUTTON_UP | (GPIO_PCDR & POWEROFF_BUTTON); - } else if (adc_val < 250) { - return BUTTON_RIGHT | (GPIO_PCDR & POWEROFF_BUTTON); - } else if (adc_val < 380) { - return BUTTON_LEFT | (GPIO_PCDR & POWEROFF_BUTTON); - } else if (adc_val < 450) { - return BUTTON_DOWN | (GPIO_PCDR & POWEROFF_BUTTON); - } else if (adc_val < 560) { - return BUTTON_PLAY | (GPIO_PCDR & POWEROFF_BUTTON); + int gpio_btn = GPIO_PCDR & BUTTON_POWER; + + if (adc_val < 380) { /* 0 - 379 */ + if (adc_val < 250) { /* 0 - 249 */ + if (adc_val < 30) { /* 0 - 29 */ + return BUTTON_UP | gpio_btn; + } else { /* 30 - 249 */ + return BUTTON_RIGHT | gpio_btn; + } + } else { /* 250 - 379 */ + return BUTTON_LEFT | gpio_btn; + } + } else { /* > 380 */ + if (adc_val < 460) { /* 380 - 459 */ + return BUTTON_DOWN | gpio_btn; + } else { /* > 460 */ + if (adc_val < 560) { + return BUTTON_SELECT | gpio_btn; + } + } } - return (GPIO_PCDR & POWEROFF_BUTTON); + return gpio_btn; } |