diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-08-02 20:34:47 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-08-02 20:34:47 +0000 |
commit | 240923a801382c86545d10be167a15892a556fb6 (patch) | |
tree | 3c0e07ec3abf0c493a0b24b0b57e8bbd0200f7f6 /firmware/target/hosted/android | |
parent | 850efead04f10488b478a0f255a2464a01156a7f (diff) | |
download | rockbox-240923a801382c86545d10be167a15892a556fb6.tar.gz rockbox-240923a801382c86545d10be167a15892a556fb6.zip |
Rockbox as an application: Commit current Android port progress.
General state is: Rockbox is usable (plays music, saves configuration, touchscreen works too).
Problems:
- Playing music in the background (i.e. when switching to another app) doesn't work reliably, but I'm working on that now.
- no cabbiev2 (only some preliminary files for it), no other default theme.
- screen flickers sometimes if the updates are too frequent
- no multi screen apk/package
- strange behavior when a phone call comes in
The java files (and the eclipse project) resides in android/, which is also supposed to be the build folder.
I've put a small README in there for instructions. There are some steps needed after the make part, which are described there,
and which eclipse mostly handles. But there ought to be some script/makefile rules which do that instead in the future.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27668 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android')
-rw-r--r-- | firmware/target/hosted/android/app/adc-target.h | 25 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/backlight-target.h | 25 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/button-application.c | 29 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/button-target.h | 64 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/i2c-target.h | 25 | ||||
-rw-r--r-- | firmware/target/hosted/android/app/usb-target.h | 25 | ||||
-rw-r--r-- | firmware/target/hosted/android/button-android.c | 87 | ||||
-rw-r--r-- | firmware/target/hosted/android/buttonmap.h | 43 | ||||
-rw-r--r-- | firmware/target/hosted/android/kernel-android.c | 106 | ||||
-rw-r--r-- | firmware/target/hosted/android/lcd-android.c | 291 | ||||
-rw-r--r-- | firmware/target/hosted/android/pcm-android.c | 174 | ||||
-rw-r--r-- | firmware/target/hosted/android/system-android.c | 59 | ||||
-rw-r--r-- | firmware/target/hosted/android/system-target.h | 39 | ||||
-rw-r--r-- | firmware/target/hosted/android/thread-android-arm.c | 98 |
14 files changed, 1090 insertions, 0 deletions
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 | |||
25 | int 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 | ||
29 | void button_init_device(void); | ||
30 | int 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 | |||
30 | static long last_touch; | ||
31 | static int last_y, last_x; | ||
32 | |||
33 | static 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 */ | ||
43 | JNIEXPORT void JNICALL | ||
44 | Java_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 */ | ||
57 | JNIEXPORT void JNICALL | ||
58 | Java_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 | |||
69 | void button_init_device(void) | ||
70 | { | ||
71 | last_touch = current_tick; | ||
72 | } | ||
73 | |||
74 | int 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 */ | ||
28 | struct button_map { | ||
29 | int button, x, y, radius; | ||
30 | char *description; | ||
31 | }; | ||
32 | |||
33 | extern struct button_map bm[]; | ||
34 | |||
35 | int xy2button( int x, int y); | ||
36 | |||
37 | /* for the sim, these function is implemented in uisimulator/buttonmap/ *.c */ | ||
38 | int key_to_button(int keyboard_button); | ||
39 | #ifdef HAVE_TOUCHSCREEN | ||
40 | int 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 | |||
27 | extern JNIEnv *env_ptr; | ||
28 | extern jclass RockboxActivity_class; | ||
29 | extern jobject RockboxActivity_instance; | ||
30 | |||
31 | static jclass RockboxTimer_class; | ||
32 | static jobject RockboxTimer_instance; | ||
33 | static jmethodID java_wait_for_interrupt; | ||
34 | static 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 | */ | ||
46 | JNIEXPORT void JNICALL | ||
47 | Java_org_rockbox_RockboxTimer_timerTask(JNIEnv *env, jobject this) | ||
48 | { | ||
49 | (void)env; | ||
50 | (void)this; | ||
51 | call_tick_tasks(); | ||
52 | } | ||
53 | |||
54 | void 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 | |||
78 | void 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 | |||
88 | bool 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 | |||
98 | bool timer_set_period(long cycles) | ||
99 | { | ||
100 | (void)cycles; | ||
101 | return false; | ||
102 | } | ||
103 | |||
104 | void 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 | |||
28 | extern JNIEnv *env_ptr; | ||
29 | extern jclass RockboxActivity_class; | ||
30 | extern jobject RockboxActivity_instance; | ||
31 | |||
32 | static jobject Framebuffer_instance; | ||
33 | static jmethodID java_lcd_update; | ||
34 | |||
35 | void 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 | |||
75 | void 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 | |||
81 | void 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 | |||
105 | static 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 | |||
114 | void 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 */ | ||
121 | void 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 | |||
27 | extern JNIEnv *env_ptr; | ||
28 | extern jclass RockboxActivity_class; | ||
29 | extern jobject RockboxActivity_instance; | ||
30 | |||
31 | /* infos about our pcm chunks */ | ||
32 | static size_t pcm_data_size; | ||
33 | static char *pcm_data_start; | ||
34 | |||
35 | /* cache frequently called methods */ | ||
36 | static jmethodID play_pause_method; | ||
37 | static jmethodID stop_method; | ||
38 | static jmethodID set_volume_method; | ||
39 | static jclass RockboxPCM_class; | ||
40 | static 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 | **/ | ||
55 | JNIEXPORT void JNICALL | ||
56 | Java_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 | |||
96 | void pcm_play_lock(void) | ||
97 | { | ||
98 | } | ||
99 | |||
100 | void pcm_play_unlock(void) | ||
101 | { | ||
102 | } | ||
103 | |||
104 | void pcm_dma_apply_settings(void) | ||
105 | { | ||
106 | } | ||
107 | |||
108 | void 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 | |||
116 | void pcm_play_dma_stop(void) | ||
117 | { | ||
118 | (*env_ptr)->CallVoidMethod(env_ptr, | ||
119 | RockboxPCM_instance, | ||
120 | stop_method); | ||
121 | } | ||
122 | |||
123 | void 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 | |||
131 | size_t pcm_get_bytes_waiting(void) | ||
132 | { | ||
133 | return pcm_data_size; | ||
134 | } | ||
135 | |||
136 | const 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 | |||
143 | void 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 | |||
167 | void pcm_postinit(void) | ||
168 | { | ||
169 | } | ||
170 | |||
171 | void 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 | |||
27 | void system_exception_wait(void) { } | ||
28 | void system_reboot(void) { } | ||
29 | void power_off(void) { } | ||
30 | void system_init(void) { } | ||
31 | |||
32 | |||
33 | /* global fields for use with various JNI calls */ | ||
34 | JNIEnv *env_ptr; | ||
35 | jobject RockboxActivity_instance; | ||
36 | jclass RockboxActivity_class; | ||
37 | |||
38 | uintptr_t *stackbegin; | ||
39 | uintptr_t *stackend; | ||
40 | |||
41 | extern int main(void); | ||
42 | /* this is the entry point of the android app initially called by jni */ | ||
43 | JNIEXPORT void JNICALL | ||
44 | Java_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 | |||
29 | void 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 | */ | ||
30 | static 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 | */ | ||
57 | static 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 | */ | ||
69 | static 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 | |||
92 | extern void wait_for_interrupt(void); | ||
93 | static inline void core_sleep(void) | ||
94 | { | ||
95 | wait_for_interrupt(); | ||
96 | } | ||
97 | |||
98 | |||