summaryrefslogtreecommitdiff
path: root/apps/plugin.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2014-08-08 21:34:00 -0400
committerFranklin Wei <frankhwei536@gmail.com>2014-09-18 20:20:10 -0400
commite15d79265fed7868b8f3b53fd61ed2514fbad733 (patch)
tree71712dfede2ce7715699ee5d6437555565fc5f6e /apps/plugin.c
parent7d112053abefb9574e922b467ccf2f04a49591e3 (diff)
downloadrockbox-e15d79265fed7868b8f3b53fd61ed2514fbad733.zip
rockbox-e15d79265fed7868b8f3b53fd61ed2514fbad733.tar.gz
rockbox-e15d79265fed7868b8f3b53fd61ed2514fbad733.tar.bz2
rockbox-e15d79265fed7868b8f3b53fd61ed2514fbad733.tar.xz
Added piezo functions to plugin API, as well as some demo plugins
Change-Id: I3e51cc2ac3f408994f690ed6c24da33bf26a0608
Diffstat (limited to 'apps/plugin.c')
-rw-r--r--apps/plugin.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/apps/plugin.c b/apps/plugin.c
index 8a6c577..4a738a1 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -46,6 +46,10 @@
#include "load_code.h"
#include "file.h"
+#ifdef HAVE_HARDWARE_CLICK
+#include "piezo.h"
+#endif
+
#if CONFIG_CHARGING
#include "power.h"
#endif
@@ -147,6 +151,54 @@ static int WRAPPER(close)(int fildes)
return rc;
}
+#if defined(HAVE_HARDWARE_CLICK) && !defined(SIMULATOR)
+void piezo_click(bool wait)
+{
+ piezo_button_beep(false, true);
+ if(wait)
+ while(piezo_busy())
+ yield();
+}
+
+void piezo_beep(bool wait)
+{
+ piezo_button_beep(true, true);
+ if(wait)
+ while(piezo_busy())
+ yield();
+}
+void piezo_play(unsigned int usecs, unsigned int freq, bool wait)
+{
+#if defined(IPOD_6G) || defined(IPOD_NANO2G)
+ if(freq)
+ {
+ /* integer overflow? */
+ unsigned long long periods=freq*(usecs/1000000.0);
+ unsigned short cycles=50000.0/freq;
+ if(periods>65535)
+ {
+ while(periods>65535)
+ {
+ piezo_start(cycles, 65535);
+ while(piezo_busy())
+ yield();
+ periods-=65535;
+ }
+ }
+ piezo_start(cycles, periods);
+ }
+#else
+ if(freq)
+ {
+ piezo_play_for_usec(piezo_hz(freq), 0x80, usecs);
+ }
+#endif
+ if(wait)
+ while(piezo_busy())
+ yield();
+}
+#endif /* HAVE_HARDWARE_CLICK */
+
static void plugin_check_open_close__exit(void)
{
if (current_plugin_handle)
@@ -840,6 +892,14 @@ static const struct plugin_api rockbox_api = {
/* new stuff at the end, sort into place next time
the API gets incompatible */
+
+ /* piezo */
+#if defined(HAVE_HARDWARE_CLICK) && !defined(SIMULATOR)
+ /* all these are defined in plugin.c */
+ piezo_click,
+ piezo_beep,
+ piezo_play,
+#endif
};
static int plugin_buffer_handle;