-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- 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]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ target_include_directories(app PRIVATE | |
|
||
target_sources(app PRIVATE | ||
src/main.c | ||
src/buzzer.c | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/ { | ||
aliases { | ||
Check failure on line 2 in app/boards/croxel_cx1825.overlay
|
||
buzzer-pwm = &buzzer; | ||
Check failure on line 3 in app/boards/croxel_cx1825.overlay
|
||
}; | ||
Check failure on line 4 in app/boards/croxel_cx1825.overlay
|
||
|
||
pwmbuzzer { | ||
Check failure on line 6 in app/boards/croxel_cx1825.overlay
|
||
compatible = "pwm-leds"; | ||
Check failure on line 7 in app/boards/croxel_cx1825.overlay
|
||
status = "okay"; | ||
Check failure on line 8 in app/boards/croxel_cx1825.overlay
|
||
|
||
buzzer: buzzer_pwm { | ||
pwms = <&pwm0 0 PWM_HZ(4000) PWM_POLARITY_NORMAL>; | ||
Check failure on line 11 in app/boards/croxel_cx1825.overlay
|
||
}; | ||
Check failure on line 12 in app/boards/croxel_cx1825.overlay
|
||
}; | ||
Check failure on line 13 in app/boards/croxel_cx1825.overlay
|
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
CONFIG_LOG=y | ||
CONFIG_PWM=y |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <zephyr/kernel.h> | ||
#include <zephyr/logging/log.h> | ||
#include <zephyr/drivers/pwm.h> | ||
#include <user_alerts/user_alerts.h> | ||
|
||
LOG_MODULE_REGISTER(buzzer); | ||
|
||
#define MORSE_DI_FREQ 4400 | ||
#define MORSE_DA_FREQ 3600 | ||
#define MORSE_TIME_MS 100 | ||
#define MORSE_SPACE {.freq = 0, .ms = MORSE_TIME_MS} | ||
#define MORSE_DI {.freq = MORSE_DI_FREQ, .ms = 1 * MORSE_TIME_MS}, MORSE_SPACE | ||
#define MORSE_DA {.freq = MORSE_DA_FREQ, .ms = 3 * MORSE_TIME_MS}, MORSE_SPACE | ||
#define MORSE_LETTER_SPACE MORSE_SPACE, MORSE_SPACE, MORSE_SPACE | ||
#define MORSE_WORD_SPACE MORSE_LETTER_SPACE, MORSE_LETTER_SPACE, MORSE_SPACE | ||
|
||
static const struct buzzer_alert_step _bootup_buzzer_beep_steps[] = { | ||
MORSE_DA, MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* c */ | ||
MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* r */ | ||
MORSE_DA, MORSE_DA, MORSE_DA, MORSE_LETTER_SPACE, /* o */ | ||
MORSE_DA, MORSE_DI, MORSE_DI, MORSE_DA, MORSE_LETTER_SPACE, /* x */ | ||
MORSE_DI, MORSE_LETTER_SPACE, /* e */ | ||
MORSE_DI, MORSE_DA, MORSE_DI, MORSE_DI, MORSE_LETTER_SPACE, /* l */ | ||
MORSE_WORD_SPACE, /* */ | ||
MORSE_DI, MORSE_DI, MORSE_LETTER_SPACE, /* i */ | ||
MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* n */ | ||
MORSE_DA, MORSE_DI, MORSE_DA, MORSE_DI, MORSE_LETTER_SPACE, /* c */ | ||
MORSE_WORD_SPACE, /* */ | ||
MORSE_WORD_SPACE, /* */ | ||
}; | ||
|
||
static const struct user_alerts_pattern _bootup_buzzer_beeps = { | ||
.steps = _bootup_buzzer_beep_steps, | ||
.steps_count = ARRAY_SIZE(_bootup_buzzer_beep_steps), | ||
.loop_count = 2, | ||
}; | ||
|
||
int pwm_user_alerts_step_exec(const struct user_alerts_channel *ch, const void *step) | ||
{ | ||
int err; | ||
const struct buzzer_alert_step *b_step = step; | ||
const struct pwm_dt_spec *pwm = ch->io; | ||
|
||
err = (b_step && b_step->freq) | ||
? pwm_set_dt(pwm, PWM_HZ(b_step->freq), PWM_HZ(b_step->freq) / 2) | ||
: pwm_set_dt(pwm, PWM_HZ(4000), 0); | ||
return err; | ||
} | ||
|
||
static const struct pwm_dt_spec _buzzer_ch_pwm = PWM_DT_SPEC_GET(DT_ALIAS(buzzer_pwm)); | ||
static struct user_alerts_channel _buzzer_ch = { | ||
.step_size = sizeof(_bootup_buzzer_beep_steps[0]), | ||
.io = &_buzzer_ch_pwm, | ||
.exec = pwm_user_alerts_step_exec, | ||
.cur_step_idx = 0, | ||
.cur_loop_idx = 0, | ||
/*".timer" wil be init using api */ | ||
.pattern = NULL, | ||
}; | ||
|
||
int play_bootup_buzzer_beeps(void) | ||
{ | ||
user_alerts_channel_init_timer(&_buzzer_ch); | ||
user_alerts_channel_play(&_buzzer_ch, &_bootup_buzzer_beeps, true); | ||
return 0; | ||
} | ||
|
||
SYS_INIT(play_bootup_buzzer_beeps, APPLICATION, 99); |