-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi_uart_functions.c
99 lines (87 loc) · 3.28 KB
/
midi_uart_functions.c
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
/*
* UART_midi_functions.c
*
* Created on: Apr 15, 2021
* Author: steph
*/
#include <assert.h>
#include <midi_uart_functions.h>
#include <stdbool.h>
#include <stdint.h>
#include "driverlib/uart.h"
#include "driverlib/inc/hw_memmap.h"
static const uint8_t STATUS_BIT = 0x80;
static const uint8_t NOTE_OFF_MSG_TYPE = 0x00;
static const uint8_t POLYPHON_MSG_TYPE = 0x02;
static const uint8_t NOTE_ON_MSG_TYPE = 0x01;
static const uint8_t CTRL_CHG_MSG_TYPE = 0x03;
static const uint8_t PITCH_MSG_TYPE = 0x06;
static const uint8_t MOD_CRTL_CHG = 0x01;
static const uint8_t EFFECT1_CTRL_CHG = 0x0C;
static const uint8_t EFFECT2_CTRL_CHG = 0x0D;
static const uint8_t PAN_CTRL_CHG = 0x0A;
static const uint8_t CHAN_VOL_CTRL_CHG = 0x07;
static uint8_t msg_bytes[3];
void send_midi_message(uart_msg_u msg) {
switch(msg.bitfield.message_type) {
case NOTE_ON :
msg_bytes[0] = (STATUS_BIT | NOTE_ON_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & msg.bitfield.pad_num;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case NOTE_OFF :
msg_bytes[0] = (STATUS_BIT | NOTE_OFF_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & msg.bitfield.pad_num;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case PITCH :
msg_bytes[0] = (STATUS_BIT | PITCH_MSG_TYPE << 4) | msg.bitfield.channel ;
msg_bytes[1] = 0x7F & (msg.bitfield.value >> 7);
msg_bytes[2] = (0x7F & msg.bitfield.value);
break;
case MODULATION :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & MOD_CRTL_CHG;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case OVERDRIVE :
msg_bytes[0] = (STATUS_BIT | POLYPHON_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & msg.bitfield.pad_num;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case KNOB1 :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & EFFECT1_CTRL_CHG;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case KNOB2 :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & EFFECT2_CTRL_CHG;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case KNOB3 :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & PAN_CTRL_CHG;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case KNOB4 :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & CHAN_VOL_CTRL_CHG;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
case LOOP :
case 10 :
case EFFECT:
case MASTER :
msg_bytes[0] = (STATUS_BIT | CTRL_CHG_MSG_TYPE << 4) | msg.bitfield.channel;
msg_bytes[1] = 0x7F & msg.bitfield.pad_num;
msg_bytes[2] = 0x7F & msg.bitfield.value;
break;
default :
assert(0);
break;
}
UARTCharPutNonBlocking(UART1_BASE, msg_bytes[0]);
UARTCharPutNonBlocking(UART1_BASE, msg_bytes[1]);
UARTCharPutNonBlocking(UART1_BASE, msg_bytes[2]);
} // End process_midi_message