Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions cmake/at32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -423,20 +423,14 @@ function(target_at32)
endif()

# clean_<target>
set(generator_cmd "")
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(generator_cmd "make")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(generator_cmd "ninja")
endif()
if (NOT generator_cmd STREQUAL "")
set(clean_target "clean_${name}")
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${generator_cmd} clean
COMMENT "Removing intermediate files for ${name}")
set_property(TARGET ${clean_target} PROPERTY
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
set(clean_executables ${main_target_name})
set(clean_files ${main_hex_filename} ${main_bin_filename})
if(args_BOOTLOADER)
list(APPEND clean_executables ${bl_target_name} ${for_bl_target_name})
list(APPEND clean_files
${bl_hex_filename} ${bl_bin_filename}
${for_bl_hex_filename} ${for_bl_bin_filename}
${combined_hex})
endif()
add_clean_target(${name} EXECUTABLES ${clean_executables} FILES ${clean_files})
endfunction()
26 changes: 26 additions & 0 deletions cmake/clean_target.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Removes the build artefacts of a single firmware target. Run at build time
# by the clean_<target> targets added by add_clean_target():
#
# cmake -P cmake/clean_target.cmake <path> [<path>...]
#
# Every path that is a directory is treated as the object directory of an
# executable and only the compiler output below it is removed. The directory
# itself is kept, because the Makefile generator stores the build rules of the
# target (build.make, DependInfo.cmake, ...) next to the object files and
# removing those breaks the next "make <target>" until CMake is run again.
# Every other path is removed as a file, missing files are ignored.

if(CMAKE_ARGC GREATER 3)
math(EXPR last_argument "${CMAKE_ARGC} - 1")
foreach(argument RANGE 3 ${last_argument})
set(path "${CMAKE_ARGV${argument}}")
if(IS_DIRECTORY "${path}")
file(GLOB_RECURSE objects "${path}/*.o" "${path}/*.obj" "${path}/*.d")
if(objects)
file(REMOVE ${objects})
endif()
else()
file(REMOVE "${path}")
endif()
endforeach()
endif()
34 changes: 34 additions & 0 deletions cmake/main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,40 @@ function(exclude_from_all target)
EXCLUDE_FROM_DEFAULT_BUILD ON)
endfunction()

# Adds a clean_<name> target which removes the artefacts of the firmware
# target <name>. Neither "make clean" nor "ninja clean" can be limited to a
# single target, so the artefacts are removed explicitly by cmake, which
# behaves the same for the Makefile and the Ninja generator.
#
# EXECUTABLES: executable targets of <name>. Their binary, map file and
# object files are removed.
# FILES: additional artefacts of <name>, e.g. the .hex and .bin files.
function(add_clean_target name)
cmake_parse_arguments(args "" "" "EXECUTABLES;FILES" ${ARGN})

get_generated_files_dir(generated_dir ${name})
set(paths ${args_FILES}
${generated_dir}/${SETTINGS_GENERATED_H}
${generated_dir}/${SETTINGS_GENERATED_C})
foreach(exe ${args_EXECUTABLES})
list(APPEND paths $<TARGET_FILE:${exe}>)
# Same name as the map file added by generate_map_file()
if(CMAKE_VERSION VERSION_LESS 3.15)
list(APPEND paths $<TARGET_FILE:${exe}>.map)
else()
list(APPEND paths $<TARGET_FILE_DIR:${exe}>/$<TARGET_FILE_BASE_NAME:${exe}>.map)
endif()
# Object directory used by both generators for ${exe}
list(APPEND paths ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${exe}.dir)
endforeach()

set(clean_target clean_${name})
add_custom_target(${clean_target}
COMMAND ${CMAKE_COMMAND} -P ${MAIN_DIR}/cmake/clean_target.cmake ${paths}
COMMENT "Removing intermediate files for ${name}")
exclude_from_all(${clean_target})
endfunction()

function(collect_targets)
get_property(targets GLOBAL PROPERTY VALID_TARGETS)
list(SORT targets)
Expand Down
19 changes: 3 additions & 16 deletions cmake/rp2350.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -419,20 +419,7 @@ function(target_rp2350 name)
setup_firmware_target(${exe_target} ${name} ${ARGN})

