Merge branch 'master' of github.com:c3d2/pentabug
Conflicts: firmware/main.c
This commit is contained in:
commit
36cca6cfcf
|
@ -60,7 +60,7 @@ EXTRAINCDIRS =
|
||||||
# -Wall...: warning level
|
# -Wall...: warning level
|
||||||
# -Wa,...: tell GCC to pass this to the assembler.
|
# -Wa,...: tell GCC to pass this to the assembler.
|
||||||
# -ahlms: create assembler listing
|
# -ahlms: create assembler listing
|
||||||
CFLAGS = -O$(OPT)
|
CFLAGS = -O$(OPT) -g
|
||||||
CFLAGS += -funsigned-char
|
CFLAGS += -funsigned-char
|
||||||
CFLAGS += -funsigned-bitfields
|
CFLAGS += -funsigned-bitfields
|
||||||
CFLAGS += -fpack-struct
|
CFLAGS += -fpack-struct
|
||||||
|
|
|
@ -6,11 +6,54 @@
|
||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
volatile uint8_t sample_pending;
|
||||||
|
|
||||||
//25kHz
|
//25kHz
|
||||||
ISR(TIMER0_OVF_vect)
|
ISR(TIMER0_OVF_vect)
|
||||||
{
|
{
|
||||||
|
ICR1 = synth.output;
|
||||||
|
sample_pending = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sample rate is 8M / (5 * 64) = 25000
|
||||||
|
|
||||||
|
enum {
|
||||||
|
synth_channel_count = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t phase;
|
||||||
|
uint16_t speed;
|
||||||
|
|
||||||
|
} synth_channel_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
synth_channel_t channels[synth_channel_count];
|
||||||
|
uint16_t output;
|
||||||
|
} synth_t;
|
||||||
|
|
||||||
|
static synth_t synth;
|
||||||
|
|
||||||
|
static void synth_init(void)
|
||||||
|
{
|
||||||
|
// some test values
|
||||||
|
synth.channels[0].phase = 0;
|
||||||
|
synth.channels[0].speed = 1153;
|
||||||
|
|
||||||
|
synth.channels[1].phase = 0;
|
||||||
|
synth.channels[1].speed = 23456;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void synth_mix(void)
|
||||||
|
{
|
||||||
|
synth.output = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < synth_channel_count; i++) {
|
||||||
|
synth_channel_t *chan = &synth.channels[i];
|
||||||
|
chan->phase += chan->speed;
|
||||||
|
|
||||||
|
synth.output += (chan->phase >> 16) & 0xff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_sampletimer(void)
|
static void init_sampletimer(void)
|
||||||
|
@ -27,7 +70,6 @@ static void init_sampletimer(void)
|
||||||
TIMSK0 |= (1 << TOIE0);
|
TIMSK0 |= (1 << TOIE0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline void init_pwm(void)
|
static inline void init_pwm(void)
|
||||||
{
|
{
|
||||||
//PB1 set to output:
|
//PB1 set to output:
|
||||||
|
@ -68,17 +110,16 @@ static void stupid_pwmtest(void)
|
||||||
{
|
{
|
||||||
uint8_t i, t, r;
|
uint8_t i, t, r;
|
||||||
ICR1 = 0xAA00;
|
ICR1 = 0xAA00;
|
||||||
r=1;
|
t = r = 1;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
||||||
t = (r) ? (t + 1) : (t - 1);
|
t = (r) ? (t + 1) : (t - 1);
|
||||||
|
|
||||||
ICR1 = (t << 7);
|
ICR1 = (t << 7);
|
||||||
if(t=0) r ^= 1;
|
if (t == 0)
|
||||||
for(i=1;i<100;i++) __asm("nop");
|
r ^= 1;
|
||||||
|
for (i = 1; i < 100; i++)
|
||||||
|
__asm("nop");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return; //never
|
return; //never
|
||||||
|
@ -91,10 +132,17 @@ int main(void)
|
||||||
init_leds();
|
init_leds();
|
||||||
init_motor();
|
init_motor();
|
||||||
init_pwm();
|
init_pwm();
|
||||||
|
sample_pending=0;
|
||||||
|
synth_init();
|
||||||
|
|
||||||
//just stupid test for now....
|
sei();
|
||||||
stupid_pwmtest();
|
|
||||||
|
while(1){
|
||||||
|
while (0 == sample_pending) ;
|
||||||
|
sample_pending = 0;
|
||||||
|
synth_mix();
|
||||||
|
}
|
||||||
|
|
||||||
//never get here
|
//never get here
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user