diff options
Diffstat (limited to 'OpenModelicaArduino/Firmware/Tiva C/StandardFirmata/Servo.h')
-rw-r--r-- | OpenModelicaArduino/Firmware/Tiva C/StandardFirmata/Servo.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/OpenModelicaArduino/Firmware/Tiva C/StandardFirmata/Servo.h b/OpenModelicaArduino/Firmware/Tiva C/StandardFirmata/Servo.h new file mode 100644 index 0000000..1ed6c78 --- /dev/null +++ b/OpenModelicaArduino/Firmware/Tiva C/StandardFirmata/Servo.h @@ -0,0 +1,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 |