-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcppm.h
72 lines (56 loc) · 1.94 KB
/
cppm.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Combined-PPM signal generator
* Copyright 2016 by Thomas Buck <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2.
*/
#ifndef __CPPM_H__
#define __CPPM_H__
#include <stdint.h>
#include <avr/interrupt.h>
#include "config.h"
ISR(TIMER1_COMPA_vect);
class CPPM {
public:
inline static CPPM& instance() {
if (!inst) {
inst = new CPPM();
}
return *inst;
}
void init(void);
void copy(uint16_t* d);
inline uint16_t getChannels() { return channels; }
inline void setChannels(uint16_t c) {
if (c > CHANNELS_MAX)
c = CHANNELS_MAX;
channels = c;
}
inline uint16_t getFrameLength() { return frameLength; }
inline void setFrameLength(uint16_t fl) { frameLength = fl; }
inline uint16_t getPulseLength() { return pulseLength; }
inline void setPulseLength(uint16_t pl) { pulseLength = pl; }
inline uint8_t getInvert() { return !onState; }
inline void setInvert(uint8_t i) { onState = !i; }
inline uint8_t getOutput() { return output; }
void setOutput(uint8_t i);
private:
CPPM() : channels(DEFAULT_CHANNELS), frameLength(DEFAULT_FRAME_LENGTH),
pulseLength(DEFAULT_PULSE_LENGTH), onState(!DEFAULT_INVERT_STATE),
output(CPPM_OUTPUT_PIN_DEFAULT) { }
CPPM(CPPM&) { }
volatile uint16_t channels;
volatile uint16_t frameLength; // PPM frame length in microseconds (1ms = 1000µs)
volatile uint16_t pulseLength;
volatile uint8_t onState; // polarity of the pulses: 1 is positive, 0 is negative
volatile uint8_t output;
volatile uint16_t data[CHANNELS_MAX];
volatile uint8_t state;
volatile uint8_t currentChannel;
volatile uint16_t calcRest;
static CPPM* inst;
friend void TIMER1_COMPA_vect(void);
};
#endif // __CPPM_H__