blob: 1ed6c78f9b5c9c6fcafdb8b56c00aec83a380ca4 (
plain)
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
|
#ifndef SERVO_H
#define SERVO_H
#include "Energia.h"
#include <inttypes.h>
// Hardware limitations information
#define MIN_SERVO_PULSE_WIDTH 544
#define MAX_SERVO_PULSE_WIDTH 2400
#define DEFAULT_SERVO_PULSE_WIDTH 1500
#define REFRESH_INTERVAL 20000
// Aliases for timer config and loading
#define SERVO_TIMER TIMER2_BASE
#define SERVO_TIME_CFG TIMER_CFG_PERIODIC
#define SERVO_TIMER_TRIGGER TIMER_TIMA_TIMEOUT
#define SERVO_TIMER_INTERRUPT INT_TIMER2A
#define SERVO_TIMER_A TIMER_A
#define SERVO_TIMER_PERIPH SYSCTL_PERIPH_TIMER2
// Other defines
#define SERVOS_PER_TIMER 8
#define INVALID_SERVO 255
#define MAX_SERVOS 8
typedef struct
{
unsigned int pin_number;
unsigned int pulse_width;
bool enabled;
} servo_t;
class Servo
{
private:
unsigned int index;
int min;
int max;
public:
Servo();
unsigned int attach(unsigned int pin, int min = MIN_SERVO_PULSE_WIDTH, int max = MAX_SERVO_PULSE_WIDTH);
void detach();
void writeMicroseconds(int value);
int readMicroseconds();
void write(int value);
int read();
bool attached();
};
extern "C" void ServoIntHandler(void);
#endif // SERVO_H
|