From aee2b8acbd1abe7bef10718504a18990ff209cd7 Mon Sep 17 00:00:00 2001 From: tbarnes98 Date: Tue, 22 Feb 2022 09:49:23 -0600 Subject: [PATCH] lw6 reformatting --- labW6barnestr/Inc/piezoSpeaker.h | 15 +++--- labW6barnestr/Src/main.c | 21 +++++++-- labW6barnestr/Src/piezoSpeaker.c | 81 ++++++++++++++++++-------------- 3 files changed, 73 insertions(+), 44 deletions(-) diff --git a/labW6barnestr/Inc/piezoSpeaker.h b/labW6barnestr/Inc/piezoSpeaker.h index 428669d..609ba4f 100644 --- a/labW6barnestr/Inc/piezoSpeaker.h +++ b/labW6barnestr/Inc/piezoSpeaker.h @@ -1,10 +1,11 @@ /** * @file piezoSpeaker.h * @author Trevor Barnes - * @brief Header file for the piezo speaker's C file that provides all of the necessary timer, RCC, - * and GPIOB values for working with the respective components. Note frequency values and durations - * are also defined. - * @version 0.1 + * @brief Header file for the piezo speaker's C file that provides all of the + * necessary timer, RCC, and GPIOB values for working with the respective + * components. Note frequency values and durations are also defined. + * Registers addresses converted to structs in this new version + * @version 0.2 * @date 2022-01-12 * * @copyright Copyright (c) 2022 @@ -129,13 +130,15 @@ extern Note songIM[]; extern Note songMT[]; extern Note songFG[]; -// Initializes the piezo speaker to be used with timer 3. Also initializes timer 4 for note duration interrupt +// Initializes the piezo speaker to be used with timer 3. +// Also initializes timer 4 for note duration interrupt void piezo_init(); // Plays a given note at a certain frequency for a certain duration void play_note(Note noteToPlay); -// Iterates through an array of note structs and ends at the termination value "END" +// Iterates through an array of note structs +// and ends at the termination value "END" void play_song(Note *songToPlay); void play_song_br(Note *songToPlay); diff --git a/labW6barnestr/Src/main.c b/labW6barnestr/Src/main.c index 881aa6c..0bde64f 100644 --- a/labW6barnestr/Src/main.c +++ b/labW6barnestr/Src/main.c @@ -1,7 +1,19 @@ /** * @file main.c * @author Trevor Barnes - * @brief + * @brief Main Driver for the Week 6 "Background Music" 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. However, the user can now select whether or not the + * music should play in the background to allow other functionality. + * Experience: This lab was a challenge for me. I found that understanding + * interrupts, and mainly how to configure them, was a roadblock that took me + * awhile to figure out. Cleary, as this lab is incomplete I was not able to + * fully implement my design. I do have a general idea of the structure of the + * program I would like to implement. For my own sake and sanity, I am going to + * work on trying finish this lab at the very least over break just so I can + * see what it is like to get an interrupt driven program working. In this + * case I just managed my time wrong and let myself get behind on labs. * @version 0.1 * @date 2022-01-19 * @@ -24,9 +36,10 @@ void printHelp() { printf("*Commands*\n\r"); printf("'rmw {hex address}' - Reads mem at a given address\n\r"); - printf("'wmw {hex address} {value}' - Writes the given value as a word to the given address\n\r"); - printf("'dm {hex address} {length}' - Dumps the memory at a given address. Defaults to 16 B if no " - "length is given\n\r"); + printf("'wmw {hex address} {value}' - Writes the given value as a word to " + "the given address\n\r"); + printf("'dm {hex address} {length}' - Dumps the memory at a given address. " + "Defaults to 16 B if no length is given\n\r"); printf("'ps {song choice}' - Plays a song with the given selection\n\r"); printf("'songs' - Prints info about each song selection\n\r"); } diff --git a/labW6barnestr/Src/piezoSpeaker.c b/labW6barnestr/Src/piezoSpeaker.c index a43d1e7..94dbf3a 100644 --- a/labW6barnestr/Src/piezoSpeaker.c +++ b/labW6barnestr/Src/piezoSpeaker.c @@ -1,8 +1,10 @@ /** * @file piezoSpeaker.c * @author Trevor Barnes - * @brief Provides functionality for initializing, playing notes, and playing songs on the piezo speaker. - * @version 0.1 + * @brief Provides functionality for initializing, playing notes, and playing + * songs on the piezo speaker. + * Added interrupt functionality for background playing + * @version 0.2 * @date 2022-01-12 * * @copyright Copyright (c) 2022 @@ -30,42 +32,50 @@ 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} - }; + {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} - }; + {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} - }; + {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} +}; int volumeDivisor = 10; @@ -132,11 +142,13 @@ void TIM4_IRQHandler(void) { (*tim3).PSC = 15; // Pitch divisor to scale with timer //current note frequency global variable - (*tim3).ARR = (pitchDivisor)/(currentSong[currentNoteIndex].noteFrequency); + (*tim3).ARR = + (pitchDivisor)/(currentSong[currentNoteIndex].noteFrequency); // Volume (Smaller dividend = louder sound) //current note frequency global variable - unsigned int freq = (currentSong[currentNoteIndex].noteFrequency/volumeDivisor); + unsigned int freq = + (currentSong[currentNoteIndex].noteFrequency/volumeDivisor); // Clear CCR (*tim3).CCR1 = ((*tim3).CCR1&~(0xFFFF)); @@ -168,6 +180,7 @@ void TIM4_IRQHandler(void) { currentNoteIndex++; } +// Might be unneccessary void play_song_br(Note *songToPlay) { // Set current song global variable currentSong = songToPlay;