diff options
author | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-12-15 16:50:39 -0800 |
---|---|---|
committer | Heinrich Schuchardt <heinrich.schuchardt@canonical.com> | 2022-12-20 16:06:48 +0100 |
commit | ea58b9a404d4cf39a3bb314804f42b213eb6d896 (patch) | |
tree | b374c20a3bedb6366168eb94efec1f9d8f5f8cb0 /cmd | |
parent | 2243922edca9f56a9d5519b9d6e36f5d7a18434d (diff) | |
download | u-boot-ea58b9a404d4cf39a3bb314804f42b213eb6d896.tar.gz |
cmd: allow sound command to play multiple sounds
Currently the sound command accepts only one value each for duration and
frequency. Allowing more duration and frequency arguments enables playing a
tune.
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/sound.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/cmd/sound.c b/cmd/sound.c index 20ac3f758e..cef71be5e3 100644 --- a/cmd/sound.c +++ b/cmd/sound.c @@ -39,26 +39,39 @@ static int do_play(struct cmd_tbl *cmdtp, int flag, int argc, int ret = 0; int msec = 1000; int freq = 400; - - if (argc > 1) - msec = dectoul(argv[1], NULL); - if (argc > 2) - freq = dectoul(argv[2], NULL); + bool first = true; ret = uclass_first_device_err(UCLASS_SOUND, &dev); - if (!ret) + if (ret) + goto err; + --argc; + ++argv; + while (argc || first) { + first = false; + if (argc && *argv[0] != '-') { + msec = dectoul(argv[0], NULL); + --argc; + ++argv; + } + if (argc && *argv[0] != '-') { + freq = dectoul(argv[0], NULL); + --argc; + ++argv; + } ret = sound_beep(dev, msec, freq); - if (ret) { - printf("Sound device failed to play (err=%d)\n", ret); - return CMD_RET_FAILURE; + if (ret) + goto err; } - return 0; + +err: + printf("Sound device failed to play (err=%d)\n", ret); + return CMD_RET_FAILURE; } static struct cmd_tbl cmd_sound_sub[] = { U_BOOT_CMD_MKENT(init, 0, 1, do_init, "", ""), - U_BOOT_CMD_MKENT(play, 2, 1, do_play, "", ""), + U_BOOT_CMD_MKENT(play, INT_MAX, 1, do_play, "", ""), }; /* process sound command */ @@ -83,8 +96,10 @@ static int do_sound(struct cmd_tbl *cmdtp, int flag, int argc, } U_BOOT_CMD( - sound, 4, 1, do_sound, + sound, INT_MAX, 1, do_sound, "sound sub-system", "init - initialise the sound driver\n" - "sound play [len [freq]] - play a sound for len ms at freq Hz\n" + "sound play [[[-q|-s] len [freq]] ...] - play sounds\n" + " len - duration in ms\n" + " freq - frequency in Hz\n" ); |