summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/maemo/maemo-thread.c
diff options
context:
space:
mode:
authorThomas Jarosch <tomj@simonv.com>2011-02-08 20:05:25 +0000
committerThomas Jarosch <tomj@simonv.com>2011-02-08 20:05:25 +0000
commit5f037ac015e6d76d030a163753db5ff58cdff49b (patch)
treef5eb7dcdc0e0c3e373227e45061c1d99a14a0819 /firmware/target/hosted/maemo/maemo-thread.c
parent4d129044390a087b6193b6ce63e035b2550b3ce4 (diff)
downloadrockbox-5f037ac015e6d76d030a163753db5ff58cdff49b.tar.gz
rockbox-5f037ac015e6d76d030a163753db5ff58cdff49b.zip
Initial maemo platform support
Adds Nokia N900, N810 and N800 support. Features: - Introduce maemo specific platform defines - Play audio in silent mode - Stop playback on incoming calls - Battery level readout - Bluetooth headset support - Save CPU by disabling screen updates if the display is off or the app doesn't have input focus - N900: GStreamer audio backend Kudos to kugel for the code review. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29248 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/maemo/maemo-thread.c')
-rw-r--r--firmware/target/hosted/maemo/maemo-thread.c220
1 files changed, 220 insertions, 0 deletions
diff --git a/firmware/target/hosted/maemo/maemo-thread.c b/firmware/target/hosted/maemo/maemo-thread.c
new file mode 100644
index 0000000000..f655ed597e
--- /dev/null
+++ b/firmware/target/hosted/maemo/maemo-thread.c
@@ -0,0 +1,220 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 by Thomas Jarosch
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 <libhal.h>
24#include <libosso.h>
25#include <SDL_thread.h>
26
27#include "config.h"
28#include "system.h"
29#include "kernel.h"
30#include "thread.h"
31#include "power.h"
32#include "debug.h"
33#include "button.h"
34
35/* Battery status information */
36#define BME_UDI "/org/freedesktop/Hal/devices/bme"
37#define BATTERY_PERCENTAGE "battery.charge_level.percentage"
38#define BATTER_REMAINING_TIME "battery.remaining_time"
39
40/* Bluetooth headset support */
41#define BT_HEADSET_UDI "/org/freedesktop/Hal/devices/computer_logicaldev_input_1"
42
43GMainLoop *maemo_main_loop = NULL;
44osso_context_t *maemo_osso_ctx = NULL;
45
46volatile int maemo_display_on = 1;
47volatile int maemo_battery_level = 0;
48volatile int maemo_remaining_time_sec = 0;
49
50extern void send_battery_level_event(void);
51extern int last_sent_battery_level;
52extern int battery_percent;
53
54void display_status_callback(osso_display_state_t state, gpointer data)
55{
56 (void)data;
57
58 if (state == OSSO_DISPLAY_OFF)
59 maemo_display_on = 0;
60 else
61 maemo_display_on = 1;
62}
63
64
65void get_battery_values(LibHalContext *ctx)
66{
67 /* Get initial battery percentage and remaining time */
68 maemo_battery_level = libhal_device_get_property_int(
69 ctx, BME_UDI,
70 BATTERY_PERCENTAGE, NULL);
71
72 maemo_remaining_time_sec = libhal_device_get_property_int(
73 ctx, BME_UDI,
74 BATTER_REMAINING_TIME, NULL);
75
76 DEBUGF("[maemo] Battery percentage: %d, remaining_time_sec: %d\n", maemo_battery_level, maemo_remaining_time_sec);
77}
78
79static void on_battery_changed (LibHalContext *ctx,
80 const char *udi,
81 const char *key,
82 dbus_bool_t is_removed,
83 dbus_bool_t is_added)
84{
85 (void)is_removed;
86 (void)is_added;
87
88 if (!g_str_equal (udi, BME_UDI))
89 return;
90
91 if (!g_str_equal (key, BATTERY_PERCENTAGE) && !g_str_equal (key, BATTER_REMAINING_TIME))
92 return;
93
94 get_battery_values(ctx);
95}
96
97static void on_bt_button_pressed(LibHalContext *ctx,
98 const char *udi,
99 const char *condition_name,
100 const char *condition_detail)
101{
102 (void)ctx;
103
104 if (!g_str_equal (udi, BT_HEADSET_UDI) || !g_str_equal(condition_name, "ButtonPressed"))
105 return;
106
107 sim_enter_irq_handler();
108
109 if (g_str_equal(condition_detail, "play-cd") || g_str_equal(condition_detail, "pause-cd"))
110 queue_post(&button_queue, BUTTON_MULTIMEDIA_PLAYPAUSE, 0);
111 else if (g_str_equal(condition_detail, "stop-cd"))
112 queue_post(&button_queue, BUTTON_MULTIMEDIA_STOP, 0);
113 else if (g_str_equal(condition_detail, "next-song"))
114 queue_post(&button_queue, BUTTON_MULTIMEDIA_NEXT, 0);
115 else if (g_str_equal(condition_detail, "previous-song"))
116 queue_post(&button_queue, BUTTON_MULTIMEDIA_PREV, 0);
117 else if (g_str_equal(condition_detail, "fast-forward"))
118 queue_post(&button_queue, BUTTON_MULTIMEDIA_FFWD, 0);
119 else if (g_str_equal(condition_detail, "rewind"))
120 queue_post(&button_queue, BUTTON_MULTIMEDIA_REW, 0);
121
122 sim_exit_irq_handler();
123}
124
125int maemo_thread_func (void *wait_for_osso_startup)
126{
127 maemo_main_loop = g_main_loop_new (NULL, FALSE);
128
129 /* Register display callback */
130 maemo_osso_ctx = osso_initialize ("rockbox", "666", FALSE, NULL);
131 osso_hw_set_display_event_cb(maemo_osso_ctx, display_status_callback, NULL);
132
133 /* Register battery status callback */
134 LibHalContext *hal_ctx;
135 hal_ctx = libhal_ctx_new();
136
137 DBusConnection *system_bus = (DBusConnection*)osso_get_sys_dbus_connection(maemo_osso_ctx);
138 libhal_ctx_set_dbus_connection(hal_ctx, system_bus);
139
140 libhal_ctx_init(hal_ctx, NULL);
141 libhal_ctx_set_device_property_modified (hal_ctx, on_battery_changed);
142 libhal_device_add_property_watch (hal_ctx, BME_UDI, NULL);
143
144 /* Work around libhal API issue: We need to add a property watch
145 to get the condition change callback working */
146 libhal_device_add_property_watch (hal_ctx, BT_HEADSET_UDI, NULL);
147 libhal_ctx_set_device_condition(hal_ctx, on_bt_button_pressed);
148
149 get_battery_values(hal_ctx);
150
151 /* let system_init proceed */
152 SDL_SemPost((SDL_sem *)wait_for_osso_startup);
153
154 g_main_loop_run (maemo_main_loop);
155
156 /* Cleanup */
157 osso_deinitialize (maemo_osso_ctx);
158 libhal_device_remove_property_watch (hal_ctx, BT_HEADSET_UDI, NULL);
159 libhal_device_remove_property_watch (hal_ctx, BME_UDI, NULL);
160 libhal_ctx_shutdown (hal_ctx, NULL);
161 libhal_ctx_free(hal_ctx);
162
163 return 0;
164}
165
166/** Rockbox battery related functions */
167void battery_status_update(void)
168{
169 battery_percent = maemo_battery_level;
170 send_battery_level_event();
171}
172
173/* Returns true if any power input is connected - charging-capable
174 * or not. */
175bool power_input_present(void)
176{
177 return false;
178}
179
180unsigned battery_voltage(void)
181{
182 return 0;
183}
184
185/* Returns battery level in percent */
186int battery_level(void)
187{
188 battery_status_update();
189 return maemo_battery_level;
190}
191
192/* Return remaining battery time in minutes */
193int battery_time(void)
194{
195 battery_status_update();
196 return maemo_remaining_time_sec / 60;
197}
198
199bool battery_level_safe(void)
200{
201 return battery_level() >= 5;
202}
203
204/** Rockbox stubs */
205void set_poweroff_timeout(int timeout)
206{
207 (void)timeout;
208}
209
210void reset_poweroff_timer(void)
211{
212}
213
214void shutdown_hw(void)
215{
216}
217
218void cancel_shutdown(void)
219{
220}