# clean_<target>
set(generator_cmd "")
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(generator_cmd "make")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(generator_cmd "ninja")
endif()
if (NOT generator_cmd STREQUAL "")
set(clean_target "clean_${name}")
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${generator_cmd} clean
COMMENT "Removing intermediate files for ${name}")
set_property(TARGET ${clean_target} PROPERTY
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()
add_clean_target(${name}
EXECUTABLES ${exe_target}
FILES ${hex_filename} ${bin_filename} ${uf2_filename})
endfunction()
17 changes: 1 addition & 16 deletions cmake/sitl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,5 @@ function (target_sitl name)

setup_firmware_target(${exe_target} ${name} ${ARGN})
#clean_<target>
set(generator_cmd "")
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(generator_cmd "make")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(generator_cmd "ninja")
endif()
if (NOT generator_cmd STREQUAL "")
set(clean_target "clean_${name}")
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${generator_cmd} clean
COMMENT "Removing intermediate files for ${name}")
set_target_properties(${clean_target} PROPERTIES
EXCLUDE_FROM_ALL ON
EXCLUDE_FROM_DEFAULT_BUILD ON)
endif()
add_clean_target(${name} EXECUTABLES ${exe_target} FILES ${exe_filename})
endfunction()
25 changes: 10 additions & 15 deletions cmake/stm32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ function(target_stm32)
LINKER_SCRIPT ${args_LINKER_SCRIPT}
OPTIMIZATION ${args_OPTIMIZATION}

OUTPUT_BIN_FILENAME main_bin_filename
OUTPUT_HEX_FILENAME main_hex_filename
OUTPUT_TARGET_NAME main_target_name
)
Expand Down Expand Up @@ -433,20 +434,14 @@ function(target_stm32)
endif()

# clean_<target>
set(generator_cmd "")
if (CMAKE_GENERATOR STREQUAL "Unix Makefiles")
set(generator_cmd "make")
elseif(CMAKE_GENERATOR STREQUAL "Ninja")
set(generator_cmd "ninja")
endif()
if (NOT generator_cmd STREQUAL "")
set(clean_target "clean_${name}")
add_custom_target(${clean_target}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMAND ${generator_cmd} clean
COMMENT "Removing intermediate files for ${name}")
set_property(TARGET ${clean_target} PROPERTY
EXCLUDE_FROM_ALL 1
EXCLUDE_FROM_DEFAULT_BUILD 1)
set(clean_executables ${main_target_name})
set(clean_files ${main_hex_filename} ${main_bin_filename})
if(args_BOOTLOADER AND NOT args_NO_BOOTLOADER)
list(APPEND clean_executables ${bl_target_name} ${for_bl_target_name})
list(APPEND clean_files
${bl_hex_filename} ${bl_bin_filename}
${for_bl_hex_filename} ${for_bl_bin_filename}
${combined_hex})
endif()
add_clean_target(${name} EXECUTABLES ${clean_executables} FILES ${clean_files})
endfunction()
42 changes: 1 addition & 41 deletions src/main/telemetry/srxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@

#include "sensors/battery.h"
//#include "sensors/adcinternal.h"
#include "sensors/esc_sensor.h"

#include "telemetry/telemetry.h"
#include "telemetry/srxl.h"
Expand Down Expand Up @@ -175,50 +174,11 @@ typedef struct

#define SPEKTRUM_RPM_UNUSED 0xffff
#define SPEKTRUM_TEMP_UNUSED 0x7fff
#define MICROSEC_PER_MINUTE 60000000

//Original range of 1 - 65534 uSec gives an RPM range of 915 - 60000000rpm, 60MegaRPM
#define SPEKTRUM_MIN_RPM 999 // Min RPM to show the user, indicating RPM is really below 999
#define SPEKTRUM_MAX_RPM 60000000

uint16_t getMotorAveragePeriod(void)
{

#if defined( USE_ESC_SENSOR_TELEMETRY) || defined( USE_DSHOT_TELEMETRY)
uint32_t rpm = 0;
uint16_t period_us = SPEKTRUM_RPM_UNUSED;

#if defined( USE_ESC_SENSOR_TELEMETRY)
escSensorData_t *escData = getEscSensorData(ESC_SENSOR_COMBINED);
if (escData != NULL) {
rpm = escData->rpm;
}
#endif

#if defined(USE_DSHOT_TELEMETRY)
if (useDshotTelemetry) {
uint16_t motors = getMotorCount();

if (motors > 0) {
for (int motor = 0; motor < motors; motor++) {
rpm += getDshotTelemetry(motor);
}
rpm = 100.0f / (motorConfig()->motorPoleCount / 2.0f) * rpm; // convert erpm freq to RPM.
rpm /= motors; // Average combined rpm
}
}
#endif

if (rpm > SPEKTRUM_MIN_RPM && rpm < SPEKTRUM_MAX_RPM) {
period_us = MICROSEC_PER_MINUTE / rpm; // revs/minute -> microSeconds
} else {
period_us = MICROSEC_PER_MINUTE / SPEKTRUM_MIN_RPM;
}

return period_us;
#else
// Not implemented for INAV, report the RPM field as unused
return SPEKTRUM_RPM_UNUSED;
#endif
}

bool srxlFrameRpm(sbuf_t *dst, timeUs_t currentTimeUs)
Expand Down