Skip to content

Commit 3b54dfe

Browse files
committed
Servo library to the new format
1 parent 77f8dd6 commit 3b54dfe

File tree

13 files changed

+189
-335
lines changed

13 files changed

+189
-335
lines changed

hardware/arduino/sam/libraries/Servo/Servo.h

Lines changed: 0 additions & 155 deletions
This file was deleted.

hardware/arduino/sam/libraries/Servo/examples/Knob/Knob.ino

Lines changed: 0 additions & 22 deletions
This file was deleted.

hardware/arduino/sam/libraries/Servo/examples/Sweep/Sweep.ino

Lines changed: 0 additions & 31 deletions
This file was deleted.

hardware/arduino/sam/libraries/Servo/keywords.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

hardware/arduino/avr/libraries/Servo/Servo.cpp renamed to libraries/Servo/arch/avr/Servo.cpp

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,6 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
/*
21-
22-
A servo is activated by creating an instance of the Servo class passing the desired pin to the attach() method.
23-
The servos are pulsed in the background using the value most recently written using the write() method
24-
25-
Note that analogWrite of PWM on pins associated with the timer are disabled when the first servo is attached.
26-
Timers are seized as needed in groups of 12 servos - 24 servos use two timers, 48 servos will use four.
27-
28-
The methods are:
29-
30-
Servo - Class for manipulating servo motors connected to Arduino pins.
31-
32-
attach(pin ) - Attaches a servo motor to an i/o pin.
33-
attach(pin, min, max ) - Attaches to a pin setting min and max values in microseconds
34-
default min is 544, max is 2400
35-
36-
write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
37-
writeMicroseconds() - Sets the servo pulse width in microseconds
38-
read() - Gets the last written servo pulse width as an angle between 0 and 180.
39-
readMicroseconds() - Gets the last written servo pulse width in microseconds. (was read_us() in first release)
40-
attached() - Returns true if there is a servo attached.
41-
detach() - Stops an attached servos from pulsing its i/o pin.
42-
43-
*/
44-
4520
#include <avr/interrupt.h>
4621
#include <Arduino.h>
4722

@@ -100,28 +75,28 @@ static inline void handle_interrupts(timer16_Sequence_t timer, volatile uint16_t
10075
#ifndef WIRING // Wiring pre-defines signal handlers so don't define any if compiling for the Wiring platform
10176
// Interrupt handlers for Arduino
10277
#if defined(_useTimer1)
103-
ISR(TIMER1_COMPA_vect)
78+
SIGNAL (TIMER1_COMPA_vect)
10479
{
10580
handle_interrupts(_timer1, &TCNT1, &OCR1A);
10681
}
10782
#endif
10883

10984
#if defined(_useTimer3)
110-
ISR(TIMER3_COMPA_vect)
85+
SIGNAL (TIMER3_COMPA_vect)
11186
{
11287
handle_interrupts(_timer3, &TCNT3, &OCR3A);
11388
}
11489
#endif
11590

11691
#if defined(_useTimer4)
117-
ISR(TIMER4_COMPA_vect)
92+
SIGNAL (TIMER4_COMPA_vect)
11893
{
11994
handle_interrupts(_timer4, &TCNT4, &OCR4A);
12095
}
12196
#endif
12297

12398
#if defined(_useTimer5)
124-
ISR(TIMER5_COMPA_vect)
99+
SIGNAL (TIMER5_COMPA_vect)
125100
{
126101
handle_interrupts(_timer5, &TCNT5, &OCR5A);
127102
}
@@ -335,3 +310,4 @@ bool Servo::attached()
335310
{
336311
return servos[this->servoIndex].Pin.isActive ;
337312
}
313+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Servo.h - Interrupt driven Servo library for Arduino using 16 bit timers- Version 2
3+
Copyright (c) 2009 Michael Margolis. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
/*
21+
* Defines for 16 bit timers used with Servo library
22+
*
23+
* If _useTimerX is defined then TimerX is a 16 bit timer on the current board
24+
* timer16_Sequence_t enumerates the sequence that the timers should be allocated
25+
* _Nbr_16timers indicates how many 16 bit timers are available.
26+
*/
27+
28+
/**
29+
* AVR Only definitions
30+
* --------------------
31+
*/
32+
33+
// Say which 16 bit timers can be used and in what order
34+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
35+
#define _useTimer5
36+
#define _useTimer1
37+
#define _useTimer3
38+
#define _useTimer4
39+
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
40+
41+
#elif defined(__AVR_ATmega32U4__)
42+
#define _useTimer1
43+
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
44+
45+
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
46+
#define _useTimer3
47+
#define _useTimer1
48+
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
49+
50+
#elif defined(__AVR_ATmega128__) ||defined(__AVR_ATmega1281__)||defined(__AVR_ATmega2561__)
51+
#define _useTimer3
52+
#define _useTimer1
53+
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
54+
55+
#else // everything else
56+
#define _useTimer1
57+
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
58+
#endif
59+

0 commit comments

Comments
 (0)