mirror of
https://github.com/supleed2/EIE4-FYP.git
synced 2024-12-22 22:25:50 +00:00
Create note control library for testing
This commit is contained in:
parent
2717f4e417
commit
cf504787e2
|
@ -3,7 +3,7 @@ BUILD_DIR?=../build/
|
|||
include $(BUILD_DIR)/software/include/generated/variables.mak
|
||||
include $(SOC_DIRECTORY)/software/common.mak
|
||||
|
||||
OBJECTS = crt0.o donut.o led.o main.o
|
||||
OBJECTS = crt0.o donut.o led.o main.o note.o
|
||||
CFLAGS += -DWITH_CXX
|
||||
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <libbase/console.h>
|
||||
#include <libbase/uart.h>
|
||||
|
||||
#include "note"
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Uart */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -90,6 +92,8 @@ static void help(void) {
|
|||
#endif
|
||||
#ifdef CSR_AUDIO_BASE
|
||||
puts("saw - Sawtooth Audio demo");
|
||||
puts("imperial - Imperial March demo");
|
||||
puts("roll - Music demo");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -122,6 +126,65 @@ static void saw_cmd(char **val) {
|
|||
printf("Setting Sawtooth to %dHz\n", value);
|
||||
audio_targ_write(value);
|
||||
}
|
||||
|
||||
static void imperial_cmd() {
|
||||
note(NOTE_G4, 400);
|
||||
note(NOTE_NONE, 400);
|
||||
note(NOTE_G4, 400);
|
||||
note(NOTE_NONE, 400);
|
||||
note(NOTE_G4, 600);
|
||||
note(NOTE_NONE, 600);
|
||||
note(NOTE_D4S, 200);
|
||||
note(NOTE_A4S, 200);
|
||||
note(NOTE_G4, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D4S, 400);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_A4S, 200);
|
||||
note(NOTE_G4, 1000);
|
||||
note(NOTE_D4S, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D5, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D5, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D5, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D5S, 400);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_A4S, 200);
|
||||
note(NOTE_F4S, 600);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_D4S, 400);
|
||||
note(NOTE_NONE, 200);
|
||||
note(NOTE_A4S, 200);
|
||||
note(NOTE_G4, 800);
|
||||
}
|
||||
|
||||
static void roll_cmd() {
|
||||
note(NOTE_C4S, 450);
|
||||
note(NOTE_D4S, 600);
|
||||
note(NOTE_G3S, 150);
|
||||
note(NOTE_D4S, 450);
|
||||
note(NOTE_F4, 450);
|
||||
note(NOTE_G4S, 90);
|
||||
note(NOTE_F4S, 90);
|
||||
note(NOTE_F4, 90);
|
||||
note(NOTE_C4S, 510);
|
||||
note(NOTE_D4S, 600);
|
||||
note(NOTE_G3S, 1500);
|
||||
note(NOTE_C4S, 450);
|
||||
note(NOTE_D4S, 600);
|
||||
note(NOTE_G3S, 150);
|
||||
note(NOTE_D4S, 450);
|
||||
note(NOTE_F4, 450);
|
||||
note(NOTE_G4S, 90);
|
||||
note(NOTE_F4S, 90);
|
||||
note(NOTE_F4, 90);
|
||||
note(NOTE_C4S, 510);
|
||||
note(NOTE_D4S, 600);
|
||||
note(NOTE_G3S, 1500);
|
||||
}
|
||||
#endif
|
||||
|
||||
void donut(void);
|
||||
|
@ -160,6 +223,10 @@ static void console_service(void) {
|
|||
#ifdef CSR_AUDIO_BASE
|
||||
else if (strcmp(token, "saw") == 0)
|
||||
saw_cmd(&str);
|
||||
else if (strcmp(token, "imperial") == 0)
|
||||
imperial_cmd();
|
||||
else if (strcmp(token, "roll") == 0)
|
||||
roll_cmd();
|
||||
#endif
|
||||
prompt();
|
||||
}
|
||||
|
|
78
demo/note
Normal file
78
demo/note
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
// Function Definition
|
||||
|
||||
void note(uint32_t frequency, unsigned int duration_ms);
|
||||
|
||||
// Notes
|
||||
|
||||
#define NOTE_NONE 0
|
||||
|
||||
#define NOTE_C2 65
|
||||
#define NOTE_C2S 69
|
||||
#define NOTE_D2 73
|
||||
#define NOTE_D2S 78
|
||||
#define NOTE_E2 82
|
||||
#define NOTE_F2 87
|
||||
#define NOTE_F2S 93
|
||||
#define NOTE_G2 98
|
||||
#define NOTE_G2S 104
|
||||
#define NOTE_A2 110
|
||||
#define NOTE_A2S 117
|
||||
#define NOTE_B2 123
|
||||
|
||||
#define NOTE_C3 131
|
||||
#define NOTE_C3S 139
|
||||
#define NOTE_D3 147
|
||||
#define NOTE_D3S 156
|
||||
#define NOTE_E3 165
|
||||
#define NOTE_F3 175
|
||||
#define NOTE_F3S 185
|
||||
#define NOTE_G3 196
|
||||
#define NOTE_G3S 208
|
||||
#define NOTE_A3 220
|
||||
#define NOTE_A3S 233
|
||||
#define NOTE_B3 247
|
||||
|
||||
#define NOTE_C4 262
|
||||
#define NOTE_C4S 277
|
||||
#define NOTE_D4 294
|
||||
#define NOTE_D4S 311
|
||||
#define NOTE_E4 330
|
||||
#define NOTE_F4 349
|
||||
#define NOTE_F4S 370
|
||||
#define NOTE_G4 392
|
||||
#define NOTE_G4S 415
|
||||
#define NOTE_A4 440
|
||||
#define NOTE_A4S 466
|
||||
#define NOTE_B4 494
|
||||
|
||||
#define NOTE_C5 523
|
||||
#define NOTE_C5S 554
|
||||
#define NOTE_D5 587
|
||||
#define NOTE_D5S 622
|
||||
#define NOTE_E5 659
|
||||
#define NOTE_F5 698
|
||||
#define NOTE_F5S 740
|
||||
#define NOTE_G5 784
|
||||
#define NOTE_G5S 831
|
||||
#define NOTE_A5 880
|
||||
#define NOTE_A5S 932
|
||||
#define NOTE_B5 988
|
||||
|
||||
#define NOTE_C6 1047
|
||||
#define NOTE_C6S 1109
|
||||
#define NOTE_D6 1175
|
||||
#define NOTE_D6S 1245
|
||||
#define NOTE_E6 1319
|
||||
#define NOTE_F6 1397
|
||||
#define NOTE_F6S 1480
|
||||
#define NOTE_G6 1568
|
||||
#define NOTE_G6S 1661
|
||||
#define NOTE_A6 1760
|
||||
#define NOTE_A6S 1865
|
||||
#define NOTE_B6 1976
|
||||
|
||||
#define NOTE_C7 2093
|
8
demo/note.cpp
Normal file
8
demo/note.cpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <generated/csr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void note(uint32_t frequency, unsigned int duration_ms) {
|
||||
audio_targ_write(frequency);
|
||||
busy_wait(duration_ms);
|
||||
audio_targ_write(0);
|
||||
}
|
Loading…
Reference in a new issue