diff options
Diffstat (limited to 'firmware/target/arm/rk27xx/ihifi2/button-ihifi.c')
-rw-r--r-- | firmware/target/arm/rk27xx/ihifi2/button-ihifi.c | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c new file mode 100644 index 0000000000..172853a83a --- /dev/null +++ b/firmware/target/arm/rk27xx/ihifi2/button-ihifi.c | |||
@@ -0,0 +1,99 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2016 by Roman Stolyarov | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "button.h" | ||
26 | #include "adc.h" | ||
27 | #include "backlight.h" | ||
28 | |||
29 | static bool soft_hold = false; | ||
30 | #ifndef BOOTLOADER | ||
31 | static unsigned hold_counter = 0; | ||
32 | #ifndef IHIFI800 | ||
33 | #define HOLDBUTTON gpio_btn | ||
34 | #define HOLDCNTMAX HZ | ||
35 | #else | ||
36 | #define HOLDBUTTON (gpio_btn) && (adc_val > 325) && (adc_val < 480) | ||
37 | #define HOLDCNTMAX (HZ/10) | ||
38 | #endif | ||
39 | #endif | ||
40 | |||
41 | void button_init_device(void) { | ||
42 | GPIO_PCCON &= ~(1<<1); /* PWR BTN */ | ||
43 | GPIO_PCCON &= ~(1<<7); /* CD */ | ||
44 | } | ||
45 | |||
46 | bool button_hold(void) | ||
47 | { | ||
48 | return soft_hold; | ||
49 | } | ||
50 | |||
51 | int button_read_device(void) { | ||
52 | int adc_val = adc_read(ADC_BUTTONS); | ||
53 | int gpio_btn = GPIO_PCDR & (1<<1); | ||
54 | |||
55 | int button = BUTTON_NONE; | ||
56 | |||
57 | if (gpio_btn) | ||
58 | button |= BUTTON_POWER; | ||
59 | |||
60 | #ifndef BOOTLOADER | ||
61 | if (HOLDBUTTON) { | ||
62 | if (++hold_counter == HOLDCNTMAX) { | ||
63 | soft_hold = !soft_hold; | ||
64 | backlight_hold_changed(soft_hold); | ||
65 | } | ||
66 | } else { | ||
67 | hold_counter = 0; | ||
68 | } | ||
69 | if (soft_hold) { | ||
70 | return (hold_counter <= HOLDCNTMAX) ? BUTTON_NONE : button; | ||
71 | } | ||
72 | #endif | ||
73 | |||
74 | if (adc_val < 792) { | ||
75 | if (adc_val < 480) { | ||
76 | if (adc_val < 170) { | ||
77 | if (adc_val < 46) { | ||
78 | button |= BUTTON_HOME; // 0-45 | ||
79 | } else { | ||
80 | button |= BUTTON_PLAY; // 46-169 | ||
81 | } | ||
82 | } else { | ||
83 | if (adc_val < 325) { | ||
84 | button |= BUTTON_NEXT; // 170-324 | ||
85 | } else { | ||
86 | button |= BUTTON_VOL_UP;// 325-479 | ||
87 | } | ||
88 | } | ||
89 | } else { | ||
90 | if (adc_val < 636) { | ||
91 | button |= BUTTON_VOL_DOWN;// 480-635 | ||
92 | } else { | ||
93 | button |= BUTTON_PREV; // 636-791 | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | |||
98 | return button; | ||
99 | } | ||