From 12bc3b4fe999c15b500d1ed4acd13c7a4c1e6948 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Tue, 18 Nov 2025 20:46:16 +0100 Subject: [PATCH] Do even more examples tuning --- ...hapter03_22-001_mersenne_twister_19937.cpp | 9 +- examples/chapter09_08/build.bat | 14 +- examples/chapter09_08/build.sh | 12 +- examples/chapter09_08/chapter09_08.vcxproj | 2 + .../chapter09_08/chapter09_08.vcxproj.filters | 2 + examples/chapter09_08/src/app/led/app_led.cpp | 127 +++++++++++------- examples/chapter09_08a/build.bat | 14 +- .../chapter09_08a/src/app/led/app_led.cpp | 72 +++++----- .../chapter09_08a/src/mcal/avr/mcal_gpt.cpp | 2 +- .../src/mcal/mcal_reg_access_dynamic.h | 20 +-- .../chapter09_08a/src/util/STL/type_traits | 24 ++-- .../src/util/memory/util_placed_pointer.h | 22 +-- .../src/util/memory/util_static_allocator.h | 58 ++++---- .../chapter09_08b/src/app/led/app_led.cpp | 74 +++++----- .../src/mcal/mcal_reg_access_dynamic.h | 20 +-- .../src/mcal/stm32f100/mcal_irq.h | 2 +- .../src/mcal/stm32f100/mcal_port.cpp | 2 +- .../src/mcal/stm32f100/mcal_pwm.cpp | 2 +- .../chapter09_08b/src/util/STL/type_traits | 24 ++-- .../src/util/memory/util_placed_pointer.h | 22 +-- .../src/util/memory/util_static_allocator.h | 58 ++++---- ref_app/src/mcal/avr/mcal_benchmark.h | 6 +- ref_app/src/mcal/avr/mcal_cpu.h | 2 +- ref_app/src/mcal/avr/mcal_gpt.cpp | 2 +- ref_app/src/mcal/avr/mcal_irq.h | 4 +- ref_app/src/mcal/mcal_gcc_cxx_completion.cpp | 2 +- ref_app/src/mcal/stm32f100/mcal_benchmark.h | 8 +- ref_app/src/mcal/stm32f100/mcal_cpu.cpp | 4 +- ref_app/src/mcal/stm32f100/mcal_irq.cpp | 4 +- ref_app/src/mcal/stm32f100/mcal_irq.h | 17 +-- ref_app/src/mcal/stm32f100/mcal_led.cpp | 4 +- ref_app/src/mcal/stm32f100/mcal_led.h | 10 +- .../src/mcal/stm32f100/mcal_memory_progmem.h | 8 +- ref_app/src/mcal/stm32f100/mcal_osc.h | 13 +- ref_app/src/mcal/stm32f100/mcal_port.cpp | 6 +- ref_app/src/mcal/stm32f100/mcal_port.h | 25 ++-- ref_app/src/mcal/stm32f100/mcal_pwm.cpp | 4 +- ref_app/src/mcal/stm32f100/mcal_pwm.h | 14 +- ref_app/src/mcal/stm32f100/mcal_reg.h | 8 +- ref_app/src/mcal/stm32f100/mcal_ser.h | 12 +- ref_app/src/mcal/stm32f100/mcal_spi.cpp | 6 +- ref_app/src/mcal/stm32f100/mcal_spi.h | 14 +- ref_app/src/mcal/stm32f100/mcal_wdg.h | 6 +- .../stm32f100/startup/crt0_init_ram.cpp | 12 ++ 44 files changed, 414 insertions(+), 359 deletions(-) diff --git a/code_snippets/chapter03/chapter03_22-001_mersenne_twister_19937.cpp b/code_snippets/chapter03/chapter03_22-001_mersenne_twister_19937.cpp index 471edb86b..6ac1a2a48 100644 --- a/code_snippets/chapter03/chapter03_22-001_mersenne_twister_19937.cpp +++ b/code_snippets/chapter03/chapter03_22-001_mersenne_twister_19937.cpp @@ -15,6 +15,9 @@ #include #include +template +auto do_something() -> void; + template auto do_something() -> void { @@ -61,6 +64,8 @@ auto do_something() -> void std::cout << strm.str() << std::endl; } +auto main() -> int; + auto main() -> int { // Generate 8 sequences of 3 pseudo-random numbers. @@ -77,8 +82,8 @@ auto main() -> int // Generate 8 sequences of 3 pseudo-random numbers. for(std::uint_fast8_t i = { UINT8_C(0) }; i < std::uint_fast8_t { UINT8_C(8) }; ++i) { - // For std::mt19937_64. - using eng64_type = std::mt19937_64; + // For std::mt19937_64. + using eng64_type = std::mt19937_64; do_something(); } diff --git a/examples/chapter09_08/build.bat b/examples/chapter09_08/build.bat index feff714bf..1c08c13fb 100644 --- a/examples/chapter09_08/build.bat +++ b/examples/chapter09_08/build.bat @@ -12,22 +12,22 @@ @rem build.bat directory_of_gcc_bin prefix_of_avr_gcc @rem Usage example A, -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" -@rem build.bat "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" +@rem build.bat "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr @rem Usage example A1 (use a relative tool path), -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" -@rem build.bat ".\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" +@rem build.bat ".\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr @rem Usage example B, -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" -@rem build.bat "C:\Program Files (x86)\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08" +@rem build.bat "C:\Program Files (x86)\gcc-15.1.0-avr\bin" avr @set TOOL_PATH=%1 @set TOOL_PREFIX=%2 -@set CFLAGS=-Wall -Wextra -Wpedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions +@set CFLAGS=-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -fno-exceptions @set CPPFLAGS=-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs @set CINCLUDES=-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr diff --git a/examples/chapter09_08/build.sh b/examples/chapter09_08/build.sh index d3b2e8246..a47477c3d 100755 --- a/examples/chapter09_08/build.sh +++ b/examples/chapter09_08/build.sh @@ -12,7 +12,7 @@ # # If command # /usr/bin/avr-g++ -# installed, e.g. via command apt-get install gcc-avr avr-libc +# installed, e.g. via command sudo apt-get install gcc-avr avr-libc # then: # ./build.sh # @@ -23,11 +23,11 @@ # # Usage example A (from *nix shell) # cd /usr/local/real-time-cpp/examples/chapter09_08 -# ./build.sh /usr/local/real-time-cpp/examples/chapter09_08/tools/Util/MinGW/msys/1.0/local/gcc-9.2.0-avr/bin avr +# ./build.sh /usr/local/real-time-cpp/examples/chapter09_08a/tools/Util/msys64/usr/local/gcc-15.1.0-avr/bin avr # Usage example B (from Win* shell such as in Git for Win*) -# cd C:/Users/User/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08 -# ./build.sh C:/Users/User/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08/tools/Util/MinGW/msys/1.0/local/gcc-9.2.0-avr/bin avr +# cd C:/Users/ckorm/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08 +# ./build.sh C:/Users/ckorm/Documents/Ks/uC_Software/Boards/real-time-cpp/examples/chapter09_08/tools/Util/msys64/usr/local/gcc-15.1.0-avr/bin avr if [[ $# == 0 ]]; then ## $# is the number of arguments if [[ -n "$(which avr-g++)" ]]; then ## -n tests if string is not empty @@ -47,9 +47,9 @@ else TOOL_PREFIX="$2" fi -CFLAGS="-Wall -Wextra -pedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions -gdwarf-2 -ffunction-sections -fdata-sections" +CFLAGS="-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -finline-functions -finline-limit=64 -fno-exceptions -gdwarf-2 -ffunction-sections -fdata-sections" CPPFLAGS="-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs" -CINCLUDES="-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr" +CINCLUDES="-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc/mcal/avr -Isrc" echo echo "Building with : build.sh" diff --git a/examples/chapter09_08/chapter09_08.vcxproj b/examples/chapter09_08/chapter09_08.vcxproj index b098befcb..6e91d290a 100644 --- a/examples/chapter09_08/chapter09_08.vcxproj +++ b/examples/chapter09_08/chapter09_08.vcxproj @@ -320,6 +320,8 @@ + + true true diff --git a/examples/chapter09_08/chapter09_08.vcxproj.filters b/examples/chapter09_08/chapter09_08.vcxproj.filters index 08e8698a6..1f5d3f7a7 100644 --- a/examples/chapter09_08/chapter09_08.vcxproj.filters +++ b/examples/chapter09_08/chapter09_08.vcxproj.filters @@ -490,6 +490,8 @@ src\util\STL + + diff --git a/examples/chapter09_08/src/app/led/app_led.cpp b/examples/chapter09_08/src/app/led/app_led.cpp index c2eb88199..ef9ae8a91 100644 --- a/examples/chapter09_08/src/app/led/app_led.cpp +++ b/examples/chapter09_08/src/app/led/app_led.cpp @@ -1,97 +1,128 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2018. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#include - #include #include #include +#include +#include + namespace app { namespace led { - void task_init(); - void task_func(); + auto task_init() -> void; + auto task_func() -> void; } } -namespace +auto app::led::task_init() -> void { - using app_led_monochrome_timer_type = util::timer; - using app_led_rgb_timer_type = util::timer; - - app_led_monochrome_timer_type app_led_monochrome_timer(app_led_monochrome_timer_type::seconds(1U)); - app_led_rgb_timer_type app_led_rgb_timer (app_led_rgb_timer_type::milliseconds(20U)); + mcal::led::led_monochrome0().on(); - std::uint_fast8_t app_led_hue_r = UINT8_C(255); - std::uint_fast8_t app_led_hue_g; - std::uint_fast8_t app_led_hue_b; + mcal::led::led_rgb0().set_color(UINT8_C(255), UINT8_C(0), UINT8_C(0)); } -void app::led::task_init() +auto app::led::task_func() -> void { - mcal::led::led_monochrome0().on(); + using app_led_monochrome_timer_type = util::timer; - mcal::led::led_rgb0().set_color(app_led_hue_r, - app_led_hue_g, - app_led_hue_b); -} + static app_led_monochrome_timer_type app_led_monochrome_timer { app_led_monochrome_timer_type::seconds(UINT8_C(1)) }; -void app::led::task_func() -{ if(app_led_monochrome_timer.timeout()) { // Toggle the monochrome user LED at 1/2 Hz. mcal::led::led_monochrome0().toggle(); - // Start the next timer interval for the monochrome user LED. + // Start the next 1s timer interval for the monochrome user LED. app_led_monochrome_timer.start_interval(app_led_monochrome_timer_type::seconds(1U)); } + // Define the color transition states. + enum class color_transition_type + { + red_to_yellow, + yellow_to_green, + green_to_cyan, + cyan_to_blue, + blue_to_magenta, + magenta_to_red + }; + + using app_led_rgb_timer_type = util::timer; + + static app_led_rgb_timer_type app_led_rgb_timer { app_led_rgb_timer_type::milliseconds(UINT8_C(30)) }; + if(app_led_rgb_timer.timeout()) { - // Animate the RGB LED with the colors of the spectrum at 50 Hz. + // Initialize the color hues. + static std::uint_fast8_t app_led_hue_r { UINT8_C(255) }; + static std::uint_fast8_t app_led_hue_g { UINT8_C(0) }; + static std::uint_fast8_t app_led_hue_b { UINT8_C(0) }; + + // Initialize the color transition state. + static color_transition_type color_transition_state { color_transition_type::red_to_yellow }; + + // Animate the RGB LED with the colors of the spectrum. + + const auto rgb_hue_sum = + static_cast + ( + static_cast(app_led_hue_r) + + static_cast(app_led_hue_g) + + static_cast(app_led_hue_b) + ); - // Define the color transition states. - typedef enum color_transition_enum + const bool rgb_hue_sum_is_in_bump_range { - red_to_yellow, - yellow_to_green, - green_to_cyan, - cyan_to_blue, - blue_to_magenta, - magenta_to_red + (rgb_hue_sum >= std::uint_fast16_t { UINT16_C(250) }) + && (rgb_hue_sum <= std::uint_fast16_t { UINT16_C(260) }) + }; + + const bool rgb_hue_is_near_bump_point + { + ((app_led_hue_r > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_g > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_b > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + }; + + unsigned color_persist_time { UINT8_C(30) }; + + if(rgb_hue_is_near_bump_point) + { + const auto delta_bump_point = std::abs(static_cast(rgb_hue_sum) - static_cast(INT16_C(255))); + + if (delta_bump_point == int { INT8_C(0) }) { color_persist_time = unsigned { UINT16_C(600) }; } + else if(delta_bump_point == int { INT8_C(1) }) { color_persist_time = unsigned { UINT16_C(500) }; } + else if(delta_bump_point == int { INT8_C(2) }) { color_persist_time = unsigned { UINT16_C(400) }; } + else if(delta_bump_point == int { INT8_C(3) }) { color_persist_time = unsigned { UINT16_C(300) }; } + else if(delta_bump_point == int { INT8_C(4) }) { color_persist_time = unsigned { UINT16_C(200) }; } + else { color_persist_time = unsigned { UINT16_C(100) }; } } - color_transition_type; - // Initialize the color transition state. - static color_transition_type color_transition_state = red_to_yellow; + // Make a smooth color transition and increment the color + // transition state if necessary. - // Make a smooth color transition and - // increment the color transition state - // if necessary. switch(color_transition_state) { - case red_to_yellow: { if(++app_led_hue_g == UINT8_C(255)) { color_transition_state = yellow_to_green; } } break; - case yellow_to_green: { if(--app_led_hue_r == UINT8_C( 0)) { color_transition_state = green_to_cyan; } } break; - case green_to_cyan: { if(++app_led_hue_b == UINT8_C(255)) { color_transition_state = cyan_to_blue; } } break; - case cyan_to_blue: { if(--app_led_hue_g == UINT8_C( 0)) { color_transition_state = blue_to_magenta; } } break; - case blue_to_magenta: { if(++app_led_hue_r == UINT8_C(255)) { color_transition_state = magenta_to_red; } } break; + case color_transition_type::red_to_yellow: { if(++app_led_hue_g == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::yellow_to_green; } } break; + case color_transition_type::yellow_to_green: { if(--app_led_hue_r == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::green_to_cyan; } } break; + case color_transition_type::green_to_cyan: { if(++app_led_hue_b == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::cyan_to_blue; } } break; + case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::blue_to_magenta; } } break; + case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::magenta_to_red; } } break; default: - case magenta_to_red: { if(--app_led_hue_b == UINT8_C( 0)) { color_transition_state = red_to_yellow; } } break; + case color_transition_type::magenta_to_red: { if(--app_led_hue_b == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::red_to_yellow; } } break; } // Write the next color to the RGB LED. - mcal::led::led_rgb0().set_color(app_led_hue_r, - app_led_hue_g, - app_led_hue_b); + mcal::led::led_rgb0().set_color(app_led_hue_r, app_led_hue_g, app_led_hue_b); // Start the next timer interval for the RGB LED. - app_led_rgb_timer.start_interval(app_led_rgb_timer_type::milliseconds(20U)); + app_led_rgb_timer.start_interval(app_led_rgb_timer_type::milliseconds(color_persist_time)); } } diff --git a/examples/chapter09_08a/build.bat b/examples/chapter09_08a/build.bat index a53396a57..ec2353c3c 100644 --- a/examples/chapter09_08a/build.bat +++ b/examples/chapter09_08a/build.bat @@ -12,22 +12,22 @@ @rem build.bat directory_of_gcc_bin prefix_of_avr_gcc @rem Usage example A, -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" -@rem build.bat "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" +@rem build.bat "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr @rem Usage example A1 (use a relative tool path), -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" -@rem build.bat ".\tools\Util\msys64\usr\local\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" +@rem build.bat ".\tools\Util\msys64\usr\local\gcc-15.1.0-avr\bin" avr @rem Usage example B, -@rem cd "C:\Users\User\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" -@rem build.bat "C:\Program Files (x86)\gcc-11.2.0-avr\bin" avr +@rem cd "C:\Users\ckorm\Documents\Ks\uC_Software\Boards\real-time-cpp\examples\chapter09_08a" +@rem build.bat "C:\Program Files (x86)\gcc-15.1.0-avr\bin" avr @set TOOL_PATH=%1 @set TOOL_PREFIX=%2 -@set CFLAGS=-Wall -Wextra -Wpedantic -mmcu=atmega328p -fsigned-char -O2 -fno-exceptions +@set CFLAGS=-Wall -Wextra -Wpedantic -O2 -mmcu=atmega328p -fsigned-char -fno-exceptions @set CPPFLAGS=-std=c++14 -fno-rtti -fstrict-enums -fno-use-cxa-atexit -fno-use-cxa-get-exception-ptr -fno-nonansi-builtins -fno-threadsafe-statics -fno-enforce-eh-specs @set CINCLUDES=-Isrc/util/STL_C++XX_stdfloat -Isrc/util/STL -Isrc -Isrc/mcal/avr diff --git a/examples/chapter09_08a/src/app/led/app_led.cpp b/examples/chapter09_08a/src/app/led/app_led.cpp index d6d7b6c3b..7427b96b6 100644 --- a/examples/chapter09_08a/src/app/led/app_led.cpp +++ b/examples/chapter09_08a/src/app/led/app_led.cpp @@ -31,14 +31,8 @@ auto app::led::task_init() -> void auto app::led::task_func() -> void { using app_led_monochrome_timer_type = util::timer; - using app_led_rgb_timer_type = util::timer; - static auto app_led_monochrome_timer = static_cast(app_led_monochrome_timer_type::seconds(UINT8_C(1))); - static auto app_led_rgb_timer = static_cast(app_led_rgb_timer_type::milliseconds(UINT8_C(30))); - - static std::uint_fast8_t app_led_hue_r { UINT8_C(255) }; - static std::uint_fast8_t app_led_hue_g { UINT8_C(0) }; - static std::uint_fast8_t app_led_hue_b { UINT8_C(0) }; + static app_led_monochrome_timer_type app_led_monochrome_timer { app_led_monochrome_timer_type::seconds(UINT8_C(1)) }; if(app_led_monochrome_timer.timeout()) { @@ -60,16 +54,21 @@ auto app::led::task_func() -> void magenta_to_red }; + using app_led_rgb_timer_type = util::timer; - // Initialize the color transition state. - static auto color_transition_state = color_transition_type::red_to_yellow; + static app_led_rgb_timer_type app_led_rgb_timer { app_led_rgb_timer_type::milliseconds(UINT8_C(30)) }; if(app_led_rgb_timer.timeout()) { - // Animate the RGB LED with the colors of the spectrum. + // Initialize the color hues. + static std::uint_fast8_t app_led_hue_r { UINT8_C(255) }; + static std::uint_fast8_t app_led_hue_g { UINT8_C(0) }; + static std::uint_fast8_t app_led_hue_b { UINT8_C(0) }; - // Implement the enhanced RGB-color-light-show mentioned - // in the readme markdown of this example. + // Initialize the color transition state. + static color_transition_type color_transition_state { color_transition_type::red_to_yellow }; + + // Animate the RGB LED with the colors of the spectrum. const auto rgb_hue_sum = static_cast @@ -79,18 +78,18 @@ auto app::led::task_func() -> void + static_cast(app_led_hue_b) ); - const auto rgb_hue_sum_is_in_bump_range = - ( - (rgb_hue_sum >= static_cast(UINT16_C(250))) - && (rgb_hue_sum <= static_cast(UINT16_C(260))) - ); + const bool rgb_hue_sum_is_in_bump_range + { + (rgb_hue_sum >= std::uint_fast16_t { UINT16_C(250) }) + && (rgb_hue_sum <= std::uint_fast16_t { UINT16_C(260) }) + }; - const auto rgb_hue_is_near_bump_point = - ( - ((app_led_hue_r > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - || ((app_led_hue_g > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - || ((app_led_hue_b > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - ); + const bool rgb_hue_is_near_bump_point + { + ((app_led_hue_r > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_g > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_b > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + }; unsigned color_persist_time { UINT8_C(30) }; @@ -98,23 +97,24 @@ auto app::led::task_func() -> void { const auto delta_bump_point = std::abs(static_cast(rgb_hue_sum) - static_cast(INT16_C(255))); - if (delta_bump_point == static_cast(INT8_C(0))) { color_persist_time = static_cast(UINT16_C(600)); } - else if(delta_bump_point == static_cast(INT8_C(1))) { color_persist_time = static_cast(UINT16_C(500)); } - else if(delta_bump_point == static_cast(INT8_C(2))) { color_persist_time = static_cast(UINT16_C(400)); } - else if(delta_bump_point == static_cast(INT8_C(3))) { color_persist_time = static_cast(UINT16_C(300)); } - else if(delta_bump_point == static_cast(INT8_C(4))) { color_persist_time = static_cast(UINT16_C(200)); } - else { color_persist_time = static_cast(UINT16_C(100)); } + if (delta_bump_point == int { INT8_C(0) }) { color_persist_time = unsigned { UINT16_C(600) }; } + else if(delta_bump_point == int { INT8_C(1) }) { color_persist_time = unsigned { UINT16_C(500) }; } + else if(delta_bump_point == int { INT8_C(2) }) { color_persist_time = unsigned { UINT16_C(400) }; } + else if(delta_bump_point == int { INT8_C(3) }) { color_persist_time = unsigned { UINT16_C(300) }; } + else if(delta_bump_point == int { INT8_C(4) }) { color_persist_time = unsigned { UINT16_C(200) }; } + else { color_persist_time = unsigned { UINT16_C(100) }; } } - // Make a smooth color transition and increment the color transition state - // if necessary. + // Make a smooth color transition and increment the color + // transition state if necessary. + switch(color_transition_state) { - case color_transition_type::red_to_yellow: { if(++app_led_hue_g == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::yellow_to_green; } } break; - case color_transition_type::yellow_to_green: { if(--app_led_hue_r == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::green_to_cyan; } } break; - case color_transition_type::green_to_cyan: { if(++app_led_hue_b == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::cyan_to_blue; } } break; - case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::blue_to_magenta; } } break; - case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::magenta_to_red; } } break; + case color_transition_type::red_to_yellow: { if(++app_led_hue_g == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::yellow_to_green; } } break; + case color_transition_type::yellow_to_green: { if(--app_led_hue_r == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::green_to_cyan; } } break; + case color_transition_type::green_to_cyan: { if(++app_led_hue_b == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::cyan_to_blue; } } break; + case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::blue_to_magenta; } } break; + case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::magenta_to_red; } } break; default: case color_transition_type::magenta_to_red: { if(--app_led_hue_b == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::red_to_yellow; } } break; } diff --git a/examples/chapter09_08a/src/mcal/avr/mcal_gpt.cpp b/examples/chapter09_08a/src/mcal/avr/mcal_gpt.cpp index 1c715a12b..d55060b24 100644 --- a/examples/chapter09_08a/src/mcal/avr/mcal_gpt.cpp +++ b/examples/chapter09_08a/src/mcal/avr/mcal_gpt.cpp @@ -30,7 +30,7 @@ auto __vector_16() -> void ATTRIBUTE(signal, used, externally_visible); auto __vector_16() -> void { - // Increment the 32-bit system tick with 0x100, representing 256 [(1/2) us]. + // Increment the 64-bit system tick with 0x100, representing 256 [(1/2) us]. // This is basically the roll-over of the 8-bit timer0 at 2MHz each 128us. const auto new_tick = diff --git a/examples/chapter09_08a/src/mcal/mcal_reg_access_dynamic.h b/examples/chapter09_08a/src/mcal/mcal_reg_access_dynamic.h index 3bc3cf54b..db1195c93 100644 --- a/examples/chapter09_08a/src/mcal/mcal_reg_access_dynamic.h +++ b/examples/chapter09_08a/src/mcal/mcal_reg_access_dynamic.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2013 - 2024. +// Copyright Christopher Kormanyos 2013 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -25,18 +25,18 @@ using register_value_type = RegisterValueType; static auto reg_get(const register_address_type address) -> register_value_type { return *reinterpret_cast(address); } - static auto reg_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = value; } - static auto reg_and(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & value); } - static auto reg_or (const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa | value); } - static auto reg_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & static_cast(~value)); } + static auto reg_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = value; } + static auto reg_and(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & value); } + static auto reg_or (const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr | value); } + static auto reg_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & static_cast(~value)); } static auto reg_msk(const register_address_type address, const register_value_type value, const register_value_type mask_value) -> void { - volatile register_value_type* pa = reinterpret_cast(address); + volatile register_value_type* p_addr = reinterpret_cast(address); - *pa = + *p_addr = static_cast ( static_cast(reg_get(address) & static_cast(~mask_value)) @@ -44,9 +44,9 @@ ); } - static auto bit_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa | static_cast(1UL << value)); } - static auto bit_clr(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & static_cast(~static_cast(1UL << value))); } - static auto bit_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa ^ static_cast(1UL << value)); } + static auto bit_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr | static_cast(1UL << value)); } + static auto bit_clr(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & static_cast(~static_cast(1UL << value))); } + static auto bit_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr ^ static_cast(1UL << value)); } static auto bit_get(const register_address_type address, const register_value_type value) -> bool { return (static_cast(reg_get(address) & static_cast(1UL << value)) != static_cast(0U)); } }; } diff --git a/examples/chapter09_08a/src/util/STL/type_traits b/examples/chapter09_08a/src/util/STL/type_traits index 7c9d8caa4..81529d10a 100644 --- a/examples/chapter09_08a/src/util/STL/type_traits +++ b/examples/chapter09_08a/src/util/STL/type_traits @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2013 - 2022. +// Copyright Christopher Kormanyos 2013 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef TYPE_TRAITS_2013_09_01_ - #define TYPE_TRAITS_2013_09_01_ +#ifndef TYPE_TRAITS_2013_09_01 + #define TYPE_TRAITS_2013_09_01 #include #include @@ -296,7 +296,7 @@ }; template - using void_t = void; + using void_t = void; // primary template (used for zero types) template @@ -304,7 +304,7 @@ // 1 type template - struct common_type : common_type {}; + struct common_type : common_type { }; // 2 types template @@ -335,7 +335,7 @@ struct common_type : common_type_multi_impl {}; } - #if(__cplusplus >= 201703L) + #if (defined(__cplusplus) && (__cplusplus >= 201703L)) // C++17 and later namespace std { @@ -353,7 +353,7 @@ } #endif - #if(__cplusplus > 202002L) + #if (defined(__cplusplus) && (__cplusplus > 202002L)) // C++20 and later namespace std { @@ -394,7 +394,7 @@ struct no_type { - char padding[8]; + char padding[std::size_t { UINT8_C(8) }]; }; struct is_constructible_imp @@ -419,14 +419,14 @@ struct ok_tag { double d; char c[N]; }; template - ok_tag check_is_complete(int); + ok_tag(sizeof(T))> check_is_complete(int); template char check_is_complete(...); struct is_default_constructible_imp { - template + template static traits_helper::yes_type test(int); template @@ -440,7 +440,7 @@ template static traits_helper::no_type test(...); }; - } + } // namespace traits_helper namespace std { @@ -501,4 +501,4 @@ template struct is_constructible : public is_default_constructible { }; } -#endif // TYPE_TRAITS_2013_09_01_ +#endif // TYPE_TRAITS_2013_09_01 diff --git a/examples/chapter09_08a/src/util/memory/util_placed_pointer.h b/examples/chapter09_08a/src/util/memory/util_placed_pointer.h index bc933ca3b..4c1a69bba 100644 --- a/examples/chapter09_08a/src/util/memory/util_placed_pointer.h +++ b/examples/chapter09_08a/src/util/memory/util_placed_pointer.h @@ -1,26 +1,26 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef UTIL_PLACED_PTR_2010_02_23_H_ - #define UTIL_PLACED_PTR_2010_02_23_H_ +#ifndef UTIL_PLACED_PTR_2010_02_23_H + #define UTIL_PLACED_PTR_2010_02_23_H + + #include #include #include - #include - namespace util { template class placed_ptr : private util::noncopyable { public: - typedef T value_type; - typedef value_type* pointer; + using value_type = T; + using pointer = value_type*; placed_ptr() { @@ -38,17 +38,17 @@ my_ptr()->~value_type(); } - pointer operator->() const { return my_ptr(); } - pointer get() { return my_ptr(); } + auto operator->() const -> pointer { return my_ptr(); } + auto get() -> pointer { return my_ptr(); } private: std::uint8_t my_buf[sizeof(T)]; - pointer my_ptr() const + auto my_ptr() const -> pointer { return reinterpret_cast(const_cast(static_cast(my_buf))); } }; } -#endif // UTIL_PLACED_PTR_2010_02_23_H_ +#endif // UTIL_PLACED_PTR_2010_02_23_H diff --git a/examples/chapter09_08a/src/util/memory/util_static_allocator.h b/examples/chapter09_08a/src/util/memory/util_static_allocator.h index 29ed13a29..6d30b80ad 100644 --- a/examples/chapter09_08a/src/util/memory/util_static_allocator.h +++ b/examples/chapter09_08a/src/util/memory/util_static_allocator.h @@ -5,21 +5,21 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef UTIL_STATIC_ALLOCATOR_2010_02_23_H_ - #define UTIL_STATIC_ALLOCATOR_2010_02_23_H_ +#ifndef UTIL_STATIC_ALLOCATOR_2010_02_23_H + #define UTIL_STATIC_ALLOCATOR_2010_02_23_H + + #include #include #include #include - #include - namespace util { class static_allocator_base { public: - typedef std::size_t size_type; + using size_type = std::size_t; virtual ~static_allocator_base() = default; @@ -31,7 +31,7 @@ // The static allocator's buffer type. struct buffer_type { - static constexpr size_type size = 640U; + static constexpr size_type size { UINT16_C(640) }; std::uint8_t data[size]; @@ -40,9 +40,9 @@ // The static allocator's memory allocation. template - static void* do_allocate(size_type chunk_size, - size_type& remaining, - bool& is_overflow) + static auto do_allocate(size_type chunk_size, + size_type& remaining, + bool& is_overflow) -> void* { ALIGNAS(16) static buffer_type buffer; @@ -89,14 +89,14 @@ }; // Global comparison operators (required by the standard). - inline bool operator==(const static_allocator_base&, - const static_allocator_base&) + inline auto operator==(const static_allocator_base&, + const static_allocator_base&) -> bool { return true; } - inline bool operator!=(const static_allocator_base&, - const static_allocator_base&) + inline auto operator!=(const static_allocator_base&, + const static_allocator_base&) -> bool { return false; } @@ -109,9 +109,9 @@ class static_allocator : public static_allocator_base { public: - typedef void value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; + using value_type = void; + using pointer = value_type*; + using const_pointer = const value_type*; template struct rebind @@ -128,11 +128,11 @@ static_assert(sizeof(T) <= buffer_type::size, "The size of the allocation object can not exceed the buffer size."); - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; + using value_type = T; + using pointer = value_type*; + using const_pointer = const value_type*; + using reference = value_type&; + using const_reference = const value_type&; static_allocator() = default; @@ -147,7 +147,7 @@ using other = static_allocator; }; - size_type max_size() const + auto max_size() const -> size_type { size_type remaining; bool is_overflow; @@ -162,11 +162,11 @@ return remaining / sizeof(value_type); } - pointer address( reference x) const { return &x; } - const_pointer address(const_reference x) const { return &x; } + auto address( reference x) const -> pointer { return &x; } + auto address(const_reference x) const -> const_pointer { return &x; } - pointer allocate(size_type count, - typename static_allocator::const_pointer = nullptr) + auto allocate(size_type count, + typename static_allocator::const_pointer = nullptr) -> pointer { const size_type chunk_size = count * sizeof(value_type); @@ -183,15 +183,15 @@ return static_cast(p); } - void construct(pointer p, const value_type& x) + auto construct(pointer p, const value_type& x) -> void { new(static_cast(p)) value_type(x); } - void destroy(pointer p) { p->~value_type(); } + auto destroy(pointer p) -> void { p->~value_type(); } void deallocate(pointer, size_type) { } }; } -#endif // UTIL_STATIC_ALLOCATOR_2010_02_23_H_ +#endif // UTIL_STATIC_ALLOCATOR_2010_02_23_H diff --git a/examples/chapter09_08b/src/app/led/app_led.cpp b/examples/chapter09_08b/src/app/led/app_led.cpp index d6d7b6c3b..7527079da 100644 --- a/examples/chapter09_08b/src/app/led/app_led.cpp +++ b/examples/chapter09_08b/src/app/led/app_led.cpp @@ -31,21 +31,15 @@ auto app::led::task_init() -> void auto app::led::task_func() -> void { using app_led_monochrome_timer_type = util::timer; - using app_led_rgb_timer_type = util::timer; - static auto app_led_monochrome_timer = static_cast(app_led_monochrome_timer_type::seconds(UINT8_C(1))); - static auto app_led_rgb_timer = static_cast(app_led_rgb_timer_type::milliseconds(UINT8_C(30))); - - static std::uint_fast8_t app_led_hue_r { UINT8_C(255) }; - static std::uint_fast8_t app_led_hue_g { UINT8_C(0) }; - static std::uint_fast8_t app_led_hue_b { UINT8_C(0) }; + static app_led_monochrome_timer_type app_led_monochrome_timer { app_led_monochrome_timer_type::seconds(UINT8_C(1)) }; if(app_led_monochrome_timer.timeout()) { // Toggle the monochrome user LED at 1/2 Hz. mcal::led::led0().toggle(); - // Start the next timer interval for the monochrome user LED. + // Start the next 1s timer interval for the monochrome user LED. app_led_monochrome_timer.start_interval(app_led_monochrome_timer_type::seconds(1U)); } @@ -60,16 +54,21 @@ auto app::led::task_func() -> void magenta_to_red }; + using app_led_rgb_timer_type = util::timer; - // Initialize the color transition state. - static auto color_transition_state = color_transition_type::red_to_yellow; + static app_led_rgb_timer_type app_led_rgb_timer { app_led_rgb_timer_type::milliseconds(UINT8_C(30)) }; if(app_led_rgb_timer.timeout()) { - // Animate the RGB LED with the colors of the spectrum. + // Initialize the color hues. + static std::uint_fast8_t app_led_hue_r { UINT8_C(255) }; + static std::uint_fast8_t app_led_hue_g { UINT8_C(0) }; + static std::uint_fast8_t app_led_hue_b { UINT8_C(0) }; - // Implement the enhanced RGB-color-light-show mentioned - // in the readme markdown of this example. + // Initialize the color transition state. + static color_transition_type color_transition_state { color_transition_type::red_to_yellow }; + + // Animate the RGB LED with the colors of the spectrum. const auto rgb_hue_sum = static_cast @@ -79,18 +78,18 @@ auto app::led::task_func() -> void + static_cast(app_led_hue_b) ); - const auto rgb_hue_sum_is_in_bump_range = - ( - (rgb_hue_sum >= static_cast(UINT16_C(250))) - && (rgb_hue_sum <= static_cast(UINT16_C(260))) - ); + const bool rgb_hue_sum_is_in_bump_range + { + (rgb_hue_sum >= std::uint_fast16_t { UINT16_C(250) }) + && (rgb_hue_sum <= std::uint_fast16_t { UINT16_C(260) }) + }; - const auto rgb_hue_is_near_bump_point = - ( - ((app_led_hue_r > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - || ((app_led_hue_g > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - || ((app_led_hue_b > static_cast(UINT8_C(250))) && rgb_hue_sum_is_in_bump_range) - ); + const bool rgb_hue_is_near_bump_point + { + ((app_led_hue_r > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_g > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + || ((app_led_hue_b > std::uint_fast8_t { UINT8_C(250) }) && rgb_hue_sum_is_in_bump_range) + }; unsigned color_persist_time { UINT8_C(30) }; @@ -98,23 +97,24 @@ auto app::led::task_func() -> void { const auto delta_bump_point = std::abs(static_cast(rgb_hue_sum) - static_cast(INT16_C(255))); - if (delta_bump_point == static_cast(INT8_C(0))) { color_persist_time = static_cast(UINT16_C(600)); } - else if(delta_bump_point == static_cast(INT8_C(1))) { color_persist_time = static_cast(UINT16_C(500)); } - else if(delta_bump_point == static_cast(INT8_C(2))) { color_persist_time = static_cast(UINT16_C(400)); } - else if(delta_bump_point == static_cast(INT8_C(3))) { color_persist_time = static_cast(UINT16_C(300)); } - else if(delta_bump_point == static_cast(INT8_C(4))) { color_persist_time = static_cast(UINT16_C(200)); } - else { color_persist_time = static_cast(UINT16_C(100)); } + if (delta_bump_point == int { INT8_C(0) }) { color_persist_time = unsigned { UINT16_C(600) }; } + else if(delta_bump_point == int { INT8_C(1) }) { color_persist_time = unsigned { UINT16_C(500) }; } + else if(delta_bump_point == int { INT8_C(2) }) { color_persist_time = unsigned { UINT16_C(400) }; } + else if(delta_bump_point == int { INT8_C(3) }) { color_persist_time = unsigned { UINT16_C(300) }; } + else if(delta_bump_point == int { INT8_C(4) }) { color_persist_time = unsigned { UINT16_C(200) }; } + else { color_persist_time = unsigned { UINT16_C(100) }; } } - // Make a smooth color transition and increment the color transition state - // if necessary. + // Make a smooth color transition and increment the color + // transition state if necessary. + switch(color_transition_state) { - case color_transition_type::red_to_yellow: { if(++app_led_hue_g == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::yellow_to_green; } } break; - case color_transition_type::yellow_to_green: { if(--app_led_hue_r == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::green_to_cyan; } } break; - case color_transition_type::green_to_cyan: { if(++app_led_hue_b == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::cyan_to_blue; } } break; - case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::blue_to_magenta; } } break; - case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == static_cast(UINT8_C(255))) { color_transition_state = color_transition_type::magenta_to_red; } } break; + case color_transition_type::red_to_yellow: { if(++app_led_hue_g == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::yellow_to_green; } } break; + case color_transition_type::yellow_to_green: { if(--app_led_hue_r == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::green_to_cyan; } } break; + case color_transition_type::green_to_cyan: { if(++app_led_hue_b == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::cyan_to_blue; } } break; + case color_transition_type::cyan_to_blue: { if(--app_led_hue_g == std::uint_fast8_t { UINT8_C( 0) }) { color_transition_state = color_transition_type::blue_to_magenta; } } break; + case color_transition_type::blue_to_magenta: { if(++app_led_hue_r == std::uint_fast8_t { UINT8_C(255) }) { color_transition_state = color_transition_type::magenta_to_red; } } break; default: case color_transition_type::magenta_to_red: { if(--app_led_hue_b == static_cast(UINT8_C( 0))) { color_transition_state = color_transition_type::red_to_yellow; } } break; } diff --git a/examples/chapter09_08b/src/mcal/mcal_reg_access_dynamic.h b/examples/chapter09_08b/src/mcal/mcal_reg_access_dynamic.h index 3bc3cf54b..db1195c93 100644 --- a/examples/chapter09_08b/src/mcal/mcal_reg_access_dynamic.h +++ b/examples/chapter09_08b/src/mcal/mcal_reg_access_dynamic.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2013 - 2024. +// Copyright Christopher Kormanyos 2013 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -25,18 +25,18 @@ using register_value_type = RegisterValueType; static auto reg_get(const register_address_type address) -> register_value_type { return *reinterpret_cast(address); } - static auto reg_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = value; } - static auto reg_and(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & value); } - static auto reg_or (const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa | value); } - static auto reg_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & static_cast(~value)); } + static auto reg_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = value; } + static auto reg_and(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & value); } + static auto reg_or (const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr | value); } + static auto reg_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & static_cast(~value)); } static auto reg_msk(const register_address_type address, const register_value_type value, const register_value_type mask_value) -> void { - volatile register_value_type* pa = reinterpret_cast(address); + volatile register_value_type* p_addr = reinterpret_cast(address); - *pa = + *p_addr = static_cast ( static_cast(reg_get(address) & static_cast(~mask_value)) @@ -44,9 +44,9 @@ ); } - static auto bit_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa | static_cast(1UL << value)); } - static auto bit_clr(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa & static_cast(~static_cast(1UL << value))); } - static auto bit_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* pa = reinterpret_cast(address); *pa = static_cast(*pa ^ static_cast(1UL << value)); } + static auto bit_set(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr | static_cast(1UL << value)); } + static auto bit_clr(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr & static_cast(~static_cast(1UL << value))); } + static auto bit_not(const register_address_type address, const register_value_type value) -> void { volatile register_value_type* p_addr = reinterpret_cast(address); *p_addr = static_cast(*p_addr ^ static_cast(1UL << value)); } static auto bit_get(const register_address_type address, const register_value_type value) -> bool { return (static_cast(reg_get(address) & static_cast(1UL << value)) != static_cast(0U)); } }; } diff --git a/examples/chapter09_08b/src/mcal/stm32f100/mcal_irq.h b/examples/chapter09_08b/src/mcal/stm32f100/mcal_irq.h index 88281b9fe..09b0fcf1f 100644 --- a/examples/chapter09_08b/src/mcal/stm32f100/mcal_irq.h +++ b/examples/chapter09_08b/src/mcal/stm32f100/mcal_irq.h @@ -21,4 +21,4 @@ } } -#endif // MCAL_IRQ_2010_04_10_H_ +#endif // MCAL_IRQ_2010_04_10_H diff --git a/examples/chapter09_08b/src/mcal/stm32f100/mcal_port.cpp b/examples/chapter09_08b/src/mcal/stm32f100/mcal_port.cpp index 28a5502ac..4a927662e 100644 --- a/examples/chapter09_08b/src/mcal/stm32f100/mcal_port.cpp +++ b/examples/chapter09_08b/src/mcal/stm32f100/mcal_port.cpp @@ -11,5 +11,5 @@ auto mcal::port::init(const config_type*) -> void { // Power management: Enable power for I/O ports : porta, portb, and portc. - mcal::reg::reg_access_static::reg_or(); + mcal::reg::reg_access_static::reg_or(); } diff --git a/examples/chapter09_08b/src/mcal/stm32f100/mcal_pwm.cpp b/examples/chapter09_08b/src/mcal/stm32f100/mcal_pwm.cpp index e806a73ca..2b3bd456a 100644 --- a/examples/chapter09_08b/src/mcal/stm32f100/mcal_pwm.cpp +++ b/examples/chapter09_08b/src/mcal/stm32f100/mcal_pwm.cpp @@ -8,7 +8,7 @@ #include #include -mcal::pwm::pwm_base& mcal::pwm::pwm0() +auto mcal::pwm::pwm0() -> mcal::pwm::pwm_base& { static mcal::pwm::pwm_dummy pwm; diff --git a/examples/chapter09_08b/src/util/STL/type_traits b/examples/chapter09_08b/src/util/STL/type_traits index 7c9d8caa4..81529d10a 100644 --- a/examples/chapter09_08b/src/util/STL/type_traits +++ b/examples/chapter09_08b/src/util/STL/type_traits @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2013 - 2022. +// Copyright Christopher Kormanyos 2013 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef TYPE_TRAITS_2013_09_01_ - #define TYPE_TRAITS_2013_09_01_ +#ifndef TYPE_TRAITS_2013_09_01 + #define TYPE_TRAITS_2013_09_01 #include #include @@ -296,7 +296,7 @@ }; template - using void_t = void; + using void_t = void; // primary template (used for zero types) template @@ -304,7 +304,7 @@ // 1 type template - struct common_type : common_type {}; + struct common_type : common_type { }; // 2 types template @@ -335,7 +335,7 @@ struct common_type : common_type_multi_impl {}; } - #if(__cplusplus >= 201703L) + #if (defined(__cplusplus) && (__cplusplus >= 201703L)) // C++17 and later namespace std { @@ -353,7 +353,7 @@ } #endif - #if(__cplusplus > 202002L) + #if (defined(__cplusplus) && (__cplusplus > 202002L)) // C++20 and later namespace std { @@ -394,7 +394,7 @@ struct no_type { - char padding[8]; + char padding[std::size_t { UINT8_C(8) }]; }; struct is_constructible_imp @@ -419,14 +419,14 @@ struct ok_tag { double d; char c[N]; }; template - ok_tag check_is_complete(int); + ok_tag(sizeof(T))> check_is_complete(int); template char check_is_complete(...); struct is_default_constructible_imp { - template + template static traits_helper::yes_type test(int); template @@ -440,7 +440,7 @@ template static traits_helper::no_type test(...); }; - } + } // namespace traits_helper namespace std { @@ -501,4 +501,4 @@ template struct is_constructible : public is_default_constructible { }; } -#endif // TYPE_TRAITS_2013_09_01_ +#endif // TYPE_TRAITS_2013_09_01 diff --git a/examples/chapter09_08b/src/util/memory/util_placed_pointer.h b/examples/chapter09_08b/src/util/memory/util_placed_pointer.h index bc933ca3b..4c1a69bba 100644 --- a/examples/chapter09_08b/src/util/memory/util_placed_pointer.h +++ b/examples/chapter09_08b/src/util/memory/util_placed_pointer.h @@ -1,26 +1,26 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef UTIL_PLACED_PTR_2010_02_23_H_ - #define UTIL_PLACED_PTR_2010_02_23_H_ +#ifndef UTIL_PLACED_PTR_2010_02_23_H + #define UTIL_PLACED_PTR_2010_02_23_H + + #include #include #include - #include - namespace util { template class placed_ptr : private util::noncopyable { public: - typedef T value_type; - typedef value_type* pointer; + using value_type = T; + using pointer = value_type*; placed_ptr() { @@ -38,17 +38,17 @@ my_ptr()->~value_type(); } - pointer operator->() const { return my_ptr(); } - pointer get() { return my_ptr(); } + auto operator->() const -> pointer { return my_ptr(); } + auto get() -> pointer { return my_ptr(); } private: std::uint8_t my_buf[sizeof(T)]; - pointer my_ptr() const + auto my_ptr() const -> pointer { return reinterpret_cast(const_cast(static_cast(my_buf))); } }; } -#endif // UTIL_PLACED_PTR_2010_02_23_H_ +#endif // UTIL_PLACED_PTR_2010_02_23_H diff --git a/examples/chapter09_08b/src/util/memory/util_static_allocator.h b/examples/chapter09_08b/src/util/memory/util_static_allocator.h index 29ed13a29..6d30b80ad 100644 --- a/examples/chapter09_08b/src/util/memory/util_static_allocator.h +++ b/examples/chapter09_08b/src/util/memory/util_static_allocator.h @@ -5,21 +5,21 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef UTIL_STATIC_ALLOCATOR_2010_02_23_H_ - #define UTIL_STATIC_ALLOCATOR_2010_02_23_H_ +#ifndef UTIL_STATIC_ALLOCATOR_2010_02_23_H + #define UTIL_STATIC_ALLOCATOR_2010_02_23_H + + #include #include #include #include - #include - namespace util { class static_allocator_base { public: - typedef std::size_t size_type; + using size_type = std::size_t; virtual ~static_allocator_base() = default; @@ -31,7 +31,7 @@ // The static allocator's buffer type. struct buffer_type { - static constexpr size_type size = 640U; + static constexpr size_type size { UINT16_C(640) }; std::uint8_t data[size]; @@ -40,9 +40,9 @@ // The static allocator's memory allocation. template - static void* do_allocate(size_type chunk_size, - size_type& remaining, - bool& is_overflow) + static auto do_allocate(size_type chunk_size, + size_type& remaining, + bool& is_overflow) -> void* { ALIGNAS(16) static buffer_type buffer; @@ -89,14 +89,14 @@ }; // Global comparison operators (required by the standard). - inline bool operator==(const static_allocator_base&, - const static_allocator_base&) + inline auto operator==(const static_allocator_base&, + const static_allocator_base&) -> bool { return true; } - inline bool operator!=(const static_allocator_base&, - const static_allocator_base&) + inline auto operator!=(const static_allocator_base&, + const static_allocator_base&) -> bool { return false; } @@ -109,9 +109,9 @@ class static_allocator : public static_allocator_base { public: - typedef void value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; + using value_type = void; + using pointer = value_type*; + using const_pointer = const value_type*; template struct rebind @@ -128,11 +128,11 @@ static_assert(sizeof(T) <= buffer_type::size, "The size of the allocation object can not exceed the buffer size."); - typedef T value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; + using value_type = T; + using pointer = value_type*; + using const_pointer = const value_type*; + using reference = value_type&; + using const_reference = const value_type&; static_allocator() = default; @@ -147,7 +147,7 @@ using other = static_allocator; }; - size_type max_size() const + auto max_size() const -> size_type { size_type remaining; bool is_overflow; @@ -162,11 +162,11 @@ return remaining / sizeof(value_type); } - pointer address( reference x) const { return &x; } - const_pointer address(const_reference x) const { return &x; } + auto address( reference x) const -> pointer { return &x; } + auto address(const_reference x) const -> const_pointer { return &x; } - pointer allocate(size_type count, - typename static_allocator::const_pointer = nullptr) + auto allocate(size_type count, + typename static_allocator::const_pointer = nullptr) -> pointer { const size_type chunk_size = count * sizeof(value_type); @@ -183,15 +183,15 @@ return static_cast(p); } - void construct(pointer p, const value_type& x) + auto construct(pointer p, const value_type& x) -> void { new(static_cast(p)) value_type(x); } - void destroy(pointer p) { p->~value_type(); } + auto destroy(pointer p) -> void { p->~value_type(); } void deallocate(pointer, size_type) { } }; } -#endif // UTIL_STATIC_ALLOCATOR_2010_02_23_H_ +#endif // UTIL_STATIC_ALLOCATOR_2010_02_23_H diff --git a/ref_app/src/mcal/avr/mcal_benchmark.h b/ref_app/src/mcal/avr/mcal_benchmark.h index 4122c48b9..9e3d384b2 100644 --- a/ref_app/src/mcal/avr/mcal_benchmark.h +++ b/ref_app/src/mcal/avr/mcal_benchmark.h @@ -5,8 +5,8 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_BENCHMARK_2014_04_16_H_ - #define MCAL_BENCHMARK_2014_04_16_H_ +#ifndef MCAL_BENCHMARK_2014_04_16_H + #define MCAL_BENCHMARK_2014_04_16_H #include #include @@ -24,4 +24,4 @@ } } -#endif // MCAL_BENCHMARK_2014_04_16_H_ +#endif // MCAL_BENCHMARK_2014_04_16_H diff --git a/ref_app/src/mcal/avr/mcal_cpu.h b/ref_app/src/mcal/avr/mcal_cpu.h index d5eeb1c99..84f2d408d 100644 --- a/ref_app/src/mcal/avr/mcal_cpu.h +++ b/ref_app/src/mcal/avr/mcal_cpu.h @@ -18,7 +18,7 @@ inline auto post_init() -> void { } - inline auto nop() noexcept -> void { asm volatile("nop"); } + inline auto nop() -> void { asm volatile("nop"); } } } diff --git a/ref_app/src/mcal/avr/mcal_gpt.cpp b/ref_app/src/mcal/avr/mcal_gpt.cpp index 8540d6483..75568cdcb 100644 --- a/ref_app/src/mcal/avr/mcal_gpt.cpp +++ b/ref_app/src/mcal/avr/mcal_gpt.cpp @@ -30,7 +30,7 @@ auto __vector_16() -> void ATTRIBUTE(signal, used, externally_visible); auto __vector_16() -> void { - // Increment the 32-bit system tick with 0x100, representing 256 [(1/2) us]. + // Increment the 64-bit system tick with 0x100, representing 256 [(1/2) us]. // This is basically the roll-over of the 8-bit timer0 at 2MHz each 128us. const auto new_tick = diff --git a/ref_app/src/mcal/avr/mcal_irq.h b/ref_app/src/mcal/avr/mcal_irq.h index 9d848ab9c..225b9a37b 100644 --- a/ref_app/src/mcal/avr/mcal_irq.h +++ b/ref_app/src/mcal/avr/mcal_irq.h @@ -16,8 +16,8 @@ auto init(const config_type*) -> void; - inline auto enable_all () noexcept -> void { asm volatile("sei"); } - inline auto disable_all() noexcept -> void { asm volatile("cli"); } + inline auto enable_all () -> void { asm volatile("sei"); } + inline auto disable_all() -> void { asm volatile("cli"); } } } diff --git a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp index 530937f51..0ab716de5 100644 --- a/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp +++ b/ref_app/src/mcal/mcal_gcc_cxx_completion.cpp @@ -48,7 +48,7 @@ void* operator new(std::size_t size) // This is a naive and not completely functional // implementation of operator new(). In particular, there is // no sensible momory management or reaction to buffer overflow. - volatile static std::uint8_t buffer[8U]; + volatile static std::uint8_t buffer[std::size_t { UINT8_C(16) }]; volatile static std::uint8_t* get_ptr = buffer; // Get the newly allocated pointer. diff --git a/ref_app/src/mcal/stm32f100/mcal_benchmark.h b/ref_app/src/mcal/stm32f100/mcal_benchmark.h index d2d769ef7..b8ff4ca81 100644 --- a/ref_app/src/mcal/stm32f100/mcal_benchmark.h +++ b/ref_app/src/mcal/stm32f100/mcal_benchmark.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2014 - 2023. +// Copyright Christopher Kormanyos 2014 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_BENCHMARK_2014_04_16_H_ - #define MCAL_BENCHMARK_2014_04_16_H_ +#ifndef MCAL_BENCHMARK_2014_04_16_H + #define MCAL_BENCHMARK_2014_04_16_H #include @@ -24,4 +24,4 @@ } } -#endif // MCAL_BENCHMARK_2014_04_16_H_ +#endif // MCAL_BENCHMARK_2014_04_16_H diff --git a/ref_app/src/mcal/stm32f100/mcal_cpu.cpp b/ref_app/src/mcal/stm32f100/mcal_cpu.cpp index ed34f2ccd..43326e06c 100644 --- a/ref_app/src/mcal/stm32f100/mcal_cpu.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_cpu.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -11,7 +11,7 @@ #include #include -void mcal::cpu::init() +auto mcal::cpu::init() -> void { // Disable all interrupts and clear pending bits. mcal::reg::reg_access_static::reg_set(); diff --git a/ref_app/src/mcal/stm32f100/mcal_irq.cpp b/ref_app/src/mcal/stm32f100/mcal_irq.cpp index 99b9dc4e6..267347ec9 100644 --- a/ref_app/src/mcal/stm32f100/mcal_irq.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_irq.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,7 +7,7 @@ #include -void mcal::irq::init(const config_type*) +auto mcal::irq::init(const config_type*) -> void { // Enable all global interrupts. mcal::irq::enable_all(); diff --git a/ref_app/src/mcal/stm32f100/mcal_irq.h b/ref_app/src/mcal/stm32f100/mcal_irq.h index a2ee38b0f..dc4f5f05c 100644 --- a/ref_app/src/mcal/stm32f100/mcal_irq.h +++ b/ref_app/src/mcal/stm32f100/mcal_irq.h @@ -1,23 +1,24 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_IRQ_2010_04_10_H_ - #define MCAL_IRQ_2010_04_10_H_ +#ifndef MCAL_IRQ_2010_04_10_H + #define MCAL_IRQ_2010_04_10_H namespace mcal { namespace irq { - typedef void config_type; - void init(const config_type*); + using config_type = void; - inline void enable_all () { asm volatile("cpsie i"); } - inline void disable_all() { asm volatile("cpsid i"); } + auto init(const config_type*) -> void; + + inline auto enable_all () -> void { asm volatile("cpsie i"); } + inline auto disable_all() -> void { asm volatile("cpsid i"); } } } -#endif // MCAL_IRQ_2010_04_10_H_ +#endif // MCAL_IRQ_2010_04_10_H diff --git a/ref_app/src/mcal/stm32f100/mcal_led.cpp b/ref_app/src/mcal/stm32f100/mcal_led.cpp index f1d6877b9..79629d096 100644 --- a/ref_app/src/mcal/stm32f100/mcal_led.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_led.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,7 +8,7 @@ #include #include -mcal::led::led_base& mcal::led::led0() +auto mcal::led::led0() -> mcal::led::led_base& { using led0_port_type = mcal::port::port_pin @@ -14,8 +14,8 @@ { namespace led { - led_base& led0(); + auto led0() -> led_base&; } } -#endif // MCAL_LED_2010_09_14_H_ +#endif // MCAL_LED_2010_09_14_H diff --git a/ref_app/src/mcal/stm32f100/mcal_memory_progmem.h b/ref_app/src/mcal/stm32f100/mcal_memory_progmem.h index 9668b68c4..156bac579 100644 --- a/ref_app/src/mcal/stm32f100/mcal_memory_progmem.h +++ b/ref_app/src/mcal/stm32f100/mcal_memory_progmem.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2019 - 2020. +// Copyright Christopher Kormanyos 2019 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_MEMORY_PROGMEM_2019_08_17_H_ - #define MCAL_MEMORY_PROGMEM_2019_08_17_H_ +#ifndef MCAL_MEMORY_PROGMEM_2019_08_17_H + #define MCAL_MEMORY_PROGMEM_2019_08_17_H #include @@ -69,4 +69,4 @@ } #endif -#endif // MCAL_MEMORY_PROGMEM_2019_08_17_H_ +#endif // MCAL_MEMORY_PROGMEM_2019_08_17_H diff --git a/ref_app/src/mcal/stm32f100/mcal_osc.h b/ref_app/src/mcal/stm32f100/mcal_osc.h index c8161c254..2ace5e449 100644 --- a/ref_app/src/mcal/stm32f100/mcal_osc.h +++ b/ref_app/src/mcal/stm32f100/mcal_osc.h @@ -1,20 +1,21 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_OSC_2011_10_20_H_ - #define MCAL_OSC_2011_10_20_H_ +#ifndef MCAL_OSC_2011_10_20_H + #define MCAL_OSC_2011_10_20_H namespace mcal { namespace osc { - typedef void config_type; - void init(const config_type*); + using config_type = void; + + auto init(const config_type*) -> void; } } -#endif // MCAL_OSC_2011_10_20_H_ +#endif // MCAL_OSC_2011_10_20_H diff --git a/ref_app/src/mcal/stm32f100/mcal_port.cpp b/ref_app/src/mcal/stm32f100/mcal_port.cpp index 6d0307568..63c26ccb7 100644 --- a/ref_app/src/mcal/stm32f100/mcal_port.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_port.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,8 +8,8 @@ #include #include -void mcal::port::init(const config_type*) +auto mcal::port::init(const config_type*) -> void { // Power management: Enable power for I/O ports : porta, portb, and portc. - mcal::reg::reg_access_static::reg_or(); + mcal::reg::reg_access_static::reg_or(); } diff --git a/ref_app/src/mcal/stm32f100/mcal_port.h b/ref_app/src/mcal/stm32f100/mcal_port.h index af51baad9..bbc3b74e1 100644 --- a/ref_app/src/mcal/stm32f100/mcal_port.h +++ b/ref_app/src/mcal/stm32f100/mcal_port.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_PORT_2012_06_27_H_ - #define MCAL_PORT_2012_06_27_H_ +#ifndef MCAL_PORT_2012_06_27_H + #define MCAL_PORT_2012_06_27_H #include @@ -14,8 +14,9 @@ { namespace port { - typedef void config_type; - void init(const config_type*); + using config_type = void; + + auto init(const config_type*) -> void; template void { // Read the value of the port direction register. // Clear all the port pin control bits in the new register value. @@ -37,7 +38,7 @@ reg_type(0x3UL << pdir_shift)>::template reg_msk(); } - static void set_direction_input() + static auto set_direction_input() -> void { // Read the value of the port direction register. // Clear all the port pin control bits in the new register value. @@ -50,25 +51,25 @@ reg_type(0x4UL << pdir_shift)>::template reg_msk(); } - static void set_pin_high() + static auto set_pin_high() -> void { // Set the port output value to high. mcal::reg::reg_access_static::bit_set(); } - static void set_pin_low() + static auto set_pin_low() -> void { // Set the port output value to low. mcal::reg::reg_access_static::bit_clr(); } - static bool read_input_value() + static auto read_input_value() -> bool { // Read the port input value. return mcal::reg::reg_access_static::bit_get(); } - static void toggle_pin() + static auto toggle_pin() -> void { // Toggle the port output value. mcal::reg::reg_access_static::bit_not(); @@ -83,4 +84,4 @@ } } -#endif // MCAL_PORT_2012_06_27_H_ +#endif // MCAL_PORT_2012_06_27_H diff --git a/ref_app/src/mcal/stm32f100/mcal_pwm.cpp b/ref_app/src/mcal/stm32f100/mcal_pwm.cpp index d42a897d0..a15e9e7f9 100644 --- a/ref_app/src/mcal/stm32f100/mcal_pwm.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_pwm.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,7 +8,7 @@ #include #include -mcal::pwm::pwm_base& mcal::pwm::pwm0() noexcept +auto mcal::pwm::pwm0() -> mcal::pwm::pwm_base& { static mcal::pwm::pwm_dummy pwm; diff --git a/ref_app/src/mcal/stm32f100/mcal_pwm.h b/ref_app/src/mcal/stm32f100/mcal_pwm.h index f2f08d03f..4f8076332 100644 --- a/ref_app/src/mcal/stm32f100/mcal_pwm.h +++ b/ref_app/src/mcal/stm32f100/mcal_pwm.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_PWM_2010_09_14_H_ - #define MCAL_PWM_2010_09_14_H_ +#ifndef MCAL_PWM_2010_09_14_H + #define MCAL_PWM_2010_09_14_H #include @@ -14,12 +14,12 @@ { namespace pwm { - typedef void config_type; + using config_type = void; - inline void init(const config_type*) { } + inline auto init(const config_type*) -> void { } - mcal::pwm::pwm_base& pwm0() noexcept; + auto pwm0() -> mcal::pwm::pwm_base&; } } -#endif // MCAL_PWM_2010_09_14_H_ +#endif // MCAL_PWM_2010_09_14_H diff --git a/ref_app/src/mcal/stm32f100/mcal_reg.h b/ref_app/src/mcal/stm32f100/mcal_reg.h index 45cbf3054..e5a99369f 100644 --- a/ref_app/src/mcal/stm32f100/mcal_reg.h +++ b/ref_app/src/mcal/stm32f100/mcal_reg.h @@ -1,12 +1,12 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_REG_2010_04_10_H_ - #define MCAL_REG_2010_04_10_H_ +#ifndef MCAL_REG_2010_04_10_H + #define MCAL_REG_2010_04_10_H #include @@ -91,4 +91,4 @@ #include #include -#endif // MCAL_REG_2010_04_10_H_ +#endif // MCAL_REG_2010_04_10_H diff --git a/ref_app/src/mcal/stm32f100/mcal_ser.h b/ref_app/src/mcal/stm32f100/mcal_ser.h index 3515a81d3..bb7d0bdc5 100644 --- a/ref_app/src/mcal/stm32f100/mcal_ser.h +++ b/ref_app/src/mcal/stm32f100/mcal_ser.h @@ -1,21 +1,21 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2007 - 2020. +// Copyright Christopher Kormanyos 2007 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_SER_2011_10_20_H_ - #define MCAL_SER_2011_10_20_H_ +#ifndef MCAL_SER_2011_10_20_H + #define MCAL_SER_2011_10_20_H namespace mcal { namespace ser { - typedef void config_type; + using config_type = void; - inline void init(const config_type*) { } + inline auto init(const config_type*) -> void { } } } -#endif // MCAL_SER_2011_10_20_H_ +#endif // MCAL_SER_2011_10_20_H diff --git a/ref_app/src/mcal/stm32f100/mcal_spi.cpp b/ref_app/src/mcal/stm32f100/mcal_spi.cpp index 731c19019..799413eb6 100644 --- a/ref_app/src/mcal/stm32f100/mcal_spi.cpp +++ b/ref_app/src/mcal/stm32f100/mcal_spi.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2012 - 2020. +// Copyright Christopher Kormanyos 2012 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -9,11 +9,11 @@ #include -void mcal::spi::init(const mcal::spi::config_type*) +auto mcal::spi::init(const mcal::spi::config_type*) -> void { } -util::communication_base& mcal::spi::spi0() +auto mcal::spi::spi0() -> util::communication_base& { static mcal::spi::spi_software_dummy com; diff --git a/ref_app/src/mcal/stm32f100/mcal_spi.h b/ref_app/src/mcal/stm32f100/mcal_spi.h index 0735804cd..16d6b6ec2 100644 --- a/ref_app/src/mcal/stm32f100/mcal_spi.h +++ b/ref_app/src/mcal/stm32f100/mcal_spi.h @@ -1,23 +1,23 @@ /////////////////////////////////////////////////////////////////////////////// -// Copyright Christopher Kormanyos 2012 - 2020. +// Copyright Christopher Kormanyos 2012 - 2025. // Distributed under the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) // -#ifndef MCAL_SPI_2012_05_24_H_ - #define MCAL_SPI_2012_05_24_H_ +#ifndef MCAL_SPI_2012_05_24_H + #define MCAL_SPI_2012_05_24_H #include namespace mcal { namespace spi { - typedef void config_type; + using config_type = void; - void init(const config_type*); + auto init(const config_type*) -> void; - extern util::communication_base& spi0(); + extern auto spi0() -> util::communication_base&; } } -#endif // MCAL_SPI_2012_05_24_H_ +#endif // MCAL_SPI_2012_05_24_H diff --git a/ref_app/src/mcal/stm32f100/mcal_wdg.h b/ref_app/src/mcal/stm32f100/mcal_wdg.h index 78de3a080..ed8d468b6 100644 --- a/ref_app/src/mcal/stm32f100/mcal_wdg.h +++ b/ref_app/src/mcal/stm32f100/mcal_wdg.h @@ -12,13 +12,13 @@ { namespace wdg { - typedef void config_type; + using config_type = void; - void init(const config_type*); + auto init(const config_type*) -> void; struct secure final { - static void trigger(); + static auto trigger() -> void; }; } } diff --git a/ref_app/target/micros/stm32f100/startup/crt0_init_ram.cpp b/ref_app/target/micros/stm32f100/startup/crt0_init_ram.cpp index 82cee84b1..fd6bc57a6 100644 --- a/ref_app/target/micros/stm32f100/startup/crt0_init_ram.cpp +++ b/ref_app/target/micros/stm32f100/startup/crt0_init_ram.cpp @@ -5,6 +5,13 @@ // or copy at http://www.boost.org/LICENSE_1_0.txt) // +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstringop-overflow" +#endif + #include #include #include @@ -43,3 +50,8 @@ void crt::init_ram() static_cast(static_cast(&_bss_end)), static_cast(0U)); } + +#if defined(__GNUC__) && (__GNUC__ >= 12) +#pragma GCC diagnostic pop +#pragma GCC diagnostic pop +#endif