diff options
Diffstat (limited to 'firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c')
-rw-r--r-- | firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c | 85 |
1 files changed, 54 insertions, 31 deletions
diff --git a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c index 86a6eb0c73..d3504c97e9 100644 --- a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c +++ b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c | |||
@@ -19,47 +19,70 @@ | |||
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | 21 | ||
22 | /* Taken from button-h10.c by Barry Wardell and reverse engineering by MrH. */ | ||
23 | |||
24 | #include "system.h" | 22 | #include "system.h" |
23 | #include "button-target.h" | ||
25 | #include "button.h" | 24 | #include "button.h" |
26 | #include "backlight.h" | 25 | #include "backlight.h" |
27 | #include "powermgmt.h" | 26 | #include "powermgmt.h" |
28 | 27 | ||
29 | 28 | ||
30 | #ifndef BOOTLOADER | 29 | unsigned short _dbop_din = 0; |
31 | /* Buttons */ | 30 | |
31 | /* in the lcd driver */ | ||
32 | extern bool lcd_button_support(void); | ||
33 | |||
32 | static bool hold_button = false; | 34 | static bool hold_button = false; |
35 | #ifndef BOOTLOADER | ||
33 | static bool hold_button_old = false; | 36 | static bool hold_button_old = false; |
34 | #define _button_hold() hold_button | 37 | #endif |
35 | #else | ||
36 | #define _button_hold() false /* FIXME */ | ||
37 | #endif /* BOOTLOADER */ | ||
38 | static int int_btn = BUTTON_NONE; | ||
39 | 38 | ||
40 | void button_init_device(void) | 39 | void button_init_device(void) |
41 | { | 40 | { |
41 | GPIOA_DIR &= ~(1<<3); | ||
42 | } | 42 | } |
43 | 43 | ||
44 | bool button_hold(void) | 44 | bool button_hold(void) |
45 | { | 45 | { |
46 | return _button_hold(); | 46 | return hold_button; |
47 | } | ||
48 | |||
49 | static void button_read_dbop(void) | ||
50 | { | ||
51 | /* Set up dbop for input */ | ||
52 | DBOP_CTRL |= (1<<19); /* Tri-state DBOP on read cycle */ | ||
53 | DBOP_CTRL &= ~(1<<16); /* disable output (1:write enabled) */ | ||
54 | DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ | ||
55 | DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ | ||
56 | |||
57 | int i = 50; | ||
58 | while(i--) asm volatile ("nop\n"); | ||
59 | |||
60 | DBOP_CTRL |= (1<<15); /* start read */ | ||
61 | while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ | ||
62 | |||
63 | _dbop_din = DBOP_DIN; /* Read dbop data*/ | ||
64 | |||
65 | /* Reset dbop for output */ | ||
66 | DBOP_TIMPOL_01 = 0x6e167; /* Set Timing & Polarity regs 0 & 1 */ | ||
67 | DBOP_TIMPOL_23 = 0xa167e06f; /* Set Timing & Polarity regs 2 & 3 */ | ||
68 | DBOP_CTRL |= (1<<16); /* Enable output (0:write disable) */ | ||
69 | DBOP_CTRL &= ~(1<<19); /* Tri-state when no active write */ | ||
47 | } | 70 | } |
48 | 71 | ||
49 | /* device buttons */ | 72 | /* |
50 | void button_int(void) | 73 | * Get button pressed from hardware |
74 | */ | ||
75 | int button_read_device(void) | ||
51 | { | 76 | { |
52 | int delay = 0x50; | 77 | int delay; |
53 | int dir_save_c = 0; | 78 | int dir_save_c = 0; |
54 | int afsel_save_c = 0; | 79 | int afsel_save_c = 0; |
55 | 80 | int btn = BUTTON_NONE; | |
56 | int_btn = BUTTON_NONE; | ||
57 | 81 | ||
58 | /* Save the current direction and afsel */ | 82 | /* Save the current direction and afsel */ |
59 | dir_save_c = GPIOC_DIR; | 83 | dir_save_c = GPIOC_DIR; |
60 | afsel_save_c = GPIOC_AFSEL; | 84 | afsel_save_c = GPIOC_AFSEL; |
61 | 85 | ||
62 | GPIOA_DIR &= ~(1<<3); | ||
63 | GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3); | 86 | GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3); |
64 | GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3); | 87 | GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3); |
65 | 88 | ||
@@ -72,32 +95,32 @@ void button_int(void) | |||
72 | GPIOC_PIN(3) = (1<<3); | 95 | GPIOC_PIN(3) = (1<<3); |
73 | GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3); | 96 | GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3); |
74 | 97 | ||
75 | while(delay--); | 98 | delay = 100; |
99 | while(delay--) | ||
100 | asm volatile("nop\n"); | ||
76 | 101 | ||
77 | /* direct GPIO connections */ | 102 | /* direct GPIO connections */ |
78 | if (GPIOA_PIN(3)) | 103 | if (GPIOA_PIN(3)) |
79 | int_btn |= BUTTON_POWER; | 104 | btn |= BUTTON_POWER; |
80 | if (!GPIOC_PIN(6)) | 105 | if (!GPIOC_PIN(6)) |
81 | int_btn |= BUTTON_RIGHT; | 106 | btn |= BUTTON_RIGHT; |
82 | if (!GPIOC_PIN(5)) | 107 | if (!GPIOC_PIN(5)) |
83 | int_btn |= BUTTON_UP; | 108 | btn |= BUTTON_UP; |
84 | if (!GPIOC_PIN(4)) | 109 | if (!GPIOC_PIN(4)) |
85 | int_btn |= BUTTON_SELECT; | 110 | btn |= BUTTON_SELECT; |
86 | if (!GPIOC_PIN(3)) | 111 | if (!GPIOC_PIN(3)) |
87 | int_btn |= BUTTON_DOWN; | 112 | btn |= BUTTON_DOWN; |
88 | 113 | ||
89 | /* return to settings needed for lcd */ | 114 | /* return to settings needed for lcd */ |
90 | GPIOC_DIR = dir_save_c; | 115 | GPIOC_DIR = dir_save_c; |
91 | GPIOC_AFSEL = afsel_save_c; | 116 | GPIOC_AFSEL = afsel_save_c; |
92 | } | ||
93 | 117 | ||
94 | /* | 118 | if(lcd_button_support()) |
95 | * Get button pressed from hardware | 119 | button_read_dbop(); |
96 | */ | 120 | |
97 | int button_read_device(void) | 121 | if(_dbop_din & (1<<6)) |
98 | { | 122 | btn |= BUTTON_LEFT; |
99 | /* Read buttons directly */ | 123 | |
100 | button_int(); | ||
101 | #ifndef BOOTLOADER | 124 | #ifndef BOOTLOADER |
102 | /* light handling */ | 125 | /* light handling */ |
103 | if (hold_button != hold_button_old) | 126 | if (hold_button != hold_button_old) |
@@ -107,5 +130,5 @@ int button_read_device(void) | |||
107 | } | 130 | } |
108 | #endif /* BOOTLOADER */ | 131 | #endif /* BOOTLOADER */ |
109 | 132 | ||
110 | return int_btn; | 133 | return btn; |
111 | } | 134 | } |