mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-26 20:09:53 +00:00
Polish the generic STM32 instructions
This includes removal of the SLINT_STYLE setting, as a default is set there for FEATURE_FREESTANDING.
This commit is contained in:
parent
9894eca229
commit
ec4a95f031
1 changed files with 83 additions and 18 deletions
|
@ -12,30 +12,95 @@ as well as the peripherals of our board.
|
||||||
- Enable all peripherals needed. This includes LTDC and typically the FMC to be able
|
- Enable all peripherals needed. This includes LTDC and typically the FMC to be able
|
||||||
to place the framebuffers in RAM.
|
to place the framebuffers in RAM.
|
||||||
- Select CMake in the code generator options.
|
- Select CMake in the code generator options.
|
||||||
3. General the CMake project and skeleton code.
|
3. Generate the CMake project and skeleton code.
|
||||||
4. In the STM32 VS Code Extension, choose the command to import a CMake project.
|
4. In the STM32 VS Code Extension, choose the command to import a CMake project.
|
||||||
5. In STM32CubeMX select the STM32Cube BSP that matches your board and install it.
|
5. In STM32CubeMX select the STM32Cube BSP that matches your board and install it.
|
||||||
6. Copy the BSP drivers into your project's source tree and modify `CMakeLists.txt` to
|
6. Copy the BSP drivers into your project's source tree and modify `CMakeLists.txt` to
|
||||||
add them to the build.
|
add them to the build.
|
||||||
7. Add C++ support to the generated CMake project by adding `CXX` to the `LANGUAGES` option
|
7. Add C++ support to the generated CMake project by adding `CXX` to the `LANGUAGES` option
|
||||||
of the `project` command.
|
of the `project` command.
|
||||||
8. Download and extract <https://github.com/slint-ui/slint/releases/latest/download/Slint-cpp-nightly-thumbv7em-none-eabihf.tar.gz>
|
8. Open a web browser, navigate to <https://github.com/slint-ui/slint/releases/latest>, and download
|
||||||
9. Set `CMAKE_PREFIX_PATH` to the extracted directory.
|
and extract `Slint-cpp-VERSION-thumbv7em-none-eabihf.tar.gz`, replace `VERSION` with the version you see.
|
||||||
10. Adjust your `CMakeLists.txt` for Slint use:
|
10. Set `CMAKE_PREFIX_PATH` to the extracted directory.
|
||||||
1. Add a `find_package(Slint)` call.
|
11. Adjust your `CMakeLists.txt` for use of Slint. Copy the follow snippets and adjust the target names as needed:
|
||||||
2. Enable resource embedding by adding `set(DEFAULT_SLINT_EMBED_RESOURCES embed-for-software-renderer)`.
|
```cmake
|
||||||
3. Set the default style to `Fluent` with `set(SLINT_STYLE "fluent-light")`.
|
# Locate Slint
|
||||||
4. Add `SLINT_STM32_BSP_NAME=<name>` to your `target_compile_definitions` and replace `<name>` with the
|
find_package(Slint)
|
||||||
name of your BSP (for example `stm32h735g_discovery` or `stm32h747i_discovery`).
|
|
||||||
5. Add `Slint::Slint` to your `target_link_libraries`.
|
# Default to pre-compiling images and fonts
|
||||||
11. Add a C++ source file to your project, for example `appmain.cpp`, with an `appmain` function and call it
|
set(DEFAULT_SLINT_EMBED_RESOURCES embed-for-software-renderer)
|
||||||
|
|
||||||
|
# Replace $BSP_NAME with the name of your concrete BSP,
|
||||||
|
# for example stm32h735g_discovery.
|
||||||
|
target_compile_definitions(your-target PRIVATE
|
||||||
|
SLINT_STM32_BSP_NAME=$BSP_NAME
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link Slint run-time library
|
||||||
|
target_link_libraries(your-target PRIVATE
|
||||||
|
Slint::Slint
|
||||||
|
)
|
||||||
|
```
|
||||||
|
12. Add a C++ source file to your project, for example `appmain.cpp`, with an `appmain` function and call it
|
||||||
from the generated `main.c`.
|
from the generated `main.c`.
|
||||||
12. Add a `.slint` file to your project and include it in your project by calling `slint_target_sources`.
|
13. Create `app-window.slint` with the following contents:
|
||||||
13. In your `appmain` function, initialize the screen via `BSP_LCD_InitEx` as well as the touch screen via `BSP_TS_Init`.
|
```slint,no-preview
|
||||||
14. Include `#include <slint-stm32.h>` and call `slint_stm32_init(SlintPlatformConfiguration());` to initialize the
|
import { VerticalBox, AboutSlint } from "std-widgets.slint";
|
||||||
Slint platform integration for STM32.
|
export component AppWindow inherits Window {
|
||||||
15. Finally, include the header file for your `.slint` file, instantiate the generated class, and invoke the event loop by
|
VerticalBox {
|
||||||
calling `->run()` on the instance.
|
AboutSlint {}
|
||||||
|
Text {
|
||||||
|
text: "Hello World";
|
||||||
|
font-size: 18px;
|
||||||
|
horizontal-alignment: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
14. Add a `.slint` file to your project and include it in your project by calling `slint_target_sources`:
|
||||||
|
```cmake
|
||||||
|
slint_target_sources(your-target app-window.slint)
|
||||||
|
```
|
||||||
|
15. In your `appmain` function, initialize the screen via `BSP_LCD_InitEx` as well as the touch screen via `BSP_TS_Init`,
|
||||||
|
include `#include <slint-stm32.h>` and call `slint_stm32_init(SlintPlatformConfiguration());` to initialize the
|
||||||
|
Slint platform integration for STM32. Finally, include the header file for your `.slint` file, instantiate the generated class, and invoke the event loop by calling `->run()` on the instance. Use the following example as reference:
|
||||||
|
```cpp
|
||||||
|
#include <slint-stm32.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stm32h735g_discovery.h>
|
||||||
|
#include <stm32h735g_discovery_lcd.h>
|
||||||
|
#include <stm32h735g_discovery_ts.h>
|
||||||
|
|
||||||
|
#include "app-window.h"
|
||||||
|
|
||||||
|
// Called from main()
|
||||||
|
extern "C" void appmain() {
|
||||||
|
if (BSP_LCD_InitEx(0, LCD_ORIENTATION_LANDSCAPE, LCD_PIXEL_FORMAT_RGB565,
|
||||||
|
LCD_DEFAULT_WIDTH, LCD_DEFAULT_HEIGHT) != 0) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
BSP_LCD_DisplayOn(0);
|
||||||
|
BSP_LCD_SetActiveLayer(0, 0);
|
||||||
|
|
||||||
|
TS_Init_t hTS;
|
||||||
|
hTS.Width = LCD_DEFAULT_WIDTH;
|
||||||
|
hTS.Height = LCD_DEFAULT_HEIGHT;
|
||||||
|
hTS.Orientation = TS_SWAP_XY;
|
||||||
|
hTS.Accuracy = 0;
|
||||||
|
/* Touchscreen initialization */
|
||||||
|
if (BSP_TS_Init(0, &hTS) != 0) {
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
|
||||||
|
slint_stm32_init(SlintPlatformConfiguration());
|
||||||
|
|
||||||
|
auto app_window = AppWindow::create();
|
||||||
|
|
||||||
|
app_window->run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue