1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Bertrik Sikken
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
35 #include "backlight.h"
36 #include "backlight-target.h"
42 #include "bitmaps/rockboxlogo.h"
45 #include "adc-target.h"
49 #include "i2c-s5l8700.h"
50 #include "dma-target.h"
56 #include "fmradio_i2c.h"
59 char version
[] = APPSVERSION
;
60 #define LONG_DELAY 200000
61 #define SHORT_DELAY 50000
62 #define PAUSE_DELAY 50000
64 static inline void delay(unsigned int duration
)
66 volatile unsigned int i
;
67 for(i
=0;i
<duration
;i
++);
70 // forward declaration
71 static int rds_decode(int line
, struct si4700_dbg_info
*nfo
);
77 unsigned char read_data
[16];
79 struct si4700_dbg_info si4700_info
;
81 int brightness
= DEFAULT_BRIGHTNESS_SETTING
;
83 unsigned int fm_frequency
= 100700000;
86 // enable all peripherals
89 // disable all interrupts
92 // start with all GPIOs as input
105 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
110 lcd_bitmap(rockboxlogo
, 0, 160, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
119 button_init_device();
124 si4700_set(RADIO_SLEEP
, 0);
125 si4700_set(RADIO_MUTE
, 0);
126 si4700_set(RADIO_FREQUENCY
, fm_frequency
);
128 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
130 // WM1800 codec configuration
131 wmcodec_write(0x0F, 0); // codec reset
132 wmcodec_write(0x19, 0xF0); // pwr mgmt1: VMID = 1, VREF, AINL, AINR
133 wmcodec_write(0x1A, 0x60); // pwr mgmt2: LOUT1, ROUT1
134 wmcodec_write(0x2F, 0x0C); // pwr mgmt3: LOMIX, ROMIX
135 wmcodec_write(0x02, audiovol
); // LOUT1VOL
136 wmcodec_write(0x03, audiovol
| (1 << 8)); // ROUT1VOL
137 wmcodec_write(0x22, (1 << 7) | (7 << 4)); // left out mix (1)
138 wmcodec_write(0x25, (1 << 7) | (7 << 4)); // right out mix (2)
141 PCON5
= (PCON5
& ~0x0000000F) | 0x00000001;
148 #if 1 /* enable to see GPIOs */
149 snprintf(mystring
, 64, "%02X %02X %02X %02X %02X %02X %02X %02X", PDAT0
, PDAT1
, PDAT2
, PDAT3
, PDAT4
, PDAT5
, PDAT6
, PDAT7
);
150 lcd_puts(0, line
++, mystring
);
153 #if 1 /* enable this to see info about the RTC */
154 rtc_read_datetime(read_data
);
155 snprintf(mystring
, 64, "RTC:");
156 for (i
= 0; i
< 7; i
++) {
157 snprintf(mystring
+ 2 * i
+ 4, 64, "%02X", read_data
[i
]);
159 lcd_puts(0, line
++, mystring
);
162 #if 1 /* enable this to see radio debug info */
163 button
= button_read_device();
164 if (button
& BUTTON_RIGHT
) {
165 fm_frequency
+= 100000;
166 si4700_set(RADIO_FREQUENCY
, fm_frequency
);
168 if (button
& BUTTON_LEFT
) {
169 fm_frequency
-= 100000;
170 si4700_set(RADIO_FREQUENCY
, fm_frequency
);
172 snprintf(mystring
, 64, "FM frequency: %9d", fm_frequency
);
173 lcd_puts(0, line
++, mystring
);
175 si4700_dbg_info(&si4700_info
);
176 col
= snprintf(mystring
, 64, "FM: ");
177 for (i
= 0; i
< 16; i
++) {
178 col
+= snprintf(mystring
+ col
, 64, "%04X ", si4700_info
.regs
[i
]);
179 if (((i
+ 1) % 4) == 0) {
180 lcd_puts(0, line
++, mystring
);
184 line
= rds_decode(line
, &si4700_info
);
187 #if 1 /* volume control with up/down keys */
188 button
= button_read_device();
189 if (button
& BUTTON_UP
) {
190 if (audiovol
< 127) {
192 wmcodec_write(0x02, audiovol
);
193 wmcodec_write(0x03, (1 << 8) | audiovol
);
196 if (button
& BUTTON_DOWN
) {
199 wmcodec_write(0x02, audiovol
);
200 wmcodec_write(0x03, (1 << 8) | audiovol
);
203 snprintf(mystring
, 64, "volume %3d", audiovol
);
204 lcd_puts(0, line
++, mystring
);
207 #if 1 /* enable this to see ADC info */
208 snprintf(mystring
, 64, "%04X %04X %04X %04X", adc_read(0), adc_read(1), adc_read(2), adc_read(3));
209 lcd_puts(0, line
++, mystring
);
210 snprintf(mystring
, 64, "ADC:USB %4d mV BAT %4d mV",
211 (adc_read(0) * 6000) >> 10, (adc_read(2) * 4650) >> 10);
212 lcd_puts(0, line
++, mystring
);
215 #if 1 /* enable this so see USB info */
216 snprintf(mystring
, 64, "CLK %08X CLK2 %08X", CLKCON
, CLKCON2
);
217 lcd_puts(0, line
++, mystring
);
219 snprintf(mystring
, 64, "%04X %04X %04X %04X", PHYCTRL
, PHYPWR
, URSTCON
, UCLKCON
);
220 lcd_puts(0, line
++, mystring
);
222 snprintf(mystring
, 64, "SCR %04X SSR %04X EIR %04X", SCR
, SSR
, EIR
);
223 lcd_puts(0, line
++, mystring
);
225 snprintf(mystring
, 64, "FAR %04X FNR %04X EP0 %04X", FAR
, FNR
, EP0SR
);
226 lcd_puts(0, line
++, mystring
);
229 #if 1 /* button lights controlled by keypad */
230 button
= button_read_device();
231 if (button
& (BUTTON_UP
| BUTTON_DOWN
| BUTTON_LEFT
| BUTTON_RIGHT
)) {
237 if (button
& (BUTTON_BACK
| BUTTON_MENU
)) {
243 if (button
& (BUTTON_SELECT
)) {
251 #if 1 /* backlight brightness controlled by up/down keys */
252 button
= button_read_device();
253 if (button
& BUTTON_MENU
) {
254 if (brightness
< MAX_BRIGHTNESS_SETTING
) {
256 _backlight_set_brightness(brightness
);
259 else if (button
& BUTTON_BACK
) {
260 if (brightness
> MIN_BRIGHTNESS_SETTING
) {
262 _backlight_set_brightness(brightness
);
265 snprintf(mystring
, 64, "bright %3d", brightness
);
266 lcd_puts(0, line
++, mystring
);
269 #if 1 /* power off using power button */
270 button
= button_read_device();
271 if (button
& BUTTON_POWER
) {
276 #if 1 /* button info */
277 snprintf(mystring
, 64, "BUTTONS %08X, %s", button_read_device(),
278 headphones_inserted() ? "HP" : "hp");
279 lcd_puts(0, line
++, mystring
);
287 static int rds_decode(int line
, struct si4700_dbg_info
*nfo
)
289 unsigned short rdsdata
[4];
290 unsigned int pi
, group
, tp
, pty
, segment
, abflag
;
291 static unsigned int af1
= 0, af2
= 0;
292 static unsigned int day
= 0, hour
= 0, minute
= 0;
293 static unsigned int abflag_prev
= -1;
294 static char mystring
[64];
300 rdsdata
[0] = nfo
->regs
[12];
301 rdsdata
[1] = nfo
->regs
[13];
302 rdsdata
[2] = nfo
->regs
[14];
303 rdsdata
[3] = nfo
->regs
[15];
306 group
= (rdsdata
[1] >> 11) & 0x1F;
307 tp
= (rdsdata
[1] >> 10) & 1;
308 pty
= (rdsdata
[1] >> 5) & 0x1F;
312 case 0: /* group 0A: basic info */
313 af1
= (rdsdata
[2] >> 8) & 0xFF;
314 af2
= (rdsdata
[2] >> 0) & 0xFF;
316 case 1: /* group 0B: basic info */
317 segment
= rdsdata
[1] & 3;
318 ps
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
319 ps
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
322 case 2: /* group 1A: programme item */
323 case 3: /* group 1B: programme item */
324 day
= (rdsdata
[3] >> 11) & 0x1F;
325 hour
= (rdsdata
[3] >> 6) & 0x1F;
326 minute
= (rdsdata
[3] >> 0) & 0x3F;
329 case 4: /* group 2A: radio text */
330 segment
= rdsdata
[1] & 0xF;
331 abflag
= (rdsdata
[1] >> 4) & 1;
332 if (abflag
!= abflag_prev
) {
334 abflag_prev
= abflag
;
336 rt
[segment
* 4 + 0] = (rdsdata
[2] >> 8) & 0xFF;
337 rt
[segment
* 4 + 1] = (rdsdata
[2] >> 0) & 0xFF;
338 rt
[segment
* 4 + 2] = (rdsdata
[3] >> 8) & 0xFF;
339 rt
[segment
* 4 + 3] = (rdsdata
[3] >> 0) & 0xFF;
342 case 5: /* group 2B: radio text */
343 segment
= rdsdata
[1] & 0xF;
344 abflag
= (rdsdata
[1] >> 4) & 1;
345 if (abflag
!= abflag_prev
) {
347 abflag_prev
= abflag
;
349 rt
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
350 rt
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
357 snprintf(mystring
, 64, "PI:%04X,TP:%d,PTY:%2d,AF:%02X/%02X", pi
, tp
, pty
, af1
, af2
);
358 lcd_puts(0, line
++, mystring
);
359 snprintf(mystring
, 64, "PS:%s,ITEM:%02d-%02d:%02d", ps
, day
, hour
, minute
);
360 lcd_puts(0, line
++, mystring
);
361 snprintf(mystring
, 64, "RT:%s", rt
);
362 lcd_puts(0, line
++, mystring
);