diff --git a/docs/integration/driver/windows.rst b/docs/integration/driver/windows.rst index 036c2a00d..8f20ecf0a 100644 --- a/docs/integration/driver/windows.rst +++ b/docs/integration/driver/windows.rst @@ -102,7 +102,7 @@ Usage while (1) { uint32_t time_till_next = lv_timer_handler(); - Sleep(time_till_next); + lv_delay_ms(time_till_next); } return 0; diff --git a/src/drivers/windows/lv_windows_context.c b/src/drivers/windows/lv_windows_context.c index 7bb1f4a35..1479d0ff6 100644 --- a/src/drivers/windows/lv_windows_context.c +++ b/src/drivers/windows/lv_windows_context.c @@ -1,4 +1,4 @@ -/** +/** * @file lv_windows_context.c * */ @@ -26,6 +26,8 @@ static uint32_t lv_windows_tick_count_callback(void); +static void lv_windows_delay_callback(uint32_t ms); + static void lv_windows_check_display_existence_timer_callback( lv_timer_t * timer); @@ -72,6 +74,8 @@ void lv_windows_platform_init(void) { lv_tick_set_cb(lv_windows_tick_count_callback); + lv_delay_set_cb(lv_windows_delay_callback); + lv_timer_create( lv_windows_check_display_existence_timer_callback, 200, @@ -118,7 +122,33 @@ lv_windows_window_context_t * lv_windows_get_window_context( static uint32_t lv_windows_tick_count_callback(void) { - return GetTickCount(); + LARGE_INTEGER Frequency; + if(QueryPerformanceFrequency(&Frequency)) { + LARGE_INTEGER PerformanceCount; + if(QueryPerformanceCounter(&PerformanceCount)) { + return (uint32_t)(PerformanceCount.QuadPart * 1000 / Frequency.QuadPart); + } + } + + return (uint32_t)GetTickCount64(); +} + +static void lv_windows_delay_callback(uint32_t ms) +{ + HANDLE timer_handle = CreateWaitableTimerExW( + NULL, + NULL, + CREATE_WAITABLE_TIMER_MANUAL_RESET | + CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, + TIMER_ALL_ACCESS); + if(timer_handle) { + LARGE_INTEGER due_time; + due_time.QuadPart = -((int64_t)ms) * 1000 * 10; + SetWaitableTimer(timer_handle, &due_time, 0, NULL, NULL, FALSE); + WaitForSingleObject(timer_handle, INFINITE); + + CloseHandle(timer_handle); + } } static void lv_windows_check_display_existence_timer_callback(