From 8ebdb77321b633bca069754f5b24eb9ee135ccf2 Mon Sep 17 00:00:00 2001 From: RobertGawron Date: Sat, 30 Nov 2024 16:43:49 +0100 Subject: [PATCH] poc --- DevOps/Docker/Dockerfile | 43 ++- DevOps/README.md | 5 + .../Diagrams/DisplayClassDiagram.plantuml | 54 +++ .../Diagrams/DisplayClassDiagram.svg | 1 + Simulation/FirmwarePCSimulator/CMakeLists.txt | 1 + .../Driver/Inc/St7735DisplayDriverStub.hpp | 3 +- .../Driver/Src/St7735DisplayDriverStub.cpp | 1 + Simulation/FirmwarePCSimulator/README.md | 24 ++ .../BusinessLogic/Src/HmiViewManager.cpp | 64 +++- .../STM32F103RBTx/Application/CMakeLists.txt | 14 +- .../Application/Device/Inc/Display.hpp | 24 ++ .../Device/Interfaces/IDisplay.hpp | 19 + .../Application/Device/Src/Display.cpp | 351 ++++++++++++++++++ 13 files changed, 591 insertions(+), 13 deletions(-) create mode 100644 Documentation/Diagrams/DisplayClassDiagram.plantuml create mode 100644 Documentation/Diagrams/DisplayClassDiagram.svg create mode 100644 Software/STM32F103RBTx/Application/Device/Inc/Display.hpp create mode 100644 Software/STM32F103RBTx/Application/Device/Interfaces/IDisplay.hpp create mode 100644 Software/STM32F103RBTx/Application/Device/Src/Display.cpp diff --git a/DevOps/Docker/Dockerfile b/DevOps/Docker/Dockerfile index 4a558cfd..6c0519b1 100644 --- a/DevOps/Docker/Dockerfile +++ b/DevOps/Docker/Dockerfile @@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y \ clang-tools \ python3 \ python3-pip \ + python3-dbg \ graphviz \ doxygen \ wget \ @@ -38,25 +39,52 @@ RUN apt-get update && apt-get install -y \ python3-pyqt6 \ python3-venv \ llvm-15 \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + gdb \ + strace \ + elfutils \ + file \ + libxcb-cursor0 \ + libxcb-cursor-dev \ + libx11-xcb1 \ + libxcb-render0 \ + libxcb-shm0 \ + libxcb-xfixes0 \ + libxcb1 \ + libxrender1 \ + libxkbcommon-x11-0 \ + libxcb-icccm4 \ + libxcb-keysyms1 \ + libxcb-image0 \ + libxcb-randr0 \ + libxcb-render-util0 \ + libxcb-shape0 \ + libxcb-sync1 \ + libxcb-xinerama0 \ + libfontconfig1 \ + libfreetype6 \ + && apt-get clean && rm -rf /var/lib/apt/lists/* # Install Python-based tools in one step # Create a virtual environment in /workspace/venv RUN python3 -m venv /workspace/venv # Activate the virtual environment and install the packages -RUN /workspace/venv/bin/pip install \ +RUN /workspace/venv/bin/pip install --upgrade pip && \ + /workspace/venv/bin/pip install \ cpplint \ gprof2dot \ coverxygen \ - hpp2plantuml + hpp2plantuml \ + PyQt6 # Add virtual environment binaries to the PATH ENV PATH="/workspace/venv/bin:$PATH" +# Set the QT_PLUGIN_PATH environment variable +ENV QT_PLUGIN_PATH="/workspace/venv/lib/python3.12/site-packages/PyQt6/Qt6/plugins" + # Install CMake manually (version 3.22.0) -#RUN apt-get update && \ +# RUN apt-get update && \ # wget https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0-linux-x86_64.sh && \ # mkdir /opt/cmake && \ # sh cmake-3.22.0-linux-x86_64.sh --skip-license --prefix=/opt/cmake && \ @@ -64,7 +92,7 @@ ENV PATH="/workspace/venv/bin:$PATH" # rm cmake-3.22.0-linux-x86_64.sh # Clean up # Install include-what-you-use from source -#RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /usr/local/src/iwyu && \ +# RUN git clone https://github.com/include-what-you-use/include-what-you-use.git /usr/local/src/iwyu && \ # cd /usr/local/src/iwyu && \ # git checkout clang_15 && \ # git pull && \ @@ -76,9 +104,6 @@ ENV PATH="/workspace/venv/bin:$PATH" # workaround for cppcheck html generator that needs older version RUN pip uninstall -y pygments && pip install pygments==2.7.4 -RUN pip uninstall -y pygments && \ - pip install pygments==2.7.4 - RUN mkdir -p /workspace/build WORKDIR /workspace/build diff --git a/DevOps/README.md b/DevOps/README.md index ebc40da3..07b25ead 100644 --- a/DevOps/README.md +++ b/DevOps/README.md @@ -55,6 +55,11 @@ cd /workspace/build/ && cmake .. && make -j24 cd /workspace/Simulation/FirmwarePCSimulator/ && python3 main.py +* all at once: + +cd /workspace/build/ && cmake .. && make -j24 && cd /workspace/Simulation/FirmwarePCSimulator/ && python3 main.py + + ### Troubleshooting: The simulation is a desktop application that runs in Docker. Docker needs to be configured to display the simulation window. To test this, you can temporarily install some X11 applications and run them: diff --git a/Documentation/Diagrams/DisplayClassDiagram.plantuml b/Documentation/Diagrams/DisplayClassDiagram.plantuml new file mode 100644 index 00000000..d59f73b0 --- /dev/null +++ b/Documentation/Diagrams/DisplayClassDiagram.plantuml @@ -0,0 +1,54 @@ +@startuml +abstract U8G2 +class Display +class St7735DisplayDriver +class "stm32-st7735" +class "CubeMX HAL" +class MUIU8G2 +class "User Defined Layouts" +class Hardware + +U8G2 <|-- Display + +Display *-- St7735DisplayDriver + +St7735DisplayDriver ..> "CubeMX HAL" : uses + +"stm32-st7735" .up.> St7735DisplayDriver : uses + +"CubeMX HAL" --> Hardware : communicates via SPI + +MUIU8G2 ..> U8G2 : uses + +"User Defined Layouts" ..> MUIU8G2 : uses + +"User Defined Layouts" ..> Display : uses + +note on link +U8G2 and MUIU8G2 libraries are monochrome by default. +As a workaround, the color can be changed +directly through the Display class. +end note + +' Note for "stm32-st7735" +note bottom of "stm32-st7735" +Library from STMicroelectronics +(not the commonly used stm32-st7735 library). +Implements communication with the ST7735 via SPI. +end note + +' Note for "CubeMX HAL" +note as CubeMX_NOTE +Generated with CubeMX. +end note +"CubeMX HAL" .right. CubeMX_NOTE + +' Note for U8G2 and MUIU8G2 +note as U8G2_NOTE +Part of the u8g2 library, +providing GUI and fonts. +end note + +MUIU8G2 .left. U8G2_NOTE +U8G2 .left. U8G2_NOTE +@enduml \ No newline at end of file diff --git a/Documentation/Diagrams/DisplayClassDiagram.svg b/Documentation/Diagrams/DisplayClassDiagram.svg new file mode 100644 index 00000000..a1bd9173 --- /dev/null +++ b/Documentation/Diagrams/DisplayClassDiagram.svg @@ -0,0 +1 @@ +U8G2DisplaySt7735DisplayDriverstm32-st7735CubeMX HALMUIU8G2User Defined LayoutsHardwareLibrary from STMicroelectronics(not the commonly used stm32-st7735 library).Implements communication with the ST7735 via SPI.Generated with CubeMX.Part of the u8g2 library,providing GUI and fonts.usesusescommunicates via SPIusesusesusesU8G2 and MUIU8G2 libraries are monochrome by default.As a workaround, the color can be changeddirectly through the Display class. \ No newline at end of file diff --git a/Simulation/FirmwarePCSimulator/CMakeLists.txt b/Simulation/FirmwarePCSimulator/CMakeLists.txt index 32608a49..25878f0c 100644 --- a/Simulation/FirmwarePCSimulator/CMakeLists.txt +++ b/Simulation/FirmwarePCSimulator/CMakeLists.txt @@ -56,4 +56,5 @@ target_link_libraries(FirmwarePCSimulator BusinessLogic Device DriverForSimulation + u8g2 ) diff --git a/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Inc/St7735DisplayDriverStub.hpp b/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Inc/St7735DisplayDriverStub.hpp index 3bac07f9..3934020f 100644 --- a/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Inc/St7735DisplayDriverStub.hpp +++ b/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Inc/St7735DisplayDriverStub.hpp @@ -121,7 +121,8 @@ namespace Driver */ bool onReset() override; - private: + // todo uncomment + // private: // No mater if the dispaly is configured as horisontal or vertical, ST7735_HEIGHT is the longer dimention so it will always fit static const uint8_t MAX_WIDTH = ST7735_HEIGHT; static const uint8_t MAX_HEIGHT = ST7735_HEIGHT; diff --git a/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Src/St7735DisplayDriverStub.cpp b/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Src/St7735DisplayDriverStub.cpp index e322d034..9ed228f8 100644 --- a/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Src/St7735DisplayDriverStub.cpp +++ b/Simulation/FirmwarePCSimulator/Mock/Application/Driver/Src/St7735DisplayDriverStub.cpp @@ -109,6 +109,7 @@ namespace Driver uint8_t y, DisplayPixelColor::PixelColor color) { + content[x][y] = color; return IDisplayDriver::Status::Ok; } diff --git a/Simulation/FirmwarePCSimulator/README.md b/Simulation/FirmwarePCSimulator/README.md index 7e8aa30f..5b3bbdff 100644 --- a/Simulation/FirmwarePCSimulator/README.md +++ b/Simulation/FirmwarePCSimulator/README.md @@ -4,8 +4,12 @@ The reasons for using a simulator are explained in the [main README](../../README.md). +![PC Simulation Screenshot](../../Documentation/Pictures/PCSimulation_17_11_2024.png) + ## Architecture +![PC Simulation Component Diagram](../../Documentation/Diagrams/PCSimulationComponentDiagram.svg) + Simulation consists of: - Firmware (.so file) - High-level logic is used as-is, without modification for simulation mode. This code is located in the [Application/BusinessLogic/](../../Software/STM32F103RBTx/Application/BusinessLogic) and [Application/Device/](../../Software/STM32F103RBTx/Application/Device) folders within the firmware directory. @@ -32,3 +36,23 @@ main_window.py: Main window of the application. ## Compilation and usage [This part is covered in the DevOps section.](../../DevOps/README.md). + +cd /workspace/build/ && cmake .. && make -j24 && cd /workspace/Simulation/FirmwarePCSimulator/ && python3 main.py + +## Troubleshooting + +Check if Core Dumps Are Enabled Core dumps might be disabled by default on your system. Check the current core dump settings using: + +ulimit -c + +If it shows 0, core dumps are disabled, enable core dumps by running: + +ulimit -c unlimited + +On WSL (Docker runs in Windows), disable wsl-capture-crash for Core Dumps: + +echo "/tmp/core.%e.%p" | tee /proc/sys/kernel/core_pattern + + +debug core: +gdb /workspace/venv/bin/python3 /tmp/core.python3.2430 diff --git a/Software/STM32F103RBTx/Application/BusinessLogic/Src/HmiViewManager.cpp b/Software/STM32F103RBTx/Application/BusinessLogic/Src/HmiViewManager.cpp index 6517af4e..86b77980 100644 --- a/Software/STM32F103RBTx/Application/BusinessLogic/Src/HmiViewManager.cpp +++ b/Software/STM32F103RBTx/Application/BusinessLogic/Src/HmiViewManager.cpp @@ -1,6 +1,11 @@ #include "BusinessLogic/Inc/HmiViewManager.hpp" -// for test +// for test of muiminimal lib +#include "U8g2lib.h" +#include "MUIU8g2.h" +#include "Device/Inc/Display.hpp" + +// for test of driver lib #include #include "Driver/Inc/DisplayPixelColor.hpp" #include "BusinessLogic/Interfaces/IPlatformFactory.hpp" @@ -18,9 +23,64 @@ namespace BusinessLogic // for tests auto color = Driver::DisplayPixelColor::getColor(0x2f, 0xff, 0xff); - display.drawHorizontalLine(1, 1, 20, color); + // display.drawHorizontalLine(1, 1, 20, color); printf("hello drawHorizontalLine\n"); + Device::Display u8g2(display); + + MUIU8G2 mui; + + muif_t muif_list[] = { + MUIF_U8G2_FONT_STYLE(0, u8g2_font_helvR08_tr), /* define style 0 */ + MUIF_U8G2_LABEL(), /* allow MUI_LABEL command */ + MUIF_BUTTON("BN", mui_u8g2_btn_exit_wm_fi) /* define exit button */ + }; + + fds_t fds_data[] = /* Don't use comma between the commands! */ + MUI_FORM(1) /* This will start the definition of form 1 */ + MUI_STYLE(0) /* select the font defined with style 0 */ + MUI_LABEL(5, 15, "Hello U8g2") /* place text at postion x=5, y=15 */ + MUI_XYT("BN", 64, 30, " Select Me ") /* place a button at pos x=64, y=30 */ + ; + + printf("%s %d\n", __FILE__, __LINE__); + + u8g2.begin(/* menu_select_pin= */ 5, /* menu_next_pin= */ 4, /* menu_prev_pin= */ 2, /* menu_up_pin= */ U8X8_PIN_NONE, /* menu_down_pin= */ U8X8_PIN_NONE, /* menu_home_pin= */ 3); + + printf("%s %d\n", __FILE__, __LINE__); +#if 1 + mui.begin(u8g2, fds_data, muif_list, sizeof(muif_list) / sizeof(muif_t)); + mui.gotoForm(/* form_id= */ 1, /* initial_cursor_position= */ 0); + u8g2.firstPage(); + u8g2.setCursor(0, 0); + printf("wwwwwwwwwwwwwwwwwww\n"); + u8g2.drawLine(0, 3, 5, 9); + + u8g2.drawLine(10, 3, 15, 9); + + u8g2.drawLine(0, 3, 0, 9); + + u8g2.sendBuffer(); + u8g2.check(); + /* + u8g2.drawLine(0, 0, 1, 1); + 12 + u8g2.drawLine(0, 0, 0, 1); + 3 + */ + /* printf("ready to draw\n"); + u8g2.drawLine(0, 0, 220, 220); + // u8g2.firstPage(); + */ + + u8g2.firstPage(); + mui.draw(); + // u8g2.check(); + + u8g2.display(); + u8g2.sendBuffer(); + u8g2.check(); +#endif return true; } bool HmiViewManager::start() diff --git a/Software/STM32F103RBTx/Application/CMakeLists.txt b/Software/STM32F103RBTx/Application/CMakeLists.txt index ebe51f00..1a8798c3 100644 --- a/Software/STM32F103RBTx/Application/CMakeLists.txt +++ b/Software/STM32F103RBTx/Application/CMakeLists.txt @@ -49,6 +49,9 @@ endif() message(STATUS "VariableName: ${CMAKE_CURRENT_SOURCE_DIR}/../Middlewares/Third_Party/stm32-st7735/") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../Middlewares/Third_Party/stm32-st7735/") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../Middlewares/Third_Party/u8g2/cppsrc") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../Middlewares/Third_Party/u8g2/csrc") + include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../Core/Inc/") #include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../FATFS/Target/") #include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../cubeide-sd-card/cubeide-sd-card/Drivers/CMSIS/Include/") @@ -61,6 +64,15 @@ file(GLOB BUSINESS_LOGIC_SRC "${CMAKE_CURRENT_SOURCE_DIR}/BusinessLogic/Src/*.cp file(GLOB DEVICE_SRC "${CMAKE_CURRENT_SOURCE_DIR}/Device/Src/*.cpp") file(GLOB DRIVER_SRC "${CMAKE_CURRENT_SOURCE_DIR}/Driver/Src/*.cpp") + +# Add u8g2 as a subdirectory +# Add u8g2 as a subdirectory +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../Middlewares/Third_Party/u8g2 ${CMAKE_BINARY_DIR}/u8g2_build) + +# Link the u8g2 library (produced by its own CMakeLists.txt) to ApplicationLib +#target_link_libraries(${PROJECT_NAME} PRIVATE u8g2) + + # Add library target for each module add_library(BusinessLogic STATIC ${BUSINESS_LOGIC_SRC}) add_library(Device STATIC ${DEVICE_SRC}) @@ -75,6 +87,6 @@ print_include_dirs(Driver) # Add the main ApplicationLib shared library and link the individual module libraries add_library(${PROJECT_NAME} STATIC ${BUSINESS_LOGIC_SRC} ${DEVICE_SRC} ${DRIVER_SRC}) - +target_link_libraries(${PROJECT_NAME} PRIVATE u8g2) # Link the individual libraries to the main library #target_link_libraries(${PROJECT_NAME} PRIVATE BusinessLogic Device Driver) diff --git a/Software/STM32F103RBTx/Application/Device/Inc/Display.hpp b/Software/STM32F103RBTx/Application/Device/Inc/Display.hpp new file mode 100644 index 00000000..2ec28fca --- /dev/null +++ b/Software/STM32F103RBTx/Application/Device/Inc/Display.hpp @@ -0,0 +1,24 @@ +#ifndef Display_h +#define Display_h +#include "Device/Interfaces/IDisplay.hpp" +#include "Driver/Interfaces/IDisplayDriver.hpp" + +namespace Device +{ + class Display : public IDisplay + { + public: + explicit Display(Driver::IDisplayDriver &displayDriver); + + void check(); + + // void my_u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir); + // void my_u8g2_Setup_uc1617_jlx128128_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb); + + private: + Driver::IDisplayDriver &displayDriver; + }; + +}; + +#endif \ No newline at end of file diff --git a/Software/STM32F103RBTx/Application/Device/Interfaces/IDisplay.hpp b/Software/STM32F103RBTx/Application/Device/Interfaces/IDisplay.hpp new file mode 100644 index 00000000..5d6ff5e1 --- /dev/null +++ b/Software/STM32F103RBTx/Application/Device/Interfaces/IDisplay.hpp @@ -0,0 +1,19 @@ +#ifndef IDisplay_h +#define IDisplay_h +#include "U8g2lib.h" +#include "u8g2.h" + +namespace Device +{ + class IDisplay : public U8G2 + { + public: + // todo + // IDisplay() = default; + // IDisplay() : U8G2(U8G2_R0) {} + IDisplay() : U8G2() {}; + }; + +}; + +#endif \ No newline at end of file diff --git a/Software/STM32F103RBTx/Application/Device/Src/Display.cpp b/Software/STM32F103RBTx/Application/Device/Src/Display.cpp new file mode 100644 index 00000000..ee3a28e1 --- /dev/null +++ b/Software/STM32F103RBTx/Application/Device/Src/Display.cpp @@ -0,0 +1,351 @@ +#include "Device/Inc/Display.hpp" +#include "Driver/Inc/DisplayPixelColor.hpp" +// #define U8X8_USE_PINS 1 +#include + +// #include "u8x8_d_uc1617.h" + +#include "u8g2.h" +#include "u8x8.h" + +#include + +uint16_t hackBuff[300][300] = {0}; + +static const u8x8_display_info_t u8x8_uc1617_128x128_display_info = + { + /* chip_enable_level = */ 0, + /* chip_disable_level = */ 1, + + /* post_chip_enable_wait_ns = */ 10, /* uc1617 datasheet, page 54, actually 5 */ + /* pre_chip_disable_wait_ns = */ 10, /* uc1617 datasheet, page 54, actually 5 */ + /* reset_pulse_width_ms = */ 10, + /* post_reset_wait_ms = */ 20, /* uc1617 datasheet, page 56 */ + /* sda_setup_time_ns = */ 24, /* uc1617 datasheet, page 54 */ + /* sck_pulse_width_ns = */ 45, /* half of cycle time uc1617 datasheet, page 54*/ + /* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */ + /* spi_mode = */ 0, /* active high, rising edge */ + /* i2c_bus_clock_100kHz = */ 4, + /* data_setup_time_ns = */ 30, /* uc1617 datasheet, page 52 */ + /* write_pulse_width_ns = */ 65, /* uc1617 datasheet, page 52 */ + /* tile_width = */ 16, /* width of 16*8=128 pixel */ + /* tile_hight = */ 16, + /* default_x_offset = */ 0, + /* flipmode_x_offset = */ 0, + /* pixel_width = */ 128, + /* pixel_height = */ 128}; + +static const uint8_t u8x8_d_uc1617_jlx128128_init_seq[] = {0}; + +void my_u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir); + +uint8_t my_u8x8_d_uc1617_jlx128128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + printf("%s %d\n", __FILE__, __LINE__); + switch (msg) + { + case U8X8_MSG_DISPLAY_DRAW_TILE: + { + u8x8_cad_StartTransfer(u8x8); + uint8_t x, y, c; + uint8_t *ptr; + + x = ((u8x8_tile_t *)arg_ptr)->x_pos; + x *= 8; + x += u8x8->x_offset; + + // u8x8_cad_SendCmd(u8x8, 0x000 | ((x & 15))); + // u8x8_cad_SendCmd(u8x8, 0x010 | (x >> 4)); + + y = ((u8x8_tile_t *)arg_ptr)->y_pos; + // u8x8_cad_SendCmd(u8x8, 0x060 | (y & 15)); + // u8x8_cad_SendCmd(u8x8, 0x070 | (y >> 4)); + + c = ((u8x8_tile_t *)arg_ptr)->cnt; + c *= 8; + ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; + // ptr = u8x8-> + + printf("%s %d x=%d y =%d count=%d \n", __FILE__, __LINE__, x, y, c); + + // hackBuff[x][y] = 1; + + for (int i = 0; i < c; i++) + { + // printf("%d", *ptr); + // ptr += 8; + if (ptr[i]) + printf("xxxxxxxxxxx%d", ptr[i]); + } + } + break; + } + + /* msg not handled, then try here */ + switch (msg) + { + case U8X8_MSG_DISPLAY_SETUP_MEMORY: + u8x8_d_helper_display_setup_memory(u8x8, &u8x8_uc1617_128x128_display_info); + break; + case U8X8_MSG_DISPLAY_INIT: + u8x8_d_helper_display_init(u8x8); + u8x8_cad_SendSequence(u8x8, u8x8_d_uc1617_jlx128128_init_seq); + // for (;;) + ; + break; + default: + return 0; /* msg unknown */ + } + + return 1; +} + +void my_u8g2_Setup_uc1617_jlx128128_1(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb) +{ + uint8_t tile_buf_height; + uint8_t *buf; + u8g2_SetupDisplay(u8g2, u8x8_d_uc1617_jlx128128, u8x8_cad_001, byte_cb, gpio_and_delay_cb); + buf = u8g2_m_16_16_1(&tile_buf_height); + u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation); + + printf("%s %d\n", __FILE__, __LINE__); +} + +void my_u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir) +{ + printf("%s %d dir=%d, x=%d y=%d, len=%d\n", __FILE__, __LINE__, dir, x, y, len); + // ptr to memory area with u8x8.display_info->tile_width * 8 * tile_buf_height bytes + + uint16_t offset; + uint8_t *ptr; + offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ + offset &= ~7; + offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width; + ptr = u8g2->tile_buf_ptr; + ptr += offset; + ptr += x; + + // hack start + // hackBuff[x][y] = 200; + // hack end + int mx = x; + int my = y; + printf("width %d height %d\n", u8g2->u8x8.display_info->tile_width, u8g2->tile_buf_height); + + // ptr++; + for (int bi = 0; bi < 8; bi++) + // for (int bi = 7; bi >= 0; bi--) + { + auto byte_val = (*ptr >> bi) & 1; + // Print the bit by shifting the byte right + if (byte_val) + printf("%d", byte_val); + hackBuff[x][y * 8 + bi] = byte_val; + } + + // hackBuff[x][y * 8] = 1; + + /* + for (int j = 0; j < u8g2->tile_buf_height * 8; j++) + { + for (int i = 0; i < u8g2->u8x8.display_info->tile_width; i++) + + { + // + // hackBuff[j][i] = u8g2->tile_buf_ptr[i + j]; + // printf("%d", hackBuff[j][i]); + + auto byte = *ptr; + printf("("); + // for (int bi = 7; bi >= 0; bi--) + for (int bi = 0; bi < 8; bi++) + //{ + { + auto byte_val = (byte >> bi) & 1; + // Print the bit by shifting the byte right + if (byte_val) + printf("%d", byte_val); + hackBuff[x + j][y + i + bi] = byte_val; + } + printf(")"); + + // if (hackBuff[i][j] != 0) + { + // displayDriver.setPixel(i, j, Driver::DisplayPixelColor::getColor(0x2f, 0xff, 0xff)); + } + ptr++; + } + printf("\n\n"); + } + */ + + /* for (int i = 0; i < u8g2->u8x8.display_info->tile_width * 8; i++) + { + for (int j = 0; j < u8g2->tile_buf_height; j++) + { + // + hackBuff[j][i] = u8g2->tile_buf_ptr[i + j]; + printf("%d", hackBuff[j][i]); + + // if (hackBuff[i][j] != 0) + { + // displayDriver.setPixel(i, j, Driver::DisplayPixelColor::getColor(0x2f, 0xff, 0xff)); + } + // hackBuff + } + printf("\n"); + } + */ +#if 0 + uint16_t offset; + uint8_t *ptr; + uint8_t bit_pos, mask; + uint8_t or_mask, xor_mask; +#ifdef __unix + uint8_t *max_ptr = u8g2->tile_buf_ptr + u8g2_GetU8x8(u8g2)->display_info->tile_width * u8g2->tile_buf_height * 8; +#endif + + + // assert(x >= u8g2->buf_x0); + // assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8); + // assert(y >= u8g2->buf_y0); + // assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8); + + /* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */ + bit_pos = y; /* overflow truncate is ok here... */ + bit_pos &= 7; /* ... because only the lowest 3 bits are needed */ + mask = 1; + mask <<= bit_pos; + + or_mask = 0; + xor_mask = 0; + if (u8g2->draw_color <= 1) + or_mask = mask; + if (u8g2->draw_color != 1) + xor_mask = mask; + + offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */ + offset &= ~7; + offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width; + ptr = u8g2->tile_buf_ptr; + ptr += offset; + ptr += x; + + if (dir == 0) + { + do + { +#ifdef __unix + assert(ptr < max_ptr); +#endif + + *ptr |= or_mask; + *ptr ^= xor_mask; + + // printf("%s %d ptr=%d\n", __FILE__, __LINE__, *ptr); + + ptr++; + + // hackBuff[mx][my++] = *ptr; + + len--; + } while (len != 0); + } + else + { + do + { +#ifdef __unix + assert(ptr < max_ptr); +#endif + *ptr |= or_mask; + *ptr ^= xor_mask; + + // hackBuff[x][y++] = *ptr; + + bit_pos++; + bit_pos &= 7; + + len--; + + if (bit_pos == 0) + { + ptr += u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */ + + if (u8g2->draw_color <= 1) + or_mask = 1; + if (u8g2->draw_color != 1) + xor_mask = 1; + } + else + { + or_mask <<= 1; + xor_mask <<= 1; + } + } while (len != 0); + } +#endif +} + +uint8_t my_u8x8_byte_rtthread_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + // printf("%s %d\n", __FILE__, __LINE__); + return 0; +} + +uint8_t my_u8x8_gpio_and_delay_rtthread(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) +{ + + // printf("%s %d\n", __FILE__, __LINE__); + return 0; +} +namespace Device +{ + Display::Display(Driver::IDisplayDriver &_displayDriver) : displayDriver(_displayDriver) + // Display::Display() /*: U8G2(U8G2_R0)*/ + { + // u8x8_Setup(getU8x8(), my_u8x8_d_sh1108_128x160, u8x8_cad_001, my_u8x8_byte_arduino_4wire_sw_spi, my_u8x8_gpio_and_delay_arduino); + + /*public: U8G2_UC1617_JLX128128_1_4W_HW_SPI(const u8g2_cb_t *rotation, uint8_t cs, uint8_t dc, uint8_t reset = U8X8_PIN_NONE) : U8G2() { + u8g2_Setup_uc1617_jlx128128_1(&u8g2, rotation, u8x8_byte_rtthread_4wire_hw_spi, u8x8_gpio_and_delay_rtthread); + u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + */ + + const u8g2_cb_t *rotation = U8G2_R0; + uint8_t cs; + uint8_t dc; + uint8_t reset = 0; // U8X8_PIN_NONE; + my_u8g2_Setup_uc1617_jlx128128_1(&u8g2, rotation, my_u8x8_byte_rtthread_4wire_hw_spi, my_u8x8_gpio_and_delay_rtthread); + printf("%s %d\n", __FILE__, __LINE__); + // u8x8_SetPin_4Wire_HW_SPI(getU8x8(), cs, dc, reset); + } + + void Display::check() + { + // printf("curr: %d", u8g2->tile_curr_row); + + for (int i = 0; i < 100 * 8 * u8g2.tile_buf_height; i++) + { + + // if (u8g2.tile_buf_ptr[i] != 0) + { + printf("(%d)", u8g2.tile_buf_ptr[i]); + } + } + printf("\n"); + + // copy data to driver buffer + for (int i = 0; i < 200; i++) + { + for (int j = 0; j < 200; j++) + { + if (hackBuff[i][j] != 0) + { + displayDriver.setPixel(i, j, Driver::DisplayPixelColor::getColor(0x2f, 0xff, 0xff)); + } + // hackBuff + } + } + } + +}; \ No newline at end of file