From 74e454cd0b6ee5d1caa448636717f28420c44cbd Mon Sep 17 00:00:00 2001 From: bsongis Date: Mon, 30 Jan 2012 18:42:14 +0000 Subject: [PATCH] Some more optimizations on AUDIO. AUDIO option set to false by default. --- src/Makefile | 27 ++++++++++++++------------- src/audio.cpp | 23 ++--------------------- src/audio.h | 21 ++++++++++++++++++++- src/beeper.cpp | 1 + src/beeper.h | 36 ++++++++++++++++++------------------ src/open9x.cpp | 12 ------------ 6 files changed, 55 insertions(+), 65 deletions(-) diff --git a/src/Makefile b/src/Makefile index 01eb7ea10..278662f2d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -62,7 +62,7 @@ endif # AUDIO Mods # Values = YES, NO -AUDIO = YES +AUDIO = NO # HAPTIC Mods # Values = YES, NO @@ -229,16 +229,6 @@ ifeq ($(SPLASH), YES) CPPDEFS += -DSPLASH endif -ifeq ($(AUDIO), YES) - CPPDEFS += -DAUDIO - CPPSRC += audio.cpp - ifeq ($(HAPTIC), YES) - CPPDEFS += -DHAPTIC - endif -else - CPPSRC += beeper.cpp -endif - # If ARDUPILOT-Support is enabled ifeq ($(EXT), ARDUPILOT) CPPDEFS += -DARDUPILOT @@ -273,7 +263,8 @@ endif ifeq ($(PCB), V4) # V4 PCB, so ... - CPPDEFS += -DPCBV4 + CPPDEFS += -DPCBV4 -DAUDIO + CPPSRC += audio.cpp ifeq ($(NAVIGATION), RE1) CPPDEFS += -DNAVIGATION_RE1 @@ -284,7 +275,7 @@ ifeq ($(PCB), V4) CPPDEFS += -DLOGS MODS:=${MODS}L endif - + ifeq ($(SOMO), YES) CPPSRC += somo14d.cpp CPPDEFS += -DSOMO @@ -293,6 +284,16 @@ else # STD PCB, so ... CPPDEFS += -DPCBSTD + ifeq ($(AUDIO), YES) + CPPDEFS += -DAUDIO + CPPSRC += audio.cpp + ifeq ($(HAPTIC), YES) + CPPDEFS += -DHAPTIC + endif + else + CPPSRC += beeper.cpp + endif + # If BandGap is not rock solid ifeq ($(BATT), UNSTABLE_BANDGAP) CPPDEFS += -DBATT_UNSTABLE_BANDGAP diff --git a/src/audio.cpp b/src/audio.cpp index 06559bd41..da7a14ade 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -52,30 +52,11 @@ bool audioQueue::freeslots(uint8_t slots) } */ -//heartbeat is responsibile for issueing the audio tones and general square waves +// heartbeat is responsibile for issueing the audio tones and general square waves // it is essentially the life of the class. +// it is called every 10ms void audioQueue::heartbeat() { -#if defined(PCBSTD) - if (toneTimeLeft > 0) { - //square wave generator use for speaker mod - //simply generates a square wave for toneFreq for - //as long as the toneTimeLeft is more than 0 - static uint8_t toneCounter; - toneCounter += toneFreq; - if ((toneCounter & 0x80) == 0x80) - PORTE |= (1 << OUT_E_BUZZER); // speaker output 'high' - else - PORTE &= ~(1 << OUT_E_BUZZER); // speaker output 'low' - } - - static uint8_t cnt10ms = 77; // execute 10ms code once every 78 ISRs - if (cnt10ms-- == 0) // every 10ms ... - cnt10ms = 77; - else - return; -#endif - if (toneTimeLeft > 0) { #if defined(PCBV4) OCR0A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). diff --git a/src/audio.h b/src/audio.h index 74bc85fc6..fde16cda3 100644 --- a/src/audio.h +++ b/src/audio.h @@ -166,6 +166,25 @@ void audioDefevent(uint8_t e); #define AUDIO_MIX_WARNING_1() audioDefevent(AU_MIX_WARNING_1) #define AUDIO_MIX_WARNING_3() audioDefevent(AU_MIX_WARNING_3) -#define AUDIO_HEARTBEAT() audio.heartbeat() +#if defined(PCBSTD) +#define AUDIO_HEARTBEAT() \ + if (audio.toneTimeLeft > 0) { \ + static uint8_t toneCounter; \ + toneCounter += audio.toneFreq; \ + if ((toneCounter & 0x80) == 0x80) \ + PORTE |= (1 << OUT_E_BUZZER); \ + else \ + PORTE &= ~(1 << OUT_E_BUZZER); \ + } \ + static uint8_t cnt10ms = 77; \ + if (cnt10ms-- == 0) \ + cnt10ms = 77; \ + else \ + return; \ + audio.heartbeat() +#else +#define AUDIO_HEARTBEAT() \ + audio.heartbeat() +#endif #endif // audio_h diff --git a/src/beeper.cpp b/src/beeper.cpp index 2e93eebe6..7322bea5c 100644 --- a/src/beeper.cpp +++ b/src/beeper.cpp @@ -26,6 +26,7 @@ uint8_t beepAgain = 0; uint8_t beepAgainOrig = 0; uint8_t beepOn = false; bool warble = false; +bool warbleC; // The various "beep" tone lengths static prog_uint8_t APM beepTab[]= { diff --git a/src/beeper.h b/src/beeper.h index 88d1180a4..f75720972 100644 --- a/src/beeper.h +++ b/src/beeper.h @@ -27,29 +27,29 @@ extern uint8_t beepAgain; extern uint8_t beepAgainOrig; extern uint8_t beepOn; extern bool warble; +extern bool warbleC; extern void beep(uint8_t val); -#define AUDIO_KEYPAD_UP() beep(0) -#define AUDIO_KEYPAD_DOWN() beep(0) -#define AUDIO_MENUS() beep(0) -#define AUDIO_TRIM() beep(1) -#define AUDIO_WARNING2() beep(2) -#define AUDIO_WARNING1() beep(3) -#define AUDIO_ERROR() beep(4) - -#define IS_AUDIO_BUSY() (g_beepCnt || beepAgain || beepOn) - -#define AUDIO_TIMER_30() { beepAgain=2; beep(2); } -#define AUDIO_TIMER_20() { beepAgain=1; beep(2); } -#define AUDIO_TIMER_10() beep(2) -#define AUDIO_TIMER_LT3() beep(2) -#define AUDIO_MINUTE_BEEP() beep(2) -#define AUDIO_INACTIVITY() beep(3) +#define AUDIO_KEYPAD_UP() beep(0) +#define AUDIO_KEYPAD_DOWN() beep(0) +#define AUDIO_MENUS() beep(0) +#define AUDIO_TRIM() beep(1) +#define AUDIO_WARNING2() beep(2) +#define AUDIO_WARNING1() beep(3) +#define AUDIO_ERROR() beep(4) +#define AUDIO_TIMER_30() { beepAgain=2; beep(2); } +#define AUDIO_TIMER_20() { beepAgain=1; beep(2); } +#define AUDIO_TIMER_10() beep(2) +#define AUDIO_TIMER_LT3() beep(2) +#define AUDIO_MINUTE_BEEP() beep(2) +#define AUDIO_INACTIVITY() beep(3) #define AUDIO_MIX_WARNING_1() beep(1) #define AUDIO_MIX_WARNING_3() beep(1) -inline void AUDIO_HEARTBEAT() +#define IS_AUDIO_BUSY() (g_beepCnt || beepAgain || beepOn) + +FORCEINLINE void AUDIO_HEARTBEAT() { //cnt >/=0 //beepon/off @@ -77,7 +77,7 @@ inline void AUDIO_HEARTBEAT() // G: use original external buzzer for beeps if (beepOn) { - static bool warbleC; + //static bool warbleC; warbleC = warble && !warbleC; if (warbleC) PORTE &= ~(1 << OUT_E_BUZZER); // speaker output 'low' diff --git a/src/open9x.cpp b/src/open9x.cpp index e147f8d32..b969a44d9 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -1778,14 +1778,6 @@ ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer AUDIO_HEARTBEAT(); -#if defined (PCBSTD) && defined (AUDIO) - static uint8_t cnt10ms = 77; // execute 10ms code once every 78 ISRs - if (cnt10ms-- == 0) // BEGIN { ... every 10ms ... } - { - // Begin 10ms event - cnt10ms = 77; -#endif - #ifdef DEBUG // Record start time from TCNT1 to record excution time cli(); @@ -1807,10 +1799,6 @@ ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer uint16_t dt2 = TCNT1; // capture end time sei(); g_time_per10 = dt2 - dt; // NOTE: These spike to nearly 65535 just now and then. Why? :/ -#endif - -#if defined (PCBSTD) && defined (AUDIO) - } // end 10ms event #endif cli();