summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2009-02-10 23:43:37 +0000
committerJens Arnold <amiconn@rockbox.org>2009-02-10 23:43:37 +0000
commit11ad7b4bc8bcb049040c02fae04074faf5dfaf27 (patch)
treece92c57120cb9b019743a863083f654e8d80f95f /firmware
parenteddb5680f9aefecdaccf24279cff2d3cf4fd5d86 (diff)
downloadrockbox-11ad7b4bc8bcb049040c02fae04074faf5dfaf27.tar.gz
rockbox-11ad7b4bc8bcb049040c02fae04074faf5dfaf27.zip
Move screendump from apps to firmware, solving two nasty firmware-to-apps calls. This required to move the filename creation functions as well. * Fix bug in the BMP header of Clip screendumps. * Add remote screendump for targets with an LCD remote. * Simplify some ifdefs and rename a macro in the sim.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19967 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES5
-rw-r--r--firmware/backlight.c10
-rw-r--r--firmware/export/general.h35
-rw-r--r--firmware/general.c117
-rw-r--r--firmware/usb.c11
5 files changed, 165 insertions, 13 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index a9a0b17632..4d33c7949b 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -2,6 +2,7 @@ ata_idle_notify.c
2events.c 2events.c
3backlight.c 3backlight.c
4buffer.c 4buffer.c
5general.c
5powermgmt.c 6powermgmt.c
6system.c 7system.c
7usb.c 8usb.c
@@ -73,6 +74,9 @@ font_cache.c
73font.c 74font.c
74hangul.c 75hangul.c
75lru.c 76lru.c
77#ifndef BOOTLOADER
78screendump.c
79#endif
76#if LCD_DEPTH == 1 80#if LCD_DEPTH == 1
77drivers/lcd-1bit-vert.c 81drivers/lcd-1bit-vert.c
78#elif LCD_DEPTH == 2 82#elif LCD_DEPTH == 2
@@ -201,7 +205,6 @@ sound.c
201#if CONFIG_CODEC == SWCODEC 205#if CONFIG_CODEC == SWCODEC
202 206
203#ifndef BOOTLOADER 207#ifndef BOOTLOADER
204general.c
205pcm_sampr.c 208pcm_sampr.c
206pcm.c 209pcm.c
207#ifdef HAVE_RECORDING 210#ifdef HAVE_RECORDING
diff --git a/firmware/backlight.c b/firmware/backlight.c
index 9c153e885a..513f643171 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -35,6 +35,7 @@
35#include "timer.h" 35#include "timer.h"
36#include "backlight.h" 36#include "backlight.h"
37#include "lcd.h" 37#include "lcd.h"
38#include "screendump.h"
38 39
39#ifdef HAVE_REMOTE_LCD 40#ifdef HAVE_REMOTE_LCD
40#include "lcd-remote.h" 41#include "lcd-remote.h"
@@ -57,9 +58,6 @@ int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
57#include "backlight-sw-fading.h" 58#include "backlight-sw-fading.h"
58#endif 59#endif
59#ifdef SIMULATOR 60#ifdef SIMULATOR
60/* TODO: find a better way to do it but we need a kernel thread somewhere to
61 handle this */
62extern void screen_dump(void);
63 61
64static inline void _backlight_on(void) 62static inline void _backlight_on(void)
65{ 63{
@@ -600,9 +598,13 @@ void backlight_thread(void)
600#endif /* HAVE_REMOTE_LCD/ HAVE_REMOTE_LCD_AS_MAIN */ 598#endif /* HAVE_REMOTE_LCD/ HAVE_REMOTE_LCD_AS_MAIN */
601#endif /* !SIMULATOR */ 599#endif /* !SIMULATOR */
602#ifdef SIMULATOR 600#ifdef SIMULATOR
603 /* This one here too for lack of a better place */ 601 /* TODO: find a better way to do it but we need
602 * a kernel thread somewhere to handle this */
604 case SYS_SCREENDUMP: 603 case SYS_SCREENDUMP:
605 screen_dump(); 604 screen_dump();
605#ifdef HAVE_REMOTE_LCD
606 remote_screen_dump();
607#endif
606 break; 608 break;
607#endif 609#endif
608 case SYS_USB_CONNECTED: 610 case SYS_USB_CONNECTED:
diff --git a/firmware/export/general.h b/firmware/export/general.h
index d1bd14558c..8da4a0ad59 100644
--- a/firmware/export/general.h
+++ b/firmware/export/general.h
@@ -24,7 +24,9 @@
24 24
25#include <stdbool.h> 25#include <stdbool.h>
26#include <stddef.h> 26#include <stddef.h>
27#include "config.h"
27 28
29#if CONFIG_CODEC == SWCODEC
28/* round a signed/unsigned 32bit value to the closest of a list of values */ 30/* round a signed/unsigned 32bit value to the closest of a list of values */
29/* returns the index of the closest value */ 31/* returns the index of the closest value */
30int round_value_to_list32(unsigned long value, 32int round_value_to_list32(unsigned long value,
@@ -36,5 +38,38 @@ int make_list_from_caps32(unsigned long src_mask,
36 const unsigned long *src_list, 38 const unsigned long *src_list,
37 unsigned long caps_mask, 39 unsigned long caps_mask,
38 unsigned long *caps_list); 40 unsigned long *caps_list);
41#endif /* CONFIG_CODEC == SWCODEC */
42
43/* Create a filename with a number part in a way that the number is 1
44 * higher than the highest numbered file matching the same pattern.
45 * It is allowed that buffer and path point to the same memory location,
46 * saving a strcpy(). Path must always be given without trailing slash.
47 *
48 * "num" can point to an int specifying the number to use or NULL or a value
49 * less than zero to number automatically. The final number used will also
50 * be returned in *num. If *num is >= 0 then *num will be incremented by
51 * one. */
52#if defined(HAVE_RECORDING) && (CONFIG_RTC == 0)
53/* this feature is needed by recording without a RTC to prevent disk access
54 when changing files */
55#define IF_CNFN_NUM_(...) __VA_ARGS__
56#define IF_CNFN_NUM
57#else
58#define IF_CNFN_NUM_(...)
59#endif
60char *create_numbered_filename(char *buffer, const char *path,
61 const char *prefix, const char *suffix,
62 int numberlen IF_CNFN_NUM_(, int *num));
63
64#if CONFIG_RTC
65/* Create a filename with a date+time part.
66 It is allowed that buffer and path point to the same memory location,
67 saving a strcpy(). Path must always be given without trailing slash.
68 unique_time as true makes the function wait until the current time has
69 changed. */
70char *create_datetime_filename(char *buffer, const char *path,
71 const char *prefix, const char *suffix,
72 bool unique_time);
73#endif /* CONFIG_RTC */
39 74
40#endif /* GENERAL_H */ 75#endif /* GENERAL_H */
diff --git a/firmware/general.c b/firmware/general.c
index ff6594086e..1ff3340d27 100644
--- a/firmware/general.c
+++ b/firmware/general.c
@@ -18,11 +18,20 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include <limits.h> 21
22#include "system.h"
23#include "config.h" 22#include "config.h"
24#include "general.h" 23#include "general.h"
25 24
25#include "dir.h"
26#include "limits.h"
27#include "sprintf.h"
28#include "stdlib.h"
29#include "string.h"
30#include "system.h"
31#include "time.h"
32#include "timefuncs.h"
33
34#if CONFIG_CODEC == SWCODEC
26int round_value_to_list32(unsigned long value, 35int round_value_to_list32(unsigned long value,
27 const unsigned long list[], 36 const unsigned long list[],
28 int count, 37 int count,
@@ -78,3 +87,107 @@ int make_list_from_caps32(unsigned long src_mask,
78 87
79 return count; 88 return count;
80} /* make_list_from_caps32 */ 89} /* make_list_from_caps32 */
90#endif /* CONFIG_CODEC == SWCODEC */
91
92/* Create a filename with a number part in a way that the number is 1
93 * higher than the highest numbered file matching the same pattern.
94 * It is allowed that buffer and path point to the same memory location,
95 * saving a strcpy(). Path must always be given without trailing slash.
96 * "num" can point to an int specifying the number to use or NULL or a value
97 * less than zero to number automatically. The final number used will also
98 * be returned in *num. If *num is >= 0 then *num will be incremented by
99 * one. */
100char *create_numbered_filename(char *buffer, const char *path,
101 const char *prefix, const char *suffix,
102 int numberlen IF_CNFN_NUM_(, int *num))
103{
104 DIR *dir;
105 struct dirent *entry;
106 int max_num;
107 int pathlen;
108 int prefixlen = strlen(prefix);
109 char fmtstring[12];
110
111 if (buffer != path)
112 strncpy(buffer, path, MAX_PATH);
113
114 pathlen = strlen(buffer);
115
116#ifdef IF_CNFN_NUM
117 if (num && *num >= 0)
118 {
119 /* number specified */
120 max_num = *num;
121 }
122 else
123#endif
124 {
125 /* automatic numbering */
126 max_num = 0;
127
128 dir = opendir(pathlen ? buffer : "/");
129 if (!dir)
130 return NULL;
131
132 while ((entry = readdir(dir)))
133 {
134 int curr_num;
135
136 if (strncasecmp((char *)entry->d_name, prefix, prefixlen)
137 || strcasecmp((char *)entry->d_name + prefixlen + numberlen, suffix))
138 continue;
139
140 curr_num = atoi((char *)entry->d_name + prefixlen);
141 if (curr_num > max_num)
142 max_num = curr_num;
143 }
144
145 closedir(dir);
146 }
147
148 max_num++;
149
150 snprintf(fmtstring, sizeof(fmtstring), "/%%s%%0%dd%%s", numberlen);
151 snprintf(buffer + pathlen, MAX_PATH - pathlen, fmtstring, prefix,
152 max_num, suffix);
153
154#ifdef IF_CNFN_NUM
155 if (num)
156 *num = max_num;
157#endif
158
159 return buffer;
160}
161
162
163#if CONFIG_RTC
164/* Create a filename with a date+time part.
165 It is allowed that buffer and path point to the same memory location,
166 saving a strcpy(). Path must always be given without trailing slash.
167 unique_time as true makes the function wait until the current time has
168 changed. */
169char *create_datetime_filename(char *buffer, const char *path,
170 const char *prefix, const char *suffix,
171 bool unique_time)
172{
173 struct tm *tm = get_time();
174 static struct tm last_tm;
175 int pathlen;
176
177 while (unique_time && !memcmp(get_time(), &last_tm, sizeof (struct tm)))
178 sleep(HZ/10);
179
180 last_tm = *tm;
181
182 if (buffer != path)
183 strncpy(buffer, path, MAX_PATH);
184
185 pathlen = strlen(buffer);
186 snprintf(buffer + pathlen, MAX_PATH - pathlen,
187 "/%s%02d%02d%02d-%02d%02d%02d%s", prefix,
188 tm->tm_year % 100, tm->tm_mon + 1, tm->tm_mday,
189 tm->tm_hour, tm->tm_min, tm->tm_sec, suffix);
190
191 return buffer;
192}
193#endif /* CONFIG_RTC */
diff --git a/firmware/usb.c b/firmware/usb.c
index a1e552a321..a720215731 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -42,7 +42,8 @@
42#ifdef HAVE_USBSTACK 42#ifdef HAVE_USBSTACK
43#include "usb_core.h" 43#include "usb_core.h"
44#endif 44#endif
45#include "logf.h" 45#include "logf.h"
46#include "screendump.h"
46 47
47/* Conditions under which we want the entire driver */ 48/* Conditions under which we want the entire driver */
48#if !defined(BOOTLOADER) || (CONFIG_CPU == SH7034) || \ 49#if !defined(BOOTLOADER) || (CONFIG_CPU == SH7034) || \
@@ -55,11 +56,6 @@
55 56
56#ifdef HAVE_LCD_BITMAP 57#ifdef HAVE_LCD_BITMAP
57bool do_screendump_instead_of_usb = false; 58bool do_screendump_instead_of_usb = false;
58#if defined(USB_FULL_INIT) && defined(BOOTLOADER)
59static void screen_dump(void) {}
60#else
61void screen_dump(void); /* Nasty again. Defined in apps/ too */
62#endif
63#endif 59#endif
64 60
65#if !defined(SIMULATOR) && !defined(USB_NONE) 61#if !defined(SIMULATOR) && !defined(USB_NONE)
@@ -262,6 +258,9 @@ static void usb_thread(void)
262 { 258 {
263 usb_state = USB_SCREENDUMP; 259 usb_state = USB_SCREENDUMP;
264 screen_dump(); 260 screen_dump();
261#ifdef HAVE_REMOTE_LCD
262 remote_screen_dump();
263#endif
265 break; 264 break;
266 } 265 }
267#endif 266#endif