-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlightControllerTGSTEENSY.h
More file actions
70 lines (62 loc) · 1.82 KB
/
FlightControllerTGSTEENSY.h
File metadata and controls
70 lines (62 loc) · 1.82 KB
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
#include <Arduino.h>
#ifdef __AVR__
#error "Sorry, FlightControllerTGSTEENSY does not work on Teensy 2.0 and other AVR-based boards"
#elif defined(__IMXRT1062__)
#include "FlightControllerTGSTEENSYIMXRT.h"
#else
#define FlightControllerTGSTEENSY_MAXCHANNELS 16
struct ftm_channel_struct {
uint32_t csc;
uint32_t cv;
};
class FlightControllerTGSTEENSYOutput
{
public:
FlightControllerTGSTEENSYOutput(void);
FlightControllerTGSTEENSYOutput(int polarity);
bool begin(uint8_t txPin); // txPin can be 5,6,9,10,20,21,22,23
bool begin(uint8_t txPin, uint8_t framePin);
bool write(uint8_t channel, float microseconds);
friend void ftm0_isr(void);
private:
void isr(void);
uint32_t pulse_width[FlightControllerTGSTEENSY_MAXCHANNELS+1];
uint32_t pulse_buffer[FlightControllerTGSTEENSY_MAXCHANNELS+1];
uint32_t pulse_remaining;
volatile uint8_t *framePinReg;
volatile uint8_t framePinMask;
struct ftm_channel_struct *ftm;
uint8_t state;
uint8_t current_channel;
uint8_t total_channels;
uint8_t total_channels_buffer;
uint8_t cscSet;
uint8_t cscClear;
static FlightControllerTGSTEENSYOutput *list[8];
static uint8_t channelmask;
};
class FlightControllerTGSTEENSYInput
{
public:
FlightControllerTGSTEENSYInput(void);
FlightControllerTGSTEENSYInput(int polarity);
bool begin(uint8_t rxPin); // rxPin can be 5,6,9,10,20,21,22,23
int available(void);
float read(uint8_t channel);
friend void ftm0_isr(void);
private:
void isr(void);
struct ftm_channel_struct *ftm;
uint32_t pulse_width[FlightControllerTGSTEENSY_MAXCHANNELS];
uint32_t pulse_buffer[FlightControllerTGSTEENSY_MAXCHANNELS];
uint32_t prev;
uint8_t write_index;
uint8_t total_channels;
uint8_t cscEdge;
bool available_flag;
static bool overflow_inc;
static uint16_t overflow_count;
static FlightControllerTGSTEENSYInput *list[8];
static uint8_t channelmask;
};
#endif