Index: apps/features.txt
===================================================================
--- apps/features.txt (revision 17730)
+++ apps/features.txt (working copy)
@@ -157,6 +157,10 @@
usbstack
#endif
+#if defined(HAVE_PIEZO)
+piezo
+#endif
+
#if defined(HAVE_ACCESSORY_SUPPLY)
accessory_supply
#endif
Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang (revision 17730)
+++ apps/lang/english.lang (working copy)
@@ -11750,3 +11750,20 @@
gigabeatf: "High"
+
+ id: LANG_BUTTON_BEEP
+ desc: in lcd options
+ user:
+
+ *: none
+ piezo: "Enable button click"
+
+
+ *: none
+ piezo: "Enable button click"
+
+
+ *: none
+ piezo: "Enable button click"
+
+
\ No newline at end of file
Index: apps/main.c
===================================================================
--- apps/main.c (revision 17730)
+++ apps/main.c (working copy)
@@ -71,6 +71,10 @@
#include "scrobbler.h"
#include "icon.h"
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
+
#if (CONFIG_CODEC == SWCODEC)
#include "playback.h"
#endif
@@ -583,9 +587,12 @@
#if CONFIG_CHARGING
car_adapter_mode_init();
#endif
#ifdef HAVE_ACCESSORY_SUPPLY
accessory_supply_set(global_settings.accessory_supply);
#endif
+#ifdef HAVE_PIEZO
+ piezo_init();
+#endif
}
#ifdef CPU_PP
Index: apps/menus/playback_menu.c
===================================================================
--- apps/menus/playback_menu.c (revision 17730)
+++ apps/menus/playback_menu.c (working copy)
@@ -33,10 +33,13 @@
#include "dsp.h"
#include "scrobbler.h"
#include "audio.h"
-#include "cuesheet.h"
-#if CONFIG_CODEC == SWCODEC
-#include "playback.h"
-#endif
+#include "cuesheet.h"
+#if CONFIG_CODEC == SWCODEC
+#include "playback.h"
+#endif
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
#if CONFIG_CODEC == SWCODEC
@@ -129,6 +132,9 @@
MENUITEM_SETTING(beep, &global_settings.beep ,NULL);
#endif /* CONFIG_CODEC == SWCODEC */
+#ifdef HAVE_PIEZO
+MENUITEM_SETTING(button_beep, &global_settings.button_beep, NULL);
+#endif
#ifdef HAVE_SPDIF_POWER
MENUITEM_SETTING(spdif_enable, &global_settings.spdif_enable, NULL);
@@ -191,6 +197,9 @@
#if CONFIG_CODEC == SWCODEC
&crossfade_settings_menu, &replaygain_settings_menu, &beep,
#endif
+#ifdef HAVE_PIEZO
+ &button_beep,
+#endif
#ifdef HAVE_SPDIF_POWER
&spdif_enable,
Index: apps/settings.c
===================================================================
--- apps/settings.c (revision 17730)
+++ apps/settings.c (working copy)
@@ -94,6 +94,10 @@
#include "lcd-remote.h"
#endif
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
+
long lasttime = 0;
/** NVRAM stuff, if the target doesnt have NVRAM it is saved in ROCKBOX_DIR /nvram.bin **/
@@ -916,6 +920,10 @@
spdif_power_enable(global_settings.spdif_enable);
#endif
+#ifdef HAVE_PIEZO
+ set_button_beep_type(global_settings.button_beep);
+#endif
+
#ifdef HAVE_BACKLIGHT
set_backlight_filter_keypress(global_settings.bl_filter_first_keypress);
#ifdef HAVE_REMOTE_LCD
Index: apps/settings.h
===================================================================
--- apps/settings.h (revision 17730)
+++ apps/settings.h (working copy)
@@ -701,7 +701,10 @@
#endif
/* Encoder Settings End */
#endif /* CONFIG_CODEC == SWCODEC */
- bool cuesheet;
+#ifdef HAVE_PIEZO
+ bool button_beep;
+#endif
+ bool cuesheet;
int start_in_screen;
#if defined(HAVE_RTC_ALARM) && \
(defined(HAVE_RECORDING) || CONFIG_TUNER)
Index: apps/settings_list.c
===================================================================
--- apps/settings_list.c (revision 17730)
+++ apps/settings_list.c (working copy)
@@ -47,6 +47,9 @@
#if CONFIG_TUNER
#include "radio.h"
#endif
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
#define NVRAM(bytes) (bytes< ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006-2007 Robert Keevil
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "thread.h"
+#include "system.h"
+#include "kernel.h"
+#include "usb.h"
+#include "logf.h"
+#include "piezo.h"
+
+#define PIEZO_HZ_CONVERSION 91225
+/* conversion factor based on the following data
+
+ period Hz
+ 10 8547
+ 20 4465
+ 30 3024
+ 40 2286
+ 50 1846
+ 60 1537
+ 70 1320
+ 80 1165
+ 90 1030
+ 100 928
+
+ someone with better recording/analysing equipment should be able
+ to get more accurate figures
+*/
+
+static long piezo_stack[DEFAULT_STACK_SIZE/sizeof(long)];
+static const char piezo_thread_name[] = "piezo";
+static struct event_queue piezo_queue;
+static unsigned int duration;
+static bool beeping;
+static bool button_beep = false;
+
+enum {
+ Q_PIEZO_BEEP = 1,
+ Q_PIEZO_BEEP_FOR_TICK,
+ Q_PIEZO_BEEP_FOR_USEC,
+ Q_PIEZO_STOP
+};
+
+static inline void piezo_hw_init(void)
+{
+ logf("PIEZO: hw_init");
+ outl(inl(0x70000010) & ~0xc, 0x70000010);
+ outl(inl(0x6000600c) | 0x20000, 0x6000600c); /* enable device */
+}
+
+static void piezo_hw_tick(unsigned int form_and_period)
+{
+ outl(0x80000000 | form_and_period, 0x7000a000); /* set pitch */
+}
+
+static inline void piezo_hw_stop(void)
+{
+ outl(0x0, 0x7000a000); /* piezo off */
+}
+
+
+static void piezo_thread(void)
+{
+ struct queue_event ev;
+ long piezo_usec_off;
+
+ while(1)
+ {
+ queue_wait(&piezo_queue, &ev);
+ switch(ev.id)
+ {
+ case Q_PIEZO_BEEP:
+ piezo_hw_tick((unsigned int)ev.data);
+ beeping = true;
+ break;
+ case Q_PIEZO_BEEP_FOR_TICK:
+ piezo_hw_tick((unsigned int)ev.data);
+ beeping = true;
+ sleep(duration);
+ if (beeping)
+ piezo_hw_stop();
+ beeping = false;
+ /* remove anything that appeared while sleeping */
+ queue_clear(&piezo_queue);
+ break;
+ case Q_PIEZO_BEEP_FOR_USEC:
+ piezo_usec_off = USEC_TIMER + duration;
+ piezo_hw_tick((unsigned int)ev.data);
+ beeping = true;
+ while (TIME_BEFORE(USEC_TIMER, piezo_usec_off))
+ yield();
+ if (beeping)
+ piezo_hw_stop();
+ beeping = false;
+ /* remove anything that appeared while sleeping */
+ queue_clear(&piezo_queue);
+ break;
+ case Q_PIEZO_STOP:
+ if (beeping)
+ piezo_hw_stop();
+ beeping = false;
+ break;
+#ifndef SIMULATOR
+ case SYS_USB_CONNECTED:
+ /*logf("USB: Piezo core");*/
+ piezo_hw_stop();
+ queue_clear(&piezo_queue);
+ usb_acknowledge(SYS_USB_CONNECTED_ACK);
+ usb_wait_for_disconnect(&piezo_queue);
+ break ;
+#endif
+ case SYS_TIMEOUT:
+ break;
+ }
+ yield();
+ }
+}
+
+
+void piezo_play(unsigned short inv_freq, unsigned char form)
+{
+ queue_post(&piezo_queue, Q_PIEZO_BEEP,
+ (intptr_t)((unsigned int)form << 16 | inv_freq));
+}
+
+void piezo_play_for_tick(unsigned short inv_freq,
+ unsigned char form, unsigned int dur)
+{
+ duration = dur;
+ queue_post(&piezo_queue, Q_PIEZO_BEEP_FOR_TICK,
+ (intptr_t)((unsigned int)form << 16 | inv_freq));
+}
+
+void piezo_play_for_usec(unsigned short inv_freq,
+ unsigned char form, unsigned int dur)
+{
+ duration = dur;
+ queue_post(&piezo_queue, Q_PIEZO_BEEP_FOR_USEC,
+ (intptr_t)((unsigned int)form << 16 | inv_freq));
+}
+
+void piezo_stop(void)
+{
+ queue_post(&piezo_queue, Q_PIEZO_STOP, 0);
+}
+
+void piezo_clear(void)
+{
+ queue_clear(&piezo_queue);
+ piezo_stop();
+}
+
+bool piezo_busy(void)
+{
+ return !queue_empty(&piezo_queue);
+}
+
+unsigned int piezo_hz(unsigned int hz)
+{
+ if (hz > 0)
+ return PIEZO_HZ_CONVERSION/hz;
+ else
+ return 0;
+}
+
+void piezo_init(void)
+{
+ logf("PIEZO: init");
+ piezo_hw_init();
+ queue_init(&piezo_queue, true);
+ create_thread(piezo_thread, piezo_stack, sizeof(piezo_stack), 0,
+ piezo_thread_name IF_PRIO(, PRIORITY_REALTIME)
+ IF_COP(, CPU));
+}
+
+void set_button_beep_type(bool enabled)
+{
+ button_beep = enabled;
+}
+
+void piezo_button_beep(bool wheel)
+{
+ if(button_beep && queue_empty(&piezo_queue))
+ {
+ if(wheel)
+ piezo_play_for_usec(50, 0x80, 400);
+ else
+ piezo_play_for_usec(50, 0x80, 3000);
+ }
+
+}
Index: firmware/target/arm/ipod/piezo.h
===================================================================
--- firmware/target/arm/ipod/piezo.h (revision 0)
+++ firmware/target/arm/ipod/piezo.h (revision 0)
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006-2007 Robert Keevil
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+void piezo_init(void);
+void piezo_play(unsigned short inv_freq, unsigned char form);
+void piezo_play_for_tick(unsigned short inv_freq,
+ unsigned char form, unsigned int dur);
+void piezo_play_for_usec(unsigned short inv_freq,
+ unsigned char form, unsigned int dur);
+void piezo_stop(void);
+void piezo_clear(void);
+bool piezo_busy(void);
+unsigned int piezo_hz(unsigned int hz);
+void set_button_beep_type(bool);
+void piezo_button_beep(bool wheel);
Index: firmware/SOURCES
===================================================================
--- firmware/SOURCES (revision 17730)
+++ firmware/SOURCES (working copy)
@@ -792,6 +792,7 @@
target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-4g_color.c
target/arm/ipod/button-clickwheel.c
+target/arm/ipod/piezo.c
target/arm/ipod/lcd-as-gray.S
target/arm/ipod/lcd-gray.c
target/arm/ipod/power-ipod.c
@@ -810,6 +811,7 @@
target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-4g_color.c
target/arm/ipod/button-clickwheel.c
+target/arm/ipod/piezo.c
target/arm/ipod/lcd-color_nano.c
target/arm/ipod/power-ipod.c
target/arm/ipod/powermgmt-ipod-pcf.c
@@ -827,6 +829,7 @@
target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-nano_video.c
target/arm/ipod/button-clickwheel.c
+target/arm/ipod/piezo.c
target/arm/ipod/lcd-color_nano.c
target/arm/ipod/power-ipod.c
target/arm/ipod/powermgmt-ipod-pcf.c
@@ -844,6 +847,7 @@
target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-nano_video.c
target/arm/ipod/button-clickwheel.c
+target/arm/ipod/piezo.c
target/arm/ipod/power-ipod.c
target/arm/ipod/powermgmt-ipod-pcf.c
target/arm/ipod/video/lcd-as-video.S
@@ -895,6 +899,7 @@
target/arm/ipod/adc-ipod-pcf.c
target/arm/ipod/backlight-mini1g_mini2g.c
target/arm/ipod/button-mini1g.c
+target/arm/ipod/piezo.c
target/arm/ipod/lcd-as-gray.S
target/arm/ipod/lcd-gray.c
target/arm/ipod/power-ipod.c
Index: firmware/drivers/button.c
===================================================================
--- firmware/drivers/button.c (revision 17730)
+++ firmware/drivers/button.c (working copy)
@@ -37,6 +37,10 @@
#include "lcd-remote.h"
#endif
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
+
#ifndef SIMULATOR
#if 0
/* Older than MAX_EVENT_AGE button events are going to be ignored.
@@ -264,7 +268,12 @@
|| (btn & BUTTON_REMOTE)
#endif
)
+ {
queue_post(&button_queue, btn, data);
+#ifdef HAVE_PIEZO
+ piezo_button_beep(false);
+#endif
+ }
else
skip_release = true;
#else /* no backlight, nothing to skip */