Update the LV24020 FM driver so that it can be used on the D2. Register read/write...
[kugel-rb.git] / firmware / logf.c
blobda05a0a0c748b72290abb780b6ef4a55f88a2ddf
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 * logf() logs MAX_LOGF_ENTRY (21) bytes per entry in a circular buffer. Each
22 * logged string is space- padded for easier and faster output on screen. Just
23 * output MAX_LOGF_ENTRY characters on each line. MAX_LOGF_ENTRY bytes fit
24 * nicely on the iRiver remote LCD (128 pixels with an 8x6 pixels font).
27 #include <string.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include "config.h"
31 #include "lcd-remote.h"
32 #include "logf.h"
33 #include "serial.h"
35 #ifdef HAVE_USBSTACK
36 #include "usb_core.h"
37 #include "usbstack/usb_serial.h"
38 #endif
40 /* Only provide all this if asked to */
41 #ifdef ROCKBOX_HAS_LOGF
43 #ifndef __PCTOOL__
44 unsigned char logfbuffer[MAX_LOGF_LINES][MAX_LOGF_ENTRY];
45 int logfindex;
46 bool logfwrap;
47 #endif
49 #ifdef HAVE_REMOTE_LCD
50 static void displayremote(void)
52 /* TODO: we should have a debug option that enables/disables this! */
53 int w, h;
54 int lines;
55 int columns;
56 int i;
57 int index;
59 lcd_remote_getstringsize("A", &w, &h);
60 lines = LCD_REMOTE_HEIGHT/h;
61 columns = LCD_REMOTE_WIDTH/w;
62 lcd_remote_setmargins(0, 0);
63 lcd_remote_clear_display();
65 index = logfindex;
66 for(i = lines-1; i>=0; i--) {
67 unsigned char buffer[columns+1];
69 if(--index < 0) {
70 if(logfwrap)
71 index = MAX_LOGF_LINES-1;
72 else
73 break; /* done */
76 memcpy(buffer, logfbuffer[index], columns);
77 buffer[columns]=0;
78 lcd_remote_puts(0, i, buffer);
80 lcd_remote_update();
82 #else
83 #define displayremote()
84 #endif
86 #ifdef __PCTOOL__
87 void _logf(const char *format, ...)
89 char buf[1024];
90 va_list ap;
91 va_start(ap, format);
93 vsnprintf(buf, sizeof buf, format, ap);
94 printf("DEBUG: %s\n", buf);
96 #else
97 void _logf(const char *format, ...)
99 int len;
100 unsigned char *ptr;
101 va_list ap;
102 va_start(ap, format);
104 if(logfindex >= MAX_LOGF_LINES) {
105 /* wrap */
106 logfwrap = true;
107 logfindex = 0;
109 ptr = logfbuffer[logfindex];
110 len = vsnprintf(ptr, MAX_LOGF_ENTRY, format, ap);
111 #ifdef HAVE_SERIAL
112 serial_tx(ptr);
113 serial_tx("\r\n");
114 #endif
115 #ifdef USB_SERIAL
116 usb_serial_send(ptr,len);
117 usb_serial_send("\r\n",2);
118 #endif
120 va_end(ap);
121 if(len < MAX_LOGF_ENTRY)
122 /* pad with spaces up to the MAX_LOGF_ENTRY byte border */
123 memset(ptr+len, ' ', MAX_LOGF_ENTRY-len);
125 logfindex++; /* leave it where we write the next time */
127 displayremote();
129 #endif
131 #endif