-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
271 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
#include "buzzer.h" | ||
|
||
#include <drivers/pwm.h> | ||
|
||
#define BUZZER_PWM_NODE DT_ALIAS(buzzer_pwm) | ||
#define BUZZER_PWM_NAME DT_LABEL(BUZZER_PWM_NODE) | ||
#define BUZZER_PWM_PIN DT_PROP(BUZZER_PWM_NODE, ch0_pin) | ||
#define BUZZER_PWM_FLAGS DT_PWMS_FLAGS(BUZZER_PWM_NODE) | ||
|
||
constexpr uint16_t kBuzzerPwmPeriodUs = 10000; | ||
constexpr uint16_t kBuzzerPwmDutyCycleUs = 5000; | ||
|
||
const device *kBuzzerDevice; | ||
static bool sBuzzerState; | ||
|
||
int BuzzerInit() { | ||
kBuzzerDevice = device_get_binding(BUZZER_PWM_NAME); | ||
if (!kBuzzerDevice) | ||
{ | ||
return -ENODEV; | ||
} | ||
return 0; | ||
} | ||
|
||
void BuzzerSetState(bool onOff) { | ||
sBuzzerState = onOff; | ||
pwm_pin_set_usec(kBuzzerDevice, BUZZER_PWM_PIN, kBuzzerPwmPeriodUs, sBuzzerState ? kBuzzerPwmDutyCycleUs : 0, | ||
BUZZER_PWM_FLAGS); | ||
} | ||
|
||
void BuzzerToggleState() { | ||
sBuzzerState = !sBuzzerState; | ||
pwm_pin_set_usec(kBuzzerDevice, BUZZER_PWM_PIN, kBuzzerPwmPeriodUs, sBuzzerState ? kBuzzerPwmDutyCycleUs : 0, | ||
BUZZER_PWM_FLAGS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright (c) 2021 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||
*/ | ||
|
||
int BuzzerInit(); | ||
void BuzzerSetState(bool onOff); | ||
void BuzzerToggleState(); |
Oops, something went wrong.