summaryrefslogtreecommitdiff
path: root/controller/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'controller/src/main.c')
-rw-r--r--controller/src/main.c104
1 files changed, 103 insertions, 1 deletions
diff --git a/controller/src/main.c b/controller/src/main.c
index 1bfe8b0..a5f47c4 100644
--- a/controller/src/main.c
+++ b/controller/src/main.c
@@ -1,6 +1,108 @@
#include "base_midi.h"
-#include "uart.h"
+
+#include "driverlib/uart.h"
+#include "driverlib/sysctl.h"
+#include "driverlib/gpio.h"
+#include "driverlib/pin_map.h"
+#include "inc/hw_uart.h"
+#include "inc/hw_ints.h"
+#include "inc/hw_memmap.h"
+
+
+void UART1IntHandler(void) {
+ UARTIntClear(UART1_BASE, UART_INT_RX);
+ while (UARTCharsAvail(UART1_BASE)) {
+ parse_midi_stream(UARTCharGet(UART1_BASE));
+ }
+}
+
+void UARTWrite(uint8_t byte) {
+ UARTCharPut(UART1_BASE, byte);
+}
+
+static void nothing0(void) {}
+static void nothing1(uint8_t) {}
+static void nothing2(uint8_t, uint8_t) {}
+static void nothing3(uint8_t, uint8_t, uint8_t) {}
+static bool quit_parsing(uint8_t) { // TODO: fix library parsers so this works.
+ return false;
+}
+
+
+bool note_on_flag = false;
+
+void button_handler(void) {
+ GPIOIntClear(GPIO_PORTF_BASE, GPIO_INT_PIN_4);
+ if (!note_on_flag) {
+ note_on(0x02, 0x40, 0x40);
+ note_on_flag = true;
+ } else {
+ note_off(0x02, 0x40);
+ note_on_flag = false;
+ }
+}
+
+
int main() {
+ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
+
+ // Initialize UART1.
+ SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
+
+
+ while(!SysCtlPeripheralReady(SYSCTL_PERIPH_UART1));
+
+ // Initialize the GPIO pins for UART1.
+ GPIOPinConfigure(GPIO_PC4_U1RX);
+ GPIOPinConfigure(GPIO_PC5_U1TX);
+ GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
+
+ // Configure the UART using the specifications found in the minipix_uart_interface.
+ // Cource code: word length - 8, 1 stop bit, no parity.
+ UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 31250, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
+ UARTEnable(UART1_BASE);
+ UARTIntEnable(UART1_BASE, UART_INT_RX);
+ UARTIntRegister(UART1_BASE, UART1IntHandler);
+
+ // Set up MIDI 1.0 library to ignore basically everything.
+ ConsumerBehavior new_pfns = {.uart_write = UARTWrite,
+ .note_on_handler = nothing3,
+ .note_off_handler = nothing3,
+ .poly_key_handler = nothing3,
+ .control_change_handler = nothing3,
+ .program_change_handler = nothing2,
+ .all_sound_off_handler = nothing1,
+ .local_control_handler = nothing2,
+ .all_notes_off_handler = nothing1,
+ .poly_on_handler = nothing1,
+ .mtc_quarter_frame_handler = nothing2,
+ .song_position_pointer_handler = nothing2,
+ .song_select_handler = nothing1,
+ .tune_request_handler = nothing0,
+ .timing_clock_handler = nothing0,
+ .start_handler = nothing0,
+ .continue_handler = nothing0,
+ .stop_handler = nothing0,
+ .active_sensing_handler = nothing0,
+ .system_reset_handler = nothing0, // TODO: change.
+ .sysex_collector = quit_parsing,
+ .end_of_sysex_handler = nothing0,
+ /* .bulk_tuning_dump_request_handler = nothing, // TODO: change. */
+ /* .bulk_tuning_dump_handler = nothing, */
+ /* .single_note_tuning_change_handler = nothing, */
+ .unimplemented_universal_sysex_collector = quit_parsing};
+
+ midi_init(new_pfns);
+
+ // Interrupt whenever GPIO pin PF4 changes, due to SW1 button press.
+ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
+ GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
+ GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
+ GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_RISING_EDGE);
+ GPIOIntEnable(GPIO_PORTF_BASE, GPIO_INT_PIN_4);
+ GPIOIntRegister(GPIO_PORTF_BASE, button_handler);
+ while(true); // Main application loop.
+
}