Skip to content

Commit 53876e6

Browse files
author
fpr
committed
Update Servo library to match with official Servo library
Signed-off-by: fpr <[email protected]>
1 parent 1ae377b commit 53876e6

File tree

4 files changed

+34
-15
lines changed

4 files changed

+34
-15
lines changed

Diff for: libraries/Servo/library.properties

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=Servo
2-
version=1.1.1
2+
version=1.1.2
33
author=Michael Margolis, Arduino
44
maintainer=Arduino <[email protected]>
5-
sentence=Allows Arduino boards to control a variety of servo motors. For all Arduino boards.
5+
sentence=Allows Arduino/Genuino boards to control a variety of servo motors.
66
paragraph=This library can control a great number of servos.<br />It makes careful use of timers: the library can control 12 servos using only 1 timer.<br />On the Arduino Due you can control up to 60 servos.<br />
77
category=Device Control
88
url=http://www.arduino.cc/en/Reference/Servo
9-
architectures=stm32
9+
architectures=avr,sam,samd,nrf52,stm32f4,stm32

Diff for: libraries/Servo/Servo.h renamed to libraries/Servo/src/Servo.h

+25-9
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,36 @@
5959
*/
6060

6161
// Architecture specific include
62-
#include "ServoTimers.h"
62+
#if defined(ARDUINO_ARCH_AVR)
63+
#include "avr/ServoTimers.h"
64+
#elif defined(ARDUINO_ARCH_SAM)
65+
#include "sam/ServoTimers.h"
66+
#elif defined(ARDUINO_ARCH_SAMD)
67+
#include "samd/ServoTimers.h"
68+
#elif defined(ARDUINO_ARCH_STM32F4)
69+
#include "stm32f4/ServoTimers.h"
70+
#elif defined(ARDUINO_ARCH_NRF52)
71+
#include "nrf52/ServoTimers.h"
72+
#elif defined(ARDUINO_ARCH_STM32)
73+
#include "stm32/ServoTimers.h"
74+
#else
75+
#error "This library only supports boards with an AVR, SAM, SAMD, NRF52, STM32F4 or STM32 processor."
76+
#endif
6377

6478
#define Servo_VERSION 2 // software version of this library
6579

66-
#define MIN_PULSE_WIDTH 480 // the shortest pulse sent to a servo
67-
#define MAX_PULSE_WIDTH 2200 // the longest pulse sent to a servo
68-
#define DEFAULT_PULSE_WIDTH 1300 // default pulse width when servo is attached
80+
#define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo
81+
#define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo
82+
#define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached
6983
#define REFRESH_INTERVAL 20000 // minumim time to refresh servos in microseconds
7084

71-
#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer
85+
#define SERVOS_PER_TIMER 12 // the maximum number of servos controlled by one timer
7286
#define MAX_SERVOS (_Nbr_16timers * SERVOS_PER_TIMER)
7387

7488
#define INVALID_SERVO 255 // flag indicating an invalid servo index
7589

90+
#if !defined(ARDUINO_ARCH_STM32F4)
91+
7692
typedef struct {
7793
uint8_t nbr :6 ; // a pin number from 0 to 63
7894
uint8_t isActive :1 ; // true if this channel is enabled, pin not pulsed if false
@@ -96,10 +112,10 @@ class Servo
96112
int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release)
97113
bool attached(); // return true if this servo is attached, otherwise false
98114
private:
99-
uint8_t servoIndex; // index into the channel data for this servo
100-
int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH
101-
int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH
102-
stimer_t _timer;
115+
uint8_t servoIndex; // index into the channel data for this servo
116+
int8_t min; // minimum is this value times 4 added to MIN_PULSE_WIDTH
117+
int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH
103118
};
104119

105120
#endif
121+
#endif

Diff for: libraries/Servo/Servo.cpp renamed to libraries/Servo/src/stm32/Servo.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
//#if defined(ARDUINO_ARCH_SAMD)
19+
#if defined(ARDUINO_ARCH_STM32)
2020

2121
#include <Arduino.h>
2222
#include <Servo.h>
@@ -199,3 +199,5 @@ bool Servo::attached()
199199
{
200200
return servos[this->servoIndex].Pin.isActive;
201201
}
202+
203+
#endif // ARDUINO_ARCH_STM32

Diff for: libraries/Servo/ServoTimers.h renamed to libraries/Servo/src/stm32/ServoTimers.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#ifndef __SERVO_TIMERS_H__
2828
#define __SERVO_TIMERS_H__
2929

30-
typedef enum {
30+
// Uses one timer. Allows until 12 servos.
31+
typedef enum {
3132
_timer1,
32-
_Nbr_16timers
33+
_Nbr_16timers
3334
} timer16_Sequence_t;
3435

3536
#endif // __SERVO_TIMERS_H__

0 commit comments

Comments
 (0)