-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (53 loc) · 1.12 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* main.c
* AVR_FM
*
* Created by Tiago Rezende on 8/4/13.
* Copyright 2011 Pixel of View. All rights reserved.
*
*/
#ifdef BUILD_FOR_AVR
#include <avr/io.h>
#include <avr/interrupt.h>
#else
#include <stdint.h>
#endif
#include "fm_synth.h"
#include "fm_command.h"
#ifdef BUILD_FOR_AVR
ISR(TIMER1_OVF_vect) {
OCR1A = fm_current_sample.left;
OCR2A = fm_current_sample.right;
FMSynth_Sample(); // sample after so it doesn't suffer aliasing problems
}
static void FMSampleOutputInit() {
TIMSK1 = (1<<TOIE1);
TCNT0 = 0x00;
TCCR1B |= (1<<WGM12)|(1<<WGM13)| 1; // clkio
DDRB |= (1<<DDB1)|(1<<DDB2);
}
ISR(SPI_STC_vect) {
SPDR = FMCommandReceive(SPDR);
}
#define DD_MOSI 5
#define DD_MISO 6
#define DD_SCK 7
#define DDR_SPI DDRB
static void FMCommandSPIInputInit() {
DDR_SPI |= (1<<DD_MISO);
// set SPI enable, spi clock polarity , spi interrupts enable
SPCR = (1<<SPE)|(1<<CPOL)|(1<<SPIE);
}
int main(void)
{
FMSampleOutputInit();
FMCommandSPIInputInit();
sei(); // enable interrupts
while(1) {
}
return 0;
}
#else
int main(int argc, char *argv) {
}
#endif