summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-03-29 23:03:06 +0000
committerThomas Martitz <kugel@rockbox.org>2010-03-29 23:03:06 +0000
commit71393c701c319e7b78ee81b6a8f0cc9830e88e2a (patch)
tree928f45da8e69436a5f74cd014f68b410e0a8d1fc
parenta4c68705593aa89752a8e913e83d17b7f5520f78 (diff)
downloadrockbox-71393c701c319e7b78ee81b6a8f0cc9830e88e2a.tar.gz
rockbox-71393c701c319e7b78ee81b6a8f0cc9830e88e2a.zip
Fuzev2: Preliminary button support. Scrollwheel does not work yet.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25392 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c94
1 files changed, 92 insertions, 2 deletions
diff --git a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c b/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c
index 287e159e53..5bd8afebc1 100644
--- a/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c
+++ b/firmware/target/arm/as3525/sansa-fuzev2/button-fuzev2.c
@@ -22,7 +22,15 @@
22#include "config.h" 22#include "config.h"
23#include "system.h" 23#include "system.h"
24#include "button.h" 24#include "button.h"
25#include "backlight.h"
25 26
27/*
28 * TODO: Scrollwheel!
29 */
30
31#ifdef HAS_BUTTON_HOLD
32static bool hold_button = false;
33#endif
26void button_init_device(void) 34void button_init_device(void)
27{ 35{
28} 36}
@@ -30,12 +38,94 @@ void button_init_device(void)
30/* 38/*
31 * Get button pressed from hardware 39 * Get button pressed from hardware
32 */ 40 */
41
33int button_read_device(void) 42int button_read_device(void)
34{ 43{
35 return 0; 44 int btn = 0;
45 volatile int delay;
46 static bool hold_button_old = false;
47 static long power_counter = 0;
48 unsigned gpiod = GPIOD_DATA;
49 unsigned gpioa_dir = GPIOA_DIR;
50 unsigned gpiod6;
51 for(delay = 500; delay; delay--) nop;
52 CCU_IO &= ~(1<<12);
53 for(delay=8;delay;delay--) nop;
54 GPIOB_DIR |= 1<<3;
55 GPIOB_PIN(3) = 1<<3;
56 GPIOC_DIR = 0;
57 GPIOB_DIR &= ~(1<<1);
58 GPIOB_DIR |= 1<<0;
59 GPIOB_PIN(0) = 1;
60 for(delay = 500; delay; delay--)
61 nop;
62 gpiod6 = GPIOD_PIN(6);
63 GPIOB_PIN(0) = 0;
64 for(delay = 240; delay; delay--)
65 nop;
66 GPIOD_DIR = 0xff;
67 GPIOA_DIR &= ~(1<<6|1<<7);
68 GPIOD_DATA = 0;
69 GPIOD_DIR = 0;
70 if (GPIOC_PIN(1) & 1<<1)
71 btn |= BUTTON_DOWN;
72 if (GPIOC_PIN(2) & 1<<2)
73 btn |= BUTTON_UP;
74 if (GPIOC_PIN(3) & 1<<3)
75 btn |= BUTTON_LEFT;
76 if (GPIOC_PIN(4) & 1<<4)
77 btn |= BUTTON_SELECT;
78 if (GPIOC_PIN(5) & 1<<5)
79 btn |= BUTTON_RIGHT;
80 if (GPIOB_PIN(1) & 1<<1)
81 btn |= BUTTON_HOME;
82 if (gpiod6 & 1<<6)
83 { /* power/hold is on the same pin. we know it's hold if the bit isn't
84 * set now anymore */
85 if (GPIOD_PIN(6) & 1<<6)
86 {
87 hold_button = false;
88 btn |= BUTTON_POWER;
89 }
90 else
91 {
92 hold_button = true;
93 }
94 }
95
96 GPIOD_DIR = 0xff;
97 GPIOD_DATA = gpiod;
98 GPIOA_DIR = gpioa_dir;
99 GPIOD_DIR = 0;
100 CCU_IO |= 1<<12;
101#ifdef HAS_BUTTON_HOLD
102 /* light handling */
103 if (hold_button != hold_button_old)
104 {
105 hold_button_old = hold_button;
106 backlight_hold_changed(hold_button);
107 }
108 if (hold_button)
109 {
110 power_counter = HZ;
111 return 0;
112 }
113 /* read power, but not if hold button was just released, since
114 * you basically always hit power due to the slider mechanism after releasing
115 * (fuze only)
116 */
117 else if (power_counter > 0)
118 {
119 power_counter--;
120 btn &= ~BUTTON_POWER;
121 }
122#endif
123 return btn;
36} 124}
37 125
126#ifdef HAS_BUTTON_HOLD
38bool button_hold(void) 127bool button_hold(void)
39{ 128{
40 return false; 129 return hold_button;
41} 130}
131#endif