2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
23 #include "drivers/time.h"
24 #include "drivers/io.h"
26 #include "drivers/timer.h"
27 #include "drivers/pwm_mapping.h"
28 #include "drivers/pwm_output.h"
29 #include "fc/config.h"
30 #include "fc/runtime_config.h"
32 #include "sound_beeper.h"
37 static IO_t beeperIO
= DEFIO_IO(NONE
);
38 static bool beeperInverted
= false;
39 static bool beeperState
= false;
43 void systemBeep(bool onoff
)
50 if (ARMING_FLAG(SIMULATOR_MODE
)) {
51 if (SIMULATOR_HAS_OPTION(HITL_MUTE_BEEPER
)) {
57 if (beeperConfig()->pwmMode
) {
58 pwmWriteBeeper(onoff
);
61 IOWrite(beeperIO
, beeperInverted
? onoff
: !onoff
);
69 void systemBeepToggle(void)
72 systemBeep(!beeperState
);
76 void beeperInit(const beeperDevConfig_t
*config
)
81 beeperIO
= IOGetByTag(config
->ioTag
);
82 beeperInverted
= config
->isInverted
;
85 IOInit(beeperIO
, OWNER_BEEPER
, RESOURCE_OUTPUT
, 0);
86 if (beeperConfig()->pwmMode
) {
87 beeperPwmInit(config
->ioTag
, BEEPER_PWM_FREQUENCY
);
89 IOConfigGPIO(beeperIO
, config
->isOD
? IOCFG_OUT_OD
: IOCFG_OUT_PP
);