Index: apps/lang/english.lang
===================================================================
--- apps/lang/english.lang (revision 14888)
+++ apps/lang/english.lang (working copy)
@@ -11327,4 +11327,20 @@
lcd_color: "Bar (Gradient Colour)"
-
+
+ id: LANG_BUTTON_BEEP
+ desc: in lcd options
+ user:
+
+ *: none
+ piezo: "Enable button click"
+
+
+ *: none
+ piezo: "Enable button click"
+
+
+ *: none
+ piezo: "Enable button click"
+
+
Index: apps/settings.c
===================================================================
--- apps/settings.c (revision 14888)
+++ apps/settings.c (working copy)
@@ -102,6 +102,10 @@
#include "usbstack.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 **/
@@ -855,6 +859,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 14888)
+++ apps/settings.h (working copy)
@@ -720,6 +720,9 @@
#endif
/* Encoder Settings End */
#endif /* CONFIG_CODEC == SWCODEC */
+#ifdef HAVE_PIEZO
+ bool button_beep;
+#endif
bool cuesheet;
int start_in_screen;
#if defined(HAVE_RTC_ALARM) && \
Index: apps/menus/playback_menu.c
===================================================================
--- apps/menus/playback_menu.c (revision 14888)
+++ apps/menus/playback_menu.c (working copy)
@@ -35,6 +35,10 @@
#include "audio.h"
#include "cuesheet.h"
+#ifdef HAVE_PIEZO
+#include "piezo.h"
+#endif
+
#if CONFIG_CODEC == SWCODEC
int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item)
{
@@ -125,6 +129,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);
@@ -182,6 +189,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_list.c
===================================================================
--- apps/settings_list.c (revision 14888)
+++ apps/settings_list.c (working copy)
@@ -50,6 +50,9 @@
#ifdef HAVE_USBSTACK
#include "usbstack.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 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),
+ piezo_thread_name IF_PRIO(, PRIORITY_REALTIME)
+ IF_COP(, CPU, false));
+}
+
+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);
+ }
+
+}
Property changes on: firmware/target/arm/ipod/piezo.c
___________________________________________________________________
Name: svn:keywords
+ Author ID Date Rev
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);
Property changes on: firmware/target/arm/ipod/piezo.h
___________________________________________________________________
Name: svn:keywords
+ Author ID Date Rev
Index: firmware/drivers/button.c
===================================================================
--- firmware/drivers/button.c (revision 14888)
+++ 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.
@@ -243,7 +247,12 @@
|| (btn&BUTTON_REMOTE)
#endif
)
+ {
queue_post(&button_queue, btn, 0);
+#ifdef HAVE_PIEZO
+ piezo_button_beep(false);
+#endif
+ }
else
skip_release = true;
#else /* no backlight, nothing to skip */