Skip to content

Commit

Permalink
Update various utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Nov 28, 2024
1 parent a57db52 commit b2c4463
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 22 deletions.
1 change: 1 addition & 0 deletions ref_app/ref_app.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="src\mcal_lcd\mcal_lcd_base.h" />
<ClInclude Include="src\mcal_lcd\mcal_lcd_buffered_instance.h" />
<ClInclude Include="src\mcal_lcd\mcal_lcd_console.h" />
<ClInclude Include="src\mcal_lcd\mcal_lcd_generic_st7066.h" />
<ClInclude Include="src\mcal_led\mcal_led_base.h" />
Expand Down
3 changes: 3 additions & 0 deletions ref_app/ref_app.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2670,6 +2670,9 @@
<ClInclude Include="src\mcal\rpi_pico2_rp2350\mcal_cpu_rp2350.h">
<Filter>src\mcal\rpi_pico2_rp2350</Filter>
</ClInclude>
<ClInclude Include="src\mcal_lcd\mcal_lcd_buffered_instance.h">
<Filter>src\mcal_lcd</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="src\util\STL\algorithm">
Expand Down
4 changes: 4 additions & 0 deletions ref_app/src/math/wide_decimal/decwide_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
namespace std { using ::lround; }
#endif

#if (defined(__GNUC__) && (defined(__arm__) || defined(__AVR__)))
namespace std { using ::strtold; }
#endif

WIDE_DECIMAL_NAMESPACE_BEGIN

#if(__cplusplus >= 201703L)
Expand Down
13 changes: 7 additions & 6 deletions ref_app/src/mcal_lcd/mcal_lcd_base.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2020 - 2022.
// Copyright Christopher Kormanyos 2020 - 2024.
// 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)
Expand All @@ -8,10 +8,11 @@
#ifndef MCAL_LCD_BASE_2020_06_10_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_BASE_2020_06_10_H

#include <cstdint>

#include <util/utility/util_noncopyable.h>

#include <cstddef>
#include <cstdint>

#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
Expand All @@ -25,9 +26,9 @@

virtual auto init() -> bool = 0;

virtual auto write(const char* pstr,
std::uint_fast8_t length,
std::uint_fast8_t line_index) -> bool = 0;
virtual auto write(const char* pstr,
const std::size_t length,
const std::uint_fast8_t line_index) -> bool = 0;

protected:
lcd_base() = default; // LCOV_EXCL_LINE
Expand Down
101 changes: 101 additions & 0 deletions ref_app/src/mcal_lcd/mcal_lcd_buffered_instance.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2024.
// 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_LCD_BUFFERED_INSTANCE_2024_02_07_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_BUFFERED_INSTANCE_2024_02_07_H

#include <mcal_lcd/mcal_lcd_base.h>

#include <algorithm>
#include <array>

#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
namespace mcal { namespace lcd { // NOLINT(modernize-concat-nested-namespaces)
#endif

template<typename BackendDisplayType,
const unsigned HeightInRows,
const unsigned WidthInCols>
class lcd_buffered_instance : public mcal::lcd::lcd_base
{
private:
using backend_display_type = BackendDisplayType;

using row_array_type = std::array<char, static_cast<std::size_t>(WidthInCols)>;

using row_col_array_buffer_type = std::array<row_array_type, static_cast<std::size_t>(HeightInRows)>;

public:
explicit lcd_buffered_instance(backend_display_type& backend_display)
: my_backend_display(backend_display)
{
for(auto& row : row_col_array_buffer)
{
row.fill(' ');
}
}

lcd_buffered_instance() = delete;

~lcd_buffered_instance() override = default;

static constexpr auto width () noexcept -> std::size_t { return std::tuple_size<row_array_type>::value; }
static constexpr auto height() noexcept -> std::size_t { return std::tuple_size<row_col_array_buffer_type>::value; }

auto init() -> bool override { return my_backend_display.init(); }

auto write(const char* pstr,
const std::size_t length,
const std::uint_fast8_t line_index) -> bool override
{
bool result_write_is_ok { };

if(line_index < static_cast<std::uint_fast8_t>(height()))
{
result_write_is_ok = true;

row_array_type candidate_row;

candidate_row.fill(' ');

const auto length_to_copy = (std::min)(static_cast<std::ptrdiff_t>(length), static_cast<std::ptrdiff_t>(width()));

std::copy(pstr, pstr + length_to_copy, candidate_row.begin());

if(candidate_row != row_col_array_buffer[static_cast<std::size_t>(line_index)])
{
result_write_is_ok =
my_backend_display.write
(
candidate_row.data(),
static_cast<std::size_t>(width()),
line_index
);

row_col_array_buffer[static_cast<std::size_t>(line_index)] = candidate_row;
}
}

return result_write_is_ok;
}

private:
backend_display_type& my_backend_display;

row_col_array_buffer_type row_col_array_buffer { };
};

#if(__cplusplus >= 201703L)
} // namespace mcal::lcd
#else
} // namespace lcd
} // namespace mcal
#endif

