diff options
Diffstat (limited to 'firmware/target/arm/as3525/sansa-c200v2')
-rw-r--r-- | firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c | 54 |
1 files changed, 15 insertions, 39 deletions
diff --git a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c index d3504c97e9..965006ce61 100644 --- a/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c +++ b/firmware/target/arm/as3525/sansa-c200v2/button-c200v2.c | |||
@@ -36,6 +36,12 @@ static bool hold_button = false; | |||
36 | static bool hold_button_old = false; | 36 | static bool hold_button_old = false; |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | /* for the debug menu */ | ||
40 | unsigned short button_dbop_data(void) | ||
41 | { | ||
42 | return _dbop_din; | ||
43 | } | ||
44 | |||
39 | void button_init_device(void) | 45 | void button_init_device(void) |
40 | { | 46 | { |
41 | GPIOA_DIR &= ~(1<<3); | 47 | GPIOA_DIR &= ~(1<<3); |
@@ -54,9 +60,6 @@ static void button_read_dbop(void) | |||
54 | DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ | 60 | DBOP_TIMPOL_01 = 0xe167e167; /* Set Timing & Polarity regs 0 & 1 */ |
55 | DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ | 61 | DBOP_TIMPOL_23 = 0xe167006e; /* Set Timing & Polarity regs 2 & 3 */ |
56 | 62 | ||
57 | int i = 50; | ||
58 | while(i--) asm volatile ("nop\n"); | ||
59 | |||
60 | DBOP_CTRL |= (1<<15); /* start read */ | 63 | DBOP_CTRL |= (1<<15); /* start read */ |
61 | while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ | 64 | while (!(DBOP_STAT & (1<<16))); /* wait for valid data */ |
62 | 65 | ||
@@ -74,52 +77,25 @@ static void button_read_dbop(void) | |||
74 | */ | 77 | */ |
75 | int button_read_device(void) | 78 | int button_read_device(void) |
76 | { | 79 | { |
77 | int delay; | ||
78 | int dir_save_c = 0; | ||
79 | int afsel_save_c = 0; | ||
80 | int btn = BUTTON_NONE; | 80 | int btn = BUTTON_NONE; |
81 | 81 | ||
82 | /* Save the current direction and afsel */ | ||
83 | dir_save_c = GPIOC_DIR; | ||
84 | afsel_save_c = GPIOC_AFSEL; | ||
85 | |||
86 | GPIOC_AFSEL &= ~(1<<6|1<<5|1<<4|1<<3); | ||
87 | GPIOC_DIR |= (1<<6|1<<5|1<<4|1<<3); | ||
88 | |||
89 | /* These should not be needed with button event interupts */ | ||
90 | /* they are necessary now to clear out lcd data */ | ||
91 | |||
92 | GPIOC_PIN(6) = (1<<6); | ||
93 | GPIOC_PIN(5) = (1<<5); | ||
94 | GPIOC_PIN(4) = (1<<4); | ||
95 | GPIOC_PIN(3) = (1<<3); | ||
96 | GPIOC_DIR &= ~(1<<6|1<<5|1<<4|1<<3); | ||
97 | |||
98 | delay = 100; | ||
99 | while(delay--) | ||
100 | asm volatile("nop\n"); | ||
101 | |||
102 | /* direct GPIO connections */ | 82 | /* direct GPIO connections */ |
103 | if (GPIOA_PIN(3)) | 83 | if (GPIOA_PIN(3)) |
104 | btn |= BUTTON_POWER; | 84 | btn |= BUTTON_POWER; |
105 | if (!GPIOC_PIN(6)) | ||
106 | btn |= BUTTON_RIGHT; | ||
107 | if (!GPIOC_PIN(5)) | ||
108 | btn |= BUTTON_UP; | ||
109 | if (!GPIOC_PIN(4)) | ||
110 | btn |= BUTTON_SELECT; | ||
111 | if (!GPIOC_PIN(3)) | ||
112 | btn |= BUTTON_DOWN; | ||
113 | |||
114 | /* return to settings needed for lcd */ | ||
115 | GPIOC_DIR = dir_save_c; | ||
116 | GPIOC_AFSEL = afsel_save_c; | ||
117 | 85 | ||
118 | if(lcd_button_support()) | 86 | if(lcd_button_support()) |
119 | button_read_dbop(); | 87 | button_read_dbop(); |
120 | 88 | ||
121 | if(_dbop_din & (1<<6)) | 89 | if(!(_dbop_din & (1<<2))) |
122 | btn |= BUTTON_LEFT; | 90 | btn |= BUTTON_LEFT; |
91 | if(!(_dbop_din & (1<<3))) | ||
92 | btn |= BUTTON_DOWN; | ||
93 | if(!(_dbop_din & (1<<4))) | ||
94 | btn |= BUTTON_SELECT; | ||
95 | if(!(_dbop_din & (1<<5))) | ||
96 | btn |= BUTTON_UP; | ||
97 | if(!(_dbop_din & (1<<6))) | ||
98 | btn |= BUTTON_RIGHT; | ||
123 | 99 | ||
124 | #ifndef BOOTLOADER | 100 | #ifndef BOOTLOADER |
125 | /* light handling */ | 101 | /* light handling */ |