Trammell Hudson avatar Trammell Hudson committed 0a0799b Draft

MIDI decoder is working

Comments (0)

Files changed (1)

 }
 
 
+static uint8_t
+getc(void)
+{
+	while (!(UCSR1A & (1 << RXC1)))
+		continue;
+	return UDR1;
+}
+
+
 int main(void)
 {
 	uint8_t b, d, mask, i, reset_idle;
 	}
 
 	// Turn on the hardware UART for MIDI,
-	// 31250 baud == 1600000 MHz / 32
+	// 31250 N81 == 1600000 MHz / 32
 	UBRR1 = 32;
+	UCSR1C = 0
+		| (0 << UCSZ12)
+		| (1 << UCSZ11)
+		| (1 << UCSZ11)
+		;
+
 	UCSR1B = (1 << RXEN1);
 
 	// Wait an extra second for the PC's operating system to load drivers
 
 	while (1)
 	{
-		if (!(UCSR1A & (1 << RXC1)))
+		uint8_t c = getc();
+
+		if (c == 0x40)
+		{
+			uint8_t program = getc();
+			uint8_t button = program % 10;
+			program /= 10;
+
+			print("button ");
+			phex(program);
+			print(" ");
+			phex(button + 1);
+			print("\r\n");
 			continue;
+		}
 
-		char c = UDR1;
+		if (c == 0x30)
+		{
+			uint8_t chan = getc();
+			uint8_t val = getc();
+			print("pedal ");
+			phex(chan);
+			print(" ");
+			phex(val);
+			print("\r\n");
+			continue;
+		}
+
+		if (c == 0x10)
+		{
+			// Not sure?  Momentary?
+			uint8_t chan = getc();
+			uint8_t val = getc();
+			print("momentary ");
+			phex(chan);
+			print(" ");
+			phex(val);
+			print("\r\n");
+			continue;
+		}
 
 		phex(c);
-		print("\r\n");
+		print(" ?\r\n");
 	}
 
 #if 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.