From a9bdbca571577cfd43bc5d36dba26e692e955ade Mon Sep 17 00:00:00 2001 From: Simon Hardt Date: Sun, 13 Feb 2022 01:28:28 +0100 Subject: [PATCH 1/2] build fix --- .gitignore | 47 ++-------------------------------- waveshare/CMakeLists.txt | 2 +- waveshare/include/DEV_Config.h | 3 +++ 3 files changed, 6 insertions(+), 46 deletions(-) diff --git a/.gitignore b/.gitignore index d66bda0..54be2b3 100644 --- a/.gitignore +++ b/.gitignore @@ -32,48 +32,5 @@ *.out *.app -build/.ninja_deps -build/.ninja_log -build/build.ninja -build/cmake_install.cmake -build/CMakeCache.txt -build/compile_commands.json -build/.cmake/api/v1/query/client-vscode/query.json -build/.cmake/api/v1/reply/cache-v2-8e3d784e6607879cd18c.json -build/.cmake/api/v1/reply/codemodel-v2-97bfd906ef366d86b34b.json -build/.cmake/api/v1/reply/index-2022-02-11T18-35-30-0824.json -build/.cmake/api/v1/reply/target-frame-Debug-7d0b6524a58d8e907a2f.json -build/.cmake/api/v1/reply/toolchains-v1-65972111b21e4388dc41.json -build/CMakeFiles/cmake.check_cache -build/CMakeFiles/CMakeOutput.log -build/CMakeFiles/rules.ninja -build/CMakeFiles/TargetDirectories.txt -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeCCompiler.cmake -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeCXXCompiler.cmake -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeDetermineCompilerABI_C.bin -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeDetermineCompilerABI_CXX.bin -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeRCCompiler.cmake -build/CMakeFiles/3.20.21032501-MSVC_2/CMakeSystem.cmake -build/CMakeFiles/3.20.21032501-MSVC_2/CompilerIdC/CMakeCCompilerId.c -build/CMakeFiles/3.20.21032501-MSVC_2/CompilerIdCXX/CMakeCXXCompilerId.cpp -build/CMakeFiles/ShowIncludes/foo.h -build/CMakeFiles/ShowIncludes/main.c -build/frame/cmake_install.cmake -build/frame/frame.ilk -build/frame/frame.pdb -build/frame/CMakeFiles/frame.dir/embed.manifest -build/frame/CMakeFiles/frame.dir/intermediate.manifest -build/frame/CMakeFiles/frame.dir/manifest.rc -build/frame/CMakeFiles/frame.dir/manifest.res -build/frame/CMakeFiles/frame.dir/vc140.pdb -build/.cmake/api/v1/reply/cache-v2-dd95df14d5968b8bc03c.json -build/.cmake/api/v1/reply/index-2022-02-12T19-46-35-0149.json -.vscode/settings.json -build/.cmake/api/v1/reply/cache-v2-b08d9ee268491a48090a.json -build/.cmake/api/v1/reply/codemodel-v2-1315d454ed7a6fd4530a.json -build/.cmake/api/v1/reply/index-2022-02-12T20-17-15-0123.json -build/.cmake/api/v1/reply/target-bcm2835-Debug-370fe998a1b6bb8b7242.json -build/.cmake/api/v1/reply/target-frame-Debug-bbe37aa3d79fa8b439c0.json -build/.cmake/api/v1/reply/target-waveshare-Debug-223ca8c705d057f21abf.json -build/bcm2835/cmake_install.cmake -build/waveshare/cmake_install.cmake +build/* +.vscode/* diff --git a/waveshare/CMakeLists.txt b/waveshare/CMakeLists.txt index 0e6f6ea..937cb0a 100644 --- a/waveshare/CMakeLists.txt +++ b/waveshare/CMakeLists.txt @@ -10,4 +10,4 @@ set(src add_library(${target} STATIC ${src}) target_include_directories(${target} PUBLIC include/) -target_link_libraries(${target} PRIVATE bcm2835) \ No newline at end of file +target_link_libraries(${target} PUBLIC bcm2835) \ No newline at end of file diff --git a/waveshare/include/DEV_Config.h b/waveshare/include/DEV_Config.h index 105ea19..fea5f0d 100644 --- a/waveshare/include/DEV_Config.h +++ b/waveshare/include/DEV_Config.h @@ -48,6 +48,9 @@ #ifndef _DEV_CONFIG_H_ #define _DEV_CONFIG_H_ +#define RPI +#define USE_BCM2835_LIB + #include #include #include From 7a8e4f6096be309004ca45c97f4b252373f425d5 Mon Sep 17 00:00:00 2001 From: Simon Hardt Date: Wed, 2 Mar 2022 22:15:40 +0100 Subject: [PATCH 2/2] add: image --- .clang-format | 73 +++++++++++++++++++++++++++++++ frame/CMakeLists.txt | 10 ++++- frame/src/Image.cpp | 33 ++++++++++++++ frame/src/Image.hpp | 35 +++++++++++++++ frame/src/Size.hpp | 10 +++++ frame/src/display/EPD_7in5_V2.cpp | 69 +++++++++++++++++++++++++++++ frame/src/display/EPD_7in5_V2.hpp | 23 ++++++++++ frame/src/display/IDisplay.hpp | 35 +++++++++++++++ frame/{ => src}/main.cpp | 35 +++++++++++++-- 9 files changed, 319 insertions(+), 4 deletions(-) create mode 100644 .clang-format create mode 100644 frame/src/Image.cpp create mode 100644 frame/src/Image.hpp create mode 100644 frame/src/Size.hpp create mode 100644 frame/src/display/EPD_7in5_V2.cpp create mode 100644 frame/src/display/EPD_7in5_V2.hpp create mode 100644 frame/src/display/IDisplay.hpp rename frame/{ => src}/main.cpp (64%) diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..40b88e5 --- /dev/null +++ b/.clang-format @@ -0,0 +1,73 @@ +--- +AccessModifierOffset: '-4' +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: 'true' +AlignConsecutiveAssignments: 'true' +AlignConsecutiveDeclarations: 'false' +AlignEscapedNewlines: Left +AlignOperands: 'true' +AlignTrailingComments: 'true' +AllowAllArgumentsOnNextLine: 'false' +AllowAllConstructorInitializersOnNextLine: 'false' +AllowAllParametersOfDeclarationOnNextLine: 'false' +AllowShortBlocksOnASingleLine: 'false' +AllowShortCaseLabelsOnASingleLine: 'true' +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: 'false' +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: 'false' +AlwaysBreakTemplateDeclarations: 'Yes' +BinPackArguments: 'false' +BinPackParameters: 'false' +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeTernaryOperators: 'true' +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: 'true' +CompactNamespaces: 'false' +ContinuationIndentWidth: '4' +Cpp11BracedListStyle: 'true' +FixNamespaceComments: 'true' +IncludeBlocks: Regroup +IndentCaseLabels: 'true' +IndentPPDirectives: AfterHash +IndentWidth: '4' +IndentWrappedFunctionNames: 'true' +Language: Cpp +MaxEmptyLinesToKeep: '1' +NamespaceIndentation: All +PointerAlignment: Left +ReflowComments: 'true' +SortUsingDeclarations: 'true' +SpaceAfterCStyleCast: 'false' +SpaceAfterLogicalNot: 'false' +SpaceAfterTemplateKeyword: 'false' +SpaceBeforeAssignmentOperators: 'true' +SpaceBeforeCpp11BracedList: 'false' +SpaceBeforeCtorInitializerColon: 'true' +SpaceBeforeInheritanceColon: 'true' +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: 'true' +SpaceInEmptyParentheses: 'false' +SpacesInAngles: 'false' +SpacesInCStyleCastParentheses: 'false' +SpacesInContainerLiterals: 'false' +SpacesInSquareBrackets: 'false' +Standard: Auto + +BreakBeforeBraces: Custom +BraceWrapping: + AfterClass: true + AfterStruct: true + BeforeCatch: true + AfterControlStatement: "Always" + AfterFunction: true + AfterNamespace: true + AfterUnion: true + SplitEmptyFunction: true + SplitEmptyNamespace: true + SplitEmptyRecord: true + + diff --git a/frame/CMakeLists.txt b/frame/CMakeLists.txt index 4f58e0b..c1ab48c 100644 --- a/frame/CMakeLists.txt +++ b/frame/CMakeLists.txt @@ -1,6 +1,14 @@ set(target frame) +set(src + src/main.cpp + src/Image.hpp + src/Image.cpp + src/display/IDisplay.hpp + src/display/EPD_7in5_V2.hpp + src/display/EPD_7in5_V2.cpp +) -add_executable(${target} main.cpp) +add_executable(${target} ${src}) target_link_libraries(${target} PRIVATE waveshare) \ No newline at end of file diff --git a/frame/src/Image.cpp b/frame/src/Image.cpp new file mode 100644 index 0000000..4be06bf --- /dev/null +++ b/frame/src/Image.cpp @@ -0,0 +1,33 @@ +#include "Image.hpp" + +namespace frame +{ + + Image::Image(uint32_t pWidth, uint32_t pHeight) + : mWidth(pWidth) + , mHeight(pHeight) + , mBuffer(mWidth * mHeight) + { + } + + Image::Image(Size size) + : Image(size.width, size.height) + { + } + + uint8_t& Image::at(uint32_t x, uint32_t y) + { + return mBuffer.at(toInternal(x, y)); + } + + uint8_t const& Image::at(uint32_t x, uint32_t y) const + { + return mBuffer.at(toInternal(x, y)); + } + + uint8_t Image::toInternal(uint32_t x, uint32_t y) const + { + return x + mWidth * y; + } + +} // namespace frame diff --git a/frame/src/Image.hpp b/frame/src/Image.hpp new file mode 100644 index 0000000..436ba57 --- /dev/null +++ b/frame/src/Image.hpp @@ -0,0 +1,35 @@ +#pragma once +#include "Size.hpp" + +#include + +namespace frame +{ + + class Image + { + uint32_t mWidth; + uint32_t mHeight; + std::vector mBuffer; + + public: + Image(uint32_t pWidth, uint32_t pHeight); + Image(Size size); + + uint8_t& at(uint32_t x, uint32_t y); + uint8_t const& at(uint32_t x, uint32_t y) const; + + auto getWidth() const + { + return mWidth; + } + auto getHeight() const + { + return mHeight; + } + + private: + uint8_t toInternal(uint32_t x, uint32_t y) const; + }; + +} // namespace frame \ No newline at end of file diff --git a/frame/src/Size.hpp b/frame/src/Size.hpp new file mode 100644 index 0000000..f27dd6e --- /dev/null +++ b/frame/src/Size.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace frame +{ + struct Size + { + uint32_t width; + uint32_t height; + }; +} // namespace frame diff --git a/frame/src/display/EPD_7in5_V2.cpp b/frame/src/display/EPD_7in5_V2.cpp new file mode 100644 index 0000000..8c902c3 --- /dev/null +++ b/frame/src/display/EPD_7in5_V2.cpp @@ -0,0 +1,69 @@ +#include "EPD_7in5_V2.hpp" + +#include + +namespace frame::display +{ + constexpr uint32_t mWidth = EPD_7IN5_V2_WIDTH; + constexpr uint32_t mHeight = EPD_7IN5_V2_HEIGHT; + + EPD_7in5_V2::EPD_7in5_V2() + : IDisplay("EPD_7in5_V2", {mWidth, mHeight}) + { + } + + EPD_7in5_V2::~EPD_7in5_V2() + { + Sleep(); + } + + bool EPD_7in5_V2::Init() + { + return EPD_7IN5_V2_Init() == 0; + } + + void EPD_7in5_V2::Clear(Color color) + { + if(color == Color::WHITE) + { + EPD_7IN5_V2_Clear() + } else + { + EPD_7IN5_V2_ClearBlack(); + } + } + + void EPD_7in5_V2::Display(Image const& image) + { + constexpr auto bytes_width = mWidth / 8; + std::vector data(bytes_with * mHeight); + + uint8_t bit_counter; + + for(auto y = 0; y < mHeight; ++y) + { + for(auto x = 0; x < bytes_width; ++x) + { + uint8_t byte = 0; + for(auto bit = 0; bit < 8; ++bit) + { + if(image.at(x * 8 + bit, y) > 265 / 2) + { + byte ^= 1; + } + byte << 1; + } + + data[bytes_width * y + x] = byte; + } + } + + EPD_7IN5_V2_Display(data.data()); + } + + void EPD_7in5_V2::Sleep() + { + EPD_7IN5_V2_Sleep(); + } + +} // namespace frame::display \ No newline at end of file diff --git a/frame/src/display/EPD_7in5_V2.hpp b/frame/src/display/EPD_7in5_V2.hpp new file mode 100644 index 0000000..1997cc3 --- /dev/null +++ b/frame/src/display/EPD_7in5_V2.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "IDisplay.hpp" + +namespace frame::display +{ + + class EPD_7in5_V2 : public IDisplay + { + public: + EPD_7in5_V2(); + ~EPD_7in5_V2(); + + bool Init() override; + + void Clear(Color color) override; + + void Display(Image const& image) override; + + void Sleep() override; + }; + +} // namespace frame::display diff --git a/frame/src/display/IDisplay.hpp b/frame/src/display/IDisplay.hpp new file mode 100644 index 0000000..1f618cf --- /dev/null +++ b/frame/src/display/IDisplay.hpp @@ -0,0 +1,35 @@ +#pragma once +#include "../Image.hpp" + +#include + +namespace frame::display +{ + enum class Color { WHITE, BLACK }; + + class IDisplay + { + std::string mName; + Size mSize; + + public: + IDisplay(std::string_view pName, Size pSize) + : mName(pName) + , mSize(pSize){}; + virtual ~IDisplay() = default; + + virtual bool Init() = 0; + + virtual void Clear(Color color) = 0; + + virtual void Display(Image const& image) = 0; + + virtual void Sleep() = 0; + + public: + Size const& getSize() + { + return size; + } + }; +} // namespace frame::display \ No newline at end of file diff --git a/frame/main.cpp b/frame/src/main.cpp similarity index 64% rename from frame/main.cpp rename to frame/src/main.cpp index 4fc53fb..793cbf4 100644 --- a/frame/main.cpp +++ b/frame/src/main.cpp @@ -1,10 +1,38 @@ -#include #include +#include #include #include using namespace std::chrono_literals; +#include "display/EPD_7in5_V2.hpp" + +int main() +{ + + frame::display::EPD_7in5_V2 display{}; + + display.Init(); + + display.Clear(frame::display::Color::BLACK); + + std::this_thread::sleep_for(2s); + + display.Clear(frame::display::Color::WHITE); + + std::this_thread::sleep_for(2s); + + frame::Image image(display.getSize()); + + for(int x = 0; x < image.getWidth(); ++x) + { + image.at(x, 0) = 0xFF; + } + + display.Display(image); +} + +/* #include @@ -35,7 +63,7 @@ int main() color = ~color; } - + EPD_7IN5_V2_Display(image.data()); std::this_thread::sleep_for(10s); @@ -44,4 +72,5 @@ int main() EPD_7IN5_V2_Sleep(); return 0; -} \ No newline at end of file +} +*/ \ No newline at end of file