diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/sansa-connect')
15 files changed, 1692 insertions, 0 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/adc-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/adc-sansaconnect.c new file mode 100644 index 0000000000..b3e427b9a5 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/adc-sansaconnect.c | |||
@@ -0,0 +1,35 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "cpu.h" | ||
23 | #include "adc.h" | ||
24 | #include "adc-target.h" | ||
25 | #include "kernel.h" | ||
26 | |||
27 | void adc_init(void) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | /* Called to get the recent ADC reading */ | ||
32 | inline unsigned short adc_read(int channel) | ||
33 | { | ||
34 | return (short)channel; | ||
35 | } | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/adc-target.h b/firmware/target/arm/tms320dm320/sansa-connect/adc-target.h new file mode 100644 index 0000000000..49244b4c3b --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/adc-target.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _ADC_TARGET_H_ | ||
23 | #define _ADC_TARGET_H_ | ||
24 | |||
25 | #endif | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c new file mode 100644 index 0000000000..3a6a748621 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.c | |||
@@ -0,0 +1,461 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include "config.h" | ||
24 | #include "system.h" | ||
25 | #include "kernel.h" | ||
26 | #include "logf.h" | ||
27 | #include "avr-sansaconnect.h" | ||
28 | #include "uart-target.h" | ||
29 | #include "button.h" | ||
30 | #include "backlight.h" | ||
31 | #include "powermgmt.h" | ||
32 | |||
33 | //#define BUTTON_DEBUG | ||
34 | |||
35 | #ifdef BUTTON_DEBUG | ||
36 | #include "lcd-target.h" | ||
37 | #include "lcd.h" | ||
38 | #include "font.h" | ||
39 | #include "common.h" | ||
40 | #endif | ||
41 | |||
42 | #ifdef BUTTON_DEBUG | ||
43 | #define dbgprintf DEBUGF | ||
44 | #else | ||
45 | #define dbgprintf(...) | ||
46 | #endif | ||
47 | |||
48 | #define CMD_SYNC 0xAA | ||
49 | #define CMD_CLOSE 0xCC | ||
50 | #define CMD_LCM_POWER 0xC9 | ||
51 | #define LCM_POWER_OFF 0x00 | ||
52 | #define LCM_POWER_ON 0x01 | ||
53 | #define LCM_POWER_SLEEP 0x02 | ||
54 | #define LCM_POWER_WAKE 0x03 | ||
55 | #define LCM_REPOWER_ON 0x04 | ||
56 | |||
57 | #define CMD_STATE 0xBB | ||
58 | #define CMD_VER 0xBC | ||
59 | #define CMD_WHEEL_EN 0xD0 | ||
60 | #define CMD_SET_INTCHRG 0xD1 | ||
61 | #define CMD_CODEC_RESET 0xD7 | ||
62 | #define CMD_FILL 0xFF | ||
63 | |||
64 | #define CMD_SYS_CTRL 0xDA | ||
65 | #define SYS_CTRL_POWEROFF 0x00 | ||
66 | |||
67 | /* protects spi avr commands from concurrent access */ | ||
68 | static struct mutex avr_mtx; | ||
69 | |||
70 | /* buttons thread */ | ||
71 | #define BTN_INTERRUPT 1 | ||
72 | static int btn = 0; | ||
73 | static bool hold_switch; | ||
74 | #ifndef BOOTLOADER | ||
75 | static long btn_stack[DEFAULT_STACK_SIZE/sizeof(long)]; | ||
76 | static const char btn_thread_name[] = "buttons"; | ||
77 | static struct event_queue btn_queue; | ||
78 | #endif | ||
79 | |||
80 | static inline unsigned short be2short(unsigned char* buf) | ||
81 | { | ||
82 | return (unsigned short)((buf[0] << 8) | buf[1]); | ||
83 | } | ||
84 | |||
85 | #define BUTTON_DIRECT_MASK (BUTTON_LEFT | BUTTON_UP | BUTTON_RIGHT | BUTTON_DOWN | BUTTON_SELECT | BUTTON_VOL_UP | BUTTON_VOL_DOWN | BUTTON_NEXT | BUTTON_PREV) | ||
86 | |||
87 | #ifndef BOOTLOADER | ||
88 | static void handle_wheel(unsigned char wheel) | ||
89 | { | ||
90 | static int key = 0; | ||
91 | static unsigned char velocity = 0; | ||
92 | static unsigned long wheel_delta = 1ul << 24; | ||
93 | static unsigned char wheel_prev = 0; | ||
94 | static long next_backlight_on = 0; | ||
95 | static int prev_key = -1; | ||
96 | static int prev_key_post = 0; | ||
97 | |||
98 | if (TIME_AFTER(current_tick, next_backlight_on)) | ||
99 | { | ||
100 | backlight_on(); | ||
101 | reset_poweroff_timer(); | ||
102 | next_backlight_on = current_tick + HZ/4; | ||
103 | } | ||
104 | |||
105 | if (wheel_prev < wheel) | ||
106 | { | ||
107 | key = BUTTON_SCROLL_FWD; | ||
108 | velocity = wheel - wheel_prev; | ||
109 | } | ||
110 | else if (wheel_prev > wheel) | ||
111 | { | ||
112 | key = BUTTON_SCROLL_BACK; | ||
113 | velocity = wheel_prev - wheel; | ||
114 | } | ||
115 | |||
116 | if (prev_key != key && velocity < 2 /* filter "rewinds" */) | ||
117 | { | ||
118 | /* direction reversal */ | ||
119 | prev_key = key; | ||
120 | wheel_delta = 1ul << 24; | ||
121 | return; | ||
122 | } | ||
123 | |||
124 | /* TODO: take velocity into account */ | ||
125 | if (queue_empty(&button_queue)) | ||
126 | { | ||
127 | if (prev_key_post == key) | ||
128 | { | ||
129 | key |= BUTTON_REPEAT; | ||
130 | } | ||
131 | |||
132 | /* Post directly, don't update btn as avr doesn't give | ||
133 | interrupt on scroll stop */ | ||
134 | queue_post(&button_queue, key, wheel_delta); | ||
135 | |||
136 | wheel_delta = 1ul << 24; | ||
137 | |||
138 | prev_key_post = key; | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | /* skipped post - increment delta and limit to 7 bits */ | ||
143 | wheel_delta += 1ul << 24; | ||
144 | |||
145 | if (wheel_delta > (0x7ful << 24)) | ||
146 | wheel_delta = 0x7ful << 24; | ||
147 | } | ||
148 | |||
149 | wheel_prev = wheel; | ||
150 | |||
151 | prev_key = key; | ||
152 | } | ||
153 | #endif | ||
154 | |||
155 | /* buf must be 11-byte array of byte (reply from avr_hid_get_state() */ | ||
156 | static void parse_button_state(unsigned char *buf) | ||
157 | { | ||
158 | unsigned short main_btns_state = be2short(&buf[4]); | ||
159 | #ifdef BUTTON_DEBUG | ||
160 | unsigned short main_btns_changed = be2short(&buf[6]); | ||
161 | #endif | ||
162 | |||
163 | /* make sure other bits doesn't conflict with our "free bits" buttons */ | ||
164 | main_btns_state &= BUTTON_DIRECT_MASK; | ||
165 | |||
166 | if (buf[3] & 0x01) /* is power button pressed? */ | ||
167 | { | ||
168 | main_btns_state |= BUTTON_POWER; | ||
169 | } | ||
170 | |||
171 | btn = main_btns_state; | ||
172 | |||
173 | #ifndef BOOTLOADER | ||
174 | /* check if stored hold_switch state changed (prevents lost changes) */ | ||
175 | if ((buf[3] & 0x20) /* hold change notification */ || | ||
176 | (hold_switch != ((buf[3] & 0x02) >> 1))) | ||
177 | { | ||
178 | #endif | ||
179 | hold_switch = (buf[3] & 0x02) >> 1; | ||
180 | #ifdef BUTTON_DEBUG | ||
181 | dbgprintf("HOLD changed (%d)", hold_switch); | ||
182 | #endif | ||
183 | #ifndef BOOTLOADER | ||
184 | backlight_hold_changed(hold_switch); | ||
185 | } | ||
186 | #endif | ||
187 | #ifndef BOOTLOADER | ||
188 | if ((hold_switch == false) && (buf[3] & 0x80)) /* scrollwheel change */ | ||
189 | { | ||
190 | handle_wheel(buf[2]); | ||
191 | } | ||
192 | #endif | ||
193 | |||
194 | #ifdef BUTTON_DEBUG | ||
195 | if (buf[3] & 0x10) /* power button change */ | ||
196 | { | ||
197 | /* power button state has changed */ | ||
198 | main_btns_changed |= BUTTON_POWER; | ||
199 | } | ||
200 | |||
201 | if (btn & BUTTON_LEFT) dbgprintf("LEFT"); | ||
202 | if (btn & BUTTON_UP) dbgprintf("UP"); | ||
203 | if (btn & BUTTON_RIGHT) dbgprintf("RIGHT"); | ||
204 | if (btn & BUTTON_DOWN) dbgprintf("DOWN"); | ||
205 | if (btn & BUTTON_SELECT) dbgprintf("SELECT"); | ||
206 | if (btn & BUTTON_VOL_UP) dbgprintf("VOL UP"); | ||
207 | if (btn & BUTTON_VOL_DOWN) dbgprintf("VOL DOWN"); | ||
208 | if (btn & BUTTON_NEXT) dbgprintf("NEXT"); | ||
209 | if (btn & BUTTON_PREV) dbgprintf("PREV"); | ||
210 | if (btn & BUTTON_POWER) dbgprintf("POWER"); | ||
211 | if (btn & BUTTON_HOLD) dbgprintf("HOLD"); | ||
212 | if (btn & BUTTON_SCROLL_FWD) dbgprintf("SCROLL FWD"); | ||
213 | if (btn & BUTTON_SCROLL_BACK) dbgprintf("SCROLL BACK"); | ||
214 | #endif | ||
215 | } | ||
216 | |||
217 | /* HID Slave Select - GIO14 */ | ||
218 | #define HID_SS (1<<14) | ||
219 | |||
220 | static inline void select_hid(bool on) | ||
221 | { | ||
222 | if (on == true) | ||
223 | { | ||
224 | /* SS is active low */ | ||
225 | IO_GIO_BITCLR0 = HID_SS; | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | IO_GIO_BITSET0 = HID_SS; | ||
230 | } | ||
231 | } | ||
232 | |||
233 | static void spi_txrx(unsigned char *buf_tx, unsigned char *buf_rx, int n) | ||
234 | { | ||
235 | int i; | ||
236 | unsigned short rxdata; | ||
237 | |||
238 | mutex_lock(&avr_mtx); | ||
239 | |||
240 | bitset16(&IO_CLK_MOD2, CLK_MOD2_SIF1); | ||
241 | IO_SERIAL1_TX_ENABLE = 0x0001; | ||
242 | select_hid(true); | ||
243 | |||
244 | for (i = 0; i<n; i++) | ||
245 | { | ||
246 | IO_SERIAL1_TX_DATA = buf_tx[i]; | ||
247 | udelay(100); | ||
248 | |||
249 | do | ||
250 | { | ||
251 | rxdata = IO_SERIAL1_RX_DATA; | ||
252 | } while (rxdata & (1<<8)); | ||
253 | |||
254 | if (buf_rx != NULL) | ||
255 | buf_rx[i] = rxdata & 0xFF; | ||
256 | |||
257 | //udelay(100); | ||
258 | } | ||
259 | |||
260 | select_hid(false); | ||
261 | IO_SERIAL1_TX_ENABLE = 0; | ||
262 | bitclr16(&IO_CLK_MOD2, CLK_MOD2_SIF1); | ||
263 | |||
264 | mutex_unlock(&avr_mtx); | ||
265 | } | ||
266 | |||
267 | static void avr_hid_sync(void) | ||
268 | { | ||
269 | int i; | ||
270 | unsigned char prg[4] = {CMD_SYNC, CMD_VER, CMD_FILL, CMD_CLOSE}; | ||
271 | |||
272 | /* Send SYNC three times */ | ||
273 | for (i = 0; i<3; i++) | ||
274 | { | ||
275 | spi_txrx(prg, NULL, sizeof(prg)); | ||
276 | } | ||
277 | } | ||
278 | |||
279 | void avr_hid_init(void) | ||
280 | { | ||
281 | /* | ||
282 | setup alternate GIO functions: | ||
283 | GIO29 - SIF1 Enable | ||
284 | GIO30 - SIF1 Clock | ||
285 | GIO31 - SIF1 Data In | ||
286 | GIO32 - SIF1 Data Out | ||
287 | */ | ||
288 | IO_GIO_FSEL2 = (IO_GIO_FSEL2 & 0x00FF) | 0xAA00; | ||
289 | |||
290 | bitclr16(&IO_GIO_DIR0, HID_SS); /* set GIO14 as output */ | ||
291 | |||
292 | /* RATE = 219 (0xDB) -> 200 kHz */ | ||
293 | IO_SERIAL1_MODE = 0x6DB; | ||
294 | |||
295 | mutex_init(&avr_mtx); | ||
296 | |||
297 | avr_hid_sync(); | ||
298 | } | ||
299 | |||
300 | |||
301 | static void avr_hid_get_state(void) | ||
302 | { | ||
303 | static unsigned char cmd[11] = {CMD_SYNC, CMD_STATE, | ||
304 | CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, CMD_FILL, | ||
305 | CMD_CLOSE}; | ||
306 | |||
307 | static unsigned char buf[11]; | ||
308 | static unsigned char cmd_empty[1] = {0xCC}; | ||
309 | |||
310 | spi_txrx(cmd, buf, sizeof(cmd)); | ||
311 | |||
312 | spi_txrx(cmd_empty, NULL, 1); /* request interrupt on button press */ | ||
313 | |||
314 | parse_button_state(buf); | ||
315 | } | ||
316 | |||
317 | static void avr_hid_enable_wheel(void) | ||
318 | { | ||
319 | unsigned char wheel_en[4] = {CMD_SYNC, CMD_WHEEL_EN, 0x01, CMD_CLOSE}; | ||
320 | |||
321 | spi_txrx(wheel_en, NULL, sizeof(wheel_en)); | ||
322 | } | ||
323 | |||
324 | /* command that is sent by "hidtool -J 1" issued on every OF boot */ | ||
325 | void avr_hid_enable_charger(void) | ||
326 | { | ||
327 | unsigned char charger_en[4] = {CMD_SYNC, CMD_SET_INTCHRG, 0x01, CMD_CLOSE}; | ||
328 | |||
329 | spi_txrx(charger_en, NULL, sizeof(charger_en)); | ||
330 | } | ||
331 | |||
332 | void avr_hid_lcm_sleep(void) | ||
333 | { | ||
334 | unsigned char lcm_sleep[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_SLEEP, CMD_CLOSE}; | ||
335 | |||
336 | spi_txrx(lcm_sleep, NULL, sizeof(lcm_sleep)); | ||
337 | } | ||
338 | |||
339 | |||
340 | void avr_hid_lcm_wake(void) | ||
341 | { | ||
342 | unsigned char lcm_wake[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_WAKE, CMD_CLOSE}; | ||
343 | |||
344 | spi_txrx(lcm_wake, NULL, sizeof(lcm_wake)); | ||
345 | } | ||
346 | |||
347 | void avr_hid_lcm_power_on(void) | ||
348 | { | ||
349 | unsigned char lcm_power_on[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_ON, CMD_CLOSE}; | ||
350 | |||
351 | spi_txrx(lcm_power_on, NULL, sizeof(lcm_power_on)); | ||
352 | } | ||
353 | |||
354 | void avr_hid_lcm_power_off(void) | ||
355 | { | ||
356 | unsigned char lcm_power_off[4] = {CMD_SYNC, CMD_LCM_POWER, LCM_POWER_OFF, CMD_CLOSE}; | ||
357 | |||
358 | spi_txrx(lcm_power_off, NULL, sizeof(lcm_power_off)); | ||
359 | } | ||
360 | |||
361 | void avr_hid_reset_codec(void) | ||
362 | { | ||
363 | unsigned char codec_reset[4] = {CMD_SYNC, CMD_CODEC_RESET, CMD_CLOSE, CMD_FILL}; | ||
364 | |||
365 | spi_txrx(codec_reset, NULL, sizeof(codec_reset)); | ||
366 | } | ||
367 | |||
368 | void avr_hid_power_off(void) | ||
369 | { | ||
370 | unsigned char prg[4] = {CMD_SYNC, CMD_SYS_CTRL, SYS_CTRL_POWEROFF, CMD_CLOSE}; | ||
371 | |||
372 | spi_txrx(prg, NULL, sizeof(prg)); | ||
373 | } | ||
374 | |||
375 | #ifndef BOOTLOADER | ||
376 | void btn_thread(void) | ||
377 | { | ||
378 | struct queue_event ev; | ||
379 | |||
380 | while (1) | ||
381 | { | ||
382 | queue_wait(&btn_queue, &ev); | ||
383 | |||
384 | /* Ignore all messages except BTN_INTERRUPT */ | ||
385 | if (ev.id != BTN_INTERRUPT) | ||
386 | continue; | ||
387 | |||
388 | /* Enable back button interrupt */ | ||
389 | IO_INTC_EINT1 |= INTR_EINT1_EXT0; | ||
390 | |||
391 | /* Read buttons state */ | ||
392 | avr_hid_get_state(); | ||
393 | |||
394 | yield(); | ||
395 | |||
396 | if (queue_empty(&btn_queue) && ((IO_GIO_BITSET0 & 0x1) == 0)) | ||
397 | { | ||
398 | /* for some reason we have lost next interrupt */ | ||
399 | queue_post(&btn_queue, BTN_INTERRUPT, 0); | ||
400 | } | ||
401 | } | ||
402 | } | ||
403 | |||
404 | void GIO0(void) __attribute__ ((section(".icode"))); | ||
405 | void GIO0(void) | ||
406 | { | ||
407 | /* Clear interrupt */ | ||
408 | IO_INTC_IRQ1 = (1 << 5); | ||
409 | /* Disable interrupt */ | ||
410 | IO_INTC_EINT1 &= ~INTR_EINT1_EXT0; | ||
411 | |||
412 | /* interrupt will be enabled back after button read */ | ||
413 | queue_post(&btn_queue, BTN_INTERRUPT, 0); | ||
414 | } | ||
415 | #endif | ||
416 | |||
417 | void button_init_device(void) | ||
418 | { | ||
419 | btn = 0; | ||
420 | hold_switch = false; | ||
421 | #ifndef BOOTLOADER | ||
422 | queue_init(&btn_queue, true); | ||
423 | create_thread(btn_thread, btn_stack, sizeof(btn_stack), 0, | ||
424 | btn_thread_name IF_PRIO(, PRIORITY_USER_INTERFACE) | ||
425 | IF_COP(, CPU)); | ||
426 | #endif | ||
427 | IO_GIO_DIR0 |= 0x01; /* Set GIO0 as input */ | ||
428 | |||
429 | /* Enable wheel */ | ||
430 | avr_hid_enable_wheel(); | ||
431 | /* Read button status and tell avr we want interrupt on next change */ | ||
432 | avr_hid_get_state(); | ||
433 | |||
434 | #ifndef BOOTLOADER | ||
435 | IO_GIO_IRQPORT |= 0x01; /* Enable GIO0 external interrupt */ | ||
436 | IO_GIO_INV0 &= ~0x01; /* Clear INV for GIO0 (falling edge detection) */ | ||
437 | IO_GIO_IRQEDGE &= ~0x01; /* Set edge detection (falling) */ | ||
438 | |||
439 | /* Enable GIO0 interrupt */ | ||
440 | IO_INTC_EINT1 |= INTR_EINT1_EXT0; | ||
441 | #endif | ||
442 | } | ||
443 | |||
444 | int button_read_device(void) | ||
445 | { | ||
446 | if(hold_switch) | ||
447 | return 0; | ||
448 | else | ||
449 | return btn; | ||
450 | } | ||
451 | |||
452 | bool button_hold(void) | ||
453 | { | ||
454 | return hold_switch; | ||
455 | } | ||
456 | |||
457 | void lcd_enable(bool on) | ||
458 | { | ||
459 | (void)on; | ||
460 | } | ||
461 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h new file mode 100644 index 0000000000..64b44675f7 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/avr-sansaconnect.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _AVR_SANSACONNECT_H_ | ||
23 | #define _AVR_SANSACONNECT_H_ | ||
24 | |||
25 | #include "config.h" | ||
26 | |||
27 | void avr_hid_init(void); | ||
28 | |||
29 | void avr_hid_enable_charger(void); | ||
30 | |||
31 | void avr_hid_lcm_sleep(void); | ||
32 | void avr_hid_lcm_wake(void); | ||
33 | void avr_hid_lcm_power_on(void); | ||
34 | void avr_hid_lcm_power_off(void); | ||
35 | void avr_hid_reset_codec(void); | ||
36 | void avr_hid_power_off(void); | ||
37 | |||
38 | #endif /* _AVR_SANSACONNECT_H_ */ | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c new file mode 100644 index 0000000000..b7989849d7 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/backlight-sansaconnect.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include "system.h" | ||
25 | #include "backlight-target.h" | ||
26 | #include "backlight.h" | ||
27 | #include "lcd.h" | ||
28 | #include "power.h" | ||
29 | #include "spi-target.h" | ||
30 | #include "lcd-target.h" | ||
31 | |||
32 | static void _backlight_write_brightness(int brightness) | ||
33 | { | ||
34 | /* | ||
35 | Maps brightness int to percentage value found in OF | ||
36 | |||
37 | OF PWM1H | ||
38 | 5% 14 | ||
39 | 10% 140 | ||
40 | 15% 210 | ||
41 | 20% 280 | ||
42 | ... | ||
43 | 95% 1330 | ||
44 | 100% 1400 | ||
45 | */ | ||
46 | if (brightness > 20) | ||
47 | brightness = 20; | ||
48 | else if (brightness < 0) | ||
49 | brightness = 0; | ||
50 | |||
51 | IO_CLK_PWM1H = brightness*70; | ||
52 | } | ||
53 | |||
54 | void _backlight_on(void) | ||
55 | { | ||
56 | /* set GIO34 as PWM1 */ | ||
57 | IO_GIO_FSEL3 = (IO_GIO_FSEL3 & 0xFFF3) | (1 << 2); | ||
58 | |||
59 | #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_NO_FADING) | ||
60 | _backlight_write_brightness(backlight_brightness); | ||
61 | #endif | ||
62 | } | ||
63 | |||
64 | void _backlight_off(void) | ||
65 | { | ||
66 | _backlight_write_brightness(0); | ||
67 | |||
68 | bitclr16(&IO_GIO_FSEL3, 0xC); /* set GIO34 to normal GIO */ | ||
69 | bitclr16(&IO_GIO_INV2, (1 << 2)); /* make sure GIO34 is not inverted */ | ||
70 | IO_GIO_BITCLR2 = (1 << 2); /* drive GIO34 low */ | ||
71 | } | ||
72 | |||
73 | /* Assumes that the backlight has been initialized */ | ||
74 | void _backlight_set_brightness(int brightness) | ||
75 | { | ||
76 | _backlight_write_brightness(brightness); | ||
77 | } | ||
78 | |||
79 | void __backlight_dim(bool dim_now) | ||
80 | { | ||
81 | _backlight_set_brightness(dim_now ? | ||
82 | DEFAULT_BRIGHTNESS_SETTING : | ||
83 | DEFAULT_DIMNESS_SETTING); | ||
84 | } | ||
85 | |||
86 | bool _backlight_init(void) | ||
87 | { | ||
88 | IO_CLK_PWM1C = 0x58D; /* as found in OF */ | ||
89 | |||
90 | _backlight_set_brightness(backlight_brightness); | ||
91 | return true; | ||
92 | } | ||
93 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/backlight-target.h b/firmware/target/arm/tms320dm320/sansa-connect/backlight-target.h new file mode 100644 index 0000000000..89bd837cee --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/backlight-target.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef BACKLIGHT_TARGET_H | ||
23 | #define BACKLIGHT_TARGET_H | ||
24 | |||
25 | bool _backlight_init(void); | ||
26 | void _backlight_on(void); | ||
27 | void _backlight_off(void); | ||
28 | void _backlight_set_brightness(int brightness); | ||
29 | |||
30 | /* true: backlight fades off - false: backlight fades on */ | ||
31 | void __backlight_dim(bool dim); | ||
32 | |||
33 | #endif | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/button-target.h b/firmware/target/arm/tms320dm320/sansa-connect/button-target.h new file mode 100644 index 0000000000..2eb571ae68 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/button-target.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _BUTTON_TARGET_H_ | ||
23 | #define _BUTTON_TARGET_H_ | ||
24 | |||
25 | #include "config.h" | ||
26 | |||
27 | #define BUTTON_REMOTE 0 | ||
28 | |||
29 | /* these definitions match the avr hid reply */ | ||
30 | #define BUTTON_LEFT (1 << 2) | ||
31 | #define BUTTON_UP (1 << 3) | ||
32 | #define BUTTON_RIGHT (1 << 4) | ||
33 | #define BUTTON_DOWN (1 << 5) | ||
34 | #define BUTTON_SELECT (1 << 6) | ||
35 | #define BUTTON_VOL_UP (1 << 10) | ||
36 | #define BUTTON_VOL_DOWN (1 << 11) | ||
37 | #define BUTTON_NEXT (1 << 13) | ||
38 | #define BUTTON_PREV (1 << 14) | ||
39 | |||
40 | /* following definitions use "free bits" from avr hid reply */ | ||
41 | #define BUTTON_POWER (1 << 0) | ||
42 | #define BUTTON_HOLD (1 << 1) | ||
43 | #define BUTTON_SCROLL_FWD (1 << 7) | ||
44 | #define BUTTON_SCROLL_BACK (1 << 8) | ||
45 | |||
46 | |||
47 | #define BUTTON_REMOTE 0 | ||
48 | #define BUTTON_MAIN (BUTTON_LEFT | BUTTON_UP | BUTTON_RIGHT | BUTTON_DOWN |\ | ||
49 | BUTTON_SELECT | BUTTON_VOL_UP | BUTTON_VOL_DOWN |\ | ||
50 | BUTTON_NEXT | BUTTON_PREV | BUTTON_POWER |\ | ||
51 | BUTTON_SCROLL_FWD | BUTTON_SCROLL_BACK) | ||
52 | |||
53 | #define POWEROFF_BUTTON BUTTON_POWER | ||
54 | #define POWEROFF_COUNT 5 | ||
55 | |||
56 | #define HAS_BUTTON_HOLD | ||
57 | |||
58 | void button_init_device(void); | ||
59 | int button_read_device(void); | ||
60 | bool button_hold(void); | ||
61 | |||
62 | int get_debug_info(int choice); | ||
63 | |||
64 | #endif /* _BUTTON_TARGET_H_ */ | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/crt0-board.S b/firmware/target/arm/tms320dm320/sansa-connect/crt0-board.S new file mode 100644 index 0000000000..debd2cd2be --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/crt0-board.S | |||
@@ -0,0 +1,238 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include "config.h" | ||
22 | #include "cpu.h" | ||
23 | |||
24 | /* Macro for reading a register */ | ||
25 | .macro mrh register | ||
26 | ldr r1, =\register | ||
27 | ldrh r0, [r1] | ||
28 | .endm | ||
29 | |||
30 | /* Macro for writing a register */ | ||
31 | .macro mwh register, value | ||
32 | ldr r0, =\value | ||
33 | ldr r1, =\register | ||
34 | strh r0, [r1] | ||
35 | .endm | ||
36 | |||
37 | /* This version uses a mov to save on the literal pool size. Otherwise it is | ||
38 | * functionally equivalent. | ||
39 | */ | ||
40 | .macro mwhm register, value | ||
41 | mov r0, #\value | ||
42 | ldr r1, =\register | ||
43 | strh r0, [r1] | ||
44 | .endm | ||
45 | |||
46 | /* | ||
47 | * _init_board: | ||
48 | * This function initializes the specific board this SoC is on. | ||
49 | */ | ||
50 | .section .init, "ax" | ||
51 | .code 32 | ||
52 | .align 0x04 | ||
53 | .global _init_board | ||
54 | .type _init_board, %function | ||
55 | |||
56 | _init_board: | ||
57 | |||
58 | /* Setup the EMIF interface timings */ | ||
59 | |||
60 | /* FLASH interface: | ||
61 | * These are based on the OF setup | ||
62 | */ | ||
63 | /* IO_EMIF_CS0CTRL1 and | ||
64 | * IO_EMIF_CS0CTRL2 | ||
65 | */ | ||
66 | mwh 0x30A00, 0x889A | ||
67 | mwh 0x30A02, 0x1110 | ||
68 | |||
69 | mwhm 0x30A04, 0 | ||
70 | mwh 0x30A06, 0x1415 | ||
71 | mwh 0x30A08, 0x1109 | ||
72 | |||
73 | mwh 0x30A0A, 0x1220 | ||
74 | mwh 0x30A0C, 0x1104 | ||
75 | mwh 0x30A0E, 0x0222 | ||
76 | |||
77 | /* IO_EMIF_CS3CTRL1 and | ||
78 | * IO_EMIF_CS3CTRL2 | ||
79 | */ | ||
80 | mwh 0x30A10, 0x8899 | ||
81 | mwh 0x30A12, 0x5110 | ||
82 | |||
83 | /* USB interface */ | ||
84 | /* IO_EMIF_CS4CTRL1 and | ||
85 | * IO_EMIF_CS4CTRL2 | ||
86 | */ | ||
87 | mwh 0x30A14, 0x77DF | ||
88 | mwh 0x30A16, 0x7740 | ||
89 | |||
90 | /* IO_EMIF_BUSCTRL */ | ||
91 | mwhm 0x30A18, 0 | ||
92 | mwhm 0x30A1A, 0 | ||
93 | mwhm 0x30A1C, 0 | ||
94 | mwhm 0x30A1E, 0 | ||
95 | |||
96 | _clock_setup: | ||
97 | /* Clock initialization */ | ||
98 | |||
99 | /* IO_CLK_BYP: Bypass the PLLs for the following changes */ | ||
100 | mwh 0x30894, 0x1111 | ||
101 | |||
102 | /* | ||
103 | * IO_CLK_PLLA | ||
104 | * IO_CLK_PLLB | ||
105 | */ | ||
106 | mwhm 0x30880, 0x00A0 | ||
107 | mwhm 0x30882, 0x1000 | ||
108 | |||
109 | /* IO_CLK_SEL0 */ | ||
110 | mwh 0x30884, 0x0066 | ||
111 | |||
112 | /* IO_CLK_SEL1 */ | ||
113 | mwhm 0x30886, 0x0003 | ||
114 | |||
115 | # IO_CLK_SEL2: ARM, AXL, SDRAM and DSP are from PLLA */ | ||
116 | mwh 0x30888, 0 | ||
117 | |||
118 | /* IO_CLK_DIV0: Set the slow clock speed for the ARM/AHB */ | ||
119 | mwh 0x3088A, 0x0101 | ||
120 | |||
121 | /* IO_CLK_DIV1: Accelerator, SDRAM */ | ||
122 | mwh 0x3088C, 0x0102 | ||
123 | |||
124 | /* IO_CLK_DIV2: DSP, MS Clock */ | ||
125 | mwhm 0x3088E, 0x0200 | ||
126 | |||
127 | # PLLA &= ~0x1000 (BIC #0x1000) | ||
128 | mrh 0x30880 | ||
129 | bic r0, r0, #0x1000 | ||
130 | strh r0, [r1] | ||
131 | |||
132 | /* Wait for PLLs to lock before feeding them to the downstream devices */ | ||
133 | _plla_wait: | ||
134 | mrh 0x30880 | ||
135 | bic r0, r0, #0x7F | ||
136 | tst r0, r0 | ||
137 | beq _plla_wait | ||
138 | |||
139 | /* IO_CLK_BYP: Enable PLL feeds */ | ||
140 | mwhm 0x30894, 0x0 | ||
141 | |||
142 | /* IO_CLK_MOD0 */ | ||
143 | mwh 0x30898, 0x01A7 | ||
144 | |||
145 | /* IO_CLK_MOD1 */ | ||
146 | mwhm 0x3089A, 0x18 | ||
147 | |||
148 | /* IO_CLK_MOD2 */ | ||
149 | mwhm 0x3089C, 0x4A0 | ||
150 | |||
151 | /* Setup the SDRAM range on the AHB bus */ | ||
152 | /* SDRAMSA */ | ||
153 | mov r0, #0x60000 | ||
154 | mov r1, #0x1000000 | ||
155 | str r1, [r0, #0xF00] | ||
156 | |||
157 | /* SDRAMEA: 64MB */ | ||
158 | mov r1, #0x5000000 | ||
159 | str r1, [r0, #0xF04] | ||
160 | |||
161 | /* SDRC_REFCTL */ | ||
162 | mwh 0x309A8, 0 | ||
163 | |||
164 | ldr r0, =0x309A6 | ||
165 | mov r2, #0x1380 | ||
166 | orr r1, r2, #2 | ||
167 | strh r1, [r0] | ||
168 | orr r1, r2, #4 | ||
169 | strh r1, [r0] | ||
170 | strh r1, [r0] | ||
171 | strh r1, [r0] | ||
172 | strh r1, [r0] | ||
173 | strh r1, [r0] | ||
174 | strh r1, [r0] | ||
175 | strh r1, [r0] | ||
176 | strh r1, [r0] | ||
177 | orr r1, r2, #1 | ||
178 | strh r1, [r0] | ||
179 | strh r2, [r0] | ||
180 | strh r2, [r0] | ||
181 | |||
182 | mwhm 0x309A8, 0x0140 | ||
183 | |||
184 | mwhm 0x309BE, 0x4 | ||
185 | mwhm 0x309BC, 0x2 | ||
186 | ldr r0, =0x309C4 | ||
187 | ldr r1, [r0] | ||
188 | orr r1, r1, #1 | ||
189 | strh r1, [r0] | ||
190 | |||
191 | ldr r0, =0x309A6 | ||
192 | mov r1, #0x1380 | ||
193 | strh r1, [r0] | ||
194 | bic r1, r1, #0x80 | ||
195 | strh r1, [r0] | ||
196 | orr r1, r1, #0x40 | ||
197 | strh r1, [r0] | ||
198 | |||
199 | mwhm 0x309A8, 0x0140 | ||
200 | |||
201 | /* Go through the GPIO initialization */ | ||
202 | /* Warning: setting some of the functions wrong will make OF unable | ||
203 | to boot (freeze during startup) */ | ||
204 | /* IO_GIO_FSEL0: Set up the GPIO pin functions 0-16 */ | ||
205 | mwhm 0x305A4, 0xC000 | ||
206 | |||
207 | /* IO_GIO_FSEL1: 17-24 */ | ||
208 | mwh 0x305A6, 0xAAAA | ||
209 | |||
210 | /* IO_GIO_FSEL2: 18-32 */ | ||
211 | mwh 0x305A8, 0xA80A | ||
212 | |||
213 | /* IO_GIO_FSEL3: 33-40 */ | ||
214 | mwh 0x305AA, 0x1007 | ||
215 | |||
216 | /* IO_GIO_DIR0 */ | ||
217 | mwh 0x30580, 0xFF77 | ||
218 | |||
219 | /* IO_GIO_DIR1 */ | ||
220 | mwh 0x30582, 0xEFFE | ||
221 | |||
222 | /* IO_GIO_DIR2 */ | ||
223 | mwh 0x30584, 0x01FD | ||
224 | |||
225 | /* IO_GIO_INV0 */ | ||
226 | mwh 0x30586, 0x0000 | ||
227 | |||
228 | /* IO_GIO_INV1 */ | ||
229 | mwh 0x30588, 0x0000 | ||
230 | |||
231 | /* IO_GIO_INV2 */ | ||
232 | mwh 0x3058A, 0x0000 | ||
233 | |||
234 | bx lr | ||
235 | |||
236 | .ltorg | ||
237 | .size _init_board, .-_init_board | ||
238 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c new file mode 100644 index 0000000000..fcfc82e876 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/lcd-sansaconnect.c | |||
@@ -0,0 +1,273 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <sys/types.h> | ||
23 | #include "config.h" | ||
24 | #include "cpu.h" | ||
25 | #include "string.h" | ||
26 | #include "kernel.h" | ||
27 | #include "system.h" | ||
28 | #include "system-target.h" | ||
29 | #include "lcd.h" | ||
30 | #include "lcd-target.h" | ||
31 | #include "avr-sansaconnect.h" | ||
32 | |||
33 | /* Copies a rectangle from one framebuffer to another. Can be used in | ||
34 | single transfer mode with width = num pixels, and height = 1 which | ||
35 | allows a full-width rectangle to be copied more efficiently. */ | ||
36 | extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src, | ||
37 | int width, int height); | ||
38 | |||
39 | static bool lcd_on = true; | ||
40 | |||
41 | bool lcd_active(void) | ||
42 | { | ||
43 | return lcd_on; | ||
44 | } | ||
45 | |||
46 | #if defined(HAVE_LCD_SLEEP) | ||
47 | void lcd_sleep(void) | ||
48 | { | ||
49 | if (lcd_on) | ||
50 | { | ||
51 | lcd_on = false; | ||
52 | avr_hid_lcm_sleep(); | ||
53 | sleep(HZ/20); | ||
54 | |||
55 | /* disable video encoder */ | ||
56 | bitclr16(&IO_VID_ENC_VMOD, 0x01); | ||
57 | |||
58 | sleep(HZ/20); | ||
59 | |||
60 | /* disable video encoder clock */ | ||
61 | bitclr16(&IO_CLK_MOD1, CLK_MOD1_VENC); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | void lcd_awake(void) | ||
66 | { | ||
67 | if (!lcd_on) | ||
68 | { | ||
69 | lcd_on = true; | ||
70 | /* enable video encoder clock */ | ||
71 | bitset16(&IO_CLK_MOD1, CLK_MOD1_VENC); | ||
72 | |||
73 | /* enable video encoder */ | ||
74 | bitset16(&IO_VID_ENC_VMOD, 0x01); | ||
75 | |||
76 | avr_hid_lcm_wake(); | ||
77 | |||
78 | send_event(LCD_EVENT_ACTIVATION, NULL); | ||
79 | |||
80 | lcd_update(); | ||
81 | } | ||
82 | } | ||
83 | #endif | ||
84 | |||
85 | void lcd_init_device(void) | ||
86 | { | ||
87 | unsigned int addr; | ||
88 | |||
89 | /* Disable Video Encoder clock */ | ||
90 | bitclr16(&IO_CLK_MOD1, CLK_MOD1_VENC); | ||
91 | |||
92 | /* configure GIO39, GIO34 and GIO33 as outputs */ | ||
93 | IO_GIO_DIR2 &= ~((1 << 7) /* GIO39 */ | (1 << 2) /* GIO34 */ | | ||
94 | (1 << 1) /* GIO33 */); | ||
95 | |||
96 | IO_GIO_FSEL3 = (IO_GIO_FSEL3 & ~(0x300F)) | | ||
97 | (0x1000) /* GIO39 - FIELD_VENC */ | | ||
98 | (0x3) /* GIO33 - CLKOUT1B (bootloader does this) */ | | ||
99 | (0x4); /* GIO34 - PWM1 (brightness control) */ | ||
100 | |||
101 | /* OSD Clock = VENC Clock /2, | ||
102 | CCD clock PCLK, | ||
103 | VENC Clock from PLLA */ | ||
104 | IO_CLK_SEL1 = 0x3; | ||
105 | |||
106 | /* Set VENC Clock Division to 11 | ||
107 | OF bootloader sets division to 8, vmlinux sets it to 11 */ | ||
108 | IO_CLK_DIV3 = (IO_CLK_DIV3 & ~(0x1F00)) | 0xB00; | ||
109 | |||
110 | /* Enable DAC and OSD clocks */ | ||
111 | bitset16(&IO_CLK_MOD1, CLK_MOD1_DAC | CLK_MOD1_OSD); | ||
112 | |||
113 | /* magic values based on OF bootloader initialization */ | ||
114 | IO_VID_ENC_VMOD = 0x2010; | ||
115 | IO_VID_ENC_VDPRO = 0x80; | ||
116 | IO_VID_ENC_HSPLS = 0x4; | ||
117 | IO_VID_ENC_HINT = 0x4B0; | ||
118 | IO_VID_ENC_HSTART = 0x88; | ||
119 | IO_VID_ENC_HVALID = 0x3C0; | ||
120 | IO_VID_ENC_HSDLY = 0; | ||
121 | IO_VID_ENC_VSPLS = 0x2; | ||
122 | IO_VID_ENC_VINT = 0x152; | ||
123 | IO_VID_ENC_VSTART = 0x6; | ||
124 | IO_VID_ENC_VVALID = 0x140; | ||
125 | IO_VID_ENC_VSDLY = 0; | ||
126 | IO_VID_ENC_DCLKCTL = 0x3; | ||
127 | IO_VID_ENC_DCLKPTN0 = 0xC; | ||
128 | IO_VID_ENC_VDCTL = 0x6000; | ||
129 | IO_VID_ENC_SYNCTL = 0x2; | ||
130 | IO_VID_ENC_LCDOUT = 0x101; | ||
131 | IO_VID_ENC_VMOD = 0x2011; | ||
132 | |||
133 | /* Copy Rockbox frame buffer to the second framebuffer */ | ||
134 | lcd_update(); | ||
135 | |||
136 | avr_hid_lcm_power_on(); | ||
137 | |||
138 | /* set framebuffer address - OF sets RAM start address to 0x1000000 */ | ||
139 | addr = ((int)FRAME-CONFIG_SDRAM_START)/32; | ||
140 | |||
141 | IO_OSD_OSDWINADH = addr >> 16; | ||
142 | IO_OSD_OSDWIN0ADL = addr & 0xFFFF; | ||
143 | |||
144 | IO_OSD_BASEPX = 0x44; | ||
145 | IO_OSD_BASEPY = 0x6; | ||
146 | IO_OSD_OSDWIN0XP = 0; | ||
147 | IO_OSD_OSDWIN0YP = 0; | ||
148 | IO_OSD_OSDWIN0XL = LCD_WIDTH*2; /* OF bootloader sets 480 */ | ||
149 | IO_OSD_OSDWIN0YL = LCD_HEIGHT; /* OF bootloader sets 320 */ | ||
150 | IO_OSD_OSDWIN0OFST = 0xF; | ||
151 | IO_OSD_OSDWINMD0 = 0x25FB;/* OF bootloader sets 25C3, | ||
152 | vmlinux changes this to 0x25FB */ | ||
153 | IO_OSD_VIDWINMD = 0; /* disable video windows (OF sets 0x03) */ | ||
154 | |||
155 | IO_OSD_OSDWINMD1 = 0; /* disable OSD window 1 */ | ||
156 | |||
157 | /* Enable DAC, Video Encoder and OSD clocks */ | ||
158 | bitset16(&IO_CLK_MOD1, CLK_MOD1_DAC | CLK_MOD1_VENC | CLK_MOD1_OSD); | ||
159 | |||
160 | /* Enable Video Encoder - RGB666, custom timing */ | ||
161 | IO_VID_ENC_VMOD = 0x2011; | ||
162 | avr_hid_lcm_wake(); | ||
163 | } | ||
164 | |||
165 | /* Update a fraction of the display. */ | ||
166 | void lcd_update_rect(int x, int y, int width, int height) | ||
167 | __attribute__ ((section(".icode"))); | ||
168 | void lcd_update_rect(int x, int y, int width, int height) | ||
169 | { | ||
170 | register fb_data *dst, *src; | ||
171 | |||
172 | if (!lcd_on) | ||
173 | return; | ||
174 | |||
175 | if ((width | height) < 0) | ||
176 | return; /* Nothing left to do */ | ||
177 | |||
178 | if (x + width > LCD_WIDTH) | ||
179 | width = LCD_WIDTH - x; /* Clip right */ | ||
180 | if (x < 0) | ||
181 | width += x, x = 0; /* Clip left */ | ||
182 | |||
183 | if (y + height > LCD_HEIGHT) | ||
184 | height = LCD_HEIGHT - y; /* Clip bottom */ | ||
185 | if (y < 0) | ||
186 | height += y, y = 0; /* Clip top */ | ||
187 | |||
188 | dst = FRAME + LCD_WIDTH*y + x; | ||
189 | src = &lcd_framebuffer[y][x]; | ||
190 | |||
191 | /* Copy part of the Rockbox framebuffer to the second framebuffer */ | ||
192 | if (width < LCD_WIDTH) | ||
193 | { | ||
194 | /* Not full width - do line-by-line */ | ||
195 | lcd_copy_buffer_rect(dst, src, width, height); | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | /* Full width - copy as one line */ | ||
200 | lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | /* Update the display. | ||
205 | This must be called after all other LCD functions that change the display. */ | ||
206 | void lcd_update(void) __attribute__ ((section(".icode"))); | ||
207 | void lcd_update(void) | ||
208 | { | ||
209 | if (!lcd_on) | ||
210 | return; | ||
211 | |||
212 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
213 | } | ||
214 | |||
215 | void lcd_set_contrast(int val) { | ||
216 | (void) val; | ||
217 | // TODO: | ||
218 | } | ||
219 | |||
220 | void lcd_set_invert_display(bool yesno) { | ||
221 | (void) yesno; | ||
222 | // TODO: | ||
223 | } | ||
224 | |||
225 | void lcd_set_flip(bool yesno) { | ||
226 | (void) yesno; | ||
227 | // TODO: | ||
228 | } | ||
229 | |||
230 | /* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */ | ||
231 | extern void lcd_write_yuv420_lines(fb_data *dst, | ||
232 | unsigned char chroma_buf[LCD_HEIGHT/2*3], | ||
233 | unsigned char const * const src[3], | ||
234 | int width, int stride); | ||
235 | |||
236 | /* Performance function to blit a YUV bitmap directly to the LCD */ | ||
237 | void lcd_blit_yuv(unsigned char * const src[3], | ||
238 | int src_x, int src_y, int stride, | ||
239 | int x, int y, int width, int height) | ||
240 | { | ||
241 | /* Caches for chroma data so it only need be recalculated every other | ||
242 | line */ | ||
243 | unsigned char chroma_buf[LCD_HEIGHT/2*3]; /* 480 bytes */ | ||
244 | unsigned char const * yuv_src[3]; | ||
245 | off_t z; | ||
246 | |||
247 | if (!lcd_on) | ||
248 | return; | ||
249 | |||
250 | /* Sorry, but width and height must be >= 2 or else */ | ||
251 | width &= ~1; | ||
252 | height >>= 1; | ||
253 | |||
254 | fb_data *dst = (fb_data*)FRAME + x * LCD_WIDTH + (LCD_WIDTH - y) - 1; | ||
255 | |||
256 | z = stride*src_y; | ||
257 | yuv_src[0] = src[0] + z + src_x; | ||
258 | yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1); | ||
259 | yuv_src[2] = src[2] + (yuv_src[1] - src[1]); | ||
260 | |||
261 | do | ||
262 | { | ||
263 | lcd_write_yuv420_lines(dst, chroma_buf, yuv_src, width, | ||
264 | stride); | ||
265 | |||
266 | yuv_src[0] += stride << 1; /* Skip down two luma lines */ | ||
267 | yuv_src[1] += stride >> 1; /* Skip down one chroma line */ | ||
268 | yuv_src[2] += stride >> 1; | ||
269 | dst -= 2; | ||
270 | } | ||
271 | while (--height > 0); | ||
272 | } | ||
273 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/lcd-target.h b/firmware/target/arm/tms320dm320/sansa-connect/lcd-target.h new file mode 100644 index 0000000000..0c1ad0d5f5 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/lcd-target.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef _LCD_TARGET_H_ | ||
23 | #define _LCD_TARGET_H_ | ||
24 | |||
25 | #endif | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/pcm-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/pcm-sansaconnect.c new file mode 100644 index 0000000000..3f04838388 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/pcm-sansaconnect.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdlib.h> | ||
22 | #include "system.h" | ||
23 | #include "kernel.h" | ||
24 | #include "logf.h" | ||
25 | #include "audio.h" | ||
26 | #include "sound.h" | ||
27 | #include "file.h" | ||
28 | #include "dsp-target.h" | ||
29 | #include "dsp/ipc.h" | ||
30 | #include "mmu-arm.h" | ||
31 | #include "pcm-internal.h" | ||
32 | #include "dma-target.h" | ||
33 | |||
34 | /* This is global to save some latency when pcm_play_dma_get_peak_buffer is | ||
35 | * called. | ||
36 | */ | ||
37 | static void *start; | ||
38 | static int dma_channel; | ||
39 | |||
40 | void pcm_play_dma_postinit(void) | ||
41 | { | ||
42 | audiohw_postinit(); | ||
43 | } | ||
44 | |||
45 | /* Return the current location in the SDRAM to SARAM transfer along with the | ||
46 | * number of bytes read in the current buffer (count). There is latency with | ||
47 | * this method equivalent to ~ the size of the SARAM buffer since there is | ||
48 | * another buffer between your ears and this calculation, but this works for | ||
49 | * key clicks and an approximate peak meter. | ||
50 | */ | ||
51 | const void * pcm_play_dma_get_peak_buffer(int *count) | ||
52 | { | ||
53 | int cnt = DSP_(_sdem_level); | ||
54 | |||
55 | unsigned long addr = (unsigned long) start + cnt; | ||
56 | |||
57 | *count = (cnt & 0xFFFFF) >> 1; | ||
58 | return (void *)((addr + 2) & ~3); | ||
59 | } | ||
60 | |||
61 | void pcm_play_dma_init(void) | ||
62 | { | ||
63 | /* GIO16 is DSP/AIC3X CLK */ | ||
64 | IO_GIO_FSEL0 &= 0x3FFF; | ||
65 | IO_CLK_OSEL = (IO_CLK_OSEL & 0xFFF0) | 4; /* PLLIN clock */ | ||
66 | IO_CLK_O0DIV = 7; | ||
67 | IO_GIO_DIR1 &= ~(1 << 0); /* GIO16 - output */ | ||
68 | IO_GIO_FSEL0 |= 0xC000; /* GIO16 - CLKOUT0 */ | ||
69 | |||
70 | audiohw_init(); | ||
71 | audiohw_set_frequency(HW_FREQ_DEFAULT); | ||
72 | |||
73 | IO_INTC_IRQ0 = INTR_IRQ0_IMGBUF; | ||
74 | bitset16(&IO_INTC_EINT0, INTR_EINT0_IMGBUF); | ||
75 | |||
76 | /* Set this as a FIQ */ | ||
77 | bitset16(&IO_INTC_FISEL0, INTR_EINT0_IMGBUF); | ||
78 | |||
79 | /* Enable the HPIB clock */ | ||
80 | bitset16(&IO_CLK_MOD0, (CLK_MOD0_HPIB | CLK_MOD0_DSP)); | ||
81 | |||
82 | /* Enable IMGBUF clock */ | ||
83 | bitset16(&IO_CLK_MOD1, CLK_MOD1_IMGBUF); | ||
84 | |||
85 | dma_channel = dma_request_channel(DMA_PERIPHERAL_DSP, | ||
86 | DMA_MODE_1_BURST); | ||
87 | |||
88 | IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0; | ||
89 | |||
90 | dsp_reset(); | ||
91 | dsp_load(dsp_image); | ||
92 | |||
93 | DSP_(_dma0_stopped)=1; | ||
94 | dsp_wake(); | ||
95 | } | ||
96 | |||
97 | void pcm_dma_apply_settings(void) | ||
98 | { | ||
99 | audiohw_set_frequency(pcm_fsel); | ||
100 | } | ||
101 | |||
102 | /* Note that size is actually limited to the size of a short right now due to | ||
103 | * the implementation on the DSP side (and the way that we access it) | ||
104 | */ | ||
105 | void pcm_play_dma_start(const void *addr, size_t size) | ||
106 | { | ||
107 | unsigned long sdem_addr=(unsigned long)addr - CONFIG_SDRAM_START; | ||
108 | /* Initialize codec. */ | ||
109 | DSP_(_sdem_addrl) = sdem_addr & 0xffff; | ||
110 | DSP_(_sdem_addrh) = sdem_addr >> 16; | ||
111 | DSP_(_sdem_dsp_size) = size; | ||
112 | DSP_(_dma0_stopped)=0; | ||
113 | |||
114 | dsp_wake(); | ||
115 | } | ||
116 | |||
117 | void pcm_play_dma_stop(void) | ||
118 | { | ||
119 | DSP_(_dma0_stopped)=1; | ||
120 | dsp_wake(); | ||
121 | } | ||
122 | |||
123 | void pcm_play_lock(void) | ||
124 | { | ||
125 | |||
126 | } | ||
127 | |||
128 | void pcm_play_unlock(void) | ||
129 | { | ||
130 | |||
131 | } | ||
132 | |||
133 | void pcm_play_dma_pause(bool pause) | ||
134 | { | ||
135 | if (pause) | ||
136 | { | ||
137 | DSP_(_dma0_stopped)=2; | ||
138 | dsp_wake(); | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | DSP_(_dma0_stopped)=0; | ||
143 | dsp_wake(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | size_t pcm_get_bytes_waiting(void) | ||
148 | { | ||
149 | return DSP_(_sdem_dsp_size)-DSP_(_sdem_level); | ||
150 | } | ||
151 | |||
152 | /* Only used when debugging */ | ||
153 | static char buffer[80]; | ||
154 | |||
155 | void DSPHINT(void) __attribute__ ((section(".icode"))); | ||
156 | void DSPHINT(void) | ||
157 | { | ||
158 | unsigned int i; | ||
159 | size_t size; | ||
160 | |||
161 | IO_INTC_FIQ0 = INTR_IRQ0_IMGBUF; | ||
162 | |||
163 | switch (dsp_message.msg) | ||
164 | { | ||
165 | case MSG_DEBUGF: | ||
166 | /* DSP stores one character per word. */ | ||
167 | for (i = 0; i < sizeof(buffer); i++) | ||
168 | { | ||
169 | buffer[i] = dsp_message.payload.debugf.buffer[i]; | ||
170 | } | ||
171 | |||
172 | DEBUGF("DSP: %s", buffer); | ||
173 | break; | ||
174 | |||
175 | case MSG_REFILL: | ||
176 | /* Buffer empty. Try to get more. */ | ||
177 | pcm_play_get_more_callback(&start, &size); | ||
178 | |||
179 | if (size != 0) | ||
180 | { | ||
181 | unsigned long sdem_addr=(unsigned long)start - CONFIG_SDRAM_START; | ||
182 | /* Flush any pending cache writes */ | ||
183 | clean_dcache_range(start, size); | ||
184 | |||
185 | /* set the new DMA values */ | ||
186 | DSP_(_sdem_addrl) = sdem_addr & 0xffff; | ||
187 | DSP_(_sdem_addrh) = sdem_addr >> 16; | ||
188 | DSP_(_sdem_dsp_size) = size; | ||
189 | |||
190 | DEBUGF("pcm_sdram at 0x%08lx, sdem_addr 0x%08lx", | ||
191 | (unsigned long)start, (unsigned long)sdem_addr); | ||
192 | |||
193 | pcm_play_dma_started_callback(); | ||
194 | } | ||
195 | |||
196 | break; | ||
197 | default: | ||
198 | DEBUGF("DSP: unknown msg 0x%04x", dsp_message.msg); | ||
199 | break; | ||
200 | } | ||
201 | |||
202 | /* Re-Activate the channel */ | ||
203 | dsp_wake(); | ||
204 | |||
205 | DEBUGF("DSP: %s", buffer); | ||
206 | } | ||
207 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c new file mode 100644 index 0000000000..52ea9be1d9 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/power-sansaconnect.c | |||
@@ -0,0 +1,59 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "cpu.h" | ||
24 | #include <stdbool.h> | ||
25 | #include "kernel.h" | ||
26 | #include "system.h" | ||
27 | #include "power.h" | ||
28 | #include "backlight.h" | ||
29 | #include "backlight-target.h" | ||
30 | #include "avr-sansaconnect.h" | ||
31 | |||
32 | void power_init(void) | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void power_off(void) | ||
37 | { | ||
38 | avr_hid_reset_codec(); | ||
39 | avr_hid_power_off(); | ||
40 | } | ||
41 | |||
42 | #if CONFIG_CHARGING | ||
43 | unsigned int power_input_status(void) | ||
44 | { | ||
45 | return POWER_INPUT_NONE; | ||
46 | } | ||
47 | |||
48 | /* Returns true if the unit is charging the batteries. */ | ||
49 | bool charging_state(void) | ||
50 | { | ||
51 | return false; | ||
52 | } | ||
53 | #endif | ||
54 | |||
55 | void ide_power_enable(bool on) | ||
56 | { | ||
57 | (void)on; | ||
58 | } | ||
59 | |||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c new file mode 100644 index 0000000000..bd90c51072 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/powermgmt-sansaconnect.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "adc.h" | ||
24 | #include "powermgmt.h" | ||
25 | #include "kernel.h" | ||
26 | |||
27 | /* THIS CONTAINS CURRENTLY DUMMY CODE! */ | ||
28 | |||
29 | static const unsigned short current_voltage = 3910; | ||
30 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | ||
31 | { | ||
32 | 0 | ||
33 | }; | ||
34 | |||
35 | const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = | ||
36 | { | ||
37 | 0 | ||
38 | }; | ||
39 | |||
40 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ | ||
41 | const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | ||
42 | { | ||
43 | { 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320 }, | ||
44 | }; | ||
45 | |||
46 | /* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ | ||
47 | const unsigned short percent_to_volt_charge[11] = | ||
48 | { | ||
49 | 100, 300, 400, 500, 600, 700, 800, 900, 1000, 1200, 1320, | ||
50 | }; | ||
51 | |||
52 | /* Returns battery voltage from ADC [millivolts] */ | ||
53 | unsigned int battery_adc_voltage(void) | ||
54 | { | ||
55 | return current_voltage; | ||
56 | } | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c new file mode 100644 index 0000000000..ab42beb2b4 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/usb-sansaconnect.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include "system.h" | ||
24 | #include "kernel.h" | ||
25 | #include "usb.h" | ||
26 | #ifdef HAVE_USBSTACK | ||
27 | #include "usb_drv.h" | ||
28 | #include "usb_core.h" | ||
29 | #endif | ||
30 | |||
31 | bool usb_drv_connected(void) | ||
32 | { | ||
33 | return false; | ||
34 | } | ||
35 | |||
36 | int usb_detect(void) | ||
37 | { | ||
38 | return USB_EXTRACTED; | ||
39 | } | ||
40 | |||
41 | void usb_init_device(void) | ||
42 | { | ||
43 | return; | ||
44 | } | ||
45 | |||
46 | void usb_enable(bool on) | ||
47 | { | ||
48 | (void)on; | ||
49 | } | ||
50 | |||
51 | void usb_attach(void) | ||
52 | { | ||
53 | } | ||
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/usb-target.h b/firmware/target/arm/tms320dm320/sansa-connect/usb-target.h new file mode 100644 index 0000000000..6142b09f0b --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/usb-target.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef USB_TARGET_H | ||
23 | #define USB_TARGET_H | ||
24 | |||
25 | #include "dm320.h" | ||
26 | |||
27 | #include <stdbool.h> | ||
28 | int usb_detect(void); | ||
29 | void usb_init_device(void); | ||
30 | bool usb_drv_connected(void); | ||
31 | |||
32 | #endif | ||