dRonin  adbada4
dRonin firmware
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pios_sbus_priv.h
Go to the documentation of this file.
1 
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful, but
23  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25  * for more details.
26  *
27  * You should have received a copy of the GNU General Public License along
28  * with this program; if not, see <http://www.gnu.org/licenses/>
29  */
30 
31 #ifndef PIOS_SBUS_PRIV_H
32 #define PIOS_SBUS_PRIV_H
33 
34 #include <pios.h>
35 
36 #include <pios_stm32.h>
37 #include <pios_usart_priv.h>
38 
39 /*
40  * S.Bus serial port settings:
41  * 100000bps inverted serial stream, 8 bits, even parity, 2 stop bits
42  * frame period is 7ms (HS) or 14ms (FS)
43  *
44  * Frame structure:
45  * 1 byte - 0x0f (start of frame byte)
46  * 22 bytes - channel data (11 bit/channel, 16 channels, LSB first)
47  * 1 byte - bit flags:
48  * 0x01 - discrete channel 1,
49  * 0x02 - discrete channel 2,
50  * 0x04 - lost frame flag,
51  * 0x08 - failsafe flag,
52  * 0xf0 - reserved
53  *
54  * The R7008SB receiver has four different end of frame bytes, which rotates in order:
55  * 00000100
56  * 00010100
57  * 00100100
58  * 00110100 * 1 byte - 0x00 (end of frame byte)
59  */
60 
61 #define SBUS_FRAME_LENGTH (1+22+1+1)
62 #define SBUS_SOF_BYTE 0x0f
63 #define SBUS_EOF_BYTE 0x00
64 #define SBUS_FLAG_DC1 0x01
65 #define SBUS_FLAG_DC2 0x02
66 #define SBUS_FLAG_FL 0x04
67 #define SBUS_FLAG_FS 0x08
68 
69 #define SBUS_R7008SB_EOF_COUNTER_MASK 0xCF
70 #define SBUS_R7008SB_EOF_BYTE 0x04
71 
72 /* Discrete channels represented as bits, provide values for them */
73 #define SBUS_VALUE_MIN 352
74 #define SBUS_VALUE_MAX 1696
75 
76 /*
77  * S.Bus configuration programmable invertor
78  */
79 struct pios_sbus_cfg {
80  struct stm32_gpio inv;
81  void (*gpio_clk_func)(uint32_t periph, FunctionalState state);
82  uint32_t gpio_clk_periph;
83  BitAction gpio_inv_enable;
84  BitAction gpio_inv_disable;
85 };
86 
87 /*
88  * S.Bus protocol provides 16 proportional and 2 discrete channels.
89  * Do not change unless driver code is updated accordingly.
90  */
91 
92 #ifdef PIOS_INCLUDE_SBUS
93 #if (PIOS_SBUS_NUM_INPUTS != (16+2))
94 #error "S.Bus protocol provides 16 proportional and 2 discrete channels"
95 #endif
96 #endif
97 
98 extern const struct pios_rcvr_driver pios_sbus_rcvr_driver;
99 
100 extern int32_t PIOS_SBus_Init(uintptr_t *sbus_id,
101  const struct pios_com_driver *driver,
102  uintptr_t lower_id);
103 
104 
105 #endif /* PIOS_SBUS_PRIV_H */
106 
Types that are specific to the STM32 peripherals.
Main PiOS header to include all the compiled in PiOS options.
void(* gpio_clk_func)(uint32_t periph, FunctionalState state)
int32_t PIOS_SBus_Init(uintptr_t *sbus_id, const struct pios_com_driver *driver, uintptr_t lower_id)
const struct pios_rcvr_driver pios_sbus_rcvr_driver
USART private definitions.
uint32_t gpio_clk_periph
struct stm32_gpio inv
BitAction gpio_inv_disable
BitAction gpio_inv_enable
enum arena_state state