1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "base_midi.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.
}
|