-
Notifications
You must be signed in to change notification settings - Fork 1
/
in_WF_switch.ino
114 lines (106 loc) · 3.44 KB
/
in_WF_switch.ino
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
// --------------------------------------------------------------------------
// This file is part of the OCS-2 firmware.
//
// OCS-2 firmware is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OCS-2 firmware is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with OCS-2 firmware. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------------
#define PORTWFOUT3 PIOD
#define WFOUT3 0
#define PORTWFOUT2 PIOD
#define WFOUT2 2
#define PORTWFOUT1 PIOD
#define WFOUT1 6
#define PORTWFIN1 PIOB
#define WFIN1 12
uint32_t WF_state;
uint32_t WF1, WF2;
inline void init_WF(){
PORTWFOUT1->PIO_PER = 1 << WFOUT1; // out to control demux bus
PORTWFOUT1->PIO_OER = 1 << WFOUT1;
PORTWFOUT1->PIO_PUDR= 1 << WFOUT1;
PORTWFOUT2->PIO_PER = 1 << WFOUT2;
PORTWFOUT2->PIO_OER = 1 << WFOUT2;
PORTWFOUT2->PIO_PUDR= 1 << WFOUT2;
PORTWFOUT3->PIO_PER = 1 << WFOUT3;
PORTWFOUT3->PIO_OER = 1 << WFOUT3;
PORTWFOUT3->PIO_PUDR= 1 << WFOUT3;
PORTWFIN1->PIO_PER = 1 << WFIN1; // input with pull up to get switch value
PORTWFIN1->PIO_PUER = 1 << WFIN1;
}
inline void WF_in(){
switch (WF_state) {
case 0:
WF1=0;
WF2=0;
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF1 += 1;
PORTWFOUT1->PIO_SODR = 1<<WFOUT1;
//PORTWFOUT2->PIO_CODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_CODR = 1<<WFOUT3;
WF_state = 1;
break;
case 1:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF1 += 2;
PORTWFOUT1->PIO_CODR = 1<<WFOUT1;
PORTWFOUT2->PIO_SODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_CODR = 1<<WFOUT3;
WF_state = 2;
break;
case 2:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF1 += 4;
PORTWFOUT1->PIO_SODR = 1<<WFOUT1;
//PORTWFOUT2->PIO_SODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_CODR = 1<<WFOUT3;
WF_state = 3;
break;
case 3:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF1 += 8;
PORTWFOUT1->PIO_CODR = 1<<WFOUT1;
PORTWFOUT2->PIO_CODR = 1<<WFOUT2;
PORTWFOUT3->PIO_SODR = 1<<WFOUT3;
WF_state = 4;
break;
case 4:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF2 += 1;
PORTWFOUT1->PIO_SODR = 1<<WFOUT1;
//PORTWFOUT2->PIO_CODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_SODR = 1<<WFOUT3;
WF_state = 5;
break;
case 5:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF2 += 2;
PORTWFOUT1->PIO_CODR = 1<<WFOUT1;
PORTWFOUT2->PIO_SODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_SODR = 1<<WFOUT3;
WF_state = 6;
break;
case 6:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF2 += 4;
PORTWFOUT1->PIO_SODR = 1<<WFOUT1;
//PORTWFOUT2->PIO_SODR = 1<<WFOUT2;
//PORTWFOUT3->PIO_SODR = 1<<WFOUT3;
WF_state = 7;
break;
case 7:
if (!(PORTWFIN1->PIO_PDSR & (1<<WFIN1))) WF2 += 8;
PORTWFOUT1->PIO_CODR = 1<<WFOUT1;
PORTWFOUT2->PIO_CODR = 1<<WFOUT2;
PORTWFOUT3->PIO_CODR = 1<<WFOUT3;
WF_state = 8;
break;
case 8:
VCO1_WF = (WF1 + (MIDI_fader[34]>>12)) & 0b1111;
VCO2_WF = (WF2 + (MIDI_fader[35]>>12)) & 0b1111;
WF_state = 0;
break;
}
}