From 96e89a692bfada075787e892e1f1b1b413359504 Mon Sep 17 00:00:00 2001 From: Mia McMahill Date: Thu, 12 Nov 2026 06:38:52 -0600 Subject: [PATCH 1/3] Bump C++ to gnu++17 --- CMakeLists.txt | 2 +- Makefile | 2 +- cmake/DaisyProject.cmake | 2 +- core/Makefile | 2 +- tests/CMakeLists.txt | 2 +- tests/Makefile | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2bb90a39..d7e54588c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ target_compile_options(daisy PRIVATE ) set_target_properties(daisy PROPERTIES - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED C_STANDARD 11 C_STANDARD_REQUIRED diff --git a/Makefile b/Makefile index 5253e570e..4e8b1b92e 100644 --- a/Makefile +++ b/Makefile @@ -348,7 +348,7 @@ CPPFLAGS += \ -fno-rtti C_STANDARD = -std=gnu11 -CPP_STANDARD += -std=gnu++14 +CPP_STANDARD += -std=gnu++17 # default action: build all all: $(BUILD_DIR)/$(TARGET).a diff --git a/cmake/DaisyProject.cmake b/cmake/DaisyProject.cmake index 1fa234a8a..bf685f70a 100644 --- a/cmake/DaisyProject.cmake +++ b/cmake/DaisyProject.cmake @@ -73,7 +73,7 @@ target_link_libraries(${FIRMWARE_NAME} ) set_target_properties(${FIRMWARE_NAME} PROPERTIES - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES SUFFIX ".elf" LINK_DEPENDS ${LINKER_SCRIPT} diff --git a/core/Makefile b/core/Makefile index d6619f8a6..d8d774425 100644 --- a/core/Makefile +++ b/core/Makefile @@ -202,7 +202,7 @@ CPPFLAGS += \ -Wno-register C_STANDARD = -std=gnu11 -CPP_STANDARD ?= -std=gnu++14 +CPP_STANDARD ?= -std=gnu++17 ####################################### diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e0bbfeca8..26e7c191e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,7 +53,7 @@ function(add_gtest source_file) # Set the properties set_target_properties(${test_name} PROPERTIES - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES C_STANDARD 11 C_STANDARD_REQUIRED YES diff --git a/tests/Makefile b/tests/Makefile index 9e904eef1..ee87169ab 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -32,7 +32,7 @@ OBJECTS = $(SOURCES:$(SRC_PATH)/%.$(SRC_EXT)=$(BUILD_PATH)/%.o) DEPS = $(OBJECTS:.o=.d) # flags # -COMPILE_FLAGS = -std=gnu++14 -Wall -Wextra -g -Werror -pthread -DUNIT_TEST=1 +COMPILE_FLAGS = -std=gnu++17 -Wall -Wextra -g -Werror -pthread -DUNIT_TEST=1 INCLUDES = -I /usr/local/include/ \ -I googletest/ \ -I googletest/googletest/ \ @@ -92,4 +92,4 @@ $(BUILD_PATH)/%.o: $(SRC_PATH)/%.$(SRC_EXT) $(BUILD_PATH)/%.o: $(SRC_PATH)/%.cc @echo "Compiling: $< -> $@" - $(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ \ No newline at end of file + $(CXX) $(CXXFLAGS) $(INCLUDES) -MP -MMD -c $< -o $@ From 757d27b1b2c02d882fde907d6b4bc4eeb0c505b2 Mon Sep 17 00:00:00 2001 From: Mia McMahill Date: Thu, 12 Nov 2026 07:12:25 -0600 Subject: [PATCH 2/3] Use std::clamp --- src/dev/leddriver.h | 12 +++--------- src/util/FixedCapStr.h | 9 ++------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/dev/leddriver.h b/src/dev/leddriver.h index 9c70caeb9..918d135ae 100644 --- a/src/dev/leddriver.h +++ b/src/dev/leddriver.h @@ -5,6 +5,7 @@ #ifdef __cplusplus #include +#include #include "per/i2c.h" #include "per/gpio.h" @@ -87,7 +88,7 @@ class LedDriverPca9685 void SetAllTo(float brightness) { const uint8_t intBrightness - = (uint8_t)(clamp(brightness * 255.0f, 0.0f, 255.0f)); + = (uint8_t)(std::clamp(brightness * 255.0f, 0.0f, 255.0f)); SetAllTo(intBrightness); } @@ -109,7 +110,7 @@ class LedDriverPca9685 void SetLed(int ledIndex, float brightness) { const uint8_t intBrightness - = (uint8_t)(clamp(brightness * 255.0f, 0.0f, 255.0f)); + = (uint8_t)(std::clamp(brightness * 255.0f, 0.0f, 255.0f)); SetLed(ledIndex, intBrightness); } @@ -252,13 +253,6 @@ class LedDriverPca9685 } } - // no std::clamp available in C++14.... remove this when C++17 is available - template - T clamp(T in, T low, T high) - { - return (in < low) ? low : (high < in) ? high : in; - } - // an internal function to handle i2c callbacks // called when an I2C transmission completes and the next driver must be updated static void TxCpltCallback(void* context, I2CHandle::Result result) diff --git a/src/util/FixedCapStr.h b/src/util/FixedCapStr.h index 4c7258c63..2b41b6e1a 100644 --- a/src/util/FixedCapStr.h +++ b/src/util/FixedCapStr.h @@ -308,8 +308,8 @@ class FixedCapStrBase constexpr void ReverseSection(std::size_t firstIdx, std::size_t lastIdx) { - firstIdx = clamp(firstIdx, 0, size_ - 1); - lastIdx = clamp(lastIdx, 0, size_ - 1); + firstIdx = std::clamp(firstIdx, 0, size_ - 1); + lastIdx = std::clamp(lastIdx, 0, size_ - 1); while(firstIdx < lastIdx) { CharType tmp = buffer_[lastIdx]; @@ -468,11 +468,6 @@ class FixedCapStrBase } } - std::size_t clamp(std::size_t val, std::size_t min, std::size_t max) - { - return (val < min) ? min : ((val > max) ? max : val); - } - std::size_t size_{0}; const size_t capacity_; CharType* buffer_; From 82e2b6b1496f444c16c36ef9eb72ca507f4318ef Mon Sep 17 00:00:00 2001 From: Mia McMahill Date: Thu, 12 Nov 2026 07:17:14 -0600 Subject: [PATCH 3/3] Use inline for logger static members --- src/hid/logger.h | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/hid/logger.h b/src/hid/logger.h index bbbcd080c..e1706345d 100644 --- a/src/hid/logger.h +++ b/src/hid/logger.h @@ -150,35 +150,18 @@ class Logger /** member variables */ - static char tx_buff_[LOGGER_BUFFER]; /**< buffer for log data */ - static size_t tx_ptr_; /**< current position in the buffer */ - static size_t pc_sync_; /**< terminal synchronization state */ - static LoggerImpl impl_; /**< underlying trasnfer implementation */ + /** this needs to remain in SRAM to support startup-time printouts + */ + inline static char tx_buff_[LOGGER_BUFFER]; /**< buffer for log data */ + inline static size_t tx_ptr_ = 0; /**< current position in the buffer */ + /** start with non-blocking transfers to support startup-time printouts + */ + inline static size_t pc_sync_ + = LOGGER_SYNC_OUT; /**< terminal synchronization state */ + inline static LoggerImpl + impl_; /**< underlying trasnfer implementation */ }; -/** @addtogroup logger_statics LoggerStaticMembers - * @brief member variable definition (could switch to inline statics in C++17) - * @{ - */ - -/** this needs to remain in SRAM to support startup-time printouts - */ -template -char Logger::tx_buff_[LOGGER_BUFFER]; - -/** start with non-blocking transfers to support startup-time printouts - */ -template -size_t Logger::pc_sync_ = LOGGER_SYNC_OUT; - -template -size_t Logger::tx_ptr_ = 0; - -template -LoggerImpl Logger::impl_; - -/** @} */ // end logger_statics - /** Specialization for a muted log */ template <>