Companion: Russian UI (#7180)
[opentx.git] / radio / src / pulses / pxx.h
blob5d0bfaf051e5697ab26ff9202007cb4d320ef7e0
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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_PXX_H_
22 #define _PULSES_PXX_H_
24 #include "pulses_common.h"
26 #define PXX_SEND_BIND 0x01
27 #define PXX_SEND_FAILSAFE (1 << 4)
28 #define PXX_SEND_RANGECHECK (1 << 5)
30 #define PXX2_LOWSPEED_BAUDRATE 230400
31 #define PXX2_HIGHSPEED_BAUDRATE 450000
32 #define PXX2_PERIOD 4 // 4ms
33 #define PXX2_TOOLS_PERIOD 1 // 1ms
34 #define PXX2_FRAME_MAXLENGTH 64
36 #define PXX_PULSES_PERIOD 9/*ms*/
37 #define EXTMODULE_PXX1_SERIAL_PERIOD 4/*ms*/
38 #define EXTMODULE_PXX1_SERIAL_BAUDRATE 420000
40 #if defined(PXX_FREQUENCY_HIGH)
41 #define INTMODULE_PXX1_SERIAL_BAUDRATE 450000
42 #define INTMODULE_PXX1_SERIAL_PERIOD 4/*ms*/
43 #else
44 #define INTMODULE_PXX1_SERIAL_BAUDRATE 115200
45 #define INTMODULE_PXX1_SERIAL_PERIOD 9/*ms*/
46 #endif
48 // Used by the Sky9x family boards
49 class SerialPxxBitTransport: public DataBuffer<uint8_t, 64> {
50 protected:
51 uint8_t byte;
52 uint8_t bits_count;
54 void initFrame(uint32_t period)
56 initBuffer();
57 byte = 0;
58 bits_count = 0;
61 void addSerialBit(uint8_t bit)
63 byte >>= 1;
64 if (bit & 1) {
65 byte |= 0x80;
67 if (++bits_count >= 8) {
68 *ptr++ = byte;
69 bits_count = 0;
73 // 8uS/bit 01 = 0, 001 = 1
74 void addPart(uint8_t value)
76 addSerialBit(0);
77 if (value) {
78 addSerialBit(0);
80 addSerialBit(1);
83 void addTail()
85 while (bits_count != 0) {
86 addSerialBit(1);
91 class PwmPxxBitTransport: public PulsesBuffer<pulse_duration_t, 200> {
92 protected:
93 uint16_t rest;
95 void initFrame(uint32_t period)
97 initBuffer();
98 rest = period * 2000; // 0.5uS (2Mhz)
101 void addPart(uint8_t value)
103 pulse_duration_t duration = value ? 47 : 31;
104 *ptr++ = duration;
105 rest -= duration + 1;
108 void addTail()
110 // rest min value is 18000 - 200 * 48 = 8400 (4.2ms)
111 *(ptr - 1) += rest;
115 #endif