mirror of
https://github.com/supleed2/EIE4-FYP.git
synced 2024-11-10 04:15:49 +00:00
Add waveform selection to demo software
Available waveforms: Sawtooth, Square, Triangle, Sine (To be completed)
This commit is contained in:
parent
6381cb53a8
commit
79ab8cd538
|
@ -91,7 +91,10 @@ static void help(void) {
|
||||||
puts("leds - Led set demo");
|
puts("leds - Led set demo");
|
||||||
#endif
|
#endif
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
puts("saw - Sawtooth Audio demo");
|
puts("saw - Sawtooth Wave demo");
|
||||||
|
puts("square - Square Wave demo");
|
||||||
|
puts("triangle - Triangle Wave demo");
|
||||||
|
puts("sine - Sine Wave demo");
|
||||||
puts("imperial - Imperial March demo");
|
puts("imperial - Imperial March demo");
|
||||||
puts("roll - Music demo");
|
puts("roll - Music demo");
|
||||||
#endif
|
#endif
|
||||||
|
@ -123,7 +126,29 @@ static void leds_cmd(char **val) {
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
static void saw_cmd(char **val) {
|
static void saw_cmd(char **val) {
|
||||||
int value = (int)strtol(get_token(val), NULL, 0);
|
int value = (int)strtol(get_token(val), NULL, 0);
|
||||||
printf("Setting Sawtooth to %dHz\n", value);
|
printf("Setting Oscillator 0 to Sawtooth: %dHz\n", value);
|
||||||
|
wave(WAVE_SAW);
|
||||||
|
audio_targ0_write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void square_cmd(char **val) {
|
||||||
|
int value = (int)strtol(get_token(val), NULL, 0);
|
||||||
|
printf("Setting Oscillator 0 to Square: %dHz\n", value);
|
||||||
|
wave(WAVE_SQUARE);
|
||||||
|
audio_targ0_write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void triangle_cmd(char **val) {
|
||||||
|
int value = (int)strtol(get_token(val), NULL, 0);
|
||||||
|
printf("Setting Oscillator 0 to Triangle: %dHz\n", value);
|
||||||
|
wave(WAVE_TRIANGLE);
|
||||||
|
audio_targ0_write(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sine_cmd(char **val) {
|
||||||
|
int value = (int)strtol(get_token(val), NULL, 0);
|
||||||
|
printf("Setting Oscillator 0 to Sine: %dHz\n", value);
|
||||||
|
wave(WAVE_SINE);
|
||||||
audio_targ0_write(value);
|
audio_targ0_write(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,6 +248,12 @@ static void console_service(void) {
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
else if (strcmp(token, "saw") == 0)
|
else if (strcmp(token, "saw") == 0)
|
||||||
saw_cmd(&str);
|
saw_cmd(&str);
|
||||||
|
else if (strcmp(token, "square") == 0)
|
||||||
|
square_cmd(&str);
|
||||||
|
else if (strcmp(token, "triangle") == 0)
|
||||||
|
triangle_cmd(&str);
|
||||||
|
else if (strcmp(token, "sine") == 0)
|
||||||
|
sine_cmd(&str);
|
||||||
else if (strcmp(token, "imperial") == 0)
|
else if (strcmp(token, "imperial") == 0)
|
||||||
imperial_cmd();
|
imperial_cmd();
|
||||||
else if (strcmp(token, "roll") == 0)
|
else if (strcmp(token, "roll") == 0)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// Function Definition
|
// Function Definition
|
||||||
|
|
||||||
void note(uint32_t frequency, unsigned int duration_ms);
|
void note(uint32_t frequency, unsigned int duration_ms);
|
||||||
|
void wave(uint32_t wave);
|
||||||
|
|
||||||
// Notes
|
// Notes
|
||||||
|
|
||||||
|
@ -76,3 +77,10 @@ void note(uint32_t frequency, unsigned int duration_ms);
|
||||||
#define NOTE_B6 1976
|
#define NOTE_B6 1976
|
||||||
|
|
||||||
#define NOTE_C7 2093
|
#define NOTE_C7 2093
|
||||||
|
|
||||||
|
// Waves
|
||||||
|
|
||||||
|
#define WAVE_SAW 0
|
||||||
|
#define WAVE_SQUARE 1
|
||||||
|
#define WAVE_TRIANGLE 2
|
||||||
|
#define WAVE_SINE 3
|
||||||
|
|
|
@ -6,3 +6,7 @@ void note(uint32_t frequency, unsigned int duration_ms) {
|
||||||
busy_wait(duration_ms);
|
busy_wait(duration_ms);
|
||||||
audio_targ0_write(0);
|
audio_targ0_write(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wave(uint32_t wave) {
|
||||||
|
audio_wave0_write(wave);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue