summaryrefslogtreecommitdiff
path: root/firmware/target/arm
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm')
-rw-r--r--firmware/target/arm/as3525/debug-as3525.c15
-rw-r--r--firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c106
-rw-r--r--firmware/target/arm/as3525/system-as3525.c36
-rw-r--r--firmware/target/arm/as3525/system-target.h6
4 files changed, 145 insertions, 18 deletions
diff --git a/firmware/target/arm/as3525/debug-as3525.c b/firmware/target/arm/as3525/debug-as3525.c
index 9f7b46df8e..06c22c027c 100644
--- a/firmware/target/arm/as3525/debug-as3525.c
+++ b/firmware/target/arm/as3525/debug-as3525.c
@@ -256,6 +256,21 @@ bool __dbg_hw_info(void)
256 { 256 {
257 while(1) 257 while(1)
258 { 258 {
259#ifdef SANSA_C200V2
260 lcd_clear_display();
261 line = 0;
262 lcd_puts(0, line++, "[Submodel:]");
263 lcd_putsf(0, line++, "C200v2 variant %d", c200v2_variant);
264 lcd_update();
265 int btn = button_get(1);
266 if(btn == (DEBUG_CANCEL|BUTTON_REL))
267 goto end;
268 else if(btn == (BUTTON_DOWN|BUTTON_REL))
269 break;
270 }
271 while(1)
272 {
273#endif
259 lcd_clear_display(); 274 lcd_clear_display();
260 line = 0; 275 line = 0;
261 lcd_puts(0, line++, "[Clock Frequencies:]"); 276 lcd_puts(0, line++, "[Clock Frequencies:]");
diff --git a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
index e094cca8fe..9c236d3653 100644
--- a/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
+++ b/firmware/target/arm/as3525/sansa-c200v2/backlight-c200v2.c
@@ -37,26 +37,75 @@ static const int brightness_table[MAX_BRIGHTNESS_SETTING+1] = {
37 37
38static void _ll_backlight_on(void) 38static void _ll_backlight_on(void)
39{ 39{
40 GPIOA_PIN(5) = 1<<5; 40 if (c200v2_variant == 0) {
41 GPIOA_PIN(5) = 1<<5;
42 } else {
43 GPIOA_PIN(7) = 1<<7;
44 }
41} 45}
42 46
43static void _ll_backlight_off(void) 47static void _ll_backlight_off(void)
44{ 48{
45 GPIOA_PIN(5) = 0; 49 if (c200v2_variant == 0) {
50 GPIOA_PIN(5) = 0;
51 } else {
52 GPIOA_PIN(7) = 0;
53 }
54}
55
56static void _ll_buttonlight_on(void)
57{
58 if (c200v2_variant == 1) {
59 /* Main buttonlight is on A5 */
60 GPIOA_PIN(5) = 1<<5;
61 } else {
62 /* Needed for buttonlight and MicroSD to work at the same time */
63 /* Turn ROD control on, as the OF does */
64 GPIOD_DIR |= (1<<7);
65 SD_MCI_POWER |= (1<<7);
66 GPIOD_PIN(7) = (1<<7);
67 }
68}
69
70static void _ll_buttonlight_off(void)
71{
72 if (c200v2_variant == 1) {
73 /* Main buttonlight is on A5 */
74 GPIOA_PIN(5) = 0;
75 } else {
76 /* Needed for buttonlight and MicroSD to work at the same time */
77 /* Turn ROD control off, as the OF does */
78 SD_MCI_POWER &= ~(1<<7);
79 GPIOD_PIN(7) = 0;
80 GPIOD_DIR &= ~(1<<7);
81 }
46} 82}
47 83
48void _backlight_pwm(int on) 84void _backlight_pwm(int on)
49{ 85{
50 if (on) { 86 if (on) {
51 _ll_backlight_on(); 87 if (backlight_is_on)
88 _ll_backlight_on();
89
90 if (buttonlight_is_on)
91 _ll_buttonlight_on();
52 } else { 92 } else {
53 _ll_backlight_off(); 93 if (backlight_is_on)
94 _ll_backlight_off();
95
96 if (buttonlight_is_on)
97 _ll_buttonlight_off();
54 } 98 }
55} 99}
56 100
57bool _backlight_init(void) 101bool _backlight_init(void)
58{ 102{
59 GPIOA_DIR |= 1<<5; 103 GPIOA_DIR |= 1<<5;
104 if (c200v2_variant == 1) {
105 /* On this variant A7 is the backlight and
106 * A5 is the buttonlight */
107 GPIOA_DIR |= 1<<7;
108 }
60 return true; 109 return true;
61} 110}
62 111
@@ -70,21 +119,40 @@ void _backlight_set_brightness(int brightness)
70 _backlight_off(); 119 _backlight_off();
71} 120}
72 121
122static void _pwm_on(void)
123{
124 _set_timer2_pwm_ratio(backlight_level);
125}
126
127static void _pwm_off(void)
128{
129 if (buttonlight_is_on == 0 && backlight_is_on == 0)
130 _set_timer2_pwm_ratio(0);
131}
132
73void _backlight_on(void) 133void _backlight_on(void)
74{ 134{
135 if (backlight_is_on == 1) {
136 /* Update pwm ratio in case user changed the brightness */
137 _pwm_on();
138 return;
139 }
140
75#ifdef HAVE_LCD_ENABLE 141#ifdef HAVE_LCD_ENABLE
76 lcd_enable(true); /* power on lcd + visible display */ 142 lcd_enable(true); /* power on lcd + visible display */
77#endif 143#endif
78 if (!backlight_is_on) 144 _ll_backlight_on();
79 _ll_backlight_on(); 145 _pwm_on();
80 _set_timer2_pwm_ratio(backlight_level);
81 backlight_is_on = 1; 146 backlight_is_on = 1;
82} 147}
83 148
84void _backlight_off(void) 149void _backlight_off(void)
85{ 150{
151 if (backlight_is_on == 0)
152 return;
153
86 backlight_is_on = 0; 154 backlight_is_on = 0;
87 _set_timer2_pwm_ratio(0); 155 _pwm_off();
88 _ll_backlight_off(); 156 _ll_backlight_off();
89#ifdef HAVE_LCD_ENABLE 157#ifdef HAVE_LCD_ENABLE
90 lcd_enable(false); /* power off visible display */ 158 lcd_enable(false); /* power off visible display */
@@ -93,20 +161,22 @@ void _backlight_off(void)
93 161
94void _buttonlight_on(void) 162void _buttonlight_on(void)
95{ 163{
96 /* Needed for buttonlight and MicroSD to work at the same time */ 164 if (buttonlight_is_on == 1)
97 /* Turn ROD control on, as the OF does */ 165 return;
98 GPIOD_DIR |= (1<<7); 166
99 SD_MCI_POWER |= (1<<7); 167 _ll_buttonlight_on();
100 GPIOD_PIN(7) = (1<<7); 168 _pwm_on();
101 buttonlight_is_on = 1; 169 buttonlight_is_on = 1;
102} 170}
103 171
104void _buttonlight_off(void) 172void _buttonlight_off(void)
105{ 173{
106 /* Needed for buttonlight and MicroSD to work at the same time */ 174 if (buttonlight_is_on == 0)
107 /* Turn ROD control off, as the OF does */ 175 return;
108 SD_MCI_POWER &= ~(1<<7); 176
109 GPIOD_PIN(7) = 0;
110 GPIOD_DIR &= ~(1<<7);
111 buttonlight_is_on = 0; 177 buttonlight_is_on = 0;
178 _pwm_off();
179 _ll_buttonlight_off();
112} 180}
181
182/* vim:set ts=4 sw=4 et: */
diff --git a/firmware/target/arm/as3525/system-as3525.c b/firmware/target/arm/as3525/system-as3525.c
index c51d84469f..5a7d25a1f7 100644
--- a/firmware/target/arm/as3525/system-as3525.c
+++ b/firmware/target/arm/as3525/system-as3525.c
@@ -163,6 +163,41 @@ void fiq_handler(void)
163 ); 163 );
164} 164}
165 165
166#if defined(SANSA_C200V2)
167#include "dbop-as3525.h"
168
169int c200v2_variant = 0;
170
171static void check_model_variant(void)
172{
173 unsigned int i;
174 unsigned int saved_dir = GPIOA_DIR;
175
176 /* Make A7 input */
177 GPIOA_DIR &= ~(1<<7);
178 /* wait a little to allow the pullup/pulldown resistor
179 * to charge the input capacitance */
180 for (i=0; i<1000; i++) asm volatile ("nop\n");
181 /* read the pullup/pulldown value on A7 to determine the variant */
182 if (GPIOA_PIN(7) == 0) {
183 /*
184 * Backlight on A7.
185 */
186 c200v2_variant = 1;
187 } else {
188 /*
189 * Backlight on A5.
190 */
191 c200v2_variant = 0;
192 }
193 GPIOA_DIR = saved_dir;
194}
195#else
196static inline void check_model_variant(void)
197{
198}
199#endif /* SANSA_C200V2*/
200
166#if defined(BOOTLOADER) 201#if defined(BOOTLOADER)
167static void sdram_delay(void) 202static void sdram_delay(void)
168{ 203{
@@ -319,6 +354,7 @@ void system_init(void)
319 fmradio_i2c_init(); 354 fmradio_i2c_init();
320#endif 355#endif
321#endif /* !BOOTLOADER */ 356#endif /* !BOOTLOADER */
357 check_model_variant();
322} 358}
323 359
324void system_reboot(void) 360void system_reboot(void)
diff --git a/firmware/target/arm/as3525/system-target.h b/firmware/target/arm/as3525/system-target.h
index 292ad1bbea..1173515ebb 100644
--- a/firmware/target/arm/as3525/system-target.h
+++ b/firmware/target/arm/as3525/system-target.h
@@ -32,4 +32,10 @@
32#define UNCACHED_ADDR(a) ((typeof(a)) ((uintptr_t)(a) + 0x10000000)) 32#define UNCACHED_ADDR(a) ((typeof(a)) ((uintptr_t)(a) + 0x10000000))
33#endif 33#endif
34 34
35
36#ifdef SANSA_C200V2
37/* 0: Backlight on A5, 1: Backlight on A7 */
38extern int c200v2_variant;
39#endif
40
35#endif /* SYSTEM_TARGET_H */ 41#endif /* SYSTEM_TARGET_H */