diff --git a/apps/misc.c b/apps/misc.c index a054cfa7b6..ceb70f3ba2 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1007,6 +1007,13 @@ void system_sound_play(enum system_sound sound) if (*params->setting) { +#if defined(HAVE_HARDWARE_CLICK) && !defined(SIMULATOR) + if (global_settings.keyclick_hardware) + { + piezo_button_beep(params->frequency, + params->duration, true); + } +#endif beep_play(params->frequency, params->duration, params->amplitude * *params->setting); } @@ -1068,23 +1075,7 @@ void keyclick_click(bool rawbutton, int action) do_beep = keyclick_current_callback(action, keyclick_data); keyclick_current_callback = NULL; - if (do_beep) - { -#ifdef HAVE_HARDWARE_CLICK - if (global_settings.keyclick) - { - system_sound_play(SOUND_KEYCLICK); - } - if (global_settings.keyclick_hardware) - { -#if !defined(SIMULATOR) - piezo_button_beep(false, false); -#endif - } -#else - system_sound_play(SOUND_KEYCLICK); -#endif - } + if (do_beep) { system_sound_play(SOUND_KEYCLICK); } } /* Return the ReplayGain mode adjusted by other relevant settings */ diff --git a/firmware/target/arm/ipod/piezo.c b/firmware/target/arm/ipod/piezo.c index 2b77c35309..eaae1193d6 100644 --- a/firmware/target/arm/ipod/piezo.c +++ b/firmware/target/arm/ipod/piezo.c @@ -158,7 +158,7 @@ bool piezo_busy(void) return !queue_empty(&piezo_queue); } -/* conversion factor based on the following data +/* conversion factor used to based on the following data period Hz 10 8547 @@ -174,11 +174,33 @@ bool piezo_busy(void) someone with better recording/analysing equipment should be able to get more accurate figures + + + Above measurements are not measuring fundamental frequency, + but rather a subharmonic frequency + + Given a 192khz frequency with a divisor of 1, + these following values should be measurable + + Divisor Hz + 10 19200 + 20 9600 + 30 6400 + 40 4800 + 50 3840 + 60 3200 + 70 2743 + 80 2400 + 90 2133 + 100 1920 + */ + unsigned int piezo_hz(unsigned int hz) { if (hz > 0) - return 91225/hz; + // Calculated by measuring frequency cycle time on ipodvideo + return 192000/hz; else return 0; } @@ -193,19 +215,16 @@ void piezo_init(void) IF_COP(, CPU)); } -void piezo_button_beep(bool beep, bool force) +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force) { /* old on clickwheel action - piezo_play_for_usec(50, 0x80, 400); old on button action - piezo_play_for_usec(50, 0x80, 3000); */ - if (force) + if (force) { piezo_clear(); - - if (queue_empty(&piezo_queue)) + piezo_play_for_usec(piezo_hz(hz), 0x80, dur * 1000); + } else if (queue_empty(&piezo_queue)) { - if (beep) - piezo_play_for_tick(40, 0x80, HZ/5); - else - piezo_play_for_usec(91, 0x80, 4000); + piezo_play_for_usec(piezo_hz(hz), 0x80, dur * 1000); } } diff --git a/firmware/target/arm/ipod/piezo.h b/firmware/target/arm/ipod/piezo.h index 9dceac13cb..343a15153a 100644 --- a/firmware/target/arm/ipod/piezo.h +++ b/firmware/target/arm/ipod/piezo.h @@ -29,4 +29,4 @@ void piezo_stop(void); void piezo_clear(void); bool piezo_busy(void); unsigned int piezo_hz(unsigned int hz); -void piezo_button_beep(bool beep, bool force); +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force); diff --git a/firmware/target/arm/philips/piezo.c b/firmware/target/arm/philips/piezo.c index 52c3fed2d0..2705960c9a 100644 --- a/firmware/target/arm/philips/piezo.c +++ b/firmware/target/arm/philips/piezo.c @@ -56,10 +56,11 @@ void piezo_init(void) { } -void piezo_button_beep(bool beep, bool force) +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force) { /* hw can only do a click */ - (void)beep; + (void)hz; + (void)dur; (void)force; piezo_hw_voltage_on(); udelay(1000); diff --git a/firmware/target/arm/philips/piezo.h b/firmware/target/arm/philips/piezo.h index 730042c4f3..ab44e617ab 100644 --- a/firmware/target/arm/philips/piezo.h +++ b/firmware/target/arm/philips/piezo.h @@ -20,4 +20,4 @@ ****************************************************************************/ void piezo_init(void); -void piezo_button_beep(bool beep, bool force); +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force); diff --git a/firmware/target/arm/s5l8700/ipodnano2g/piezo-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/piezo-nano2g.c index 78e7f00347..d6be263047 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/piezo-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/piezo-nano2g.c @@ -81,7 +81,7 @@ void piezo_init(void) beeping = 0; } -void piezo_button_beep(bool beep, bool force) +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force) { if (force) while (beeping) @@ -89,9 +89,8 @@ void piezo_button_beep(bool beep, bool force) if (!beeping) { - if (beep) - piezo_start(22, 457); - else - piezo_start(40, 4); + /* Cycle count estimated for durations up to 2048ms + and with frequencies in 4hz increments */ + piezo_start(50000/hz, (dur << 5) / ((7999 / (hz >> 2)) + 1)); } } diff --git a/firmware/target/arm/s5l8700/ipodnano2g/piezo.h b/firmware/target/arm/s5l8700/ipodnano2g/piezo.h index 987d4ffdda..63e77e723a 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/piezo.h +++ b/firmware/target/arm/s5l8700/ipodnano2g/piezo.h @@ -23,4 +23,4 @@ void piezo_init(void); void piezo_stop(void); void piezo_clear(void); bool piezo_busy(void); -void piezo_button_beep(bool beep, bool force); +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force); diff --git a/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c b/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c index 06735673be..3c5b1038ff 100644 --- a/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c +++ b/firmware/target/arm/s5l8702/ipod6g/piezo-6g.c @@ -81,7 +81,7 @@ void piezo_init(void) piezo_stop(); } -void piezo_button_beep(bool beep, bool force) +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force) { if (force) while (beeping) @@ -89,10 +89,9 @@ void piezo_button_beep(bool beep, bool force) if (!beeping) { - if (beep) - piezo_start(22, 457); - else - piezo_start(40, 4); + /* Cycle count estimated for durations up to 2048ms + and with frequencies in 4hz increments */ + piezo_start(50000/hz, (dur << 5) / ((7999 / (hz >> 2)) + 1)); } } diff --git a/firmware/target/arm/s5l8702/ipod6g/piezo.h b/firmware/target/arm/s5l8702/ipod6g/piezo.h index 7abe05ac65..163add86fd 100644 --- a/firmware/target/arm/s5l8702/ipod6g/piezo.h +++ b/firmware/target/arm/s5l8702/ipod6g/piezo.h @@ -25,7 +25,7 @@ void piezo_init(void); void piezo_stop(void); void piezo_clear(void); bool piezo_busy(void); -void piezo_button_beep(bool beep, bool force); +void piezo_button_beep(unsigned short hz, unsigned short dur, bool force); #ifdef BOOTLOADER #include