Add EzTune to the settings.yaml
[inav.git] / src / main / drivers / sound_beeper.c
blobbb089b4cb9e3c4c38911f3dcdf9e41fa3a09c7c8
1 /*
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/>.
18 #include <stdbool.h>
19 #include <stdint.h>
21 #include "platform.h"
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"
35 #ifdef BEEPER
37 static IO_t beeperIO = DEFIO_IO(NONE);
38 static bool beeperInverted = false;
39 static bool beeperState = false;
41 #endif
43 void systemBeep(bool onoff)
45 #if !defined(BEEPER)
46 UNUSED(onoff);
47 #else
49 #ifdef USE_SIMULATOR
50 if (ARMING_FLAG(SIMULATOR_MODE)) {
51 if (SIMULATOR_HAS_OPTION(HITL_MUTE_BEEPER)) {
52 onoff = false;
55 #endif
57 if (beeperConfig()->pwmMode) {
58 pwmWriteBeeper(onoff);
59 beeperState = onoff;
60 } else {
61 IOWrite(beeperIO, beeperInverted ? onoff : !onoff);
62 beeperState = onoff;
65 #endif
69 void systemBeepToggle(void)
71 #if defined(BEEPER)
72 systemBeep(!beeperState);
73 #endif
76 void beeperInit(const beeperDevConfig_t *config)
78 #if !defined(BEEPER)
79 UNUSED(config);
80 #else
81 beeperIO = IOGetByTag(config->ioTag);
82 beeperInverted = config->isInverted;
84 if (beeperIO) {
85 IOInit(beeperIO, OWNER_BEEPER, RESOURCE_OUTPUT, 0);
86 if (beeperConfig()->pwmMode) {
87 beeperPwmInit(config->ioTag, BEEPER_PWM_FREQUENCY);
88 } else {
89 IOConfigGPIO(beeperIO, config->isOD ? IOCFG_OUT_OD : IOCFG_OUT_PP);
93 systemBeep(false);
94 #endif