summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES11
-rw-r--r--firmware/common/rbpaths.c8
-rw-r--r--firmware/drivers/audio/android.c61
-rw-r--r--firmware/export/audiohw.h2
-rw-r--r--firmware/export/config.h14
-rw-r--r--firmware/export/config/application.h28
-rw-r--r--firmware/export/config/sim.h3
-rw-r--r--firmware/export/debug.h7
-rw-r--r--firmware/export/thread.h14
-rw-r--r--firmware/sound.c2
-rw-r--r--firmware/target/hosted/android/app/adc-target.h25
-rw-r--r--firmware/target/hosted/android/app/backlight-target.h25
-rw-r--r--firmware/target/hosted/android/app/button-application.c29
-rw-r--r--firmware/target/hosted/android/app/button-target.h64
-rw-r--r--firmware/target/hosted/android/app/i2c-target.h25
-rw-r--r--firmware/target/hosted/android/app/usb-target.h25
-rw-r--r--firmware/target/hosted/android/button-android.c87
-rw-r--r--firmware/target/hosted/android/buttonmap.h43
-rw-r--r--firmware/target/hosted/android/kernel-android.c106
-rw-r--r--firmware/target/hosted/android/lcd-android.c291
-rw-r--r--firmware/target/hosted/android/pcm-android.c174
-rw-r--r--firmware/target/hosted/android/system-android.c59
-rw-r--r--firmware/target/hosted/android/system-target.h39
-rw-r--r--firmware/target/hosted/android/thread-android-arm.c98
-rw-r--r--firmware/thread.c15
25 files changed, 1236 insertions, 19 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index d8cfadef11..4092f71e04 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1698,3 +1698,14 @@ target/coldfire/mpio/fmradio_i2c-mpio.c
1698#endif /* BOOTLOADER */ 1698#endif /* BOOTLOADER */
1699#endif /* SIMULATOR */ 1699#endif /* SIMULATOR */
1700#endif 1700#endif
1701
1702
1703#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
1704target/hosted/android/lcd-android.c
1705target/hosted/android/button-android.c
1706target/hosted/android/kernel-android.c
1707target/hosted/android/pcm-android.c
1708target/hosted/android/system-android.c
1709drivers/audio/android.c
1710thread.c
1711#endif
diff --git a/firmware/common/rbpaths.c b/firmware/common/rbpaths.c
index 69bc1387ef..b63586c9f4 100644
--- a/firmware/common/rbpaths.c
+++ b/firmware/common/rbpaths.c
@@ -33,9 +33,13 @@
33void paths_init(void) 33void paths_init(void)
34{ 34{
35 /* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */ 35 /* make sure $HOME/.config/rockbox.org exists, it's needed for config.cfg */
36#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
37 mkdir("/sdcard/rockbox");
38#else
36 char home_path[MAX_PATH]; 39 char home_path[MAX_PATH];
37 snprintf(home_path, sizeof(home_path), "%s/.config/rockbox.org", getenv("HOME")); 40 snprintf(home_path, sizeof(home_path), "%s/.config/rockbox.org", getenv("HOME"));
38 mkdir(home_path); 41 mkdir(home_path);
42#endif
39} 43}
40 44
41const char* get_user_file_path(const char *path, 45const char* get_user_file_path(const char *path,
@@ -50,7 +54,11 @@ const char* get_user_file_path(const char *path,
50 pos += ROCKBOX_DIR_LEN; 54 pos += ROCKBOX_DIR_LEN;
51 if (*pos == '/') pos += 1; 55 if (*pos == '/') pos += 1;
52 56
57#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
58 if (snprintf(buf, bufsize, "/sdcard/rockbox/%s", pos)
59#else
53 if (snprintf(buf, bufsize, "%s/.config/rockbox.org/%s", getenv("HOME"), pos) 60 if (snprintf(buf, bufsize, "%s/.config/rockbox.org/%s", getenv("HOME"), pos)
61#endif
54 >= (int)bufsize) 62 >= (int)bufsize)
55 return NULL; 63 return NULL;
56 64
diff --git a/firmware/drivers/audio/android.c b/firmware/drivers/audio/android.c
new file mode 100644
index 0000000000..300bb08482
--- /dev/null
+++ b/firmware/drivers/audio/android.c
@@ -0,0 +1,61 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright © 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include "config.h"
24#include "audiohw.h"
25
26const struct sound_settings_info audiohw_settings[] = {
27 [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25},
28/* Bass and treble tone controls */
29#ifdef AUDIOHW_HAVE_BASS
30 [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
31#endif
32#ifdef AUDIOHW_HAVE_TREBLE
33 [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
34#endif
35 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
36 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
37 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
38#if defined(HAVE_RECORDING)
39 [SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0},
40 [SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0},
41 [SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16},
42#endif
43#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
44 [SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1},
45#endif
46#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
47 [SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1},
48#endif
49};
50
51
52void audiohw_set_volume(int volume)
53{
54 extern void pcm_set_mixer_volume(int);
55 pcm_set_mixer_volume(volume);
56}
57
58void audiohw_set_balance(int balance)
59{
60 (void)balance;
61}
diff --git a/firmware/export/audiohw.h b/firmware/export/audiohw.h
index d4861aac5a..658dd1301c 100644
--- a/firmware/export/audiohw.h
+++ b/firmware/export/audiohw.h
@@ -66,7 +66,7 @@
66#elif defined(HAVE_AK4537) 66#elif defined(HAVE_AK4537)
67#include "ak4537.h" 67#include "ak4537.h"
68#endif 68#endif
69#if defined(HAVE_SDL_AUDIO) 69#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
70/* #include <SDL_audio.h> gives errors in other code areas, 70/* #include <SDL_audio.h> gives errors in other code areas,
71 * we don't really need it here, so don't. but it should maybe be fixed */ 71 * we don't really need it here, so don't. but it should maybe be fixed */
72#ifndef SIMULATOR /* simulator gets values from the target .h files */ 72#ifndef SIMULATOR /* simulator gets values from the target .h files */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index 1b8a782f39..3b59004549 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -78,8 +78,10 @@
78 * bit fields to allow PLATFORM_HOSTED to be OR'ed e.g. with a 78 * bit fields to allow PLATFORM_HOSTED to be OR'ed e.g. with a
79 * possible future PLATFORM_ANDROID (some OSes might need totally different 79 * possible future PLATFORM_ANDROID (some OSes might need totally different
80 * handling to run on them than a stand-alone application) */ 80 * handling to run on them than a stand-alone application) */
81#define PLATFORM_NATIVE (1<<0) 81#define PLATFORM_NATIVE (1<<0)
82#define PLATFORM_HOSTED (1<<1) 82#define PLATFORM_HOSTED (1<<1)
83#define PLATFORM_ANDROID (1<<2)
84#define PLATFORM_SDL (1<<3)
83 85
84/* CONFIG_KEYPAD */ 86/* CONFIG_KEYPAD */
85#define PLAYER_PAD 1 87#define PLAYER_PAD 1
@@ -427,6 +429,8 @@ Lyre prototype 1 */
427 429
428#elif defined(APPLICATION) 430#elif defined(APPLICATION)
429#include "config/application.h" 431#include "config/application.h"
432#define CONFIG_CPU 0
433#define CONFIG_STORAGE 0
430#else 434#else
431/* no known platform */ 435/* no known platform */
432#endif 436#endif
@@ -689,11 +693,17 @@ Lyre prototype 1 */
689#define HAVE_EXTENDED_MESSAGING_AND_NAME 693#define HAVE_EXTENDED_MESSAGING_AND_NAME
690#define HAVE_WAKEUP_EXT_CB 694#define HAVE_WAKEUP_EXT_CB
691 695
696
697#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
698#define HAVE_PRIORITY_SCHEDULING
699#endif
700
692#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 701#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
693#define HAVE_PRIORITY_SCHEDULING 702#define HAVE_PRIORITY_SCHEDULING
694#define HAVE_SCHEDULER_BOOSTCTRL 703#define HAVE_SCHEDULER_BOOSTCTRL
695#endif /* PLATFORM_NATIVE */ 704#endif /* PLATFORM_NATIVE */
696 705
706
697#define HAVE_SEMAPHORE_OBJECTS 707#define HAVE_SEMAPHORE_OBJECTS
698 708
699#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_ARC 709#if defined(HAVE_USBSTACK) && CONFIG_USBOTG == USBOTG_ARC
diff --git a/firmware/export/config/application.h b/firmware/export/config/application.h
index a5583ded75..988f0d51ac 100644
--- a/firmware/export/config/application.h
+++ b/firmware/export/config/application.h
@@ -4,11 +4,13 @@
4#define TARGET_TREE /* this target is using the target tree system */ 4#define TARGET_TREE /* this target is using the target tree system */
5 5
6/* We don't run on hardware directly */ 6/* We don't run on hardware directly */
7#define CONFIG_PLATFORM PLATFORM_HOSTED 7#ifdef ANDROID
8#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_ANDROID)
9#else
10#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_SDL)
11#endif
8/* For Rolo and boot loader */ 12/* For Rolo and boot loader */
9/* 13#define MODEL_NUMBER 100
10#define MODEL_NUMBER 24
11*/
12 14
13#define MODEL_NAME "Rockbox" 15#define MODEL_NAME "Rockbox"
14 16
@@ -37,9 +39,17 @@
37/* define this if you would like tagcache to build on this target */ 39/* define this if you would like tagcache to build on this target */
38#define HAVE_TAGCACHE 40#define HAVE_TAGCACHE
39 41
40/* LCD dimensions */ 42/* LCD dimensions
43 *
44 * overriden by configure for application builds */
45#ifndef LCD_WIDTH
41#define LCD_WIDTH 320 46#define LCD_WIDTH 320
42#define LCD_HEIGHT 240 47#endif
48
49#ifndef LCD_HEIGHT
50#define LCD_HEIGHT 480
51#endif
52
43#define LCD_DEPTH 16 53#define LCD_DEPTH 16
44#define LCD_PIXELFORMAT 565 54#define LCD_PIXELFORMAT 565
45 55
@@ -62,10 +72,10 @@
62#define CONFIG_CODEC SWCODEC 72#define CONFIG_CODEC SWCODEC
63 73
64#define CONFIG_KEYPAD COWON_D2_PAD 74#define CONFIG_KEYPAD COWON_D2_PAD
75
76#if (CONFIG_PLATFORM & PLATFORM_SDL)
65/* Use SDL audio/pcm in a SDL app build */ 77/* Use SDL audio/pcm in a SDL app build */
66#define HAVE_SDL 78#define HAVE_SDL
67
68#ifdef HAVE_SDL
69#define HAVE_SDL_AUDIO 79#define HAVE_SDL_AUDIO
70#endif 80#endif
71 81
@@ -92,3 +102,5 @@
92 102
93/* Define this if a programmable hotkey is mapped */ 103/* Define this if a programmable hotkey is mapped */
94//#define HAVE_HOTKEY 104//#define HAVE_HOTKEY
105
106#define BOOTDIR "/.rockbox"
diff --git a/firmware/export/config/sim.h b/firmware/export/config/sim.h
index 5dcb4f6f2d..066201ad08 100644
--- a/firmware/export/config/sim.h
+++ b/firmware/export/config/sim.h
@@ -99,7 +99,8 @@
99#define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING 99#define DEFAULT_BRIGHTNESS_SETTING MAX_BRIGHTNESS_SETTING
100#endif 100#endif
101 101
102#define CONFIG_PLATFORM (PLATFORM_HOSTED|PLATFORM_SDL)
102#define HAVE_SDL 103#define HAVE_SDL
103#define HAVE_SDL_AUDIO 104#define HAVE_SDL_AUDIO
104#define CONFIG_PLATFORM PLATFORM_HOSTED 105
105#define _ISOC99_SOURCE 1 106#define _ISOC99_SOURCE 1
diff --git a/firmware/export/debug.h b/firmware/export/debug.h
index f7f0f32426..f19a96c526 100644
--- a/firmware/export/debug.h
+++ b/firmware/export/debug.h
@@ -21,6 +21,7 @@
21#ifndef DEBUG_H 21#ifndef DEBUG_H
22#define DEBUG_H 22#define DEBUG_H
23 23
24#include "config.h"
24#include "gcc_extensions.h" 25#include "gcc_extensions.h"
25 26
26extern void debug_init(void); 27extern void debug_init(void);
@@ -34,7 +35,11 @@ extern void ldebugf(const char* file, int line, const char *fmt, ...)
34/* */ 35/* */
35#if defined(SIMULATOR) && !defined(__PCTOOL__) 36#if defined(SIMULATOR) && !defined(__PCTOOL__)
36#define DEBUGF debugf 37#define DEBUGF debugf
37#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__) 38#define LDEBUGF(...) ldebugf(__FILE__, __LINE__, __VA_ARGS__) && defined(DEBUG)
39#elif (CONFIG_PLATFORM & PLATFORM_ANDROID)
40#include "system-target.h"
41#define DEBUGF LOG
42#define LDEBUGF(...)
38#else 43#else
39#if defined(DEBUG) 44#if defined(DEBUG)
40 45
diff --git a/firmware/export/thread.h b/firmware/export/thread.h
index c4b7d1fa22..2853c0b121 100644
--- a/firmware/export/thread.h
+++ b/firmware/export/thread.h
@@ -79,9 +79,19 @@
79 79
80#define MAXTHREADS (BASETHREADS+TARGET_EXTRA_THREADS) 80#define MAXTHREADS (BASETHREADS+TARGET_EXTRA_THREADS)
81 81
82/*
83 * We need more stack when we run under a host
84 * maybe more expensive C lib functions?
85 *
86 * simulator doesn't simulate stack usage anyway but well ... */
87#if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SIMULATOR))
82#define DEFAULT_STACK_SIZE 0x400 /* Bytes */ 88#define DEFAULT_STACK_SIZE 0x400 /* Bytes */
89#else
90#define DEFAULT_STACK_SIZE 0x1000 /* Bytes */
91#endif
92
83 93
84#if (CONFIG_PLATFORM & PLATFORM_NATIVE) 94#if (CONFIG_PLATFORM & (PLATFORM_NATIVE|PLATFORM_ANDROID))
85/* Need to keep structures inside the header file because debug_menu 95/* Need to keep structures inside the header file because debug_menu
86 * needs them. */ 96 * needs them. */
87#ifdef CPU_COLDFIRE 97#ifdef CPU_COLDFIRE
@@ -101,7 +111,7 @@ struct regs
101 uint32_t pr; /* 32 - Procedure register */ 111 uint32_t pr; /* 32 - Procedure register */
102 uint32_t start; /* 36 - Thread start address, or NULL when started */ 112 uint32_t start; /* 36 - Thread start address, or NULL when started */
103}; 113};
104#elif defined(CPU_ARM) 114#elif defined(CPU_ARM) || (CONFIG_PLATFORM & PLATFORM_ANDROID)
105struct regs 115struct regs
106{ 116{
107 uint32_t r[8]; /* 0-28 - Registers r4-r11 */ 117 uint32_t r[8]; /* 0-28 - Registers r4-r11 */
diff --git a/firmware/sound.c b/firmware/sound.c
index 76f1dd0df6..4cc63f4583 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -273,7 +273,7 @@ static void set_prescaled_volume(void)
273 273
274#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) 274#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
275 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); 275 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
276#elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) 276#elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
277 audiohw_set_volume(current_volume); 277 audiohw_set_volume(current_volume);
278#endif 278#endif
279#else /* HAVE_SDL_AUDIO */ 279#else /* HAVE_SDL_AUDIO */
diff --git a/firmware/target/hosted/android/app/adc-target.h b/firmware/target/hosted/android/app/adc-target.h
new file mode 100644
index 0000000000..f8069be6f5
--- /dev/null
+++ b/firmware/target/hosted/android/app/adc-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __ADC_TARGET_H__
23#define __ADC_TARGET_H__
24
25#endif /* __ADC_TARGET_H__ */
diff --git a/firmware/target/hosted/android/app/backlight-target.h b/firmware/target/hosted/android/app/backlight-target.h
new file mode 100644
index 0000000000..f753e7c1dd
--- /dev/null
+++ b/firmware/target/hosted/android/app/backlight-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __BACKLIGHT_TARGET_H__
23#define __BACKLIGHT_TARGET_H__
24
25#endif /* __BACKLIGHT_TARGET_H__ */
diff --git a/firmware/target/hosted/android/app/button-application.c b/firmware/target/hosted/android/app/button-application.c
new file mode 100644
index 0000000000..a27f769718
--- /dev/null
+++ b/firmware/target/hosted/android/app/button-application.c
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ***************************************************9*************************/
21
22
23#include "button.h"
24
25int key_to_button(int keyboard_key)
26{
27 (void)keyboard_key;
28 return BUTTON_NONE;
29}
diff --git a/firmware/target/hosted/android/app/button-target.h b/firmware/target/hosted/android/app/button-target.h
new file mode 100644
index 0000000000..329ed651af
--- /dev/null
+++ b/firmware/target/hosted/android/app/button-target.h
@@ -0,0 +1,64 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2007 by Rob Purchase
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _BUTTON_TARGET_H_
23#define _BUTTON_TARGET_H_
24
25#include <stdbool.h>
26#include "config.h"
27
28#undef button_init_device
29void button_init_device(void);
30int button_read_device(int *data);
31
32/* Main unit's buttons */
33#define BUTTON_POWER 0x00000001
34#define BUTTON_PLUS 0x00000002
35#define BUTTON_MINUS 0x00000004
36#define BUTTON_MENU 0x00000008
37
38/* Compatibility hacks for flipping. Needs a somewhat better fix. */
39#define BUTTON_LEFT BUTTON_MIDLEFT
40#define BUTTON_RIGHT BUTTON_MIDRIGHT
41#define BUTTON_UP BUTTON_TOPMIDDLE
42#define BUTTON_DOWN BUTTON_BOTTOMMIDDLE
43
44/* Touch Screen Area Buttons */
45#define BUTTON_TOPLEFT 0x00000010
46#define BUTTON_TOPMIDDLE 0x00000020
47#define BUTTON_TOPRIGHT 0x00000040
48#define BUTTON_MIDLEFT 0x00000080
49#define BUTTON_CENTER 0x00000100
50#define BUTTON_MIDRIGHT 0x00000200
51#define BUTTON_BOTTOMLEFT 0x00000400
52#define BUTTON_BOTTOMMIDDLE 0x00000800
53#define BUTTON_BOTTOMRIGHT 0x00001000
54
55#define BUTTON_MAIN 0x1FFF
56
57/* No remote */
58#define BUTTON_REMOTE 0
59
60/* Software power-off */
61#define POWEROFF_BUTTON BUTTON_POWER
62#define POWEROFF_COUNT 10
63
64#endif /* _BUTTON_TARGET_H_ */
diff --git a/firmware/target/hosted/android/app/i2c-target.h b/firmware/target/hosted/android/app/i2c-target.h
new file mode 100644
index 0000000000..89f0436b9e
--- /dev/null
+++ b/firmware/target/hosted/android/app/i2c-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __I2C_TARGET_H__
23#define __I2C_TARGET_H__
24
25#endif /* __I2C_TARGET_H__ */
diff --git a/firmware/target/hosted/android/app/usb-target.h b/firmware/target/hosted/android/app/usb-target.h
new file mode 100644
index 0000000000..10e04677f9
--- /dev/null
+++ b/firmware/target/hosted/android/app/usb-target.h
@@ -0,0 +1,25 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __USB_TARGET_H__
23#define __USB_TARGET_H__
24
25#endif /* __USB_TARGET_H__ */
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
new file mode 100644
index 0000000000..67e8ca1f89
--- /dev/null
+++ b/firmware/target/hosted/android/button-android.c
@@ -0,0 +1,87 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <jni.h>
24#include <stdbool.h>
25#include "config.h"
26#include "kernel.h"
27#include "system.h"
28#include "touchscreen.h"
29
30static long last_touch;
31static int last_y, last_x;
32
33static enum {
34 STATE_UNKNOWN,
35 STATE_UP,
36 STATE_DOWN,
37} last_state = STATE_UNKNOWN;
38
39
40/*
41 * this writes in an interrupt-like fashion the last pixel coordinates
42 * that the user pressed on the screen */
43JNIEXPORT void JNICALL
44Java_org_rockbox_RockboxFramebuffer_pixelHandler(JNIEnv*env, jobject this,
45 int x, int y)
46{
47 (void)env;
48 (void)this;
49 last_x = x;
50 last_y = y;
51 last_touch = current_tick;
52}
53
54/*
55 * this notifies us in an interrupt-like fashion whether the user just
56 * began or stopped the touch action */
57JNIEXPORT void JNICALL
58Java_org_rockbox_RockboxFramebuffer_touchHandler(JNIEnv*env, jobject this,
59 int down)
60{
61 (void)env;
62 (void)this;
63 if (down)
64 last_state = STATE_DOWN;
65 else
66 last_state = STATE_UP;
67}
68
69void button_init_device(void)
70{
71 last_touch = current_tick;
72}
73
74int button_read_device(int *data)
75{
76 /* get grid button/coordinates based on the current touchscreen mode */
77 int btn = touchscreen_to_pixels(last_x, last_y, data);
78 if (last_state == STATE_DOWN)
79 {
80 return btn;
81 }
82 else
83 {
84 *data = last_x = last_y = 0;
85 return 0;
86 }
87}
diff --git a/firmware/target/hosted/android/buttonmap.h b/firmware/target/hosted/android/buttonmap.h
new file mode 100644
index 0000000000..e90b8a40d4
--- /dev/null
+++ b/firmware/target/hosted/android/buttonmap.h
@@ -0,0 +1,43 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Fred Bauer
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef __BUTTONMAP_H__
23#define __BUTTONMAP_H__
24/* Button maps: simulated key, x, y, radius, name */
25/* Run sim with --mapping to get coordinates */
26/* or --debugbuttons to check */
27/* The First matching button is returned */
28struct button_map {
29 int button, x, y, radius;
30 char *description;
31};
32
33extern struct button_map bm[];
34
35int xy2button( int x, int y);
36
37/* for the sim, these function is implemented in uisimulator/buttonmap/ *.c */
38int key_to_button(int keyboard_button);
39#ifdef HAVE_TOUCHSCREEN
40int key_to_touch(int keyboard_button, unsigned int mouse_coords);
41#endif
42
43#endif /* __BUTTONMAP_H__ */
diff --git a/firmware/target/hosted/android/kernel-android.c b/firmware/target/hosted/android/kernel-android.c
new file mode 100644
index 0000000000..9594516460
--- /dev/null
+++ b/firmware/target/hosted/android/kernel-android.c
@@ -0,0 +1,106 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <jni.h>
24#include "config.h"
25#include "system.h"
26
27extern JNIEnv *env_ptr;
28extern jclass RockboxActivity_class;
29extern jobject RockboxActivity_instance;
30
31static jclass RockboxTimer_class;
32static jobject RockboxTimer_instance;
33static jmethodID java_wait_for_interrupt;
34static bool initialized = false;
35
36/*
37 * This is called from the separate Timer java thread. I have not added any
38 * interrupt simulation to it (like the sdl counterpart does),
39 * I think this is probably not needed, unless code calls disable_interrupt()
40 * in order to be protected from tick tasks, but I can't remember a place right
41 * now.
42 *
43 * No synchronisation mechanism either. This could possibly be problematic,
44 * but we'll see :)
45 */
46JNIEXPORT void JNICALL
47Java_org_rockbox_RockboxTimer_timerTask(JNIEnv *env, jobject this)
48{
49 (void)env;
50 (void)this;
51 call_tick_tasks();
52}
53
54void tick_start(unsigned int interval_in_ms)
55{
56 JNIEnv e = *env_ptr;
57 /* first, create a new Timer instance */
58 RockboxTimer_class = e->FindClass(env_ptr, "org/rockbox/RockboxTimer");
59 jmethodID constructor = e->GetMethodID(env_ptr,
60 RockboxTimer_class,
61 "<init>",
62 "(J)V");
63 /* the constructor will do the tick_start */
64 RockboxTimer_instance = e->NewObject(env_ptr,
65 RockboxTimer_class,
66 constructor,
67 (jlong)interval_in_ms);
68
69 /* get our wfi func also */
70 java_wait_for_interrupt = e->GetMethodID(env_ptr,
71 RockboxTimer_class,
72 "java_wait_for_interrupt",
73 "()V");
74 /* it's now safe to call java_wait_for_interrupt */
75 initialized = true;
76}
77
78void wait_for_interrupt(void)
79{
80 if (LIKELY(initialized))
81 {
82 (*env_ptr)->CallVoidMethod(env_ptr,
83 RockboxTimer_instance,
84 java_wait_for_interrupt);
85 }
86}
87
88bool timer_register(int reg_prio, void (*unregister_callback)(void),
89 long cycles, void (*timer_callback)(void))
90{
91 (void)reg_prio;
92 (void)unregister_callback;
93 (void)cycles;
94 (void)timer_callback;
95 return false;
96}
97
98bool timer_set_period(long cycles)
99{
100 (void)cycles;
101 return false;
102}
103
104void timer_unregister(void)
105{
106}
diff --git a/firmware/target/hosted/android/lcd-android.c b/firmware/target/hosted/android/lcd-android.c
new file mode 100644
index 0000000000..ef4004ef2a
--- /dev/null
+++ b/firmware/target/hosted/android/lcd-android.c
@@ -0,0 +1,291 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <jni.h>
24#include "config.h"
25#include "system.h"
26#include "lcd.h"
27
28extern JNIEnv *env_ptr;
29extern jclass RockboxActivity_class;
30extern jobject RockboxActivity_instance;
31
32static jobject Framebuffer_instance;
33static jmethodID java_lcd_update;
34
35void lcd_init_device(void)
36{
37 /* get the RockboxFramebuffer instance allocated by the activity */
38 jfieldID id = (*env_ptr)->GetFieldID(env_ptr,
39 RockboxActivity_class,
40 "fb",
41 "Lorg/rockbox/RockboxFramebuffer;");
42
43 Framebuffer_instance = (*env_ptr)->GetObjectField(env_ptr,
44 RockboxActivity_instance,
45 id);
46
47 jclass Framebuffer_class = (*env_ptr)->GetObjectClass(env_ptr,
48 Framebuffer_instance);
49
50 /* get the java init function and call it. it'll set up a bitmap
51 * based on LCD_WIDTH, LCD_HEIGHT and the ByteBuffer which directly maps
52 * our framebuffer */
53
54 jmethodID java_init_lcd = (*env_ptr)->GetMethodID(env_ptr,
55 Framebuffer_class,
56 "java_lcd_init",
57 "(IILjava/nio/ByteBuffer;)V");
58 java_lcd_update = (*env_ptr)->GetMethodID(env_ptr,
59 Framebuffer_class,
60 "java_lcd_update",
61 "()V");
62
63 /* map the framebuffer to a ByteBuffer, this way lcd updates will
64 * be directly feched from the framebuffer */
65 jobject buf = (*env_ptr)->NewDirectByteBuffer(env_ptr,
66 lcd_framebuffer,
67 sizeof(lcd_framebuffer));
68
69 (*env_ptr)->CallVoidMethod(env_ptr,
70 Framebuffer_instance,
71 java_init_lcd,
72 LCD_WIDTH, LCD_HEIGHT, buf);
73}
74
75void lcd_update()
76{
77 /* tell the system we're ready for drawing */
78 (*env_ptr)->CallVoidMethod(env_ptr, Framebuffer_instance, java_lcd_update);
79}
80
81void lcd_update_rect(int x, int y, int height, int width)
82{
83 /* can't do partial updates yet */
84 (void)x; (void)y; (void)height; (void)width;
85 lcd_update();
86}
87
88/* below is a plain copy from lcd-sdl.c */
89
90/**
91 * |R| |1.000000 -0.000001 1.402000| |Y'|
92 * |G| = |1.000000 -0.334136 -0.714136| |Pb|
93 * |B| |1.000000 1.772000 0.000000| |Pr|
94 * Scaled, normalized, rounded and tweaked to yield RGB 565:
95 * |R| |74 0 101| |Y' - 16| >> 9
96 * |G| = |74 -24 -51| |Cb - 128| >> 8
97 * |B| |74 128 0| |Cr - 128| >> 9
98 */
99#define YFAC (74)
100#define RVFAC (101)
101#define GUFAC (-24)
102#define GVFAC (-51)
103#define BUFAC (128)
104
105static inline int clamp(int val, int min, int max)
106{
107 if (val < min)
108 val = min;
109 else if (val > max)
110 val = max;
111 return val;
112}
113
114void lcd_yuv_set_options(unsigned options)
115{
116 (void)options;
117}
118
119/* Draw a partial YUV colour bitmap - similiar behavior to lcd_blit_yuv
120 in the core */
121void lcd_blit_yuv(unsigned char * const src[3],
122 int src_x, int src_y, int stride,
123 int x, int y, int width, int height)
124{
125 const unsigned char *ysrc, *usrc, *vsrc;
126 int linecounter;
127 fb_data *dst, *row_end;
128 long z;
129
130 /* width and height must be >= 2 and an even number */
131 width &= ~1;
132 linecounter = height >> 1;
133
134#if LCD_WIDTH >= LCD_HEIGHT
135 dst = &lcd_framebuffer[y][x];
136 row_end = dst + width;
137#else
138 dst = &lcd_framebuffer[x][LCD_WIDTH - y - 1];
139 row_end = dst + LCD_WIDTH * width;
140#endif
141
142 z = stride * src_y;
143 ysrc = src[0] + z + src_x;
144 usrc = src[1] + (z >> 2) + (src_x >> 1);
145 vsrc = src[2] + (usrc - src[1]);
146
147 /* stride => amount to jump from end of last row to start of next */
148 stride -= width;
149
150 /* upsampling, YUV->RGB conversion and reduction to RGB565 in one go */
151
152 do
153 {
154 do
155 {
156 int y, cb, cr, rv, guv, bu, r, g, b;
157
158 y = YFAC*(*ysrc++ - 16);
159 cb = *usrc++ - 128;
160 cr = *vsrc++ - 128;
161
162 rv = RVFAC*cr;
163 guv = GUFAC*cb + GVFAC*cr;
164 bu = BUFAC*cb;
165
166 r = y + rv;
167 g = y + guv;
168 b = y + bu;
169
170 if ((unsigned)(r | g | b) > 64*256-1)
171 {
172 r = clamp(r, 0, 64*256-1);
173 g = clamp(g, 0, 64*256-1);
174 b = clamp(b, 0, 64*256-1);
175 }
176
177 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
178
179#if LCD_WIDTH >= LCD_HEIGHT
180 dst++;
181#else
182 dst += LCD_WIDTH;
183#endif
184
185 y = YFAC*(*ysrc++ - 16);
186 r = y + rv;
187 g = y + guv;
188 b = y + bu;
189
190 if ((unsigned)(r | g | b) > 64*256-1)
191 {
192 r = clamp(r, 0, 64*256-1);
193 g = clamp(g, 0, 64*256-1);
194 b = clamp(b, 0, 64*256-1);
195 }
196
197 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
198
199#if LCD_WIDTH >= LCD_HEIGHT
200 dst++;
201#else
202 dst += LCD_WIDTH;
203#endif
204 }
205 while (dst < row_end);
206
207 ysrc += stride;
208 usrc -= width >> 1;
209 vsrc -= width >> 1;
210
211#if LCD_WIDTH >= LCD_HEIGHT
212 row_end += LCD_WIDTH;
213 dst += LCD_WIDTH - width;
214#else
215 row_end -= 1;
216 dst -= LCD_WIDTH*width + 1;
217#endif
218
219 do
220 {
221 int y, cb, cr, rv, guv, bu, r, g, b;
222
223 y = YFAC*(*ysrc++ - 16);
224 cb = *usrc++ - 128;
225 cr = *vsrc++ - 128;
226
227 rv = RVFAC*cr;
228 guv = GUFAC*cb + GVFAC*cr;
229 bu = BUFAC*cb;
230
231 r = y + rv;
232 g = y + guv;
233 b = y + bu;
234
235 if ((unsigned)(r | g | b) > 64*256-1)
236 {
237 r = clamp(r, 0, 64*256-1);
238 g = clamp(g, 0, 64*256-1);
239 b = clamp(b, 0, 64*256-1);
240 }
241
242 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
243
244#if LCD_WIDTH >= LCD_HEIGHT
245 dst++;
246#else
247 dst += LCD_WIDTH;
248#endif
249
250 y = YFAC*(*ysrc++ - 16);
251 r = y + rv;
252 g = y + guv;
253 b = y + bu;
254
255 if ((unsigned)(r | g | b) > 64*256-1)
256 {
257 r = clamp(r, 0, 64*256-1);
258 g = clamp(g, 0, 64*256-1);
259 b = clamp(b, 0, 64*256-1);
260 }
261
262 *dst = LCD_RGBPACK_LCD(r >> 9, g >> 8, b >> 9);
263
264#if LCD_WIDTH >= LCD_HEIGHT
265 dst++;
266#else
267 dst += LCD_WIDTH;
268#endif
269 }
270 while (dst < row_end);
271
272 ysrc += stride;
273 usrc += stride >> 1;
274 vsrc += stride >> 1;
275
276#if LCD_WIDTH >= LCD_HEIGHT
277 row_end += LCD_WIDTH;
278 dst += LCD_WIDTH - width;
279#else
280 row_end -= 1;
281 dst -= LCD_WIDTH*width + 1;
282#endif
283 }
284 while (--linecounter > 0);
285
286#if LCD_WIDTH >= LCD_HEIGHT
287 lcd_update_rect(x, y, width, height);
288#else
289 lcd_update_rect(LCD_WIDTH - y - height, x, height, width);
290#endif
291}
diff --git a/firmware/target/hosted/android/pcm-android.c b/firmware/target/hosted/android/pcm-android.c
new file mode 100644
index 0000000000..91978f422b
--- /dev/null
+++ b/firmware/target/hosted/android/pcm-android.c
@@ -0,0 +1,174 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <jni.h>
23#include <stdbool.h>
24#include <system.h>
25#include "pcm.h"
26
27extern JNIEnv *env_ptr;
28extern jclass RockboxActivity_class;
29extern jobject RockboxActivity_instance;
30
31/* infos about our pcm chunks */
32static size_t pcm_data_size;
33static char *pcm_data_start;
34
35/* cache frequently called methods */
36static jmethodID play_pause_method;
37static jmethodID stop_method;
38static jmethodID set_volume_method;
39static jclass RockboxPCM_class;
40static jobject RockboxPCM_instance;
41
42
43/*
44 * transfer our raw data into a java array
45 *
46 * a bit of a monster functions, but it should cover all cases to overcome
47 * the issue that the chunk size of the java layer and our pcm chunks are
48 * differently sized
49 *
50 * afterall, it only copies the raw pcm data from pcm_data_start to
51 * the passed byte[]-array
52 *
53 * it is called from the PositionMarker callback of AudioTrack
54 **/
55JNIEXPORT void JNICALL
56Java_org_rockbox_RockboxPCM_pcmSamplesToByteArray(JNIEnv *env,
57 jobject this,
58 jbyteArray arr)
59{
60 (void)this;
61 size_t len;
62 size_t array_size = (*env)->GetArrayLength(env, arr);
63 if (array_size > pcm_data_size)
64 len = pcm_data_size;
65 else
66 len = array_size;
67
68 (*env)->SetByteArrayRegion(env, arr, 0, len, pcm_data_start);
69
70 if (array_size > pcm_data_size)
71 { /* didn't have enough data for the array ? */
72 size_t remaining = array_size - pcm_data_size;
73 size_t offset = len;
74 retry:
75 pcm_play_get_more_callback((void**)&pcm_data_start, &pcm_data_size);
76 if (pcm_data_size == 0)
77 return;
78 if (remaining > pcm_data_size)
79 { /* got too little data, get more ... */
80 (*env)->SetByteArrayRegion(env, arr, offset, pcm_data_size, pcm_data_start);
81 /* advance in the java array by the amount we copied */
82 offset += pcm_data_size;
83 /* we copied at least a bit */
84 remaining -= pcm_data_size;
85 /* let's get another buch of data and try again */
86 goto retry;
87 }
88 else
89 (*env)->SetByteArrayRegion(env, arr, offset, remaining, pcm_data_start);
90 len = remaining;
91 }
92 pcm_data_start += len;
93 pcm_data_size -= len;
94}
95
96void pcm_play_lock(void)
97{
98}
99
100void pcm_play_unlock(void)
101{
102}
103
104void pcm_dma_apply_settings(void)
105{
106}
107
108void pcm_play_dma_start(const void *addr, size_t size)
109{
110 pcm_data_start = (char*)addr;
111 pcm_data_size = size;
112
113 pcm_play_dma_pause(false);
114}
115
116void pcm_play_dma_stop(void)
117{
118 (*env_ptr)->CallVoidMethod(env_ptr,
119 RockboxPCM_instance,
120 stop_method);
121}
122
123void pcm_play_dma_pause(bool pause)
124{
125 (*env_ptr)->CallVoidMethod(env_ptr,
126 RockboxPCM_instance,
127 play_pause_method,
128 (int)pause);
129}
130
131size_t pcm_get_bytes_waiting(void)
132{
133 return pcm_data_size;
134}
135
136const void * pcm_play_dma_get_peak_buffer(int *count)
137{
138 uintptr_t addr = (uintptr_t)pcm_data_start;
139 *count = pcm_data_size / 4;
140 return (void *)((addr + 3) & ~3);
141}
142
143void pcm_play_dma_init(void)
144{
145 /* in order to have background music playing after leaving the activity,
146 * we need to allocate the PCM object from the Rockbox thread (the Activity
147 * runs in a separate thread because it would otherwise kill us when
148 * stopping it)
149 *
150 * Luckily we only reference the PCM object from here, so it's safe (and
151 * clean) to allocate it here
152 **/
153 JNIEnv e = *env_ptr;
154 /* get the class and its constructor */
155 RockboxPCM_class = e->FindClass(env_ptr, "org/rockbox/RockboxPCM");
156 jmethodID constructor = e->GetMethodID(env_ptr, RockboxPCM_class, "<init>", "()V");
157 /* instance = new RockboxPCM() */
158 RockboxPCM_instance = e->NewObject(env_ptr, RockboxPCM_class, constructor);
159 /* cache needed methods */
160 play_pause_method = e->GetMethodID(env_ptr, RockboxPCM_class, "play_pause", "(Z)V");
161 set_volume_method = e->GetMethodID(env_ptr, RockboxPCM_class, "set_volume", "(I)V");
162 stop_method = e->GetMethodID(env_ptr, RockboxPCM_class, "stop", "()V");
163 /* get initial pcm data, if any */
164 pcm_play_get_more_callback((void*)&pcm_data_start, &pcm_data_size);
165}
166
167void pcm_postinit(void)
168{
169}
170
171void pcm_set_mixer_volume(int volume)
172{
173 (*env_ptr)->CallVoidMethod(env_ptr, RockboxPCM_instance, set_volume_method, volume);
174}
diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c
new file mode 100644
index 0000000000..07dff2ed56
--- /dev/null
+++ b/firmware/target/hosted/android/system-android.c
@@ -0,0 +1,59 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2010 Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22
23#include <jni.h>
24#include "config.h"
25#include "system.h"
26
27void system_exception_wait(void) { }
28void system_reboot(void) { }
29void power_off(void) { }
30void system_init(void) { }
31
32
33/* global fields for use with various JNI calls */
34JNIEnv *env_ptr;
35jobject RockboxActivity_instance;
36jclass RockboxActivity_class;
37
38uintptr_t *stackbegin;
39uintptr_t *stackend;
40
41extern int main(void);
42/* this is the entry point of the android app initially called by jni */
43JNIEXPORT void JNICALL
44Java_org_rockbox_RockboxActivity_main(JNIEnv *env, jobject this)
45{
46 /* hack!!! we can't have a valid stack pointer otherwise.
47 * but we don't really need it anyway, thread.c only needs it
48 * for overflow detection which doesn't apply for the main thread
49 * (it's managed by the OS) */
50
51 (void)env;
52 (void)this;
53 volatile uintptr_t stack = 0;
54 stackbegin = stackend = &stack;
55 env_ptr = env;
56 RockboxActivity_instance = this;
57 RockboxActivity_class = (*env)->GetObjectClass(env, this);
58 main();
59}
diff --git a/firmware/target/hosted/android/system-target.h b/firmware/target/hosted/android/system-target.h
new file mode 100644
index 0000000000..210d191d6c
--- /dev/null
+++ b/firmware/target/hosted/android/system-target.h
@@ -0,0 +1,39 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Martitz
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __SYSTEM_TARGET_H__
22#define __SYSTEM_TARGET_H__
23
24#define disable_irq()
25#define enable_irq()
26#define disable_irq_save() 0
27#define restore_irq(level) (void)level
28
29void power_off(void);
30
31#include <android/log.h>
32#define LOG_TAG "Rockbox"
33#define LOG(args...) \
34 __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, ##args);
35
36#endif /* __SYSTEM_TARGET_H__ */
37
38#define NEED_GENERIC_BYTESWAPS
39
diff --git a/firmware/target/hosted/android/thread-android-arm.c b/firmware/target/hosted/android/thread-android-arm.c
new file mode 100644
index 0000000000..baf8b84b65
--- /dev/null
+++ b/firmware/target/hosted/android/thread-android-arm.c
@@ -0,0 +1,98 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Thom Johansen
11 * Copyright (C) 2010 by Thomas Martitz (Android-suitable core_sleep())
12 *
13 * Generic ARM threading support
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#include <jni.h>
26/*---------------------------------------------------------------------------
27 * Start the thread running and terminate it if it returns
28 *---------------------------------------------------------------------------
29 */
30static void __attribute__((naked,used)) start_thread(void)
31{
32 /* r0 = context */
33 asm volatile (
34 "ldr sp, [r0, #32] \n" /* Load initial sp */
35 "ldr r4, [r0, #40] \n" /* start in r4 since it's non-volatile */
36 "mov r1, #0 \n" /* Mark thread as running */
37 "str r1, [r0, #40] \n"
38 "mov lr, pc \n" /* Call thread function */
39 "bx r4 \n"
40 ); /* No clobber list - new thread doesn't care */
41 thread_exit();
42}
43
44/* For startup, place context pointer in r4 slot, start_thread pointer in r5
45 * slot, and thread function pointer in context.start. See load_context for
46 * what happens when thread is initially going to run. */
47#define THREAD_STARTUP_INIT(core, thread, function) \
48 ({ (thread)->context.r[0] = (uint32_t)&(thread)->context, \
49 (thread)->context.r[1] = (uint32_t)start_thread, \
50 (thread)->context.start = (uint32_t)function; })
51
52
53/*---------------------------------------------------------------------------
54 * Store non-volatile context.
55 *---------------------------------------------------------------------------
56 */
57static inline void store_context(void* addr)
58{
59 asm volatile(
60 "stmia %0, { r4-r11, sp, lr } \n"
61 : : "r" (addr)
62 );
63}
64
65/*---------------------------------------------------------------------------
66 * Load non-volatile context.
67 *---------------------------------------------------------------------------
68 */
69static inline void load_context(const void* addr)
70{
71 asm volatile(
72 "ldr r0, [%0, #40] \n" /* Load start pointer */
73 "cmp r0, #0 \n" /* Check for NULL */
74
75 /* If not already running, jump to start */
76 "ldmneia %0, { r0, pc } \n"
77 "ldmia %0, { r4-r11, sp, lr } \n" /* Load regs r4 to r14 from context */
78 : : "r" (addr) : "r0" /* only! */
79 );
80}
81
82/*
83 * this core sleep suspends the OS thread rockbox runs under, which greatly
84 * reduces cpu usage (~100% to <10%)
85 *
86 * it returns when the RockboxTimer notified us, i.e. at each tick
87 * (after it called the tick tasks)
88 *
89 * wait_for_interrupt is implemented in kernel-android.c
90 **/
91
92extern void wait_for_interrupt(void);
93static inline void core_sleep(void)
94{
95 wait_for_interrupt();
96}
97
98
diff --git a/firmware/thread.c b/firmware/thread.c
index c00fc36e3f..b3d8ec3970 100644
--- a/firmware/thread.c
+++ b/firmware/thread.c
@@ -123,8 +123,13 @@ static struct core_entry cores[NUM_CORES] IBSS_ATTR;
123struct thread_entry threads[MAXTHREADS] IBSS_ATTR; 123struct thread_entry threads[MAXTHREADS] IBSS_ATTR;
124 124
125static const char main_thread_name[] = "main"; 125static const char main_thread_name[] = "main";
126#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
126extern uintptr_t stackbegin[]; 127extern uintptr_t stackbegin[];
127extern uintptr_t stackend[]; 128extern uintptr_t stackend[];
129#else
130extern uintptr_t *stackbegin;
131extern uintptr_t *stackend;
132#endif
128 133
129static inline void core_sleep(IF_COP_VOID(unsigned int core)) 134static inline void core_sleep(IF_COP_VOID(unsigned int core))
130 __attribute__((always_inline)); 135 __attribute__((always_inline));
@@ -170,7 +175,9 @@ void switch_thread(void)
170/**************************************************************************** 175/****************************************************************************
171 * Processor-specific section - include necessary core support 176 * Processor-specific section - include necessary core support
172 */ 177 */
173#if defined(CPU_ARM) 178#if defined(ANDROID)
179#include "thread-android-arm.c"
180#elif defined(CPU_ARM)
174#include "thread-arm.c" 181#include "thread-arm.c"
175#if defined (CPU_PP) 182#if defined (CPU_PP)
176#include "thread-pp.c" 183#include "thread-pp.c"
@@ -1150,7 +1157,7 @@ void switch_thread(void)
1150 store_context(&thread->context); 1157 store_context(&thread->context);
1151 1158
1152 /* Check if the current thread stack is overflown */ 1159 /* Check if the current thread stack is overflown */
1153 if (UNLIKELY(thread->stack[0] != DEADBEEF)) 1160 if (UNLIKELY(thread->stack[0] != DEADBEEF) && thread->stack_size > 0)
1154 thread_stkov(thread); 1161 thread_stkov(thread);
1155 1162
1156#if NUM_CORES > 1 1163#if NUM_CORES > 1
@@ -2319,7 +2326,9 @@ static int stack_usage(uintptr_t *stackptr, size_t stack_size)
2319 */ 2326 */
2320int thread_stack_usage(const struct thread_entry *thread) 2327int thread_stack_usage(const struct thread_entry *thread)
2321{ 2328{
2322 return stack_usage(thread->stack, thread->stack_size); 2329 if (LIKELY(thread->stack_size > 0))
2330 return stack_usage(thread->stack, thread->stack_size);
2331 return 0;
2323} 2332}
2324 2333
2325#if NUM_CORES > 1 2334#if NUM_CORES > 1