Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_dshot_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
30 #include "mcu_periph/gpio.h"
31 #include BOARD_CONFIG
32 
34 
35 #if DSHOT_CONF_TIM1
36 static DSHOTDriver DSHOTD1;
37 static DSHOTConfig dshotcfg1 = DSHOT_CONF1_DEF;
38 #endif
39 #if DSHOT_CONF_TIM2
40 static DSHOTDriver DSHOTD2;
41 static DSHOTConfig dshotcfg2 = DSHOT_CONF2_DEF;
42 #endif
43 #if DSHOT_CONF_TIM3
44 static DSHOTDriver DSHOTD3;
45 static DSHOTConfig dshotcfg3 = DSHOT_CONF3_DEF;
46 #endif
47 #if DSHOT_CONF_TIM4
48 static DSHOTDriver DSHOTD4;
49 static DSHOTConfig dshotcfg4 = DSHOT_CONF4_DEF;
50 #endif
51 #if DSHOT_CONF_TIM5
52 static DSHOTDriver DSHOTD5;
53 static DSHOTConfig dshotcfg5 = DSHOT_CONF5_DEF;
54 #endif
55 #if DSHOT_CONF_TIM8
56 static DSHOTDriver DSHOTD8;
57 static DSHOTConfig dshotcfg8 = DSHOT_CONF8_DEF;
58 #endif
59 #if DSHOT_CONF_TIM9
60 static DSHOTDriver DSHOTD9;
61 static DSHOTConfig dshotcfg9 = DSHOT_CONF9_DEF;
62 #endif
63 
64 
66 {
67  /*----------------
68  * Configure GPIO
69  *----------------*/
70 #ifdef DSHOT_SERVO_0
72 #endif
73 #ifdef DSHOT_SERVO_1
75 #endif
76 #ifdef DSHOT_SERVO_2
78 #endif
79 #ifdef DSHOT_SERVO_3
81 #endif
82 #ifdef DSHOT_SERVO_4
84 #endif
85 #ifdef DSHOT_SERVO_5
87 #endif
88 #ifdef DSHOT_SERVO_6
89  gpio_setup_pin_af(DSHOT_SERVO_6_GPIO, DSHOT_SERVO_6_PIN, DSHOT_SERVO_6_AF, true);
90 #endif
91 #ifdef DSHOT_SERVO_7
92  gpio_setup_pin_af(DSHOT_SERVO_7_GPIO, DSHOT_SERVO_7_PIN, DSHOT_SERVO_7_AF, true);
93 #endif
94 #ifdef DSHOT_SERVO_8
95  gpio_setup_pin_af(DSHOT_SERVO_8_GPIO, DSHOT_SERVO_8_PIN, DSHOT_SERVO_8_AF, true);
96 #endif
97 #ifdef DSHOT_SERVO_9
98  gpio_setup_pin_af(DSHOT_SERVO_9_GPIO, DSHOT_SERVO_9_PIN, DSHOT_SERVO_9_AF, true);
99 #endif
100 #ifdef DSHOT_SERVO_10
101  gpio_setup_pin_af(DSHOT_SERVO_10_GPIO, DSHOT_SERVO_10_PIN, DSHOT_SERVO_10_AF, true);
102 #endif
103 #ifdef DSHOT_SERVO_11
104  gpio_setup_pin_af(DSHOT_SERVO_11_GPIO, DSHOT_SERVO_11_PIN, DSHOT_SERVO_11_AF, true);
105 #endif
106 
107  /*---------------
108  * Configure DSHOT
109  *---------------*/
110 #if DSHOT_CONF_TIM1
111  dshotStart(&DSHOTD1, &dshotcfg1);
112 #endif
113 #if DSHOT_CONF_TIM2
114  dshotStart(&DSHOTD2, &dshotcfg2);
115 #endif
116 #if DSHOT_CONF_TIM3
117  dshotStart(&DSHOTD3, &dshotcfg3);
118 #endif
119 #if DSHOT_CONF_TIM4
120  dshotStart(&DSHOTD4, &dshotcfg4);
121 #endif
122 #if DSHOT_CONF_TIM5
123  dshotStart(&DSHOTD5, &dshotcfg5);
124 #endif
125 #if DSHOT_CONF_TIM8
126  dshotStart(&DSHOTD8, &dshotcfg8);
127 #endif
128 #if DSHOT_CONF_TIM9
129  dshotStart(&DSHOTD9, &dshotcfg9);
130 #endif
131 }
132 
133 
135 {
136 #ifdef DSHOT_SERVO_0
138 #endif
139 #ifdef DSHOT_SERVO_1
141 #endif
142 #ifdef DSHOT_SERVO_2
144 #endif
145 #ifdef DSHOT_SERVO_3
147 #endif
148 #ifdef DSHOT_SERVO_4
150 #endif
151 #ifdef DSHOT_SERVO_5
153 #endif
154 #ifdef DSHOT_SERVO_6
155  dshotSetThrottle(&DSHOT_SERVO_6_DRIVER, DSHOT_SERVO_6_CHANNEL, actuators_dshot_values[DSHOT_SERVO_6]);
156 #endif
157 #ifdef DSHOT_SERVO_7
158  dshotSetThrottle(&DSHOT_SERVO_7_DRIVER, DSHOT_SERVO_7_CHANNEL, actuators_dshot_values[DSHOT_SERVO_7]);
159 #endif
160 #ifdef DSHOT_SERVO_8
161  dshotSetThrottle(&DSHOT_SERVO_8_DRIVER, DSHOT_SERVO_8_CHANNEL, actuators_dshot_values[DSHOT_SERVO_8]);
162 #endif
163 #ifdef DSHOT_SERVO_9
164  dshotSetThrottle(&DSHOT_SERVO_9_DRIVER, DSHOT_SERVO_9_CHANNEL, actuators_dshot_values[DSHOT_SERVO_9]);
165 #endif
166 #ifdef DSHOT_SERVO_10
167  dshotSetThrottle(&DSHOT_SERVO_10_DRIVER, DSHOT_SERVO_10_CHANNEL, actuators_dshot_values[DSHOT_SERVO_10]);
168 #endif
169 #ifdef DSHOT_SERVO_11
170  dshotSetThrottle(&DSHOT_SERVO_11_DRIVER, DSHOT_SERVO_11_CHANNEL, actuators_dshot_values[DSHOT_SERVO_11]);
171 #endif
172 
173 #if DSHOT_CONF_TIM1
174  dshotSendFrame(&DSHOTD1);
175 #endif
176 #if DSHOT_CONF_TIM2
177  dshotSendFrame(&DSHOTD2);
178 #endif
179 #if DSHOT_CONF_TIM3
180  dshotSendFrame(&DSHOTD3);
181 #endif
182 #if DSHOT_CONF_TIM4
183  dshotSendFrame(&DSHOTD4);
184 #endif
185 #if DSHOT_CONF_TIM5
186  dshotSendFrame(&DSHOTD5);
187 #endif
188 #if DSHOT_CONF_TIM8
189  dshotSendFrame(&DSHOTD8);
190 #endif
191 #if DSHOT_CONF_TIM9
192  dshotSendFrame(&DSHOTD9);
193 #endif
194 }
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition: gpio_arch.c:61
unsigned short uint16_t
Definition: types.h:16
#define DSHOT_SERVO_3
Definition: board.h:373
#define DSHOT_SERVO_1_GPIO
Definition: board.h:360
DSHOT driver based on ChibiOS.
#define DSHOT_SERVO_4_PIN
Definition: board.h:382
uint16_t actuators_dshot_values[ACTUATORS_DSHOT_NB]
#define DSHOT_SERVO_4_GPIO
Definition: board.h:381
#define DSHOT_SERVO_1_CHANNEL
Definition: board.h:364
#define DSHOT_SERVO_5_PIN
Definition: board.h:389
Some architecture independent helper functions for GPIOs.
#define DSHOT_SERVO_2_DRIVER
Definition: board.h:370
DSHOT Driver configuration structure.
Definition: esc_dshot.h:141
void dshotStart(DSHOTDriver *driver, const DSHOTConfig *config)
Configures and activates the DSHOT peripheral.
Definition: esc_dshot.c:122
void dshotSetThrottle(DSHOTDriver *driver, const uint8_t index, const uint16_t throttle)
prepare throttle order for specified ESC
Definition: esc_dshot.c:215
#define DSHOT_SERVO_4
Definition: board.h:380
#define DSHOT_SERVO_0_CHANNEL
Definition: board.h:357
#define DSHOT_SERVO_0_PIN
Definition: board.h:354
void dshotSendFrame(DSHOTDriver *driver)
send throttle order
Definition: esc_dshot.c:303
DSHOT driver structure.
Definition: esc_dshot.h:208
#define DSHOT_CONF2_DEF
Definition: board.h:409
#define DSHOT_SERVO_2_AF
Definition: board.h:369
#define DSHOT_SERVO_5_AF
Definition: board.h:390
#define DSHOT_SERVO_3_CHANNEL
Definition: board.h:378
#define DSHOT_SERVO_0_GPIO
Definition: board.h:353
#define DSHOT_SERVO_0
DSHOT.
Definition: board.h:352
#define DSHOT_SERVO_1_AF
Definition: board.h:362
#define DSHOT_SERVO_1
Definition: board.h:359
#define DSHOT_SERVO_3_PIN
Definition: board.h:375
#define DSHOT_SERVO_5_CHANNEL
Definition: board.h:392
void actuators_dshot_arch_init(void)
Arch dependent init.
#define DSHOT_SERVO_2_PIN
Definition: board.h:368
#define DSHOT_SERVO_5_GPIO
Definition: board.h:388
#define DSHOT_SERVO_3_DRIVER
Definition: board.h:377
#define DSHOT_SERVO_1_PIN
Definition: board.h:361
#define DSHOT_SERVO_4_DRIVER
Definition: board.h:384
#define DSHOT_SERVO_2_GPIO
Definition: board.h:367
#define DSHOT_SERVO_3_AF
Definition: board.h:376
#define ACTUATORS_DSHOT_NB
Maxnum number of DSHOT commands This should be large enough for max applications: 8 motors +1 in case...
#define DSHOT_SERVO_2
Definition: board.h:366
#define DSHOT_SERVO_5
Definition: board.h:387
#define DSHOT_SERVO_4_AF
Definition: board.h:383
void actuators_dshot_arch_commit(void)
#define DSHOT_CONF4_DEF
Definition: tawaki.h:524
#define DSHOT_CONF3_DEF
Definition: board.h:417
#define DSHOT_SERVO_3_GPIO
Definition: board.h:374
#define DSHOT_SERVO_0_AF
Definition: board.h:355
#define DSHOT_SERVO_5_DRIVER
Definition: board.h:391
#define DSHOT_SERVO_2_CHANNEL
Definition: board.h:371
#define DSHOT_SERVO_0_DRIVER
Definition: board.h:356
#define DSHOT_SERVO_1_DRIVER
Definition: board.h:363
#define DSHOT_SERVO_4_CHANNEL
Definition: board.h:385