-
Notifications
You must be signed in to change notification settings - Fork 0
/
MidiAPS2.c
153 lines (120 loc) · 2.74 KB
/
MidiAPS2.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//Midi Drum Kit converter to Hardware Buttons - 2017 [email protected]
//EXP18 pin 3 desde derecha
#include <DR_Inicializacion.h>
#include <DR_tipos.h>
#include "PR_Timers.h"
#include "PR_lcd.h"
#include "PR_debounce.h"
#include "PR_UART.h"
#include "DR_JoyPS2.h"
#include "DR_Infotronic.h"
#define EV_WAIT_TIME 20
#define EV_LED 21
#define EV_MIDI_TIMEOUT 22
void bitswap(uint8_t *);
void reset_led ();
int main(void)
{
//uint8_t turn_on2=1;
uint8_t byte=0,message[3],t=0,pad=10;
int16_t data;
char txt[10]=" ";
//50 doesn't count
#define CHANNEL (10-1)
#define NOTE_ON 0x90
#define NOTE_OFF 0x80
#define NOTE1 50
#define NOTE2 0x28
#define NOTE3 0x39
#define NOTE4 0x23
#define NOTE5 0x2a
#define NOTE6 0x30
#define MIN_VEL 10 //ignored
#define LR SetPIN(RGB_R,1)
#define LG SetPIN(RGB_G,1)
#define LB SetPIN(RGB_B,1)
Initialize();
// 1 sec delay
TimerStart(EV_WAIT_TIME,11,DEC,NULL);
while(TimerGet(EV_WAIT_TIME)!=0) {};
TimerStop(EV_WAIT_TIME);
while(1) {
//Execute timer events
TimerEvent();
// TimerStart(EV_ESPERA,2,DEC,NULL);
// while(TimerGet(EV_ESPERA)!=0) {};
// TimerStop(EV_ESPERA);
data=UART1_PopRx();
if (data!=-1) {
if (TimerGet(EV_MIDI_TIMEOUT)==0) byte=0;
if (data==(NOTE_ON+CHANNEL)) byte=0;
switch (byte) {
case 0:
TimerStart(EV_MIDI_TIMEOUT,2,DEC,NULL);
message[0]=data;
byte++;
break;
case 1:
TimerStart(EV_LED,1,DEC,reset_led);
message[1]=data;
if (message[0]== (NOTE_ON+CHANNEL) ) {
switch (message[1]) {
case NOTE1: //high tom
turn_on|=1;
LG;
break;
case NOTE2: //snare
turn_on|=2;
LR;
LG;
break;
case NOTE3: //crash
turn_on|=4;
LB;
break;
case NOTE4: //pedal
turn_on|=8;
LR;
LB;
break;
case NOTE5: //hi hat
turn_on|=16;
LB;
LG;
break;
case NOTE6: //low tom
turn_on|=32;
LR;
break;
default: txt[0]=((message[1]&0xf0)>>4)+0x30;
if (txt[0]>'9') txt[0]+=7;
txt[1]=(message[1]&0x0f)+0x30;
if (txt[1]>'9') txt[1]+=7;
lcdprintf(NULL,txt);
break;
}
}
byte++;
joy_refresh(0);
break;
case 2:
message[2]=data;
//ignore velocity
TimerStop(EV_MIDI_TIMEOUT);
break;
}
}
}
}
void bitswap(uint8_t * dato){
uint8_t i, out=0;
for (i=0;i<8;i++) {
if ((*dato >> i) & 1) out|=(1<<i);
}
*dato=out;
}
void reset_led (){
SetPIN(RGB_R,0);
SetPIN(RGB_G,0);
SetPIN(RGB_B,0);
}