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
);
76 unsigned char read_data
[16];
78 struct si4700_dbg_info si4700_info
;
83 // enable all peripherals
86 // disable all interrupts
89 // start with all GPIOs as input
102 asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts
107 lcd_bitmap(rockboxlogo
, 0, 160, BMPWIDTH_rockboxlogo
, BMPHEIGHT_rockboxlogo
);
120 si4700_set(RADIO_SLEEP
, 0);
121 si4700_set(RADIO_MUTE
, 0);
122 si4700_set(RADIO_FREQUENCY
, 100700000);
124 lcd_puts_scroll(0,0,"+++ this is a very very long line to test scrolling. ---");
126 button_init_device();
132 #if 1 /* enable to see GPIOs */
133 snprintf(mystring
, 64, "%02X %02X %02X %02X %02X %02X %02X %02X", PDAT0
, PDAT1
, PDAT2
, PDAT3
, PDAT4
, PDAT5
, PDAT6
, PDAT7
);
134 lcd_puts(0, line
++, mystring
);
137 #if 1 /* enable this to see info about the RTC */
138 rtc_read_datetime(read_data
);
139 snprintf(mystring
, 64, "RTC:");
140 for (i
= 0; i
< 7; i
++) {
141 snprintf(mystring
+ 2 * i
+ 4, 64, "%02X", read_data
[i
]);
143 lcd_puts(0, line
++, mystring
);
146 #if 0 /* enable this so see info about the codec */
147 memset(read_data
, 0, sizeof(read_data
));
148 for (i
= 0; i
< 1; i
++) {
149 i2c_read(0x34, i
, 2, read_data
);
150 data
= read_data
[0] << 8 | read_data
[1];
151 snprintf(mystring
+ 4 * i
, 64, "%04X", data
);
153 lcd_puts(0, line
++, mystring
);
156 #if 1 /* enable this to see radio debug info */
157 si4700_dbg_info(&si4700_info
);
158 col
= snprintf(mystring
, 64, "FM: ");
159 for (i
= 0; i
< 16; i
++) {
160 col
+= snprintf(mystring
+ col
, 64, "%04X ", si4700_info
.regs
[i
]);
161 if (((i
+ 1) % 4) == 0) {
162 lcd_puts(0, line
++, mystring
);
166 line
= rds_decode(line
, &si4700_info
);
169 #if 1 /* enable this to see ADC info */
170 snprintf(mystring
, 64, "%04X %04X %04X %04X", adc_read(0), adc_read(1), adc_read(2), adc_read(3));
171 lcd_puts(0, line
++, mystring
);
172 snprintf(mystring
, 64, "ADC:USB %4d mV BAT %4d mV",
173 (adc_read(0) * 6000) >> 10, (adc_read(2) * 4650) >> 10);
174 lcd_puts(0, line
++, mystring
);
177 #if 1 /* enable this so see USB info */
178 snprintf(mystring
, 64, "CLK %08X CLK2 %08X", CLKCON
, CLKCON2
);
179 lcd_puts(0, line
++, mystring
);
181 snprintf(mystring
, 64, "%04X %04X %04X %04X", PHYCTRL
, PHYPWR
, URSTCON
, UCLKCON
);
182 lcd_puts(0, line
++, mystring
);
184 snprintf(mystring
, 64, "SCR %04X SSR %04X EIR %04X", SCR
, SSR
, EIR
);
185 lcd_puts(0, line
++, mystring
);
187 snprintf(mystring
, 64, "FAR %04X FNR %04X EP0 %04X", FAR
, FNR
, EP0SR
);
188 lcd_puts(0, line
++, mystring
);
191 #if 1 /* button lights controlled by keypad */
192 button
= button_read_device();
193 if (button
& (BUTTON_UP
| BUTTON_DOWN
| BUTTON_LEFT
| BUTTON_RIGHT
)) {
199 if (button
& (BUTTON_BACK
| BUTTON_MENU
)) {
205 if (button
& (BUTTON_SELECT
)) {
213 #if 1 /* backlight brightness controlled by up/down keys */
214 if (button_read_device() & BUTTON_UP
) {
215 if (brightness
< MAX_BRIGHTNESS_SETTING
) {
217 _backlight_set_brightness(brightness
);
220 else if (button_read_device() & BUTTON_DOWN
) {
221 if (brightness
> MIN_BRIGHTNESS_SETTING
) {
223 _backlight_set_brightness(brightness
);
226 snprintf(mystring
, 64, "bright %3d", brightness
);
227 lcd_puts(0, line
++, mystring
);
231 #if 1 /* button info */
232 snprintf(mystring
, 64, "BUTTONS %08X, %s", button_read_device(),
233 headphones_inserted() ? "HP" : "hp");
234 lcd_puts(0, line
++, mystring
);
242 static int rds_decode(int line
, struct si4700_dbg_info
*nfo
)
244 unsigned short rdsdata
[4];
245 unsigned int pi
, group
, tp
, pty
, segment
, abflag
;
246 static unsigned int af1
= 0, af2
= 0;
247 static unsigned int day
= 0, hour
= 0, minute
= 0;
248 static unsigned int abflag_prev
= -1;
249 static char mystring
[64];
255 rdsdata
[0] = nfo
->regs
[12];
256 rdsdata
[1] = nfo
->regs
[13];
257 rdsdata
[2] = nfo
->regs
[14];
258 rdsdata
[3] = nfo
->regs
[15];
261 group
= (rdsdata
[1] >> 11) & 0x1F;
262 tp
= (rdsdata
[1] >> 10) & 1;
263 pty
= (rdsdata
[1] >> 5) & 0x1F;
267 case 0: /* group 0A: basic info */
268 af1
= (rdsdata
[2] >> 8) & 0xFF;
269 af2
= (rdsdata
[2] >> 0) & 0xFF;
271 case 1: /* group 0B: basic info */
272 segment
= rdsdata
[1] & 3;
273 ps
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
274 ps
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
277 case 2: /* group 1A: programme item */
278 case 3: /* group 1B: programme item */
279 day
= (rdsdata
[3] >> 11) & 0x1F;
280 hour
= (rdsdata
[3] >> 6) & 0x1F;
281 minute
= (rdsdata
[3] >> 0) & 0x3F;
284 case 4: /* group 2A: radio text */
285 segment
= rdsdata
[1] & 0xF;
286 abflag
= (rdsdata
[1] >> 4) & 1;
287 if (abflag
!= abflag_prev
) {
289 abflag_prev
= abflag
;
291 rt
[segment
* 4 + 0] = (rdsdata
[2] >> 8) & 0xFF;
292 rt
[segment
* 4 + 1] = (rdsdata
[2] >> 0) & 0xFF;
293 rt
[segment
* 4 + 2] = (rdsdata
[3] >> 8) & 0xFF;
294 rt
[segment
* 4 + 3] = (rdsdata
[3] >> 0) & 0xFF;
297 case 5: /* group 2B: radio text */
298 segment
= rdsdata
[1] & 0xF;
299 abflag
= (rdsdata
[1] >> 4) & 1;
300 if (abflag
!= abflag_prev
) {
302 abflag_prev
= abflag
;
304 rt
[segment
* 2 + 0] = (rdsdata
[3] >> 8) & 0xFF;
305 rt
[segment
* 2 + 1] = (rdsdata
[3] >> 0) & 0xFF;
312 snprintf(mystring
, 64, "PI:%04X,TP:%d,PTY:%2d,AF:%02X/%02X", pi
, tp
, pty
, af1
, af2
);
313 lcd_puts(0, line
++, mystring
);
314 snprintf(mystring
, 64, "PS:%s,ITEM:%02d-%02d:%02d", ps
, day
, hour
, minute
);
315 lcd_puts(0, line
++, mystring
);
316 snprintf(mystring
, 64, "RT:%s", rt
);
317 lcd_puts(0, line
++, mystring
);