#endif // MCAL_LCD_BUFFERED_INSTANCE_2024_02_07_H
12 changes: 6 additions & 6 deletions ref_app/src/mcal_lcd/mcal_lcd_console.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
// Copyright Christopher Kormanyos 2020 - 2022.
// Copyright Christopher Kormanyos 2020 - 2024.
// 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)
Expand All @@ -8,11 +8,11 @@
#ifndef MCAL_LCD_CONSOLE_2020_06_10_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_CONSOLE_2020_06_10_H

#include <mcal_lcd/mcal_lcd_base.h>

#include <iostream>
#include <string>

#include <mcal_lcd/mcal_lcd_base.h>

#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
Expand All @@ -26,9 +26,9 @@

~lcd_console() override = default;

auto write(const char* pstr,
std::uint_fast8_t length, // NOLINT(bugprone-easily-swappable-parameters)
std::uint_fast8_t line_index) -> bool override
auto write(const char* pstr,
const std::size_t length, // NOLINT(bugprone-easily-swappable-parameters)
const std::uint_fast8_t line_index) -> bool override
{
static_cast<void>(line_index);

Expand Down
17 changes: 8 additions & 9 deletions ref_app/src/mcal_lcd/mcal_lcd_generic_st7066.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
#ifndef MCAL_LCD_GENERIC_ST7066_2020_05_07_H // NOLINT(llvm-header-guard)
#define MCAL_LCD_GENERIC_ST7066_2020_05_07_H

#include <algorithm>
#include <cstdint>
#include <cstring>

#include <mcal_lcd/mcal_lcd_base.h>
#include <mcal_wdg.h>

#include <util/utility/util_time.h>

#include <algorithm>
#include <cstring>

#if(__cplusplus >= 201703L)
namespace mcal::lcd {
#else
Expand Down Expand Up @@ -80,9 +79,9 @@
return write_clear_lines_is_ok;
}

auto write(const char* pstr,
std::uint_fast8_t length,
std::uint_fast8_t line_index) -> bool override
auto write(const char* pstr,
const std::size_t length,
const std::uint_fast8_t line_index) -> bool override
{
std::uint_fast8_t char_index = 0U;

Expand All @@ -93,13 +92,13 @@
// Write the line at line_index.
for( ; char_index < (std::min)(lcd_line_width, length); ++char_index)
{
write(std::uint8_t(pstr[char_index]));
write(std::uint8_t { pstr[char_index] });
}
}

for( ; char_index < lcd_line_width; ++char_index)
{
write(std::uint8_t(char(' ')));
write(std::uint8_t { ' ' });
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion ref_app/src/util/STL/span
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using byte = unsigned char;

STL_LOCAL_CONSTEXPR std::size_t dynamic_extent =
(std::numeric_limits<std::size_t>::max)();
static_cast<std::size_t>((std::numeric_limits<std::ptrdiff_t>::max)());

template<typename ElementType,
std::ptrdiff_t Extent = dynamic_extent>
Expand Down

0 comments on commit b2c4463

Please sign in to comment.