5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _PULSES_PXX1_H_
22 #define _PULSES_PXX1_H_
27 struct HeartbeatCapture
{
33 extern volatile HeartbeatCapture heartbeatCapture
;
42 void addToCrc(uint8_t byte
)
44 crc
= (crc
<< 8) ^ (crc16tab_1189
[((crc
>> 8) ^ byte
) & 0xFF]);
48 static const uint16_t CRCTable
[];
51 template <class BitTransport
>
52 class StandardPxx1Transport
: public BitTransport
, public Pxx1CrcMixin
{
56 void initFrame(uint32_t period
)
58 BitTransport::initFrame(period
);
62 void addByte(uint8_t byte
)
64 Pxx1CrcMixin::addToCrc(byte
);
65 addByteWithoutCrc(byte
);
68 void addRawByte(uint8_t byte
)
70 for (uint8_t i
= 0; i
< 8; i
++) {
72 BitTransport::addPart(1);
74 BitTransport::addPart(0);
79 void addByteWithoutCrc(uint8_t byte
)
81 for (uint8_t i
= 0; i
< 8; i
++) {
87 void addBit(uint8_t bit
)
90 BitTransport::addPart(1);
91 if (++ones_count
== 5) {
93 BitTransport::addPart(0); // Stuff a 0 bit in
97 BitTransport::addPart(0);
103 class UartPxx1Transport
: public DataBuffer
<uint8_t, 64>, public Pxx1CrcMixin
{
105 void initFrame(uint32_t period
)
110 void addByte(uint8_t byte
)
112 Pxx1CrcMixin::addToCrc(byte
);
113 addWithByteStuffing(byte
);
116 void addRawByte(uint8_t byte
)
121 void addByteWithoutCrc(uint8_t byte
)
123 addWithByteStuffing(byte
);
126 void addWithByteStuffing(uint8_t byte
)
132 else if (0x7D == byte
) {
147 template <class PxxTransport
>
148 class Pxx1Pulses
: public PxxTransport
151 void setupFrame(uint8_t port
);
156 // send 7E, do not CRC
157 PxxTransport::addRawByte(0x7E);
162 PxxTransport::addByteWithoutCrc(Pxx1CrcMixin::crc
>> 8);
163 PxxTransport::addByteWithoutCrc(Pxx1CrcMixin::crc
);
166 void addFlag1(uint8_t port
, uint8_t sendFailsafe
);
167 void addExtraFlags(uint8_t port
);
168 void addChannels(uint8_t port
, uint8_t sendFailsafe
, uint8_t sendUpperChannels
);
169 void add8ChannelsFrame(uint8_t port
, uint8_t sendUpperChannels
, uint8_t sendFailsafe
);
172 typedef Pxx1Pulses
<UartPxx1Transport
> UartPxx1Pulses
;
173 typedef Pxx1Pulses
<StandardPxx1Transport
<PwmPxxBitTransport
>> PwmPxx1Pulses
;
174 typedef Pxx1Pulses
<StandardPxx1Transport
<SerialPxxBitTransport
>> SerialPxx1Pulses
;