Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGawron committed Dec 11, 2024
1 parent 243512e commit 8ebdb77
Show file tree
Hide file tree
Showing 13 changed files with 591 additions and 13 deletions.
43 changes: 34 additions & 9 deletions DevOps/Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y \
clang-tools \
python3 \
python3-pip \
python3-dbg \
graphviz \
doxygen \
wget \
Expand All @@ -38,33 +39,60 @@ 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 && \
# ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake && \
# 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 && \
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions DevOps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
54 changes: 54 additions & 0 deletions Documentation/Diagrams/DisplayClassDiagram.plantuml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Documentation/Diagrams/DisplayClassDiagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Simulation/FirmwarePCSimulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ target_link_libraries(FirmwarePCSimulator
BusinessLogic
Device
DriverForSimulation
u8g2
)
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ namespace Driver
uint8_t y,
DisplayPixelColor::PixelColor color)
{
content[x][y] = color;
return IDisplayDriver::Status::Ok;
}

Expand Down
24 changes: 24 additions & 0 deletions Simulation/FirmwarePCSimulator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include "Driver/Inc/DisplayPixelColor.hpp"
#include "BusinessLogic/Interfaces/IPlatformFactory.hpp"
Expand All @@ -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()
Expand Down
14 changes: 13 additions & 1 deletion Software/STM32F103RBTx/Application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
Expand All @@ -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})
Expand All @@ -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)
24 changes: 24 additions & 0 deletions Software/STM32F103RBTx/Application/Device/Inc/Display.hpp
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions Software/STM32F103RBTx/Application/Device/Interfaces/IDisplay.hpp
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 8ebdb77

Please sign in to comment.