Skip to content

Commit

Permalink
[CXRD-17] Added bootup buzzer signal using User-Alerts
Browse files Browse the repository at this point in the history
- 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
cx-anuj-pathak committed Jul 29, 2024
1 parent 6831fda commit 5f0c047
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ target_include_directories(app PRIVATE

target_sources(app PRIVATE
src/main.c
src/buzzer.c
)
14 changes: 14 additions & 0 deletions app/boards/croxel_cx1825.overlay
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

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:2 code indent should use tabs where possible

Check warning on line 2 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:2 please, no spaces at the start of a line
buzzer-pwm = &buzzer;

Check failure on line 3 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:3 code indent should use tabs where possible

Check warning on line 3 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:3 please, no spaces at the start of a line
};

Check failure on line 4 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:4 code indent should use tabs where possible

Check warning on line 4 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:4 please, no spaces at the start of a line

pwmbuzzer {

Check failure on line 6 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:6 code indent should use tabs where possible

Check warning on line 6 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:6 please, no spaces at the start of a line
compatible = "pwm-leds";

Check failure on line 7 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:7 code indent should use tabs where possible

Check warning on line 7 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:7 please, no spaces at the start of a line
status = "okay";

Check failure on line 8 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:8 code indent should use tabs where possible

Check warning on line 8 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:8 please, no spaces at the start of a line

buzzer: buzzer_pwm {

Check failure on line 10 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:10 code indent should use tabs where possible
pwms = <&pwm0 0 PWM_HZ(4000) PWM_POLARITY_NORMAL>;

Check failure on line 11 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:11 code indent should use tabs where possible

Check warning on line 11 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:11 please, no spaces at the start of a line
};

Check failure on line 12 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:12 code indent should use tabs where possible

Check warning on line 12 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:12 please, no spaces at the start of a line
};

Check failure on line 13 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

CODE_INDENT

app/boards/croxel_cx1825.overlay:13 code indent should use tabs where possible

Check warning on line 13 in app/boards/croxel_cx1825.overlay

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LEADING_SPACE

app/boards/croxel_cx1825.overlay:13 please, no spaces at the start of a line
};
1 change: 1 addition & 0 deletions app/prj.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CONFIG_LOG=y
CONFIG_PWM=y
68 changes: 68 additions & 0 deletions app/src/buzzer.c
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

Check warning on line 12 in app/src/buzzer.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

COMPLEX_MACRO

app/src/buzzer.c:12 Macros with complex values should be enclosed in parentheses
#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);

0 comments on commit 5f0c047

Please sign in to comment.