project additions/changes

This commit is contained in:
2022-02-18 10:21:19 -06:00
parent a7303fe5f9
commit debbd37501
26 changed files with 1906 additions and 690 deletions

View File

@@ -1,13 +1,7 @@
/**
* @file main.c
* @author Trevor Barnes
* @brief Main Driver for the Week 5 "Play a Tune" Lab. This program uses a similar menu style to the previous
* lab. The user is given a new option to play 3 different hard coded songs in arrays of "Note" structs,
* provided by the piezoSpeaker.h file.
* Experience: As a former music student I enjoyed working on this lab very much, to the point that I became
* sort of a perfectionist with its implementation. Getting the timer configured and working with the piezo speaker
* was certainly the most difficult and time consuming part. Once I had that figured out though figuring
* out the best note implementation and songs to play was very enjoyable.
* @brief
* @version 0.1
* @date 2022-01-19
*
@@ -27,45 +21,6 @@
#define F_CPU 16000000UL
// Imperial March - Star Wars
Note songIM[138] = {
{A4, Q}, {A4, Q}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{E5, Q}, {E5, Q}, {E5, Q}, {F5, S*3}, {C5, S}, {Ab4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {A4, S},
{C5, Q}, {A4, S*3}, {C5, S}, {E5, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {C5, S},
{A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{END}
};
// Metropolis Theme - Ratchet & Clank
Note songMT[33] = {
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{END}
};
// Flower Garden - Yoshi's Island
Note songFG[77] = {
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {D4, E}, {E4, E}, {r, Q},
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {E4, E}, {D4, E}, {r, Q},
{G5, S}, {Gb5, S}, {G5, E+(Q*3)},
{r , E}, {F5, E}, {E5, E}, {F5, E}, {E5, E}, {C5, E}, {A4, E}, {G4, E+(Q*5)}, {r, E},
{C5, E}, {B4, E}, {D5, E}, {A5, E}, {G5, E+H+Q}, {r, E},
{A5, E}, {B5, E}, {A5, E}, {G5, E}, {F5, E}, {E5, E}, {D5, E}, {E5, Q}, {C5, E}, {G4, E+(Q*3)}, {r, E},
{C5, E}, {B4, E}, {C5, E}, {D5, E}, {E5, E+Q}, {G5, Q}, {C5, Q}, {E5, Q},
{F5, E}, {E5, E}, {F5, E}, {D5, E*2}, {C5, E}, {B4, E}, {C5, E+W},
{END}
};
void printHelp() {
printf("*Commands*\n\r");
printf("'rmw {hex address}' - Reads mem at a given address\n\r");
@@ -119,13 +74,13 @@ int main(void) {
} else if (!strcmp(command, "ps")) {
// Song Selection Command Format:
// "ps {songSelection} {background}"
sscanf(line, "%s %u %c", command, &songSelection, background);
sscanf(line, "%s %u %c", command, &songSelection, &background);
if (background == 'b') {
switch(songSelection) {
case 1:
printf("Playing Imperial March in the background\n\r");
play_song_br(songIM);
break;
break;
case 2:
printf("Playing Metropolis Theme in the background\n\r");
play_song_br(songMT);

View File

@@ -14,11 +14,55 @@
#include "piezoSpeaker.h"
#include "delay.h"
volatile RCC* const rcc = 0x40023800;
volatile GPIO* const gpiob = 0x40020400;
volatile TIM* const tim3 = 0x40000400;
volatile SYSCFG* const syscfg = 0x40013800;
volatile EXTI* const exti4 = 0x40013C00;
volatile RCC* const rcc = (RCC*) 0x40023800;
volatile GPIO* const gpiob = (GPIO*) 0x40020400;
volatile TIM* const tim3 = (TIM*) 0x40000400;
volatile SYSCFG* const syscfg = (SYSCFG*) 0x40013800;
volatile EXTI* const exti4 = (EXTI*) 0x40013C00;
volatile Note* currentSong;
volatile int currentNoteIndex;
typedef enum {PLAY, STOP}songStatus;
// Imperial March - Star Wars
Note songIM[138] = {
{A4, Q}, {A4, Q}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{E5, Q}, {E5, Q}, {E5, Q}, {F5, S*3}, {C5, S}, {Ab4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {A4, S},
{C5, Q}, {A4, S*3}, {C5, S}, {E5, H},
{A5, Q}, {A4, S*3}, {A4, S}, {A5, Q}, {Ab5, S*3}, {G5, S},
{Gb5, S}, {F5, S}, {Gb5, E}, {r, E}, {Bb4, E}, {Eb5, Q}, {D5, S*3}, {Db5, S},
{C5, S}, {B4, S}, {C5, E}, {r, E}, {F4, E}, {Ab4, Q}, {F4, S*3}, {C5, S},
{A4, Q}, {F4, S*3}, {C5, S}, {A4, H},
{END}
};
// Metropolis Theme - Ratchet & Clank
Note songMT[33] = {
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{B5, E}, {G5, E}, {E5, E}, {G5, E}, {B5, E}, {G5, E}, {E5, E}, {B5, E},
{Bb5, E}, {F5, E}, {D5, E}, {F5, E}, {Bb5, E}, {F5, E}, {D5, E}, {Bb5, E},
{END}
};
// Flower Garden - Yoshi's Island
Note songFG[77] = {
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {D4, E}, {E4, E}, {r, Q},
{E4, E}, {r, E}, {G4, E}, {r, S}, {G4, S}, {E4, E}, {C4, E}, {r, Q},
{A3, E}, {r, E}, {C4, E}, {r, S}, {A3, S}, {E4, E}, {D4, E}, {r, Q},
{G5, S}, {Gb5, S}, {G5, E+(Q*3)},
{r , E}, {F5, E}, {E5, E}, {F5, E}, {E5, E}, {C5, E}, {A4, E}, {G4, E+(Q*5)}, {r, E},
{C5, E}, {B4, E}, {D5, E}, {A5, E}, {G5, E+W+E}, {r, E},
{A5, E}, {B5, E}, {A5, E}, {G5, E}, {F5, E}, {E5, E}, {D5, E}, {E5, Q}, {C5, E}, {G4, E+(Q*3)}, {r, E},
{C5, E}, {B4, E}, {C5, E}, {D5, E}, {E5, E+Q}, {G5, Q}, {C5, Q}, {E5, Q},
{F5, E}, {E5, E}, {F5, E}, {D5, E*2}, {C5, E}, {B4, E}, {C5, E+W},
{END}
};
void piezo_init(){
@@ -73,35 +117,45 @@ void play_song(Note *songToPlay){
}
}
void play_note_br(Note noteToplay) {
}
void TIM3_IRQHandler(void) {
(*tim3).PSC = 15;
// Pitch divisor to scale with timer
(*tim3).ARR = (pitchDivisor)/(noteToPlay.noteFrequency);
// Volume (Smaller dividend = louder sound)
unsigned int freq = (noteToPlay.noteFrequency/10);
//temp
if(PLAY) {
(*tim3).PSC = 15;
// Pitch divisor to scale with timer
//current note frequency global variable
//(*tim3).ARR = (pitchDivisor)/(noteToPlay.noteFrequency);
// Clear CCR
(*tim3).CCR1 = ((*tim3).CCR1&~(0xFFFF));
(*tim3).CCR1 = freq;
// Volume (Smaller dividend = louder sound)
//current note frequency global variable
//unsigned int freq = (noteToPlay.noteFrequency/10);
// Set EGR
(*tim3).EGR |= EGR_UG;
// Clear CCR
(*tim3).CCR1 = ((*tim3).CCR1&~(0xFFFF));
//(*tim3).CCR1 = freq;
// Playing note
// Enables timer
(*tim3).CR1 |= 1;
// Delay for duration of note
// This is gonna have to change
delay_1ms(noteToPlay.noteDuration);
// Disables timer
(*tim3).CR1 &= ~1;
// Set EGR
(*tim3).EGR |= EGR_UG;
// Playing note
// Enables timer
(*tim3).CR1 |= 1;
// Delay for duration of note
// This is gonna have to change
//delay_1ms(noteToPlay.noteDuration);
// Load timer with value of note duration
//currentNote = currentSong[currentNoteIndex];
} else {
while(currentSong[currentNoteIndex].noteFrequency != END) {
}
//currentNote = currentSong
}
}
void play_song_br(Note *songToPlay) {
// Set current song global variable
currentSong = songToPlay;
// Configure Interrupt
// PB4 Connected to EXTI4
(*syscfg).EXTICR2 &= ~(0xF);
(*syscfg).EXTICR2 &= ~(0x1);