Paparazzi UAS  v5.17_devel-24-g2ae834f
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/ram_arch.h"
31 #include "mcu_periph/gpio.h"
32 #include BOARD_CONFIG
33 
35 
36 #if DSHOT_CONF_TIM1
37 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD1);
38 static DSHOTConfig dshotcfg1 = DSHOT_CONF1_DEF;
39 #endif
40 #if DSHOT_CONF_TIM2
41 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD2);
42 static DSHOTConfig dshotcfg2 = DSHOT_CONF2_DEF;
43 #endif
44 #if DSHOT_CONF_TIM3
45 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD3);
46 static DSHOTConfig dshotcfg3 = DSHOT_CONF3_DEF;
47 #endif
48 #if DSHOT_CONF_TIM4
49 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD4);
50 static DSHOTConfig dshotcfg4 = DSHOT_CONF4_DEF;
51 #endif
52 #if DSHOT_CONF_TIM5
53 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD5);
54 static DSHOTConfig dshotcfg5 = DSHOT_CONF5_DEF;
55 #endif
56 #if DSHOT_CONF_TIM8
57 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD8);
58 static DSHOTConfig dshotcfg8 = DSHOT_CONF8_DEF;
59 #endif
60 #if DSHOT_CONF_TIM9
61 static IN_DMA_SECTION_NOINIT(DSHOTDriver DSHOTD9);
62 static DSHOTConfig dshotcfg9 = DSHOT_CONF9_DEF;
63 #endif
64 
65 
67 {
68  /*----------------
69  * Configure GPIO
70  *----------------*/
71 #ifdef DSHOT_SERVO_0
73 #endif
74 #ifdef DSHOT_SERVO_1
76 #endif
77 #ifdef DSHOT_SERVO_2
79 #endif
80 #ifdef DSHOT_SERVO_3
82 #endif
83 #ifdef DSHOT_SERVO_4
85 #endif
86 #ifdef DSHOT_SERVO_5
88 #endif
89 #ifdef DSHOT_SERVO_6
90  gpio_setup_pin_af(DSHOT_SERVO_6_GPIO, DSHOT_SERVO_6_PIN, DSHOT_SERVO_6_AF, true);
91 #endif
92 #ifdef DSHOT_SERVO_7
93  gpio_setup_pin_af(DSHOT_SERVO_7_GPIO, DSHOT_SERVO_7_PIN, DSHOT_SERVO_7_AF, true);
94 #endif
95 #ifdef DSHOT_SERVO_8
96  gpio_setup_pin_af(DSHOT_SERVO_8_GPIO, DSHOT_SERVO_8_PIN, DSHOT_SERVO_8_AF, true);
97 #endif
98 #ifdef DSHOT_SERVO_9
99  gpio_setup_pin_af(DSHOT_SERVO_9_GPIO, DSHOT_SERVO_9_PIN, DSHOT_SERVO_9_AF, true);
100 #endif
101 #ifdef DSHOT_SERVO_10
102  gpio_setup_pin_af(DSHOT_SERVO_10_GPIO, DSHOT_SERVO_10_PIN, DSHOT_SERVO_10_AF, true);
103 #endif
104 #ifdef DSHOT_SERVO_11
105  gpio_setup_pin_af(DSHOT_SERVO_11_GPIO, DSHOT_SERVO_11_PIN, DSHOT_SERVO_11_AF, true);
106 #endif
107 
108  /*---------------
109  * Configure DSHOT
110  *---------------*/
111 #if DSHOT_CONF_TIM1
112  dshotStart(&DSHOTD1, &dshotcfg1);
113 #endif
114 #if DSHOT_CONF_TIM2
115  dshotStart(&DSHOTD2, &dshotcfg2);
116 #endif
117 #if DSHOT_CONF_TIM3
118  dshotStart(&DSHOTD3, &dshotcfg3);
119 #endif
120 #if DSHOT_CONF_TIM4
121  dshotStart(&DSHOTD4, &dshotcfg4);
122 #endif
123 #if DSHOT_CONF_TIM5
124  dshotStart(&DSHOTD5, &dshotcfg5);
125 #endif
126 #if DSHOT_CONF_TIM8
127  dshotStart(&DSHOTD8, &dshotcfg8);
128 #endif
129 #if DSHOT_CONF_TIM9
130  dshotStart(&DSHOTD9, &dshotcfg9);
131 #endif
132 }
133 
134 
136 {
137 #ifdef DSHOT_SERVO_0
139 #endif
140 #ifdef DSHOT_SERVO_1
142 #endif
143 #ifdef DSHOT_SERVO_2
145 #endif
146 #ifdef DSHOT_SERVO_3
148 #endif
149 #ifdef DSHOT_SERVO_4
151 #endif
152 #ifdef DSHOT_SERVO_5
154 #endif
155 #ifdef DSHOT_SERVO_6
156  dshotSetThrottle(&DSHOT_SERVO_6_DRIVER, DSHOT_SERVO_6_CHANNEL, actuators_dshot_values[DSHOT_SERVO_6]);
157 #endif
158 #ifdef DSHOT_SERVO_7
159  dshotSetThrottle(&DSHOT_SERVO_7_DRIVER, DSHOT_SERVO_7_CHANNEL, actuators_dshot_values[DSHOT_SERVO_7]);
160 #endif
161 #ifdef DSHOT_SERVO_8
162  dshotSetThrottle(&DSHOT_SERVO_8_DRIVER, DSHOT_SERVO_8_CHANNEL, actuators_dshot_values[DSHOT_SERVO_8]);
163 #endif
164 #ifdef DSHOT_SERVO_9
165  dshotSetThrottle(&DSHOT_SERVO_9_DRIVER, DSHOT_SERVO_9_CHANNEL, actuators_dshot_values[DSHOT_SERVO_9]);
166 #endif
167 #ifdef DSHOT_SERVO_10
168  dshotSetThrottle(&DSHOT_SERVO_10_DRIVER, DSHOT_SERVO_10_CHANNEL, actuators_dshot_values[DSHOT_SERVO_10]);
169 #endif
170 #ifdef DSHOT_SERVO_11
171  dshotSetThrottle(&DSHOT_SERVO_11_DRIVER, DSHOT_SERVO_11_CHANNEL, actuators_dshot_values[DSHOT_SERVO_11]);
172 #endif
173 
174 #if DSHOT_CONF_TIM1
175  dshotSendFrame(&DSHOTD1);
176 #endif
177 #if DSHOT_CONF_TIM2
178  dshotSendFrame(&DSHOTD2);
179 #endif
180 #if DSHOT_CONF_TIM3
181  dshotSendFrame(&DSHOTD3);
182 #endif
183 #if DSHOT_CONF_TIM4
184  dshotSendFrame(&DSHOTD4);
185 #endif
186 #if DSHOT_CONF_TIM5
187  dshotSendFrame(&DSHOTD5);
188 #endif
189 #if DSHOT_CONF_TIM8
190  dshotSendFrame(&DSHOTD8);
191 #endif
192 #if DSHOT_CONF_TIM9
193  dshotSendFrame(&DSHOTD9);
194 #endif
195 }
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
Specific RAM section for DMA usage on F7.
#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:145
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:216
#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:304
DSHOT driver structure.
Definition: esc_dshot.h:212
#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 IN_DMA_SECTION_NOINIT(var)
Definition: ram_arch.h:74
#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