Skip to content

Commit e4681c4

Browse files
dakejahljulianoes
andcommitted
Bidirectional DShot
Co-authored-by: Julian Oes <[email protected]>
1 parent a0e6f9c commit e4681c4

File tree

12 files changed

+1055
-182
lines changed

12 files changed

+1055
-182
lines changed

platforms/nuttx/src/px4/rpi/rpi_common/include/px4_arch/io_timer.h

-3
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,6 @@ __EXPORT int io_timer_free_channel(unsigned channel);
147147
__EXPORT int io_timer_get_channel_mode(unsigned channel);
148148
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
149149
__EXPORT extern void io_timer_trigger(void);
150-
__EXPORT void io_timer_update_dma_req(uint8_t timer, bool enable);
151-
152-
__EXPORT extern int io_timer_set_dshot_mode(uint8_t timer, unsigned dshot_pwm_rate, uint8_t dma_burst_length);
153150

154151
/**
155152
* Returns the pin configuration for a specific channel, to be used as GPIO output.

platforms/nuttx/src/px4/stm/stm32_common/dshot/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@
3434
px4_add_library(arch_dshot
3535
dshot.c
3636
)
37+
# target_compile_options(arch_dshot PRIVATE ${MAX_CUSTOM_OPT_LEVEL} -DDEBUG_BUILD)
3738
target_compile_options(arch_dshot PRIVATE ${MAX_CUSTOM_OPT_LEVEL})

platforms/nuttx/src/px4/stm/stm32_common/dshot/dshot.c

+668-112
Large diffs are not rendered by default.

platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/dshot.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
3+
* Copyright (C) 2024 PX4 Development Team. All rights reserved.
44
* Author: Igor Misic <[email protected]>
55
*
66
* Redistribution and use in source and binary forms, with or without
@@ -58,5 +58,6 @@
5858
*/
5959
typedef struct dshot_conf_t {
6060
uint32_t dma_base;
61-
uint32_t dmamap;
61+
uint32_t dma_map_up;
62+
uint32_t dma_map_ch[4];
6263
} dshot_conf_t;

platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (C) 2012, 2017 PX4 Development Team. All rights reserved.
3+
* Copyright (C) 2024 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -80,6 +80,8 @@ typedef enum io_timer_channel_mode_t {
8080
IOTimerChanMode_LED = 7,
8181
IOTimerChanMode_PPS = 8,
8282
IOTimerChanMode_Other = 9,
83+
IOTimerChanMode_DshotInverted = 10,
84+
IOTimerChanMode_CaptureDMA = 11,
8385
IOTimerChanModeSize
8486
} io_timer_channel_mode_t;
8587

@@ -158,7 +160,12 @@ __EXPORT int io_timer_unallocate_channel(unsigned channel);
158160
__EXPORT int io_timer_get_channel_mode(unsigned channel);
159161
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
160162
__EXPORT extern void io_timer_trigger(unsigned channels_mask);
163+
161164
__EXPORT void io_timer_update_dma_req(uint8_t timer, bool enable);
165+
__EXPORT int io_timer_set_dshot_burst_mode(uint8_t timer, unsigned dshot_pwm_rate, uint8_t dma_burst_length);
166+
167+
__EXPORT void io_timer_capture_dma_req(uint8_t timer, uint8_t timer_channel_index, bool enable);
168+
__EXPORT int io_timer_set_dshot_capture_mode(uint8_t timer, uint8_t timer_channel_index, unsigned dshot_pwm_freq);
162169

163170
/**
164171
* Reserve a timer
@@ -168,7 +175,6 @@ __EXPORT int io_timer_allocate_timer(unsigned timer, io_timer_channel_mode_t mod
168175

169176
__EXPORT int io_timer_unallocate_timer(unsigned timer);
170177

171-
__EXPORT extern int io_timer_set_dshot_mode(uint8_t timer, unsigned dshot_pwm_rate, uint8_t dma_burst_length);
172178

173179
/**
174180
* Returns the pin configuration for a specific channel, to be used as GPIO output.

platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer_hw_description.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (C) 2019 PX4 Development Team. All rights reserved.
3+
* Copyright (C) 2024 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -103,7 +103,7 @@ static inline constexpr timer_io_channels_t initIOTimerChannelOutputClear(const
103103
}
104104

105105

106-
static inline constexpr io_timers_t initIOTimer(Timer::Timer timer, DMA dshot_dma = {})
106+
static inline constexpr io_timers_t initIOTimer(Timer::Timer timer, DMA dma = {})
107107
{
108108
bool nuttx_config_timer_enabled = false;
109109
io_timers_t ret{};
@@ -268,9 +268,10 @@ static inline constexpr io_timers_t initIOTimer(Timer::Timer timer, DMA dshot_dm
268268
constexpr_assert(!nuttx_config_timer_enabled, "IO Timer requires NuttX timer config to be disabled (STM32_TIMx)");
269269

270270
// DShot
271-
if (dshot_dma.index != DMA::Invalid) {
272-
ret.dshot.dma_base = getDMABaseRegister(dshot_dma);
273-
ret.dshot.dmamap = getTimerUpdateDMAMap(timer, dshot_dma);
271+
if (dma.index != DMA::Invalid) {
272+
ret.dshot.dma_base = getDMABaseRegister(dma);
273+
ret.dshot.dma_map_up = getTimerUpdateDMAMap(timer, dma);
274+
getTimerChannelDMAMap(timer, dma, ret.dshot.dma_map_ch);
274275
}
275276

276277
return ret;

platforms/nuttx/src/px4/stm/stm32_common/io_pins/input_capture.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (C) 2012-2016 PX4 Development Team. All rights reserved.
3+
* Copyright (C) 2024 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -365,8 +365,10 @@ int up_input_capture_set_trigger(unsigned channel, input_capture_edge edge)
365365
rv = -ENXIO;
366366

367367
/* Any pins in capture mode */
368+
int mode = io_timer_get_channel_mode(channel);
368369

369-
if (io_timer_get_channel_mode(channel) == IOTimerChanMode_Capture) {
370+
if (mode == IOTimerChanMode_Capture ||
371+
mode == IOTimerChanMode_CaptureDMA) {
370372

371373
uint16_t edge_bits = 0xffff;
372374

0 commit comments

Comments
 (0)