diff --git a/Main.c b/Main.c index efebb3e..e361bfa 100644 --- a/Main.c +++ b/Main.c @@ -57,9 +57,10 @@ int main (void) { vMainInitApp(); //init app vPrintQr(); //print Qr + vStartAudio(); while(1) { - //calculate important things (Artificial neural network) + vUpdateLyrics(); } } @@ -86,13 +87,6 @@ static void vMainInitApp(void) // Init LED LED_Initialize(); - - vStartAudio(); - vPrintQr(); - - while (1) - { - } } /** @@ -105,9 +99,9 @@ static void vMainInitApp(void) */ static void vPrintQr(void) { - uint8_t u8DotSize = 8U; + uint8_t u8DotSize = 7U; uint8_t u8Yoffset = 30U; - uint8_t u8Xoffset = 60U; + uint8_t u8Xoffset = 72U; for(uint8_t y = 0; y < 25; y++) { for(int8_t x = 0; x < 25; x++) { diff --git a/audio.c b/audio.c index b74bbaa..cf66a9a 100644 --- a/audio.c +++ b/audio.c @@ -10,6 +10,7 @@ This file contains the main app function and init. #include "audio.h" #include "Board_DAC.h" +#include "Board_GLCD.h" #include "LPC17xx.h" #include "melody.h" @@ -24,9 +25,10 @@ struct AudioState const uint32_t *cpu32NextAction; uint32_t u32StackPointer; const uint32_t *cpu32Stack[10]; + const char *cpcExpectedText; }; -static struct AudioState sAudioState; +volatile static struct AudioState sAudioState; bool bPerformAudioStep() { @@ -72,6 +74,14 @@ bool bPerformAudioStep() LPC_TIM0->MR0 = WAVES(*sAudioState.cpu32NextAction) << 12; sAudioState.cpu32NextAction++; } + else if (FREQ(*sAudioState.cpu32NextAction) == 4) + { + // TEXT + sAudioState.highState = false; + sAudioState.cpcExpectedText = cpcTexts[WAVES(*sAudioState.cpu32NextAction)]; + sAudioState.cpu32NextAction++; + bSuccess = false; + } else { DAC_SetValue(512); @@ -97,6 +107,21 @@ bool bPerformAudioStep() return bSuccess; } +void vUpdateLyrics() +{ + static const char *cpcCurrentText = 0; + if (cpcCurrentText == 0) + { + cpcCurrentText = cpcTexts[0]; + } + const char *cpcExpectedText = sAudioState.cpcExpectedText; + if (cpcCurrentText != cpcExpectedText) + { + GLCD_DrawString(0, 213, cpcExpectedText); + cpcCurrentText = cpcExpectedText; + } +} + void TIMER0_IRQHandler() { LPC_TIM0->IR = 0x1; // acknowledge interrupt @@ -113,6 +138,7 @@ void vStartAudio() sAudioState.u16RemainingWaves = 0; sAudioState.cpu32NextAction = cpu32EntryPoint; sAudioState.u32StackPointer = 0; + sAudioState.cpcExpectedText = cpcTexts[0]; // Init timerinterrupt 0 (20 ms) LPC_SC->PCONP |= (1 << 2); // turn on diff --git a/audio.h b/audio.h index bd679a6..1874053 100644 --- a/audio.h +++ b/audio.h @@ -15,5 +15,6 @@ This file contains the main app function and init. #include void vStartAudio(void); +void vUpdateLyrics(void); #endif diff --git a/melody.c b/melody.c index 574761b..54403c9 100644 --- a/melody.c +++ b/melody.c @@ -17,6 +17,8 @@ This file contains the main app function and init. // duration: pause duration as multiple of 40ns #define PAUSE(duration) (0x30000 | ((duration >> 10) & 0xffff)) +#define TEXT(id) (0x40000 | id) + const uint32_t TACT = 2120 * 1000 * 25; // 2.12 seconds for one tact const uint32_t GIS2 = 30098; @@ -52,7 +54,53 @@ const uint32_t *jumplabels[] = { }; const uint32_t **cppu32JumpLabels = jumplabels; +const char *cpcTexts[] = { + " ", // 0 + " We're no strangers ", + " to love ", + " You know the rules ", + " and so do I ", + "A full commitment's ", // 5 + "what I'm thinking of", + " You wouldn't ", + " get this from ", + " any other guy ", + " I just wanna ", // 10 + " tell you how I'm ", + " feeling ", + " Gotta make you ", + " understand ", + " Never gonna ", // 15 + " give you up ", + " let you down ", + " run around and ", + " desert you ", + " make you cry ", // 20 + " say goodbye ", + " tell a lie ", + " and hurt you ", + " We've known ", + " each other ", // 25 + " for so long ", + " Your heart's ", + " been aching but ", + " You're too shy ", + " to say it ", // 30 + "Inside we both know ", + "what's been going on", + " We know the game ", + " and we're ", + " gonna play it ", // 35 + " And if you ", + " ask me how I'm ", + " feeling ", + " Don't tell me ", + " you're too ", // 40 + " blind to see ", +}; + const uint32_t quadrupel[] = { + TEXT(15), TONE(GIS, TACT / 16), TONE(B, TACT / 16), TONE(CIS, TACT / 16), @@ -63,11 +111,13 @@ const uint32_t quadrupel[] = { const uint32_t refrain[] = { CALL_QUADRUPEL, + TEXT(16), TONE(F, TACT * 3 / 16), TONE(F, TACT * 3 / 16), TONE(DIS, TACT * 3 / 8), CALL_QUADRUPEL, + TEXT(17), TONE(DIS, TACT * 3 / 16), TONE(DIS, TACT * 3 / 16), TONE(CIS, TACT * 3 / 16), @@ -75,22 +125,26 @@ const uint32_t refrain[] = { TONE(B, TACT / 8), CALL_QUADRUPEL, + TEXT(18), TONE(CIS, TACT / 4), TONE(DIS, TACT / 8), TONE(C, TACT * 3 / 16), TONE(B, TACT / 16), TONE(GIS, TACT / 4), + TEXT(19), TONE(GIS, TACT / 8), TONE(DIS, TACT / 4), TONE(CIS, TACT / 2), CALL_QUADRUPEL, + TEXT(20), TONE(F, TACT * 3 / 16), TONE(F, TACT * 3 / 16), TONE(DIS, TACT * 3 / 8), CALL_QUADRUPEL, + TEXT(21), TONE(GIS2,TACT / 4), TONE(C, TACT / 8), TONE(CIS, TACT * 3 / 16), @@ -98,11 +152,13 @@ const uint32_t refrain[] = { TONE(B, TACT / 8), CALL_QUADRUPEL, + TEXT(22), TONE(CIS, TACT / 4), TONE(DIS, TACT / 8), TONE(C, TACT * 3 / 16), TONE(B, TACT / 16), TONE(GIS, TACT / 4), + TEXT(23), TONE(GIS, TACT / 8), TONE(DIS, TACT / 4), @@ -113,10 +169,12 @@ const uint32_t refrain[] = { const uint32_t strophe1[] = { PAUSE(TACT / 4), + TEXT(1), TONE(B, TACT / 8), TONE(C, TACT / 8), TONE(CIS, TACT / 8), TONE(CIS, TACT / 8), + TEXT(2), TONE(DIS, TACT / 8), TONE(C, TACT * 3 / 16), // 1/8 tact before, 1/16 tact after @@ -125,12 +183,14 @@ const uint32_t strophe1[] = { TONE(GIS, TACT * 7 / 8), PAUSE(TACT / 8), + TEXT(3), TONE(B, TACT / 8), TONE(B, TACT / 8), TONE(C, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), PAUSE(TACT / 8), + TEXT(4), TONE(GIS, TACT / 8), TONE(GIS2,TACT / 4), @@ -138,11 +198,13 @@ const uint32_t strophe1[] = { TONE(DIS, TACT * 5 / 8), PAUSE(TACT / 8), + TEXT(5), TONE(B, TACT / 8), TONE(B, TACT / 8), TONE(C, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), + TEXT(6), TONE(CIS, TACT / 8), TONE(DIS, TACT / 8), @@ -154,37 +216,45 @@ const uint32_t strophe1[] = { TONE(GIS, TACT / 2), PAUSE(TACT / 8), + TEXT(7), TONE(B, TACT / 8), TONE(B, TACT / 8), TONE(C, TACT / 8), + TEXT(8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), TONE(GIS, TACT / 4), + TEXT(9), TONE(DIS, TACT / 8), TONE(DIS, TACT / 8), TONE(DIS, TACT / 8), TONE(F, TACT / 8), TONE(DIS, TACT / 2), + TEXT(10), TONE(CIS, TACT * 5 / 8), TONE(DIS, TACT / 8), TONE(F, TACT / 8), TONE(CIS, TACT / 8), + TEXT(11), TONE(DIS, TACT / 8), TONE(DIS, TACT / 8), TONE(DIS, TACT / 8), TONE(F, TACT / 8), + TEXT(12), TONE(DIS, TACT / 4), TONE(GIS, TACT / 4), PAUSE(TACT / 4), + TEXT(13), TONE(B, TACT / 8), TONE(C, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), PAUSE(TACT / 8), + TEXT(14), TONE(DIS, TACT / 8), TONE(F, TACT / 8), @@ -195,40 +265,49 @@ const uint32_t strophe1[] = { const uint32_t strophe2[] = { PAUSE(TACT / 8), + TEXT(24), TONE(CIS, TACT / 8), TONE(CIS, TACT / 8), + TEXT(25), TONE(B, TACT / 8), TONE(CIS, TACT / 8), TONE(DIS, TACT * 3 / 8), PAUSE(TACT / 8), + TEXT(26), TONE(C, TACT / 8), TONE(B, TACT / 8), TONE(B, TACT / 8), TONE(GIS, TACT / 2), PAUSE(TACT / 8), + TEXT(27), TONE(B, TACT / 8), TONE(B, TACT / 8), + TEXT(28), TONE(C, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), TONE(GIS, TACT / 4), PAUSE(TACT / 8), + TEXT(29), TONE(GIS2,TACT / 8), TONE(GIS2,TACT / 8), TONE(DIS, TACT / 4), + TEXT(30), TONE(F, TACT / 8), TONE(DIS, TACT / 8), TONE(CIS, TACT / 8), PAUSE(TACT / 8), + TEXT(31), TONE(CIS, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), TONE(CIS, TACT / 8), TONE(B, TACT / 8), + TEXT(32), TONE(CIS, TACT / 8), TONE(DIS, TACT / 8), @@ -239,39 +318,48 @@ const uint32_t strophe2[] = { TONE(GIS, TACT / 2), PAUSE(TACT / 8), + TEXT(33), TONE(B, TACT / 8), TONE(B, TACT / 8), TONE(C, TACT / 8), TONE(CIS, TACT / 8), + TEXT(34), TONE(B, TACT / 8), TONE(GIS, TACT / 4), PAUSE(TACT / 4), + TEXT(35), TONE(DIS, TACT / 8), TONE(F, TACT / 8), TONE(F, TACT / 4), TONE(DIS, TACT / 4), + TEXT(36), TONE(CIS, TACT * 5 / 8), TONE(DIS, TACT / 8), TONE(F, TACT / 8), + TEXT(37), TONE(DIS, TACT / 4), // 1/8 tact before, 1/8 tact after TONE(DIS, TACT / 8), TONE(DIS, TACT / 8), TONE(F, TACT / 8), + TEXT(38), TONE(DIS, TACT / 4), TONE(GIS, TACT / 4), PAUSE(TACT / 4), + TEXT(39), TONE(GIS, TACT / 8), TONE(B, TACT / 8), TONE(C, TACT / 8), + TEXT(40), TONE(CIS, TACT / 8), TONE(B, TACT / 8), PAUSE(TACT / 8), + TEXT(41), TONE(DIS, TACT / 8), TONE(F, TACT / 8), TONE(DIS, TACT / 4), diff --git a/melody.h b/melody.h index f2b7000..2f5cc82 100644 --- a/melody.h +++ b/melody.h @@ -15,5 +15,6 @@ This file contains the main app function and init. extern const uint32_t *cpu32EntryPoint; extern const uint32_t **cppu32JumpLabels; +extern const char *cpcTexts[]; #endif