diff options
author | Jack Halpin <jack.halpin@gmail.com> | 2010-02-15 19:29:47 +0000 |
---|---|---|
committer | Jack Halpin <jack.halpin@gmail.com> | 2010-02-15 19:29:47 +0000 |
commit | 3a60a6aa23fd441b6405b424cf311c1d765584cc (patch) | |
tree | eda7a07aea05a84fa1786188b8657768f8670c06 | |
parent | 51a8be1a0f11d329af99bf9c33a61af11d7a43ed (diff) | |
download | rockbox-3a60a6aa23fd441b6405b424cf311c1d765584cc.tar.gz rockbox-3a60a6aa23fd441b6405b424cf311c1d765584cc.zip |
Sansa Clip+: Implement button driver.
Initial button driver for clip+. I've followed the steps the OF uses to read the buttons.
There is no hold button on the clip+ so for now calling button_hold() siply returns false.
The OF actually sets an additional flag for the 2nd read from D6 and not BUTTON_POWER as I have done here.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24669 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | firmware/target/arm/as3525/sansa-clipplus/button-clip.c | 74 |
1 files changed, 73 insertions, 1 deletions
diff --git a/firmware/target/arm/as3525/sansa-clipplus/button-clip.c b/firmware/target/arm/as3525/sansa-clipplus/button-clip.c index 52917cca6f..9365c4a940 100644 --- a/firmware/target/arm/as3525/sansa-clipplus/button-clip.c +++ b/firmware/target/arm/as3525/sansa-clipplus/button-clip.c | |||
@@ -27,7 +27,79 @@ void button_init_device(void) | |||
27 | { | 27 | { |
28 | } | 28 | } |
29 | 29 | ||
30 | bool button_hold(void) | ||
31 | { | ||
32 | /* TODO OF uses long home(A1) press. Just return false for now */ | ||
33 | return false; | ||
34 | } | ||
35 | |||
30 | int button_read_device(void) | 36 | int button_read_device(void) |
31 | { | 37 | { |
32 | return 0; | 38 | static int buttons = 0; |
39 | |||
40 | /* Set pins to input for reading buttons */ | ||
41 | GPIOC_DIR = 0; /* All C pins input */ | ||
42 | GPIOA_DIR &= ~(1<<1|1<<6|1<<7); /* Pins A1,A6,A7 input */ | ||
43 | /* OF does not set D6 to input */ | ||
44 | |||
45 | /* TODO No hold button Hold toggled by long home(A1) press in OF */ | ||
46 | if(button_hold()) | ||
47 | { | ||
48 | return 0; | ||
49 | } | ||
50 | /* Buttons do not appear to need reset */ | ||
51 | /* D6 needs special handling though */ | ||
52 | |||
53 | GPIOB_DIR |= (1<<0); /* Pin B0 set output */ | ||
54 | GPIOB_PIN(0) = 1; /* set B0 */ | ||
55 | |||
56 | int delay = 500; | ||
57 | do { | ||
58 | asm volatile("nop\n"); | ||
59 | } while (delay--); | ||
60 | |||
61 | if GPIOD_PIN(6) /* read D6 */ | ||
62 | buttons |= BUTTON_POWER; | ||
63 | |||
64 | GPIOB_PIN(0) = 0; /* unset B0 */ | ||
65 | |||
66 | delay = 240; | ||
67 | do { | ||
68 | asm volatile("nop\n"); | ||
69 | } while (delay--); | ||
70 | |||
71 | if GPIOA_PIN(1) | ||
72 | buttons |= BUTTON_HOME; | ||
73 | if GPIOA_PIN(6) | ||
74 | buttons |= BUTTON_VOL_DOWN; | ||
75 | if GPIOA_PIN(7) | ||
76 | buttons |= BUTTON_VOL_UP; | ||
77 | if GPIOC_PIN(2) | ||
78 | buttons |= BUTTON_UP; | ||
79 | if GPIOC_PIN(3) | ||
80 | buttons |= BUTTON_LEFT; | ||
81 | if GPIOC_PIN(4) | ||
82 | buttons |= BUTTON_SELECT; | ||
83 | if GPIOC_PIN(5) | ||
84 | buttons |= BUTTON_RIGHT; | ||
85 | if GPIOC_PIN(1) | ||
86 | buttons |= BUTTON_DOWN; | ||
87 | |||
88 | /* TODO figure out why OF does this */ | ||
89 | if (buttons & BUTTON_POWER) | ||
90 | { | ||
91 | GPIOB_DIR |= (1<<6); /* Pin B6 output */ | ||
92 | |||
93 | delay = 8; | ||
94 | do { | ||
95 | asm volatile("nop\n"); | ||
96 | } while (delay--); | ||
97 | |||
98 | if GPIOD_PIN(6) | ||
99 | buttons |= BUTTON_POWER; /* OF sets a different flag than PWR */ | ||
100 | } | ||
101 | |||
102 | return buttons; | ||
33 | } | 103 | } |
104 | |||
105 | |||