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"
58 char version
[] = APPSVERSION
;
59 #define LONG_DELAY 200000
60 #define SHORT_DELAY 50000
61 #define PAUSE_DELAY 50000
63 static inline void delay(unsigned int duration
)
65 volatile unsigned int i
;
66 for(i
=0;i
<duration
;i
++);
69 // forward declaration
70 static int rds_decode(int line
, struct si4700_dbg_info
*nfo
);
74 static void timer_callback(void)
83 unsigned char read_data
[16];
85 struct si4700_dbg_info si4700_info
;
89 // enable all peripherals
92 // disable all interrupts
95 // start with all GPIOs as input
108 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
113 lcd_bitmap(rockboxlogo
, 0, 160, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
123 timer_register(1, NULL
, 3 * TIMER_FREQ
, timer_callback
);
126 PCON3
= (PCON3
& ~(0x0000FF00)) | 0x00001100;
127 PDAT3
|= (1 << 2) | (1 << 3);
132 si4700_set(RADIO_SLEEP
, 0);
133 si4700_set(RADIO_MUTE
, 0);
134 si4700_set(RADIO_FREQUENCY
, 100700000);
136 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
142 #if 1 /* enable to see GPIOs */
143 snprintf(mystring
, 64, "%02X %02X %02X %02X %02X %02X %02X %02X", PDAT0
, PDAT1
, PDAT2
, PDAT3
, PDAT4
, PDAT5
, PDAT6
, PDAT7
);
144 lcd_puts(0, line
++, mystring
);
147 #if 1 /* enable this to see info about the RTC */
148 rtc_read_datetime(read_data
);
149 snprintf(mystring
, 64, "RTC:");
150 for (i
= 0; i
< 7; i
++) {
151 snprintf(mystring
+ 2 * i
+ 4, 64, "%02X", read_data
[i
]);
153 lcd_puts(0, line
++, mystring
);
156 #if 0 /* enable this so see info about the codec */
157 memset(read_data
, 0, sizeof(read_data
));
158 for (i
= 0; i
< 1; i
++) {
159 i2c_read(0x34, i
, 2, read_data
);
160 data
= read_data
[0] << 8 | read_data
[1];
161 snprintf(mystring
+ 4 * i
, 64, "%04X", data
);
163 lcd_puts(0, line
++, mystring
);
166 #if 1 /* enable this to see radio debug info */
167 si4700_dbg_info(&si4700_info
);
168 col
= snprintf(mystring
, 64, "FM: ");
169 for (i
= 0; i
< 16; i
++) {
170 col
+= snprintf(mystring
+ col
, 64, "%04X ", si4700_info
.regs
[i
]);
171 if (((i
+ 1) % 4) == 0) {
172 lcd_puts(0, line
++, mystring
);
176 line
= rds_decode(line
, &si4700_info
);
179 #if 1 /* enable this to see ADC info */
180 snprintf(mystring
, 64, "%04X %04X %04X %04X", adc_read(0), adc_read(1), adc_read(2), adc_read(3));
181 lcd_puts(0, line
++, mystring
);
182 snprintf(mystring
, 64, "ADC:USB %4d mV BAT %4d mV",
183 (adc_read(0) * 6000) >> 10, (adc_read(2) * 4650) >> 10);
184 lcd_puts(0, line
++, mystring
);
187 #if 1 /* enable this so see USB info */
188 snprintf(mystring
, 64, "CLK %08X CLK2 %08X", CLKCON
, CLKCON2
);
189 lcd_puts(0, line
++, mystring
);
191 snprintf(mystring
, 64, "%04X %04X %04X %04X", PHYCTRL
, PHYPWR
, URSTCON
, UCLKCON
);
192 lcd_puts(0, line
++, mystring
);
194 snprintf(mystring
, 64, "SCR %04X SSR %04X EIR %04X", SCR
, SSR
, EIR
);
195 lcd_puts(0, line
++, mystring
);
197 snprintf(mystring
, 64, "FAR %04X FNR %04X EP0 %04X", FAR
, FNR
, EP0SR
);
198 lcd_puts(0, line
++, mystring
);
201 #if 1 /* enable to see timer/counter info */
202 snprintf(mystring
, 64, "TIMER: %08X", count
);
203 lcd_puts(0, line
++, mystring
);
204 snprintf(mystring
, 64, "current_tick: %08X", current_tick
);
205 lcd_puts(0, line
++, mystring
);
206 snprintf(mystring
, 64, "TIMER %04X %04X %04X", TDCON
, TDPRE
, TDDATA0
);
207 lcd_puts(0, line
++, mystring
);
210 #if 1 /* enable this to control backlight brightness with the hold switch */
211 if (PDAT4
& (1 << 3)) {
212 _backlight_set_brightness(10);
216 _backlight_set_brightness(15);
226 static int rds_decode(int line
, struct si4700_dbg_info
*nfo
)
228 unsigned short rdsdata
[4];
229 unsigned int pi
, group
, tp
, pty
, segment
, abflag
;
230 static unsigned int af1
= 0, af2
= 0;
231 static unsigned int day
= 0, hour
= 0, minute
= 0;
232 static unsigned int abflag_prev
= -1;
233 static char mystring
[64];
239 rdsdata
[0] = nfo
->regs
[12];
240 rdsdata
[1] = nfo
->regs
[13];
241 rdsdata
[2] = nfo
->regs
[14];
242 rdsdata
[3] = nfo
->regs
[15];
245 group
= (rdsdata
[1] >> 11) & 0x1F;
246 tp
= (rdsdata
[1] >> 10) & 1;
247 pty
= (rdsdata
[1] >> 5) & 0x1F;
251 case 0: /* group 0A: basic info */
252 af1
= (rdsdata
[2] >> 8) & 0xFF;
253 af2
= (rdsdata
[2] >> 0) & 0xFF;
255 case 1: /* group 0B: basic info */
256 segment
= rdsdata
[1] & 3;
257 ps
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
258 ps
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
261 case 2: /* group 1A: programme item */
262 case 3: /* group 1B: programme item */
263 day
= (rdsdata
[3] >> 11) & 0x1F;
264 hour
= (rdsdata
[3] >> 6) & 0x1F;
265 minute
= (rdsdata
[3] >> 0) & 0x3F;
268 case 4: /* group 2A: radio text */
269 segment
= rdsdata
[1] & 0xF;
270 abflag
= (rdsdata
[1] >> 4) & 1;
271 if (abflag
!= abflag_prev
) {
273 abflag_prev
= abflag
;
275 rt
[segment
* 4 + 0] = (rdsdata
[2] >> 8) & 0xFF;
276 rt
[segment
* 4 + 1] = (rdsdata
[2] >> 0) & 0xFF;
277 rt
[segment
* 4 + 2] = (rdsdata
[3] >> 8) & 0xFF;
278 rt
[segment
* 4 + 3] = (rdsdata
[3] >> 0) & 0xFF;
281 case 5: /* group 2B: radio text */
282 segment
= rdsdata
[1] & 0xF;
283 abflag
= (rdsdata
[1] >> 4) & 1;
284 if (abflag
!= abflag_prev
) {
286 abflag_prev
= abflag
;
288 rt
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
289 rt
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
296 snprintf(mystring
, 64, "PI:%04X,TP:%d,PTY:%2d,AF:%02X/%02X", pi
, tp
, pty
, af1
, af2
);
297 lcd_puts(0, line
++, mystring
);
298 snprintf(mystring
, 64, "PS:%s,ITEM:%02d-%02d:%02d", ps
, day
, hour
, minute
);
299 lcd_puts(0, line
++, mystring
);
300 snprintf(mystring
, 64, "RT:%s", rt
);
301 lcd_puts(0, line
++, mystring
);