2021-03-13 23:50:25 +00:00
|
|
|
#include "sys.h"
|
|
|
|
|
|
|
|
void init() {
|
|
|
|
square0->output_address = pdmout0;
|
|
|
|
square0->high_val = 0xffff;
|
|
|
|
square0->low_val = 0x0000;
|
|
|
|
square0->flags = SQUARE_FLAG_ENABLE_msk;
|
|
|
|
// will set the period later
|
|
|
|
}
|
|
|
|
|
2021-03-19 03:14:00 +00:00
|
|
|
int strlen(const char* str) {
|
|
|
|
int i = 0;
|
|
|
|
while(str[i] != '\0') {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void log(const char* stuff) {
|
|
|
|
uart_writen(uart0, stuff, strlen(stuff));
|
|
|
|
}
|
|
|
|
|
2021-03-13 23:50:25 +00:00
|
|
|
int main() {
|
|
|
|
init();
|
|
|
|
|
2021-03-18 15:35:23 +00:00
|
|
|
led0->output = 42;
|
|
|
|
|
2021-03-13 23:50:25 +00:00
|
|
|
while(1) {
|
|
|
|
uint8_t c = uart_read(uart0);
|
|
|
|
uint16_t period;
|
|
|
|
if (c == 'c') {
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 1;
|
2021-03-13 23:50:25 +00:00
|
|
|
period = 1493; // C4, 262.63 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "C4\r\n", 4);
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'd') {
|
|
|
|
period = 1330; // D4, 293.66 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "D4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 2;
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'e') {
|
|
|
|
period = 1185; // E4, 329.63 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "E4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 4;
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'f') {
|
|
|
|
period = 1119; // F4, 249.23 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "F4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 8;
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'g') {
|
|
|
|
period = 996; // G4, 392.00 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "G4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 16;
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'a') {
|
|
|
|
period = 887; // A4, 440.00 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "A4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 32;
|
2021-03-13 23:50:25 +00:00
|
|
|
} else if (c == 'b') {
|
|
|
|
period = 791; // B4, 493.88 Hz, maybe
|
2021-03-14 19:18:01 +00:00
|
|
|
uart_writen(uart0, "B4\r\n", 4);
|
2021-03-15 01:09:05 +00:00
|
|
|
led0->output = 64;
|
2021-03-18 15:35:23 +00:00
|
|
|
} else {
|
|
|
|
led0->output = 37;
|
2021-03-13 23:50:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
square0->period = period;
|
|
|
|
}
|
|
|
|
}
|