diff options
author | Sumeet Koli | 2018-06-18 14:46:14 +0530 |
---|---|---|
committer | Sumeet Koli | 2018-06-18 14:46:14 +0530 |
commit | 44ad9efa7e729739cde3103d8fc1e475efa2a923 (patch) | |
tree | f87994e13c9b4d0082f7a743f29e1eafc9690fa9 /Firmware/Tiva C/StandardFirmata/Servo.h | |
parent | 931fdbe021ec59e211ac13b807c18a9b2ca9a76c (diff) | |
download | OpenModelicaEmbedded-44ad9efa7e729739cde3103d8fc1e475efa2a923.tar.gz OpenModelicaEmbedded-44ad9efa7e729739cde3103d8fc1e475efa2a923.tar.bz2 OpenModelicaEmbedded-44ad9efa7e729739cde3103d8fc1e475efa2a923.zip |
Change in directory structure
Diffstat (limited to 'Firmware/Tiva C/StandardFirmata/Servo.h')
-rw-r--r-- | Firmware/Tiva C/StandardFirmata/Servo.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Firmware/Tiva C/StandardFirmata/Servo.h b/Firmware/Tiva C/StandardFirmata/Servo.h new file mode 100644 index 0000000..1ed6c78 --- /dev/null +++ b/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 |