|
@@ -27,7 +27,7 @@
|
27
|
27
|
|
28
|
28
|
#if HAS_SERVOS
|
29
|
29
|
|
30
|
|
-uint8_t ServoCount; //=0
|
|
30
|
+uint8_t ServoCount = 0;
|
31
|
31
|
|
32
|
32
|
#include "HAL_Servo_STM32F1.h"
|
33
|
33
|
|
|
@@ -68,16 +68,16 @@ libServo::libServo() {
|
68
|
68
|
|
69
|
69
|
bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t maxAngle) {
|
70
|
70
|
if (this->servoIndex >= MAX_SERVOS) return false;
|
|
71
|
+ if (!PWM_PIN(pin)) return false;
|
71
|
72
|
|
72
|
|
- this->pin = pin;
|
73
|
73
|
this->minAngle = minAngle;
|
74
|
74
|
this->maxAngle = maxAngle;
|
75
|
75
|
|
76
|
|
- timer_dev *tdev = PIN_MAP[this->pin].timer_device;
|
77
|
|
- uint8_t tchan = PIN_MAP[this->pin].timer_channel;
|
|
76
|
+ timer_dev *tdev = PIN_MAP[pin].timer_device;
|
|
77
|
+ uint8_t tchan = PIN_MAP[pin].timer_channel;
|
78
|
78
|
|
79
|
|
- pinMode(this->pin, PWM);
|
80
|
|
- pwmWrite(this->pin, 0);
|
|
79
|
+ pinMode(pin, PWM);
|
|
80
|
+ pwmWrite(pin, 0);
|
81
|
81
|
|
82
|
82
|
timer_pause(tdev);
|
83
|
83
|
timer_set_prescaler(tdev, SERVO_PRESCALER - 1); // prescaler is 1-based
|
|
@@ -85,6 +85,8 @@ bool libServo::attach(const int32_t pin, const int32_t minAngle, const int32_t m
|
85
|
85
|
timer_generate_update(tdev);
|
86
|
86
|
timer_resume(tdev);
|
87
|
87
|
|
|
88
|
+ this->pin = pin; // set attached()
|
|
89
|
+
|
88
|
90
|
return true;
|
89
|
91
|
}
|
90
|
92
|
|