-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathout_led.ino
162 lines (138 loc) · 3.9 KB
/
out_led.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
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
154
155
156
157
158
159
160
161
162
// --------------------------------------------------------------------------
// This file is part of the MMO-3 firmware.
//
// MMO-3 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.
//
// MMO-3 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 MMO-3 firmware. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------------
#include <Arduino.h>
#define PORTLED1 PIOC
#define LED1 12 // MIDI LED
#define PORTLEDVCO1 PIOA
#define LEDVCO1 13
#define PORTLEDVCO2 PIOA
#define LEDVCO2 12
#define PORTLEDVCO3 PIOC
#define LEDVCO3 22
#define PORTLEDVCO4 PIOC
#define LEDVCO4 21
uint32_t led_MIDI;
inline void init_led() {
PORTLED1->PIO_PER = 1 << LED1;
PORTLED1->PIO_OER = 1 << LED1;
PORTLEDVCO1->PIO_PER = 1 << LEDVCO1;
PORTLEDVCO1->PIO_OER = 1 << LEDVCO1;
PORTLEDVCO2->PIO_PER = 1 << LEDVCO2;
PORTLEDVCO2->PIO_OER = 1 << LEDVCO2;
PORTLEDVCO3->PIO_PER = 1 << LEDVCO3;
PORTLEDVCO3->PIO_OER = 1 << LEDVCO3;
PORTLEDVCO4->PIO_PER = 1 << LEDVCO4;
PORTLEDVCO4->PIO_OER = 1 << LEDVCO4;
led1_off();
led1_time = 300; // small flash at initialisation
analogWrite(7, 0); // lazy PWM configuration
analogWrite(6, 0);
analogWrite(9, 0);
blink_time = 1;
}
inline void led1_on() {
//#ifdef serialout
//if (//Serial.availableForWrite()){
// //Serial.println("led1_on");
//}
//#endif
PORTLED1->PIO_SODR = 1 << LED1;
}
inline void led1_off() {
//#ifdef serialout
//if (//Serial.availableForWrite()){
// //Serial.println("led1_off");
//}
//#endif
PORTLED1->PIO_CODR = 1 << LED1;
}
inline void led_VCO1_on() {
//#ifdef serialout
//Serial.println("VCO1_on");
//#endif
PORTLEDVCO1->PIO_SODR = 1 << LEDVCO1;
}
inline void led_VCO1_off() {
//#ifdef serialout
//Serial.println("VCO1_off");
//#endif
PORTLEDVCO1->PIO_CODR = 1 << LEDVCO1;
}
inline void led_VCO2_on() {
//#ifdef serialout
//Serial.println("VCO2_on");
//#endif
PORTLEDVCO2->PIO_SODR = 1 << LEDVCO2;
}
inline void led_VCO2_off() {
//#ifdef serialout
//Serial.println("VCO2_off");
//#endif
PORTLEDVCO2->PIO_CODR = 1 << LEDVCO2;
}
inline void led_VCO3_on() {
//#ifdef serialout
//Serial.println("VCO3_on");
//#endif
PORTLEDVCO3->PIO_SODR = 1 << LEDVCO3;
}
inline void led_VCO3_off() {
//#ifdef serialout
//Serial.println("VCO3_off");
//#endif
PORTLEDVCO3->PIO_CODR = 1 << LEDVCO3;
}
inline void led_VCO4_on() {
PORTLEDVCO4->PIO_SODR = 1 << LEDVCO4;
}
inline void led_VCO4_off() {
PORTLEDVCO4->PIO_CODR = 1 << LEDVCO4;
}
inline void update_leds() {
uint32_t time_tmp, tmp32, led, tmp;
bool led1;
if (blink_led > 0) {
blink_time = (++blink_time) & 0x0FFF;
tmp = blink_led-1; // 0 1 2 3
tmp = (1<<tmp)-1; // 0 1 3 7
tmp *= 0x3FF;
led = (tmp > blink_time)?1:0;
}
else {
if (led1_time > 0) led1_time--;
led = led1_time;
}
if ((led != 0) ){
if (MODE_MENU)
led1_off();
else
led1_on();
}
else {
if (MODE_MENU)
led1_on();
else
led1_off();
}
// todo : optimized, and more precision PWM,
tmp32 = (masque_led==0)? and_led2:(modulation_data_AM[mod_LFO1])>>7;
PWMC_SetDutyCycle(PWM_INTERFACE, 4, table_led[tmp32]);
tmp32 = (masque_led==0)? and_led3:(modulation_data_AM[mod_LFO2])>>7;
PWMC_SetDutyCycle(PWM_INTERFACE, 6, table_led[tmp32]);
tmp32 = (masque_led==0)? and_led4:(modulation_data_AM[mod_LFO3])>>7;
PWMC_SetDutyCycle(PWM_INTERFACE, 7, table_led[tmp32]);
}