Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for windows os #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
cmake_minimum_required(VERSION 3.10)
project(lvgl C CXX)

# Set the correct FreeRTOS port for your system (e.g., Posix for WSL)
set(FREERTOS_PORT GCC_POSIX CACHE STRING "Port for FreeRTOS on Posix environment")
# output compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
# Set the correct FreeRTOS port for your system (e.g., Posix for WSL)
set(FREERTOS_PORT MSVC_MINGW CACHE STRING "Port for FreeRTOS on Posix environment")
else()
# Set the correct FreeRTOS port for your system (e.g., Mingw-w64 for Windows)
set(FREERTOS_PORT GCC_POSIX CACHE STRING "Port for FreeRTOS on Posix environment")
endif()

unset(USE_FREERTOS CACHE)

Expand All @@ -21,14 +29,16 @@ if(USE_FREERTOS)

# FreeRTOS-specific include directories
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/include)
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix)
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/portable/MSVC-MingW)
else()
include_directories(${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix)
endif()
include_directories(${PROJECT_SOURCE_DIR}/config)

# Add FreeRTOS sources
file(GLOB FREERTOS_SOURCES
"${PROJECT_SOURCE_DIR}/FreeRTOS/*.c"
"${PROJECT_SOURCE_DIR}/FreeRTOS/portable/MemMang/heap_4.c"
"${PROJECT_SOURCE_DIR}/FreeRTOS/portable/ThirdParty/GCC/Posix/*.c"
)
else()
message(STATUS "FreeRTOS is disabled")
Expand Down Expand Up @@ -81,7 +91,7 @@ if(USE_FREERTOS)
${FREERTOS_SOURCES} # Add only if USE_FREERTOS is enabled
)
# Link FreeRTOS libraries
target_link_libraries(main freertos_config FreeRTOS)
target_link_libraries(main freertos_config freertos_kernel freertos_kernel_port)
else()
add_executable(main
${PROJECT_SOURCE_DIR}/main/src/main.c
Expand Down
66 changes: 61 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[LVGL](https://github.com/lvgl/lvgl) is written mainly for microcontrollers and embedded systems, however you can run the library **on your PC** as well without any embedded hardware. The code written on PC can be simply copied when your are using an embedded system.

This project is pre-configured for VSCode and should work work on Windows, Linux and MacOs as well. FreeRTOS is also included and can be optionally enabled to better simulate embedded system's behavior.
This project is pre-configured for VSCode and should work work on Windows, Linux and MacOs as well. FreeRTOS is also included and can be optionally enabled to better simulate embedded system's behavior.


## Get started
Expand Down Expand Up @@ -33,6 +33,32 @@ For ArchLinux
sudo pacman -Syu && sudo pacman -S sdl2 libsdl2-devel sdl2_mixer sdl2-devel base-devel gcc make
```

#### Windows

For Windows 10

* Install `cmake`
* Download `mingw-w64` gcc toolchain and add it to environment PATH `[1]`
* Download `SDL2` and add it to environment PATH `[2]`

**Tips:**

`[1]` If you have no idea to install Mingw-w6, please refer this link to install Mingw-w64 https://code.visualstudio.com/docs/cpp/config-mingw

`[2]`
For example to configure SDL2 in Windows OS

Download SDL2-devel-2.30.9-mingw.tar.gz from
```
https://github.com/libsdl-org/SDL/releases/tag/release-2.30.9
```

Unzip SDL2-devel-2.30.9-mingw.zip then set environment path:
```
D:\program_files\SDL2-2.30.9\x86_64-w64-mingw32\lib\cmake\SDL2
D:\program_files\SDL2-2.30.9\x86_64-w64-mingw32\bin
```

## Usage
### Visual Studio Code

Expand Down Expand Up @@ -77,21 +103,50 @@ To correctly configure the project, the RTOS (Real-Time Operating System) requir
This configuration ensures that the SDL window is displayed in a timely manner. If this value is reduced, it may cause significant delays in the SDL window's appearance. If the allocated heap memory is too small, the window may fail to appear altogether.
Therefore, it is crucial to allocate sufficient heap memory to ensure smooth execution and debugging experience.

### Enable FreeRTOS
### Enable FreeRTOS
To enable the rtos part of this project select in lv_conf.h `#define LV_USE_OS LV_OS_NONE` to `#define LV_USE_OS LV_OS_FREERTOS`
Additionaly you have to enable the compilation of all FreeRTOS Files by turn on `option(USE_FREERTOS "Enable FreeRTOS" OFF) ` in the CMakeLists.txt file.

For windows

* Disable `USE_FREERTOS_TASK_NOTIFY` in `lvgl\src\osal\lv_freertos.h` `#define USE_FREERTOS_TASK_NOTIFY 1` to `#define USE_FREERTOS_TASK_NOTIFY 0`, because enable `USE_FREERTOS_TASK_NOTIFY` will cause software crash in windows.

```diff
--- a/src/osal/lv_freertos.h
+++ b/src/osal/lv_freertos.h
@@ -43,7 +43,7 @@ extern "C" {
*
* RTOS task notifications can only be used when there is only one task that can be the recipient of the event.
*/
-#define USE_FREERTOS_TASK_NOTIFY 1
+#define USE_FREERTOS_TASK_NOTIFY 0

/**********************
* TYPEDEFS
```

### CMake

This project uses CMake under the hood which can be used without Visula Studio Code too. Just type these in a Terminal when you are in the project's root folder:

For unix like OS

```bash
mkdir build
cd build
cmake ..
make -j
```

For Windows

```cmd
mkdir build
cd build
cmake .. -G"MinGW Makefiles"
cmake --build . -j10
```

## Optional library

There are also FreeType and FFmpeg support. You can install these according to the followings:
Expand All @@ -117,12 +172,13 @@ make
sudo make install
```
### (RT)OS support
Works with any OS like pthred, Windows, FreeRTOS, etc. It has build in support for FreeRTOS.
Works with any OS like pthred, Windows, FreeRTOS, etc. It has build in support for FreeRTOS.

## Test
This project is configured for [VSCode](https://code.visualstudio.com) and is tested on:
- Ubuntu Linux
This project is configured for [VSCode](https://code.visualstudio.com) and is tested on:
- Ubuntu Linux
- Windows WSL (Ubuntu Linux)
- Windows 10

It requires a working version of GCC, GDB and make in your path.

Expand Down
2 changes: 1 addition & 1 deletion config/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern uint32_t SystemCoreClock;
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TASK_NOTIFICATIONS 0
#define configUSE_TASK_NOTIFICATIONS 1
#define configUSE_STREAM_BUFFERS 0

/* Co-routine definitions. */
Expand Down
2 changes: 1 addition & 1 deletion lv_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@

/* Enable native helium assembly to be compiled */
#define LV_USE_NATIVE_HELIUM_ASM 0

/* 0: use a simple renderer capable of drawing only simple rectangles with gradient, images, texts, and straight lines only
* 1: use a complex renderer capable of drawing rounded corners, shadow, skew lines, and arcs too */
#define LV_DRAW_SW_COMPLEX 1
Expand Down
59 changes: 59 additions & 0 deletions main/src/freertos_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@
*/

#include "lvgl/src/osal/lv_os.h"
#define _DEFAULT_SOURCE /* needed for usleep() */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include "lvgl/lvgl.h"
#include "lvgl/examples/lv_examples.h"
#include "lvgl/demos/lv_demos.h"
#ifdef __MINGW32__
#include <SDL2/SDL.h>
#else
#include "glob.h"
#endif

#if LV_USE_OS == LV_OS_FREERTOS

#include "lvgl.h"
#include <cstdio> // For printf in C++

/**********************
* STATIC PROTOTYPES
**********************/
extern "C" {
static lv_display_t * hal_init(int32_t w, int32_t h);
}

// ........................................................................................................
/**
* @brief Malloc failed hook
Expand Down Expand Up @@ -119,6 +139,9 @@ void create_hello_world_screen()
*/
void lvgl_task(void *pvParameters)
{
/*Initialize the HAL (display, input devices, tick) for LVGL*/
hal_init(480, 320);

/* Show simple hello world screen */
create_hello_world_screen();

Expand Down Expand Up @@ -176,4 +199,40 @@ extern "C" void freertos_main()
vTaskStartScheduler();
}


/**
* Initialize the Hardware Abstraction Layer (HAL) for the LVGL graphics
* library
*/
extern "C"{
static lv_display_t * hal_init(int32_t w, int32_t h)
{

lv_group_set_default(lv_group_create());

lv_display_t * disp = lv_sdl_window_create(w, h);

lv_indev_t * mouse = lv_sdl_mouse_create();
lv_indev_set_group(mouse, lv_group_get_default());
lv_indev_set_display(mouse, disp);
lv_display_set_default(disp);

LV_IMAGE_DECLARE(mouse_cursor_icon); /*Declare the image file.*/
lv_obj_t * cursor_obj;
cursor_obj = lv_image_create(lv_screen_active()); /*Create an image object for the cursor */
lv_image_set_src(cursor_obj, &mouse_cursor_icon); /*Set the image source*/
lv_indev_set_cursor(mouse, cursor_obj); /*Connect the image object to the driver*/

lv_indev_t * mousewheel = lv_sdl_mousewheel_create();
lv_indev_set_display(mousewheel, disp);
lv_indev_set_group(mousewheel, lv_group_get_default());

lv_indev_t * kb = lv_sdl_keyboard_create();
lv_indev_set_display(kb, disp);
lv_indev_set_group(kb, lv_group_get_default());

return disp;
}
}

#endif
15 changes: 10 additions & 5 deletions main/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#include "lvgl/lvgl.h"
#include "lvgl/examples/lv_examples.h"
#include "lvgl/demos/lv_demos.h"
#ifdef __MINGW32__
#include <SDL2/SDL.h>
#else
#include "glob.h"
#endif

/*********************
* DEFINES
Expand All @@ -34,7 +38,7 @@ static lv_display_t * hal_init(int32_t w, int32_t h);
* STATIC VARIABLES
**********************/

/**********************
/**********************
* MACROS
**********************/

Expand Down Expand Up @@ -72,11 +76,12 @@ int main(int argc, char **argv)
/*Initialize LVGL*/
lv_init();

#if LV_USE_OS == LV_OS_NONE

/*Initialize the HAL (display, input devices, tick) for LVGL*/
/*In FreeRTOS, move hal_init to lvgl_task to avoid SDL2 stuck when running in windows OS*/
hal_init(320, 480);

#if LV_USE_OS == LV_OS_NONE

lv_demo_widgets();

while(1) {
Expand All @@ -89,7 +94,7 @@ int main(int argc, char **argv)
#elif LV_USE_OS == LV_OS_FREERTOS

/* Run FreeRTOS and create lvgl task */
freertos_main();
freertos_main();

#endif

Expand Down Expand Up @@ -131,4 +136,4 @@ static lv_display_t * hal_init(int32_t w, int32_t h)
lv_indev_set_group(kb, lv_group_get_default());

return disp;
}
}