Tonleiter is running
This commit is contained in:
parent
152f171c66
commit
5e2f120432
@ -11,7 +11,7 @@ CFLAGS+= -g3 -ggdb -gdwarf-2
|
||||
|
||||
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
||||
|
||||
$(ARTIFACT).elf: main.o scheduler.o psg.o sequencer.o
|
||||
$(ARTIFACT).elf: main.o scheduler.o psg.o sequencer.o melody.o
|
||||
$(CC) -o $@ $(LDFLAGS) $^
|
||||
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "psg.h"
|
||||
#include "scheduler.h"
|
||||
#include "sequencer.h"
|
||||
#include "melody.h"
|
||||
|
||||
void __attribute__ ((interrupt (USCIAB0RX_VECTOR))) receive() {
|
||||
if (UC0IFG & UCB0RXIFG) {
|
||||
@ -45,6 +46,8 @@ int main() {
|
||||
|
||||
__enable_interrupt();
|
||||
|
||||
melodyInit();
|
||||
|
||||
|
||||
while (1) {
|
||||
schExec();
|
||||
|
@ -0,0 +1,68 @@
|
||||
#include "psg.h"
|
||||
#include "sequencer.h"
|
||||
|
||||
|
||||
/*
|
||||
const t_note notes[] = {
|
||||
{ .octave = e_O_2, .note = e_G, .length = },
|
||||
{ .octave = e_O_2, .note = e_D, .length = },
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_F, .length = },
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
{ .octave = e_O_2, .note = e_D, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_C, .length = },
|
||||
{ .octave = e_O_2, .note = e_C, .length = },
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_G, .length = },
|
||||
{ .octave = e_O_2, .note = e_F, .length = },
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_D, .length = },
|
||||
{ .octave = e_O_2, .note = e_D, .length = },
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_F, .length = },
|
||||
{ .octave = e_O_2, .note = e_G, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_Dis, .length = },
|
||||
{ .octave = e_O_2, .note = e_C, .length = },
|
||||
|
||||
{ .octave = e_O_2, .note = e_C, .length = },
|
||||
};
|
||||
*/
|
||||
|
||||
const t_tone ladder[16] = {
|
||||
{ .octave = e_O_2, .note = e_C, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_D, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_E, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_F, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_G, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_A, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_H, .length = e_L_1_4 },
|
||||
{ .octave = e_O_3, .note = e_C, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_H, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_A, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_G, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_F, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_E, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_D, .length = e_L_1_4 },
|
||||
{ .octave = e_O_2, .note = e_H, .length = e_L_EndMark },
|
||||
};
|
||||
|
||||
t_melody melodyLadder = {
|
||||
.idx = 0,
|
||||
.lengthCnt = 0,
|
||||
.tones = ladder
|
||||
};
|
||||
|
||||
|
||||
void melodyInit() {
|
||||
psgWrite(07, 0b11111110);
|
||||
psgWrite(010, 03);
|
||||
sequencerPlayMelody(&melodyLadder);
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "psg.h"
|
||||
#include "scheduler.h"
|
||||
#include "notes.h"
|
||||
|
||||
|
||||
|
||||
@ -62,7 +61,7 @@ asm volatile (
|
||||
);
|
||||
}
|
||||
|
||||
static void writePSG(uint8_t address, uint8_t data) {
|
||||
void psgWrite(uint8_t address, uint8_t data) {
|
||||
// according to "State Timing" (p. 15) of datasheet
|
||||
|
||||
// put bus into inactive state
|
||||
@ -87,13 +86,13 @@ static void writePSG(uint8_t address, uint8_t data) {
|
||||
BUS_OP_NACT();
|
||||
}
|
||||
|
||||
static void writeFrequency(uint8_t channel, uint16_t frequencyCode) {
|
||||
writePSG(R0 + (channel * 2), (frequencyCode & 0x00ff));
|
||||
writePSG(R1 + (channel * 2), ((frequencyCode >> 8) & 0x000f));
|
||||
void psgWriteFrequency(uint8_t channel, uint16_t frequencyCode) {
|
||||
psgWrite(R0 + (channel * 2), (frequencyCode & 0x00ff));
|
||||
psgWrite(R1 + (channel * 2), ((frequencyCode >> 8) & 0x000f));
|
||||
}
|
||||
|
||||
void psgPlayTone(uint8_t channel, t_octave octave, t_note note) {
|
||||
writeFrequency(channel, frequencyCodes[octave][note]);
|
||||
psgWriteFrequency(channel, frequencyCodes[octave][note]);
|
||||
}
|
||||
|
||||
void playSomething(void *handle) {
|
||||
@ -101,8 +100,8 @@ void playSomething(void *handle) {
|
||||
|
||||
switch (state) {
|
||||
case 0:
|
||||
writePSG(R7, 0b11111110);
|
||||
writePSG(R10, 03);
|
||||
psgWrite(R7, 0b11111110);
|
||||
psgWrite(R10, 03);
|
||||
state = 1;
|
||||
// no break;
|
||||
|
||||
@ -148,7 +147,7 @@ void psgInit() {
|
||||
delay();
|
||||
delay();
|
||||
|
||||
schAdd(playSomething, NULL, 0, 500);
|
||||
// schAdd(playSomething, NULL, 0, 500);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _PSG_H_
|
||||
#define _PSG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
e_O_1 = 0,
|
||||
@ -31,6 +32,7 @@ typedef enum {
|
||||
|
||||
void psgInit();
|
||||
void psgPlayTone(uint8_t channel, t_octave octave, t_note note);
|
||||
|
||||
void psgWriteFrequency(uint8_t channel, uint16_t frequencyCode);
|
||||
void psgWrite(uint8_t address, uint8_t data);
|
||||
|
||||
#endif // _PSG_H_
|
||||
|
@ -10,13 +10,14 @@ void sequencerExec(void *handle) {
|
||||
t_melody *melody = (t_melody*) handle;
|
||||
|
||||
if (melody->lengthCnt == 0) {
|
||||
if (melody->tones[melody->idx].octave == e_O_EndMark) {
|
||||
if (melody->tones[melody->idx].length == e_L_EndMark) {
|
||||
melody->idx = 0;
|
||||
}
|
||||
|
||||
psgPlayTone(channel, melody->tones[melody->idx].octave, melody->tones[idx].note);
|
||||
psgPlayTone(melody->channel, melody->tones[melody->idx].octave, melody->tones[melody->idx].note);
|
||||
|
||||
melody->lengthCnt = melody->tones[melody->idx].length;
|
||||
melody->idx += 1;
|
||||
}
|
||||
|
||||
melody->lengthCnt -= 1;
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define _SEQUENCER_H_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include "psg.h"
|
||||
|
||||
typedef enum {
|
||||
@ -23,7 +24,7 @@ typedef struct {
|
||||
uint16_t idx;
|
||||
uint8_t lengthCnt;
|
||||
uint8_t channel;
|
||||
t_tone *tones;
|
||||
const t_tone *tones;
|
||||
} t_melody;
|
||||
|
||||
void sequencerInit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user