From d48a6d67d7a0cf14036afc941ecd6f05537cccd6 Mon Sep 17 00:00:00 2001 From: Thammi Date: Thu, 11 Oct 2012 23:05:59 +0200 Subject: [PATCH] Revert "Move synth code from lib to app" This reverts commit 5dd5bdacaa6fcc6caa0e6b9ca2a81361f76a56e4. --- firmware/apps/crazy_synth.c | 127 ++---------------------------------- firmware/lib/synth.c | 125 +++++++++++++++++++++++++++++++++++ firmware/lib/synth.h | 5 ++ firmware/main.c | 1 + 4 files changed, 136 insertions(+), 122 deletions(-) create mode 100644 firmware/lib/synth.c create mode 100644 firmware/lib/synth.h diff --git a/firmware/apps/crazy_synth.c b/firmware/apps/crazy_synth.c index d0dc7fb..b591a6a 100644 --- a/firmware/apps/crazy_synth.c +++ b/firmware/apps/crazy_synth.c @@ -1,129 +1,12 @@ #include -#include -#include -#define __DELAY_BACKWARD_COMPATIBLE__ -#include #include -#include -#include "freq_table.h" -#include +#include #include "../lib/apps.h" - - -static uint16_t osc0 ; -static uint16_t osc1 ; -static uint16_t sample ; -static uint8_t row ; -static uint16_t speedtime; - - -void synth_init(void){ - cli(); - osc0 = osc1 = sample = row = 0; - speedtime = 3000; - - /* set timer0 to CTC & prescaler 64 → 125kHz increment */ - TCCR0A = (1 << WGM01); - TCCR0B = (1 << CS00) | (1 << CS01); - - OCR0A = 4; /* TOP */ - TCNT0 = 0; - - /*enable interrupt */ - TIMSK0 |= (1 << OCIE0A); - - sei(); - return; -} - - -void synth_deinit(void) { - cli(); - TIMSK0 = 0; - sei(); - return; -} - -enum { - SONG_LENGTH = 128, - xxx = 0, - c_0 = 0, cs0 = 1, d_0 = 2, ds0 = 3, e_0 = 4, f_0 = 5, - fs0 = 6, g_0 = 7, gs0 = 8, a_0 = 9, as0 = 10, b_0 = 11, - c_1 = 12, cs1 = 13, d_1 = 14, ds1 = 15, e_1 = 16, f_1 = 17, - fs1 = 18, g_1 = 19, gs1 = 20, a_1 = 21, as1 = 22, b_1 = 23, - c_2 = 24, cs2 = 25, d_2 = 26, ds2 = 27, e_2 = 28, f_2 = 29, - fs2 = 30, g_2 = 31, gs2 = 32, a_2 = 33, as2 = 34, b_2 = 35, - c_3 = 36, cs3 = 37, d_3 = 38, ds3 = 39, e_3 = 40, f_3 = 41, - fs3 = 42, g_3 = 43, gs3 = 44, a_3 = 45, as3 = 46, b_3 = 47, -}; - -const char music_data[2][SONG_LENGTH] PROGMEM = { - { - e_1, xxx, e_2, xxx, e_1, xxx, e_2, xxx, - e_1, xxx, e_2, xxx, e_1, xxx, e_2, xxx, - a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, - a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, - gs0, xxx, gs1, xxx, gs0, xxx, gs1, xxx, - gs0, xxx, gs1, xxx, gs0, xxx, gs1, xxx, - a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, - a_0, xxx, a_0, xxx, b_0, xxx, c_1, xxx, - d_1, xxx, d_2, xxx, d_1, xxx, d_2, xxx, - d_1, xxx, d_2, xxx, d_1, xxx, d_2, xxx, - c_1, xxx, c_2, xxx, c_1, xxx, c_2, xxx, - c_1, xxx, c_2, xxx, c_1, xxx, c_2, xxx, - b_0, xxx, b_1, xxx, b_0, xxx, b_1, xxx, - b_0, xxx, b_1, xxx, b_0, xxx, b_1, xxx, - a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, - a_0, xxx, xxx, xxx, xxx, xxx, xxx, xxx, - }, { - e_3, e_3, e_3, e_3, b_2, b_2, c_3, c_3, - d_3, d_3, e_3, d_3, c_3, c_3, b_2, b_2, - a_2, a_2, a_2, a_2, a_2, a_2, c_3, c_3, - e_3, e_3, e_3, e_3, d_3, d_3, c_3, c_3, - b_2, b_2, b_2, b_2, b_2, b_2, c_3, c_3, - d_3, d_3, d_3, d_3, e_3, e_3, e_3, e_3, - c_3, c_3, c_3, c_3, a_2, a_2, a_2, a_2, - a_2, a_2, a_2, a_2, a_2, a_2, a_2, a_2, - xxx, xxx, d_3, d_3, d_3, d_3, f_3, f_3, - a_3, a_3, a_3, a_3, g_3, g_3, f_3, f_3, - e_3, e_3, e_3, e_3, e_3, e_3, c_3, c_3, - e_3, e_3, e_3, e_3, d_3, d_3, c_3, c_3, - b_2, b_2, b_2, b_2, b_2, b_2, c_3, c_3, - d_3, d_3, d_3, d_3, e_3, e_3, e_3, e_3, - c_3, c_3, c_3, c_3, a_2, a_2, a_2, a_2, - a_2, a_2, a_2, a_2, xxx, xxx, xxx, xxx, - } -}; - - - - -ISR(TIMER0_COMPA_vect,ISR_NOBLOCK) -{ - osc0 += pgm_read_word(&freq_table[ pgm_read_byte(&music_data[0][row])]); - osc1 += pgm_read_word(&freq_table[ pgm_read_byte(&music_data[1][row])]); - if (++sample == speedtime ) { - sample = 0; - - if (speedtime > 600) speedtime -= 4; - if (++row == SONG_LENGTH) { - row = 0; - if (speedtime <= 600) speedtime = 3000; - } - if (row&4){ - led_on(LED_R); - led_off(LED_L); - }else{ - led_on(LED_L); - led_off(LED_R); - } } - - if (osc0 >= 0x8000) PORTB |= (1 << PORTB2); - else PORTB &= ~(1<< PORTB2); - if (osc1 >= 0xc000) PORTC |= (1 << PORTC5); - else PORTC &= ~(1<< PORTC5); -} +#include "../lib/bughal.h" +#include "../lib/util.h" +#include "../lib/music.h" +#include "../lib/synth.h" /** * do crazy synthesizer mode diff --git a/firmware/lib/synth.c b/firmware/lib/synth.c new file mode 100644 index 0000000..c168330 --- /dev/null +++ b/firmware/lib/synth.c @@ -0,0 +1,125 @@ +#include +#include +#include +#define __DELAY_BACKWARD_COMPATIBLE__ +#include +#include +#include +#include "freq_table.h" +#include + + + +static uint16_t osc0 ; +static uint16_t osc1 ; +static uint16_t sample ; +static uint8_t row ; +static uint16_t speedtime; + + +void synth_init(void){ + cli(); + osc0 = osc1 = sample = row = 0; + speedtime = 3000; + + /* set timer0 to CTC & prescaler 64 → 125kHz increment */ + TCCR0A = (1 << WGM01); + TCCR0B = (1 << CS00) | (1 << CS01); + + OCR0A = 4; /* TOP */ + TCNT0 = 0; + + /*enable interrupt */ + TIMSK0 |= (1 << OCIE0A); + + sei(); + return; +} + + +void synth_deinit(void) { + cli(); + TIMSK0 = 0; + sei(); + return; +} + +enum { + SONG_LENGTH = 128, + xxx = 0, + c_0 = 0, cs0 = 1, d_0 = 2, ds0 = 3, e_0 = 4, f_0 = 5, + fs0 = 6, g_0 = 7, gs0 = 8, a_0 = 9, as0 = 10, b_0 = 11, + c_1 = 12, cs1 = 13, d_1 = 14, ds1 = 15, e_1 = 16, f_1 = 17, + fs1 = 18, g_1 = 19, gs1 = 20, a_1 = 21, as1 = 22, b_1 = 23, + c_2 = 24, cs2 = 25, d_2 = 26, ds2 = 27, e_2 = 28, f_2 = 29, + fs2 = 30, g_2 = 31, gs2 = 32, a_2 = 33, as2 = 34, b_2 = 35, + c_3 = 36, cs3 = 37, d_3 = 38, ds3 = 39, e_3 = 40, f_3 = 41, + fs3 = 42, g_3 = 43, gs3 = 44, a_3 = 45, as3 = 46, b_3 = 47, +}; + +const char music_data[2][SONG_LENGTH] PROGMEM = { + { + e_1, xxx, e_2, xxx, e_1, xxx, e_2, xxx, + e_1, xxx, e_2, xxx, e_1, xxx, e_2, xxx, + a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, + a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, + gs0, xxx, gs1, xxx, gs0, xxx, gs1, xxx, + gs0, xxx, gs1, xxx, gs0, xxx, gs1, xxx, + a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, + a_0, xxx, a_0, xxx, b_0, xxx, c_1, xxx, + d_1, xxx, d_2, xxx, d_1, xxx, d_2, xxx, + d_1, xxx, d_2, xxx, d_1, xxx, d_2, xxx, + c_1, xxx, c_2, xxx, c_1, xxx, c_2, xxx, + c_1, xxx, c_2, xxx, c_1, xxx, c_2, xxx, + b_0, xxx, b_1, xxx, b_0, xxx, b_1, xxx, + b_0, xxx, b_1, xxx, b_0, xxx, b_1, xxx, + a_0, xxx, a_1, xxx, a_0, xxx, a_1, xxx, + a_0, xxx, xxx, xxx, xxx, xxx, xxx, xxx, + }, { + e_3, e_3, e_3, e_3, b_2, b_2, c_3, c_3, + d_3, d_3, e_3, d_3, c_3, c_3, b_2, b_2, + a_2, a_2, a_2, a_2, a_2, a_2, c_3, c_3, + e_3, e_3, e_3, e_3, d_3, d_3, c_3, c_3, + b_2, b_2, b_2, b_2, b_2, b_2, c_3, c_3, + d_3, d_3, d_3, d_3, e_3, e_3, e_3, e_3, + c_3, c_3, c_3, c_3, a_2, a_2, a_2, a_2, + a_2, a_2, a_2, a_2, a_2, a_2, a_2, a_2, + xxx, xxx, d_3, d_3, d_3, d_3, f_3, f_3, + a_3, a_3, a_3, a_3, g_3, g_3, f_3, f_3, + e_3, e_3, e_3, e_3, e_3, e_3, c_3, c_3, + e_3, e_3, e_3, e_3, d_3, d_3, c_3, c_3, + b_2, b_2, b_2, b_2, b_2, b_2, c_3, c_3, + d_3, d_3, d_3, d_3, e_3, e_3, e_3, e_3, + c_3, c_3, c_3, c_3, a_2, a_2, a_2, a_2, + a_2, a_2, a_2, a_2, xxx, xxx, xxx, xxx, + } +}; + + + + +ISR(TIMER0_COMPA_vect,ISR_NOBLOCK) +{ + osc0 += pgm_read_word(&freq_table[ pgm_read_byte(&music_data[0][row])]); + osc1 += pgm_read_word(&freq_table[ pgm_read_byte(&music_data[1][row])]); + if (++sample == speedtime ) { + sample = 0; + + if (speedtime > 600) speedtime -= 4; + if (++row == SONG_LENGTH) { + row = 0; + if (speedtime <= 600) speedtime = 3000; + } + if (row&4){ + led_on(LED_R); + led_off(LED_L); + }else{ + led_on(LED_L); + led_off(LED_R); + } } + + if (osc0 >= 0x8000) PORTB |= (1 << PORTB2); + else PORTB &= ~(1<< PORTB2); + if (osc1 >= 0xc000) PORTC |= (1 << PORTC5); + else PORTC &= ~(1<< PORTC5); +} diff --git a/firmware/lib/synth.h b/firmware/lib/synth.h new file mode 100644 index 0000000..2af7aed --- /dev/null +++ b/firmware/lib/synth.h @@ -0,0 +1,5 @@ + +void synth_init(void); +void synth_deinit(void); + + diff --git a/firmware/main.c b/firmware/main.c index 402618d..bee9e46 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -14,6 +14,7 @@ #include "lib/bughal.h" #include "lib/util.h" #include "lib/music.h" +#include "lib/synth.h" #include "lib/apps.h"