@@ -28,7 +28,7 @@ const uint32_t c_CycleCompensation = 4; // compensation us to trim adjust for d
28
28
29
29
struct ServoInfo {
30
30
uint8_t pin : 6 ; // a pin number from 0 to 63
31
- uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
31
+ uint8_t isActive : 1 ; // true if this channel is enabled, pin not pulsed if false
32
32
};
33
33
34
34
struct ServoState {
@@ -57,7 +57,11 @@ static uint8_t s_servoCount = 0; // the total number of attached s_se
57
57
// Interrupt handler template method that takes a class that implements
58
58
// a standard set of methods for the timer abstraction
59
59
// ------------------------------------------------------------------------------
60
- template <class T > void Servo_Handler (T* timer)
60
+ template <class T >
61
+ static void Servo_Handler (T* timer) ICACHE_RAM_ATTR;
62
+
63
+ template <class T >
64
+ static void Servo_Handler (T* timer)
61
65
{
62
66
uint8_t servoIndex;
63
67
@@ -75,7 +79,7 @@ template <class T> void Servo_Handler(T* timer)
75
79
}
76
80
timer->nextChannel ();
77
81
}
78
-
82
+
79
83
servoIndex = SERVO_INDEX (timer->timerId (), timer->getCurrentChannel ());
80
84
81
85
if (servoIndex < s_servoCount && timer->getCurrentChannel () < SERVOS_PER_TIMER) {
@@ -96,20 +100,32 @@ template <class T> void Servo_Handler(T* timer)
96
100
// at least REFRESH_INTERVAL has elapsed
97
101
timer->SetCycleCompare (timer->GetCycleCount () + c_CycleCompensation * 2 );
98
102
}
99
-
103
+
100
104
timer->setEndOfCycle ();
101
105
}
102
106
}
103
107
108
+ static void handler0 () ICACHE_RAM_ATTR;
109
+ static void handler0 ()
110
+ {
111
+ Servo_Handler<ServoTimer0>(&s_servoTimer0);
112
+ }
113
+
114
+ static void handler1 () ICACHE_RAM_ATTR;
115
+ static void handler1 ()
116
+ {
117
+ Servo_Handler<ServoTimer1>(&s_servoTimer1);
118
+ }
119
+
104
120
static void initISR (ServoTimerSequence timerId)
105
121
{
106
122
#if !defined (SERVO_EXCLUDE_TIMER0)
107
123
if (timerId == ServoTimerSequence_Timer0)
108
- s_servoTimer0.InitInterrupt ([]() {Servo_Handler<ServoTimer0>(&s_servoTimer0); } );
124
+ s_servoTimer0.InitInterrupt (&handler0 );
109
125
#endif
110
126
#if !defined (SERVO_EXCLUDE_TIMER1)
111
127
if (timerId == ServoTimerSequence_Timer1)
112
- s_servoTimer1.InitInterrupt ([]() {Servo_Handler<ServoTimer1>(&s_servoTimer1); } );
128
+ s_servoTimer1.InitInterrupt (&handler1 );
113
129
#endif
114
130
}
115
131
@@ -169,13 +185,13 @@ uint8_t Servo::attach(int pin, int minUs, int maxUs)
169
185
pinMode (pin, OUTPUT); // set servo pin to output
170
186
digitalWrite (pin, LOW);
171
187
s_servos[_servoIndex].info .pin = pin;
172
-
188
+
173
189
// keep the min and max within 200-3000 us, these are extreme
174
- // ranges and should support extreme servos while maintaining
190
+ // ranges and should support extreme servos while maintaining
175
191
// reasonable ranges
176
192
_maxUs = max (250 , min (3000 , maxUs));
177
193
_minUs = max (200 , min (_maxUs, minUs));
178
-
194
+
179
195
// initialize the timerId if it has not already been initialized
180
196
timerId = SERVO_INDEX_TO_TIMER (_servoIndex);
181
197
if (!isTimerActive (timerId)) {
@@ -242,5 +258,4 @@ bool Servo::attached()
242
258
return s_servos[_servoIndex].info .isActive ;
243
259
}
244
260
245
- #endif
246
-
261
+ #endif
0 commit comments