Skip to content

Commit 5f0c047

Browse files
[CXRD-17] Added bootup buzzer signal using User-Alerts
- defined "croxel inc" morse code in user_alert structure - user user-alerts to play "croxel inc" morse code on bootup Signed-off-by: Anuj Pathak <[email protected]>
1 parent 6831fda commit 5f0c047

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

app/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ target_include_directories(app PRIVATE
99

1010
target_sources(app PRIVATE
1111
src/main.c
12+
src/buzzer.c
1213
)

app/boards/croxel_cx1825.overlay

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/ {
2+
aliases {
3+
buzzer-pwm = &buzzer;
4+
};
5+
6+
pwmbuzzer {
7+
compatible = "pwm-leds";
8+
status = "okay";
9+
10+
buzzer: buzzer_pwm {
11+
pwms = <&pwm0 0 PWM_HZ(4000) PWM_POLARITY_NORMAL>;
12+
};
13+
};
14+
};

app/prj.conf

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
CONFIG_LOG=y
2+
CONFIG_PWM=y

app/src/buzzer.c

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include <zephyr/kernel.h>
2+
#include <zephyr/logging/log.h>
3+
#include <zephyr/drivers/pwm.h>
4+
#include <user_alerts/user_alerts.h>
5+
6+
LOG_MODULE_REGISTER(buzzer);
7+
8+
#define MORSE_DI_FREQ 4400
9+
#define MORSE_DA_FREQ 3600
10+
#define MORSE_TIME_MS 100
11+
#define MORSE_SPACE {.freq = 0, .ms = MORSE_TIME_MS}
12+
#define MORSE_DI {.freq = MORSE_DI_FREQ, .ms = 1 * MORSE_TIME_MS}, MORSE_SPACE
13+
#define MORSE_DA {.freq = MORSE_DA_FREQ, .ms = 3 * MORSE_TIME_MS}, MORSE_SPACE
14+
#define MORSE_LETTER_SPACE MORSE_SPACE, MORSE_SPACE, MORSE_SPACE
15+
#define MORSE_WORD_SPACE MORSE_LETTER_SPACE, MORSE_LETTER_SPACE, MORSE_SPACE
16+
17+
static const struct buzzer_alert_step _bootup_buzzer_beep_steps[] = {
18+
MORSE_DA, MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* c */
19+
MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* r */
20+
MORSE_DA, MORSE_DA, MORSE_DA, MORSE_LETTER_SPACE, /* o */
21+
MORSE_DA, MORSE_DI, MORSE_DI, MORSE_DA, MORSE_LETTER_SPACE, /* x */
22+
MORSE_DI, MORSE_LETTER_SPACE, /* e */
23+
MORSE_DI, MORSE_DA, MORSE_DI, MORSE_DI, MORSE_LETTER_SPACE, /* l */
24+
MORSE_WORD_SPACE, /* */
25+
MORSE_DI, MORSE_DI, MORSE_LETTER_SPACE, /* i */
26+
MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* n */
27+
MORSE_DA, MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* c */
28+
MORSE_WORD_SPACE, /* */
29+
MORSE_WORD_SPACE, /* */
30+
};
31+
32+
static const struct user_alerts_pattern _bootup_buzzer_beeps = {
33+
.steps = _bootup_buzzer_beep_steps,
34+
.steps_count = ARRAY_SIZE(_bootup_buzzer_beep_steps),
35+
.loop_count = 2,
36+
};
37+
38+
int pwm_user_alerts_step_exec(const struct user_alerts_channel *ch, const void *step)
39+
{
40+
int err;
41+
const struct buzzer_alert_step *b_step = step;
42+
const struct pwm_dt_spec *pwm = ch->io;
43+
44+
err = (b_step && b_step->freq)
45+
? pwm_set_dt(pwm, PWM_HZ(b_step->freq), PWM_HZ(b_step->freq) / 2)
46+
: pwm_set_dt(pwm, PWM_HZ(4000), 0);
47+
return err;
48+
}
49+
50+
static const struct pwm_dt_spec _buzzer_ch_pwm = PWM_DT_SPEC_GET(DT_ALIAS(buzzer_pwm));
51+
static struct user_alerts_channel _buzzer_ch = {
52+
.step_size = sizeof(_bootup_buzzer_beep_steps[0]),
53+
.io = &_buzzer_ch_pwm,
54+
.exec = pwm_user_alerts_step_exec,
55+
.cur_step_idx = 0,
56+
.cur_loop_idx = 0,
57+
/*".timer" wil be init using api */
58+
.pattern = NULL,
59+
};
60+
61+
int play_bootup_buzzer_beeps(void)
62+
{
63+
user_alerts_channel_init_timer(&_buzzer_ch);
64+
user_alerts_channel_play(&_buzzer_ch, &_bootup_buzzer_beeps, true);
65+
return 0;
66+
}
67+
68+
SYS_INIT(play_bootup_buzzer_beeps, APPLICATION, 99);

0 commit comments

Comments
 (0)