From 9c784f9c1f0ca071b7b72aeba217cc96d9c02723 Mon Sep 17 00:00:00 2001 From: yangjie Date: Mon, 26 Apr 2021 14:57:26 +0800 Subject: [bsp][simulator]delete tap_netif.c --- bsp/simulator/drivers/SConscript | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bsp/simulator/drivers/SConscript') diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index 593a3fdfdc..2fd17ddf80 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -26,10 +26,8 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_DFS_WINSHAREDIR') = SrcRemove(src, 'dfs_win32.c') if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MODULE') == False: SrcRemove(src, ['module_win32.c']) -if GetDepend('RT_USING_TAPNETIF') == False: - SrcRemove(src, ['tap_netif.c']) if sys.platform[0:5]=="linux": #check whether under linux - SrcRemove(src, ['module_win32.c', 'dfs_win32.c', 'tap_netif.c']) + SrcRemove(src, ['module_win32.c', 'dfs_win32.c']) group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH) -- cgit v1.3.1 From 7d57f6b17580c60f8b1bebdde22450a7fce570ec Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 25 Sep 2021 00:24:55 -0400 Subject: [bsp][simulator] 增加_CRT_DECLARE_NONSTDC_NAMES=0全局宏定义,防止vs内置stdc与libc定义冲突,如dev_t等 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/simulator/drivers/SConscript | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bsp/simulator/drivers/SConscript') diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index 2fd17ddf80..87a79bd4c7 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -7,6 +7,8 @@ LIBS = [] LIBPATH = [] CPPPATH = [cwd] +CPPDEFINES = ['_CRT_DECLARE_NONSTDC_NAMES=0'] # avoid to conflict with the inherent STDC in VS + # remove no need file. if GetDepend('PKG_USING_GUIENGINE') == False: SrcRemove(src, 'sdl_fb.c') @@ -30,6 +32,6 @@ if sys.platform[0:5]=="linux": #check whether under linux SrcRemove(src, ['module_win32.c', 'dfs_win32.c']) group = DefineGroup('Drivers', src, depend = [''], - CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH) + CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH, CPPDEFINES = CPPDEFINES) Return('group') -- cgit v1.3.1 From e72eb1ae95b52b61322ab4f17ab0ea8d8f874eb2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 15 Dec 2021 22:40:14 -0500 Subject: [simulator][win32] add lvgl driver --- bsp/qemu-vexpress-a9/drivers/lvgl/lv_demo.c | 1 - bsp/simulator/Kconfig | 19 +- bsp/simulator/drivers/SConscript | 6 + bsp/simulator/drivers/lvgl/SConscript | 17 + bsp/simulator/drivers/lvgl/lv_conf.h | 30 + bsp/simulator/drivers/lvgl/lv_demo.c | 68 ++ bsp/simulator/drivers/lvgl/lv_port_disp.c | 14 + bsp/simulator/drivers/lvgl/lv_port_disp.h | 25 + bsp/simulator/drivers/lvgl/lv_port_indev.c | 14 + bsp/simulator/drivers/lvgl/lv_port_indev.h | 23 + bsp/simulator/drivers/lvgl/win32drv.c | 1007 +++++++++++++++++++++++++++ bsp/simulator/drivers/lvgl/win32drv.h | 67 ++ 12 files changed, 1288 insertions(+), 3 deletions(-) create mode 100644 bsp/simulator/drivers/lvgl/SConscript create mode 100644 bsp/simulator/drivers/lvgl/lv_conf.h create mode 100644 bsp/simulator/drivers/lvgl/lv_demo.c create mode 100644 bsp/simulator/drivers/lvgl/lv_port_disp.c create mode 100644 bsp/simulator/drivers/lvgl/lv_port_disp.h create mode 100644 bsp/simulator/drivers/lvgl/lv_port_indev.c create mode 100644 bsp/simulator/drivers/lvgl/lv_port_indev.h create mode 100644 bsp/simulator/drivers/lvgl/win32drv.c create mode 100644 bsp/simulator/drivers/lvgl/win32drv.h (limited to 'bsp/simulator/drivers/SConscript') diff --git a/bsp/qemu-vexpress-a9/drivers/lvgl/lv_demo.c b/bsp/qemu-vexpress-a9/drivers/lvgl/lv_demo.c index 17d01e09cc..44288c23f2 100644 --- a/bsp/qemu-vexpress-a9/drivers/lvgl/lv_demo.c +++ b/bsp/qemu-vexpress-a9/drivers/lvgl/lv_demo.c @@ -9,7 +9,6 @@ */ #include #include -#include #define DBG_TAG "LVGL.demo" #define DBG_LVL DBG_INFO #include diff --git a/bsp/simulator/Kconfig b/bsp/simulator/Kconfig index c5e4618d76..2222df6c93 100644 --- a/bsp/simulator/Kconfig +++ b/bsp/simulator/Kconfig @@ -26,8 +26,23 @@ config SOC_SIMULATOR if RT_USING_DFS config RT_USING_DFS_WINSHAREDIR - bool "Enable shared file system between windows" - default n + bool "Enable shared file system between windows" + default n endif +config BSP_USING_LVGL + bool "Enable LVGL for LCD" + select PKG_USING_LVGL + select PKG_USING_LV_MUSIC_DEMO + default n + +if BSP_USING_LVGL + config BSP_LCD_WIDTH + int "LCD width" + default 800 + config BSP_LCD_HEIGHT + int "LCD height" + default 480 + +endif diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index 87a79bd4c7..d5a82f93b7 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -1,4 +1,5 @@ import sys +import os from building import * cwd = GetCurrentDir() @@ -34,4 +35,9 @@ if sys.platform[0:5]=="linux": #check whether under linux group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH, CPPDEFINES = CPPDEFINES) +list = os.listdir(cwd) +for item in list: + if os.path.isfile(os.path.join(cwd, item, 'SConscript')): + group = group + SConscript(os.path.join(item, 'SConscript')) + Return('group') diff --git a/bsp/simulator/drivers/lvgl/SConscript b/bsp/simulator/drivers/lvgl/SConscript new file mode 100644 index 0000000000..5952cb2e9a --- /dev/null +++ b/bsp/simulator/drivers/lvgl/SConscript @@ -0,0 +1,17 @@ +from building import * +import os + +cwd = GetCurrentDir() +group = [] +src = Glob('*.c') +CPPPATH = [cwd] + +list = os.listdir(cwd) +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + group = group + SConscript(os.path.join(d, 'SConscript')) + +group += DefineGroup('LVGL-port', src, depend = ['BSP_USING_LVGL'], CPPPATH = CPPPATH) + +Return('group') diff --git a/bsp/simulator/drivers/lvgl/lv_conf.h b/bsp/simulator/drivers/lvgl/lv_conf.h new file mode 100644 index 0000000000..ee05e7a8a2 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_conf.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man First version + */ + +#ifndef LV_CONF_H +#define LV_CONF_H + +#define LV_USE_PERF_MONITOR 1 +#define LV_COLOR_DEPTH 32 + +# define USE_WIN32DRV 1 +# define WIN32DRV_MONITOR_ZOOM 1 + +/* music player demo */ +#include +#define LV_DISP_DEF_REFR_PERIOD 10 +#define LV_HOR_RES_MAX BSP_LCD_WIDTH +#define LV_VER_RES_MAX BSP_LCD_HEIGHT +#define LV_USE_DEMO_RTT_MUSIC 1 +#define LV_DEMO_RTT_MUSIC_AUTO_PLAY 1 +#define LV_FONT_MONTSERRAT_12 1 +#define LV_FONT_MONTSERRAT_16 1 + +#endif diff --git a/bsp/simulator/drivers/lvgl/lv_demo.c b/bsp/simulator/drivers/lvgl/lv_demo.c new file mode 100644 index 0000000000..c66dd228e7 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_demo.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-17 Meco Man First version + */ +#include +#define DBG_TAG "LVGL.demo" +#define DBG_LVL DBG_INFO +#include +#include +#include +#include + +#define IDI_LVGL 101 + +#ifndef LV_THREAD_STACK_SIZE +#define LV_THREAD_STACK_SIZE 4096 +#endif + +#ifndef LV_THREAD_PRIO +#define LV_THREAD_PRIO (RT_THREAD_PRIORITY_MAX*2/3) +#endif + +static void lvgl_thread(void *parameter) +{ + /* initialize win32 driver; don't put this in lv_port_disp() */ + if (!lv_win32_init( + GetModuleHandleW(NULL), + SW_SHOW, + BSP_LCD_WIDTH, + BSP_LCD_HEIGHT, + LoadIconW(GetModuleHandleW(NULL), MAKEINTRESOURCE(IDI_LVGL)))) + { + LOG_E("lv_win32_init failure!"); + return; + } + + lv_win32_add_all_input_devices_to_group(NULL); + + /* display demo */ + extern void lv_demo_music(void); + lv_demo_music(); + + while (!lv_win32_quit_signal) + { + lv_task_handler(); + Sleep(1); + } +} + +static int lvgl_demo_init(void) +{ + rt_thread_t tid; + + tid = rt_thread_create("LVGL", lvgl_thread, RT_NULL, LV_THREAD_STACK_SIZE, LV_THREAD_PRIO, 10); + if(tid == RT_NULL) + { + LOG_E("Fail to create 'LVGL' thread"); + } + rt_thread_startup(tid); + + return 0; +} +INIT_APP_EXPORT(lvgl_demo_init); diff --git a/bsp/simulator/drivers/lvgl/lv_port_disp.c b/bsp/simulator/drivers/lvgl/lv_port_disp.c new file mode 100644 index 0000000000..220966f631 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_port_disp.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ + +void lv_port_disp_init(void) +{ + /* do nothing*/ +} diff --git a/bsp/simulator/drivers/lvgl/lv_port_disp.h b/bsp/simulator/drivers/lvgl/lv_port_disp.h new file mode 100644 index 0000000000..9bcefe5260 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_port_disp.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ +#ifndef LV_PORT_DISP_H +#define LV_PORT_DISP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void lv_port_disp_init(void); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/bsp/simulator/drivers/lvgl/lv_port_indev.c b/bsp/simulator/drivers/lvgl/lv_port_indev.c new file mode 100644 index 0000000000..882f10fa85 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_port_indev.c @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ + +void lv_port_indev_init(void) +{ + /* do nothing */ +} diff --git a/bsp/simulator/drivers/lvgl/lv_port_indev.h b/bsp/simulator/drivers/lvgl/lv_port_indev.h new file mode 100644 index 0000000000..7599bb899d --- /dev/null +++ b/bsp/simulator/drivers/lvgl/lv_port_indev.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-10-18 Meco Man The first version + */ +#ifndef LV_PORT_INDEV_H +#define LV_PORT_INDEV_H + +#ifdef __cplusplus +extern "C" { +#endif + +void lv_port_indev_init(void); + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif diff --git a/bsp/simulator/drivers/lvgl/win32drv.c b/bsp/simulator/drivers/lvgl/win32drv.c new file mode 100644 index 0000000000..b37ec99f7d --- /dev/null +++ b/bsp/simulator/drivers/lvgl/win32drv.c @@ -0,0 +1,1007 @@ +/** + * @file win32drv.c + * + */ + +/********************* + * INCLUDES + *********************/ + +#include "win32drv.h" + +#if USE_WIN32DRV + +#include + +#include +#include + +/********************* + * DEFINES + *********************/ + +#define WINDOW_EX_STYLE \ + WS_EX_CLIENTEDGE + +#define WINDOW_STYLE \ + (WS_OVERLAPPEDWINDOW & ~(WS_SIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME)) + +#ifndef WIN32DRV_MONITOR_ZOOM +#define WIN32DRV_MONITOR_ZOOM 1 +#endif + +#ifndef USER_DEFAULT_SCREEN_DPI +#define USER_DEFAULT_SCREEN_DPI 96 +#endif + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +/** + * @brief Creates a B8G8R8A8 frame buffer. + * @param WindowHandle A handle to the window for the creation of the frame + * buffer. If this value is NULL, the entire screen will be + * referenced. + * @param Width The width of the frame buffer. + * @param Height The height of the frame buffer. + * @param PixelBuffer The raw pixel buffer of the frame buffer you created. + * @param PixelBufferSize The size of the frame buffer you created. + * @return If the function succeeds, the return value is a handle to the device + * context (DC) for the frame buffer. If the function fails, the return + * value is NULL, and PixelBuffer parameter is NULL. +*/ +static HDC lv_win32_create_frame_buffer( + _In_opt_ HWND WindowHandle, + _In_ LONG Width, + _In_ LONG Height, + _Out_ UINT32** PixelBuffer, + _Out_ SIZE_T* PixelBufferSize); + +/** + * @brief Enables WM_DPICHANGED message for child window for the associated + * window. + * @param WindowHandle The window you want to enable WM_DPICHANGED message for + * child window. + * @return If the function succeeds, the return value is non-zero. If the + * function fails, the return value is zero. + * @remarks You need to use this function in Windows 10 Threshold 1 or Windows + * 10 Threshold 2. +*/ +static BOOL lv_win32_enable_child_window_dpi_message( + _In_ HWND WindowHandle); + +/** + * @brief Registers a window as being touch-capable. + * @param hWnd The handle of the window being registered. + * @param ulFlags A set of bit flags that specify optional modifications. + * @return If the function succeeds, the return value is nonzero. If the + * function fails, the return value is zero. + * @remark For more information, see RegisterTouchWindow. +*/ +static BOOL lv_win32_register_touch_window( + HWND hWnd, + ULONG ulFlags); + +/** + * @brief Retrieves detailed information about touch inputs associated with a + * particular touch input handle. + * @param hTouchInput The touch input handle received in the LPARAM of a touch + * message. + * @param cInputs The number of structures in the pInputs array. + * @param pInputs A pointer to an array of TOUCHINPUT structures to receive + * information about the touch points associated with the + * specified touch input handle. + * @param cbSize The size, in bytes, of a single TOUCHINPUT structure. + * @return If the function succeeds, the return value is nonzero. If the + * function fails, the return value is zero. + * @remark For more information, see GetTouchInputInfo. +*/ +static BOOL lv_win32_get_touch_input_info( + HTOUCHINPUT hTouchInput, + UINT cInputs, + PTOUCHINPUT pInputs, + int cbSize); + +/** + * @brief Closes a touch input handle, frees process memory associated with it, + and invalidates the handle. + * @param hTouchInput The touch input handle received in the LPARAM of a touch + * message. + * @return If the function succeeds, the return value is nonzero. If the + * function fails, the return value is zero. + * @remark For more information, see CloseTouchInputHandle. +*/ +static BOOL lv_win32_close_touch_input_handle( + HTOUCHINPUT hTouchInput); + +/** + * @brief Returns the dots per inch (dpi) value for the associated window. + * @param WindowHandle The window you want to get information about. + * @return The DPI for the window. +*/ +static UINT lv_win32_get_dpi_for_window( + _In_ HWND WindowHandle); + +static void lv_win32_display_driver_flush_callback( + lv_disp_drv_t* disp_drv, + const lv_area_t* area, + lv_color_t* color_p); + +static void lv_win32_display_driver_rounder_callback( + lv_disp_drv_t* disp_drv, + lv_area_t* area); + +static void lv_win32_pointer_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data); + +static void lv_win32_keypad_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data); + +static void lv_win32_encoder_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data); + +static LRESULT CALLBACK lv_win32_window_message_callback( + HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam); + +static void lv_win32_message_handler( + lv_timer_t* param); + +/********************** + * GLOBAL VARIABLES + **********************/ + +EXTERN_C bool lv_win32_quit_signal = false; + +EXTERN_C lv_indev_t* lv_win32_pointer_device_object = NULL; +EXTERN_C lv_indev_t* lv_win32_keypad_device_object = NULL; +EXTERN_C lv_indev_t* lv_win32_encoder_device_object = NULL; + +/********************** + * STATIC VARIABLES + **********************/ + +static HINSTANCE g_instance_handle = NULL; +static HWND g_window_handle = NULL; + +static HDC g_buffer_dc_handle = NULL; +static UINT32* g_pixel_buffer = NULL; +static SIZE_T g_pixel_buffer_size = 0; + +static lv_disp_t* g_display = NULL; + +static bool volatile g_mouse_pressed = false; +static LPARAM volatile g_mouse_value = 0; + +static bool volatile g_mousewheel_pressed = false; +static int16_t volatile g_mousewheel_value = 0; + +static bool volatile g_keyboard_pressed = false; +static WPARAM volatile g_keyboard_value = 0; + +static int volatile g_dpi_value = USER_DEFAULT_SCREEN_DPI; + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +EXTERN_C void lv_win32_add_all_input_devices_to_group( + lv_group_t* group) +{ + if (!group) + { + LV_LOG_WARN( + "The group object is NULL. Get the default group object instead."); + + group = lv_group_get_default(); + if (!group) + { + LV_LOG_WARN( + "The default group object is NULL. Create a new group object " + "and set it to default instead."); + + group = lv_group_create(); + if (group) + { + lv_group_set_default(group); + } + } + } + + LV_ASSERT_MSG(group, "Cannot obtain an available group object."); + + lv_indev_set_group(lv_win32_pointer_device_object, group); + lv_indev_set_group(lv_win32_keypad_device_object, group); + lv_indev_set_group(lv_win32_encoder_device_object, group); +} + +EXTERN_C bool lv_win32_init( + HINSTANCE instance_handle, + int show_window_mode, + lv_coord_t hor_res, + lv_coord_t ver_res, + HICON icon_handle) +{ + WNDCLASSEXW WindowClass; + + WindowClass.cbSize = sizeof(WNDCLASSEX); + + WindowClass.style = 0; + WindowClass.lpfnWndProc = lv_win32_window_message_callback; + WindowClass.cbClsExtra = 0; + WindowClass.cbWndExtra = 0; + WindowClass.hInstance = instance_handle; + WindowClass.hIcon = icon_handle; + WindowClass.hCursor = LoadCursorW(NULL, IDC_ARROW); + WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + WindowClass.lpszMenuName = NULL; + WindowClass.lpszClassName = L"lv_sim_visual_studio"; + WindowClass.hIconSm = icon_handle; + + if (!RegisterClassExW(&WindowClass)) + { + return false; + } + + g_instance_handle = instance_handle; + + g_window_handle = CreateWindowExW( + WINDOW_EX_STYLE, + WindowClass.lpszClassName, + L"LVGL Simulator for Windows Desktop", + WINDOW_STYLE, + CW_USEDEFAULT, + 0, + CW_USEDEFAULT, + 0, + NULL, + NULL, + instance_handle, + NULL); + + if (!g_window_handle) + { + return false; + } + + g_dpi_value = lv_win32_get_dpi_for_window(g_window_handle); + + RECT WindowSize; + + WindowSize.left = 0; + WindowSize.right = MulDiv( + hor_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI); + WindowSize.top = 0; + WindowSize.bottom = MulDiv( + ver_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI); + + AdjustWindowRectEx( + &WindowSize, + WINDOW_STYLE, + FALSE, + WINDOW_EX_STYLE); + OffsetRect( + &WindowSize, + -WindowSize.left, + -WindowSize.top); + + SetWindowPos( + g_window_handle, + NULL, + 0, + 0, + WindowSize.right, + WindowSize.bottom, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE); + + lv_win32_register_touch_window(g_window_handle, 0); + + lv_timer_create(lv_win32_message_handler, 0, NULL); + + lv_win32_enable_child_window_dpi_message(g_window_handle); + + HDC hNewBufferDC = lv_win32_create_frame_buffer( + g_window_handle, + hor_res, + ver_res, + &g_pixel_buffer, + &g_pixel_buffer_size); + + DeleteDC(g_buffer_dc_handle); + g_buffer_dc_handle = hNewBufferDC; + + static lv_disp_draw_buf_t display_buffer; + lv_disp_draw_buf_init( + &display_buffer, + (lv_color_t*)malloc(hor_res * ver_res * sizeof(lv_color_t)), + NULL, + hor_res * ver_res); + + static lv_disp_drv_t display_driver; + lv_disp_drv_init(&display_driver); + display_driver.hor_res = hor_res; + display_driver.ver_res = ver_res; + display_driver.flush_cb = lv_win32_display_driver_flush_callback; + display_driver.draw_buf = &display_buffer; + display_driver.rounder_cb = lv_win32_display_driver_rounder_callback; + g_display = lv_disp_drv_register(&display_driver); + + static lv_indev_drv_t pointer_driver; + lv_indev_drv_init(&pointer_driver); + pointer_driver.type = LV_INDEV_TYPE_POINTER; + pointer_driver.read_cb = lv_win32_pointer_driver_read_callback; + lv_win32_pointer_device_object = lv_indev_drv_register(&pointer_driver); + + static lv_indev_drv_t keypad_driver; + lv_indev_drv_init(&keypad_driver); + keypad_driver.type = LV_INDEV_TYPE_KEYPAD; + keypad_driver.read_cb = lv_win32_keypad_driver_read_callback; + lv_win32_keypad_device_object = lv_indev_drv_register(&keypad_driver); + + static lv_indev_drv_t encoder_driver; + lv_indev_drv_init(&encoder_driver); + encoder_driver.type = LV_INDEV_TYPE_ENCODER; + encoder_driver.read_cb = lv_win32_encoder_driver_read_callback; + lv_win32_encoder_device_object = lv_indev_drv_register(&encoder_driver); + + ShowWindow(g_window_handle, show_window_mode); + UpdateWindow(g_window_handle); + + return true; +} + +/********************** + * STATIC FUNCTIONS + **********************/ + +static HDC lv_win32_create_frame_buffer( + HWND WindowHandle, + LONG Width, + LONG Height, + UINT32** PixelBuffer, + SIZE_T* PixelBufferSize) +{ + HDC hFrameBufferDC = NULL; + + if (PixelBuffer && PixelBufferSize) + { + HDC hWindowDC = GetDC(WindowHandle); + if (hWindowDC) + { + hFrameBufferDC = CreateCompatibleDC(hWindowDC); + ReleaseDC(WindowHandle, hWindowDC); + } + + if (hFrameBufferDC) + { +#if LV_COLOR_DEPTH == 32 + BITMAPINFO BitmapInfo = { 0 }; +#elif LV_COLOR_DEPTH == 16 + typedef struct _BITMAPINFO_16BPP { + BITMAPINFOHEADER bmiHeader; + DWORD bmiColorMask[3]; + } BITMAPINFO_16BPP, *PBITMAPINFO_16BPP; + + BITMAPINFO_16BPP BitmapInfo = { 0 }; +#elif LV_COLOR_DEPTH == 8 + typedef struct _BITMAPINFO_8BPP { + BITMAPINFOHEADER bmiHeader; + RGBQUAD bmiColors[256]; + } BITMAPINFO_8BPP, *PBITMAPINFO_8BPP; + + BITMAPINFO_8BPP BitmapInfo = { 0 }; +#elif LV_COLOR_DEPTH == 1 + typedef struct _BITMAPINFO_1BPP { + BITMAPINFOHEADER bmiHeader; + RGBQUAD bmiColors[2]; + } BITMAPINFO_1BPP, *PBITMAPINFO_1BPP; + + BITMAPINFO_1BPP BitmapInfo = { 0 }; +#else + BITMAPINFO BitmapInfo = { 0 }; +#endif + + BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + BitmapInfo.bmiHeader.biWidth = Width; + BitmapInfo.bmiHeader.biHeight = -Height; + BitmapInfo.bmiHeader.biPlanes = 1; +#if LV_COLOR_DEPTH == 32 + BitmapInfo.bmiHeader.biBitCount = 32; + BitmapInfo.bmiHeader.biCompression = BI_RGB; +#elif LV_COLOR_DEPTH == 16 + BitmapInfo.bmiHeader.biBitCount = 16; + BitmapInfo.bmiHeader.biCompression = BI_BITFIELDS; + BitmapInfo.bmiColorMask[0] = 0xF800; + BitmapInfo.bmiColorMask[1] = 0x07E0; + BitmapInfo.bmiColorMask[2] = 0x001F; +#elif LV_COLOR_DEPTH == 8 + BitmapInfo.bmiHeader.biBitCount = 8; + BitmapInfo.bmiHeader.biCompression = BI_RGB; + for (size_t i = 0; i < 256; ++i) + { + lv_color8_t color; + color.full = i; + + BitmapInfo.bmiColors[i].rgbRed = LV_COLOR_GET_R(color) * 36; + BitmapInfo.bmiColors[i].rgbGreen = LV_COLOR_GET_G(color) * 36; + BitmapInfo.bmiColors[i].rgbBlue = LV_COLOR_GET_B(color) * 85; + BitmapInfo.bmiColors[i].rgbReserved = 0xFF; + } +#elif LV_COLOR_DEPTH == 1 + BitmapInfo.bmiHeader.biBitCount = 8; + BitmapInfo.bmiHeader.biCompression = BI_RGB; + BitmapInfo.bmiHeader.biClrUsed = 2; + BitmapInfo.bmiHeader.biClrImportant = 2; + BitmapInfo.bmiColors[0].rgbRed = 0x00; + BitmapInfo.bmiColors[0].rgbGreen = 0x00; + BitmapInfo.bmiColors[0].rgbBlue = 0x00; + BitmapInfo.bmiColors[0].rgbReserved = 0xFF; + BitmapInfo.bmiColors[1].rgbRed = 0xFF; + BitmapInfo.bmiColors[1].rgbGreen = 0xFF; + BitmapInfo.bmiColors[1].rgbBlue = 0xFF; + BitmapInfo.bmiColors[1].rgbReserved = 0xFF; +#else + BitmapInfo.bmiHeader.biBitCount = 32; + BitmapInfo.bmiHeader.biCompression = BI_RGB; +#endif + + HBITMAP hBitmap = CreateDIBSection( + hFrameBufferDC, + (PBITMAPINFO)(&BitmapInfo), + DIB_RGB_COLORS, + (void**)PixelBuffer, + NULL, + 0); + if (hBitmap) + { +#if LV_COLOR_DEPTH == 32 + *PixelBufferSize = Width * Height * sizeof(UINT32); +#elif LV_COLOR_DEPTH == 16 + *PixelBufferSize = Width * Height * sizeof(UINT16); +#elif LV_COLOR_DEPTH == 8 + *PixelBufferSize = Width * Height * sizeof(UINT8); +#elif LV_COLOR_DEPTH == 1 + *PixelBufferSize = Width * Height * sizeof(UINT8); +#else + *PixelBufferSize = Width * Height * sizeof(UINT32); +#endif + + DeleteObject(SelectObject(hFrameBufferDC, hBitmap)); + DeleteObject(hBitmap); + } + else + { + DeleteDC(hFrameBufferDC); + hFrameBufferDC = NULL; + } + } + } + + return hFrameBufferDC; +} + +static BOOL lv_win32_enable_child_window_dpi_message( + HWND WindowHandle) +{ + // This hack is only for Windows 10 TH1/TH2 only. + // We don't need this hack if the Per Monitor Aware V2 is existed. + OSVERSIONINFOEXW OSVersionInfoEx = { 0 }; + OSVersionInfoEx.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW); + OSVersionInfoEx.dwMajorVersion = 10; + OSVersionInfoEx.dwMinorVersion = 0; + OSVersionInfoEx.dwBuildNumber = 14393; + if (!VerifyVersionInfoW( + &OSVersionInfoEx, + VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, + VerSetConditionMask( + VerSetConditionMask( + VerSetConditionMask( + 0, + VER_MAJORVERSION, + VER_GREATER_EQUAL), + VER_MINORVERSION, + VER_GREATER_EQUAL), + VER_BUILDNUMBER, + VER_LESS))) + { + return FALSE; + } + + HMODULE ModuleHandle = GetModuleHandleW(L"user32.dll"); + if (!ModuleHandle) + { + return FALSE; + } + + typedef BOOL(WINAPI* FunctionType)(HWND, BOOL); + + FunctionType pFunction = (FunctionType)( + GetProcAddress(ModuleHandle, "EnableChildWindowDpiMessage")); + if (!pFunction) + { + return FALSE; + } + + return pFunction(WindowHandle, TRUE); +} + +static BOOL lv_win32_register_touch_window( + HWND hWnd, + ULONG ulFlags) +{ + HMODULE ModuleHandle = GetModuleHandleW(L"user32.dll"); + if (!ModuleHandle) + { + return FALSE; + } + + typedef BOOL(WINAPI* FunctionType)(HWND, ULONG); + + FunctionType pFunction = (FunctionType)( + GetProcAddress(ModuleHandle, "RegisterTouchWindow")); + if (!pFunction) + { + return FALSE; + } + + return pFunction(hWnd, ulFlags); +} + +static BOOL lv_win32_get_touch_input_info( + HTOUCHINPUT hTouchInput, + UINT cInputs, + PTOUCHINPUT pInputs, + int cbSize) +{ + HMODULE ModuleHandle = GetModuleHandleW(L"user32.dll"); + if (!ModuleHandle) + { + return FALSE; + } + + typedef BOOL(WINAPI* FunctionType)(HTOUCHINPUT, UINT, PTOUCHINPUT, int); + + FunctionType pFunction = (FunctionType)( + GetProcAddress(ModuleHandle, "GetTouchInputInfo")); + if (!pFunction) + { + return FALSE; + } + + return pFunction(hTouchInput, cInputs, pInputs, cbSize); +} + +static BOOL lv_win32_close_touch_input_handle( + HTOUCHINPUT hTouchInput) +{ + HMODULE ModuleHandle = GetModuleHandleW(L"user32.dll"); + if (!ModuleHandle) + { + return FALSE; + } + + typedef BOOL(WINAPI* FunctionType)(HTOUCHINPUT); + + FunctionType pFunction = (FunctionType)( + GetProcAddress(ModuleHandle, "CloseTouchInputHandle")); + if (!pFunction) + { + return FALSE; + } + + return pFunction(hTouchInput); +} + +static UINT lv_win32_get_dpi_for_window( + _In_ HWND WindowHandle) +{ + UINT Result = (UINT)(-1); + + HMODULE ModuleHandle = LoadLibraryW(L"SHCore.dll"); + if (ModuleHandle) + { + typedef enum MONITOR_DPI_TYPE_PRIVATE { + MDT_EFFECTIVE_DPI = 0, + MDT_ANGULAR_DPI = 1, + MDT_RAW_DPI = 2, + MDT_DEFAULT = MDT_EFFECTIVE_DPI + } MONITOR_DPI_TYPE_PRIVATE; + + typedef HRESULT(WINAPI* FunctionType)( + HMONITOR, MONITOR_DPI_TYPE_PRIVATE, UINT*, UINT*); + + FunctionType pFunction = (FunctionType)( + GetProcAddress(ModuleHandle, "GetDpiForMonitor")); + if (pFunction) + { + HMONITOR MonitorHandle = MonitorFromWindow( + WindowHandle, + MONITOR_DEFAULTTONEAREST); + + UINT dpiX = 0; + UINT dpiY = 0; + if (SUCCEEDED(pFunction( + MonitorHandle, + MDT_EFFECTIVE_DPI, + &dpiX, + &dpiY))) + { + Result = dpiX; + } + } + + FreeLibrary(ModuleHandle); + } + + if (Result == (UINT)(-1)) + { + HDC hWindowDC = GetDC(WindowHandle); + if (hWindowDC) + { + Result = GetDeviceCaps(hWindowDC, LOGPIXELSX); + ReleaseDC(WindowHandle, hWindowDC); + } + } + + if (Result == (UINT)(-1)) + { + Result = USER_DEFAULT_SCREEN_DPI; + } + + return Result; +} + +static void lv_win32_display_driver_flush_callback( + lv_disp_drv_t* disp_drv, + const lv_area_t* area, + lv_color_t* color_p) +{ +#if (LV_COLOR_DEPTH == 32) || \ + (LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0) || \ + (LV_COLOR_DEPTH == 8) || \ + (LV_COLOR_DEPTH == 1) + UNREFERENCED_PARAMETER(area); + memcpy(g_pixel_buffer, color_p, g_pixel_buffer_size); +#elif (LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP != 0) + SIZE_T count = g_pixel_buffer_size / sizeof(UINT16); + PUINT16 source = (PUINT16)color_p; + PUINT16 destination = (PUINT16)g_pixel_buffer; + for (SIZE_T i = 0; i < count; ++i) + { + UINT16 current = *source; + *destination = (LOBYTE(current) << 8) | HIBYTE(current); + + ++source; + ++destination; + } +#else + for (int y = area->y1; y <= area->y2; ++y) + { + for (int x = area->x1; x <= area->x2; ++x) + { + g_pixel_buffer[y * disp_drv->hor_res + x] = lv_color_to32(*color_p); + color_p++; + } + } +#endif + + HDC hWindowDC = GetDC(g_window_handle); + if (hWindowDC) + { + int PreviousMode = SetStretchBltMode( + hWindowDC, + HALFTONE); + + StretchBlt( + hWindowDC, + 0, + 0, + MulDiv( + disp_drv->hor_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI), + MulDiv( + disp_drv->ver_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI), + g_buffer_dc_handle, + 0, + 0, + disp_drv->hor_res, + disp_drv->ver_res, + SRCCOPY); + + SetStretchBltMode( + hWindowDC, + PreviousMode); + + ReleaseDC(g_window_handle, hWindowDC); + } + + lv_disp_flush_ready(disp_drv); +} + +static void lv_win32_display_driver_rounder_callback( + lv_disp_drv_t* disp_drv, + lv_area_t* area) +{ + area->x1 = 0; + area->x2 = disp_drv->hor_res - 1; + area->y1 = 0; + area->y2 = disp_drv->ver_res - 1; +} + +static void lv_win32_pointer_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data) +{ + UNREFERENCED_PARAMETER(indev_drv); + + data->state = (lv_indev_state_t)( + g_mouse_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL); + + data->point.x = MulDiv( + GET_X_LPARAM(g_mouse_value), + USER_DEFAULT_SCREEN_DPI, + WIN32DRV_MONITOR_ZOOM * g_dpi_value); + data->point.y = MulDiv( + GET_Y_LPARAM(g_mouse_value), + USER_DEFAULT_SCREEN_DPI, + WIN32DRV_MONITOR_ZOOM * g_dpi_value); + + if (data->point.x < 0) + { + data->point.x = 0; + } + if (data->point.x > g_display->driver->hor_res - 1) + { + data->point.x = g_display->driver->hor_res - 1; + } + if (data->point.y < 0) + { + data->point.y = 0; + } + if (data->point.y > g_display->driver->ver_res - 1) + { + data->point.y = g_display->driver->ver_res - 1; + } +} + +static void lv_win32_keypad_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data) +{ + UNREFERENCED_PARAMETER(indev_drv); + + data->state = (lv_indev_state_t)( + g_keyboard_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL); + + WPARAM KeyboardValue = g_keyboard_value; + + switch (KeyboardValue) + { + case VK_UP: + data->key = LV_KEY_UP; + break; + case VK_DOWN: + data->key = LV_KEY_DOWN; + break; + case VK_LEFT: + data->key = LV_KEY_LEFT; + break; + case VK_RIGHT: + data->key = LV_KEY_RIGHT; + break; + case VK_ESCAPE: + data->key = LV_KEY_ESC; + break; + case VK_DELETE: + data->key = LV_KEY_DEL; + break; + case VK_BACK: + data->key = LV_KEY_BACKSPACE; + break; + case VK_RETURN: + data->key = LV_KEY_ENTER; + break; + case VK_NEXT: + data->key = LV_KEY_NEXT; + break; + case VK_PRIOR: + data->key = LV_KEY_PREV; + break; + case VK_HOME: + data->key = LV_KEY_HOME; + break; + case VK_END: + data->key = LV_KEY_END; + break; + default: + if (KeyboardValue >= 'A' && KeyboardValue <= 'Z') + { + KeyboardValue += 0x20; + } + + data->key = (uint32_t)KeyboardValue; + + break; + } +} + +static void lv_win32_encoder_driver_read_callback( + lv_indev_drv_t* indev_drv, + lv_indev_data_t* data) +{ + UNREFERENCED_PARAMETER(indev_drv); + + data->state = (lv_indev_state_t)( + g_mousewheel_pressed ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL); + data->enc_diff = g_mousewheel_value; + g_mousewheel_value = 0; +} + +static LRESULT CALLBACK lv_win32_window_message_callback( + HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam) +{ + switch (uMsg) + { + case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + { + g_mouse_value = lParam; + if (uMsg == WM_LBUTTONDOWN || uMsg == WM_LBUTTONUP) + { + g_mouse_pressed = (uMsg == WM_LBUTTONDOWN); + } + else if (uMsg == WM_MBUTTONDOWN || uMsg == WM_MBUTTONUP) + { + g_mousewheel_pressed = (uMsg == WM_MBUTTONDOWN); + } + return 0; + } + case WM_KEYDOWN: + case WM_KEYUP: + { + g_keyboard_pressed = (uMsg == WM_KEYDOWN); + g_keyboard_value = wParam; + break; + } + case WM_MOUSEWHEEL: + { + g_mousewheel_value = -(GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA); + break; + } + case WM_TOUCH: + { + UINT cInputs = LOWORD(wParam); + HTOUCHINPUT hTouchInput = (HTOUCHINPUT)(lParam); + + PTOUCHINPUT pInputs = malloc(cInputs * sizeof(TOUCHINPUT)); + if (pInputs) + { + if (lv_win32_get_touch_input_info( + hTouchInput, + cInputs, + pInputs, + sizeof(TOUCHINPUT))) + { + for (UINT i = 0; i < cInputs; ++i) + { + POINT Point; + Point.x = TOUCH_COORD_TO_PIXEL(pInputs[i].x); + Point.y = TOUCH_COORD_TO_PIXEL(pInputs[i].y); + if (!ScreenToClient(hWnd, &Point)) + { + continue; + } + + uint16_t x = (uint16_t)(Point.x & 0xffff); + uint16_t y = (uint16_t)(Point.y & 0xffff); + + DWORD MousePressedMask = + TOUCHEVENTF_MOVE | TOUCHEVENTF_DOWN; + + g_mouse_value = (y << 16) | x; + g_mouse_pressed = (pInputs[i].dwFlags & MousePressedMask); + } + } + + free(pInputs); + } + + lv_win32_close_touch_input_handle(hTouchInput); + + break; + } + case WM_DPICHANGED: + { + g_dpi_value = HIWORD(wParam); + + LPRECT SuggestedRect = (LPRECT)lParam; + + SetWindowPos( + hWnd, + NULL, + SuggestedRect->left, + SuggestedRect->top, + SuggestedRect->right, + SuggestedRect->bottom, + SWP_NOZORDER | SWP_NOACTIVATE); + + RECT ClientRect; + GetClientRect(hWnd, &ClientRect); + + int WindowWidth = MulDiv( + g_display->driver->hor_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI); + int WindowHeight = MulDiv( + g_display->driver->ver_res * WIN32DRV_MONITOR_ZOOM, + g_dpi_value, + USER_DEFAULT_SCREEN_DPI); + + SetWindowPos( + hWnd, + NULL, + SuggestedRect->left, + SuggestedRect->top, + SuggestedRect->right + (WindowWidth - ClientRect.right), + SuggestedRect->bottom + (WindowHeight - ClientRect.bottom), + SWP_NOZORDER | SWP_NOACTIVATE); + + break; + } + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProcW(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + +static void lv_win32_message_handler( + lv_timer_t* param) +{ + UNREFERENCED_PARAMETER(param); + + MSG Message; + BOOL Result = PeekMessageW(&Message, NULL, 0, 0, TRUE); + if (Result != 0 && Result != -1) + { + TranslateMessage(&Message); + DispatchMessageW(&Message); + + if (Message.message == WM_QUIT) + { + lv_win32_quit_signal = true; + } + } +} + +#endif /*USE_WIN32DRV*/ diff --git a/bsp/simulator/drivers/lvgl/win32drv.h b/bsp/simulator/drivers/lvgl/win32drv.h new file mode 100644 index 0000000000..8bd5972fb5 --- /dev/null +++ b/bsp/simulator/drivers/lvgl/win32drv.h @@ -0,0 +1,67 @@ +/** + * @file win32drv.h + * + */ + +#ifndef LV_WIN32DRV_H +#define LV_WIN32DRV_H + +/********************* + * INCLUDES + *********************/ + +#include + +#if USE_WIN32DRV + +#include + +#if _MSC_VER >= 1200 + // Disable compilation warnings. +#pragma warning(push) +// nonstandard extension used : bit field types other than int +#pragma warning(disable:4214) +// 'conversion' conversion from 'type1' to 'type2', possible loss of data +#pragma warning(disable:4244) +#endif + +#if _MSC_VER >= 1200 +// Restore compilation warnings. +#pragma warning(pop) +#endif + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +EXTERN_C bool lv_win32_quit_signal; + +EXTERN_C lv_indev_t* lv_win32_pointer_device_object; +EXTERN_C lv_indev_t* lv_win32_keypad_device_object; +EXTERN_C lv_indev_t* lv_win32_encoder_device_object; + +EXTERN_C void lv_win32_add_all_input_devices_to_group( + lv_group_t* group); + +EXTERN_C bool lv_win32_init( + HINSTANCE instance_handle, + int show_window_mode, + lv_coord_t hor_res, + lv_coord_t ver_res, + HICON icon_handle); + +/********************** + * MACROS + **********************/ + +#endif /*USE_WIN32DRV*/ + +#endif /*LV_WIN32DRV_H*/ -- cgit v1.3.1 From 8565fe2448ae086d270687eba3855214b649ebc5 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 5 Jan 2022 16:43:44 -0500 Subject: [simulator] 消除vs下的警告 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bsp/simulator/.config | 97 +++++++++-------------------- bsp/simulator/Kconfig | 10 ++- bsp/simulator/drivers/SConscript | 5 +- bsp/simulator/drivers/dfs_win32.c | 4 +- bsp/simulator/rtconfig.h | 55 ++-------------- bsp/simulator/rtconfig_project.h | 9 +-- components/libc/compilers/common/sys/time.h | 18 +++--- components/libc/compilers/common/time.c | 6 +- 8 files changed, 63 insertions(+), 141 deletions(-) (limited to 'bsp/simulator/drivers/SConscript') diff --git a/bsp/simulator/.config b/bsp/simulator/.config index 6f720f01bc..8afd87ff1e 100644 --- a/bsp/simulator/.config +++ b/bsp/simulator/.config @@ -1,9 +1,13 @@ -# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) +# +# Automatically generated file; DO NOT EDIT. +# RT-Thread Configuration +# # # RT-Thread Kernel # CONFIG_RT_NAME_MAX=8 +# CONFIG_RT_USING_BIG_ENDIAN is not set # CONFIG_RT_USING_ARCH_DATA_TYPE is not set # CONFIG_RT_USING_SMP is not set CONFIG_RT_ALIGN_SIZE=4 @@ -26,8 +30,6 @@ CONFIG_IDLE_THREAD_STACK_SIZE=256 # CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set # CONFIG_RT_USING_TINY_FFS is not set # CONFIG_RT_PRINTF_LONGLONG is not set -# end of kservice optimization - CONFIG_RT_DEBUG=y CONFIG_RT_DEBUG_COLOR=y # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -50,7 +52,6 @@ CONFIG_RT_USING_EVENT=y CONFIG_RT_USING_MAILBOX=y CONFIG_RT_USING_MESSAGEQUEUE=y # CONFIG_RT_USING_SIGNALS is not set -# end of Inter-Thread communication # # Memory Management @@ -67,7 +68,6 @@ CONFIG_RT_USING_SMALL_MEM_AS_HEAP=y # CONFIG_RT_USING_MEMTRACE is not set # CONFIG_RT_USING_HEAP_ISR is not set CONFIG_RT_USING_HEAP=y -# end of Memory Management # # Kernel Device Object @@ -78,10 +78,9 @@ CONFIG_RT_USING_DEVICE=y CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="console" -# end of Kernel Device Object - CONFIG_RT_VER_NUM=0x40100 -# end of RT-Thread Kernel +# CONFIG_RT_USING_CPU_FFS is not set +# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # # RT-Thread Components @@ -96,7 +95,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # C++ features # # CONFIG_RT_USING_CPLUSPLUS is not set -# end of C++ features # # Command shell @@ -116,7 +114,6 @@ CONFIG_FINSH_USING_DESCRIPTION=y # CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set # CONFIG_FINSH_USING_AUTH is not set CONFIG_FINSH_ARG_MAX=10 -# end of Command shell # # Device virtual file system @@ -151,12 +148,9 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 # CONFIG_RT_DFS_ELM_USE_ERASE is not set CONFIG_RT_DFS_ELM_REENTRANT=y CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000 -# end of elm-chan's FatFs, Generic FAT Filesystem Module - CONFIG_RT_USING_DFS_DEVFS=y # CONFIG_RT_USING_DFS_ROMFS is not set # CONFIG_RT_USING_DFS_RAMFS is not set -# end of Device virtual file system # # Device Drivers @@ -195,25 +189,28 @@ CONFIG_RT_SERIAL_RB_BUFSZ=64 # # Using USB # +# CONFIG_RT_USING_USB is not set # CONFIG_RT_USING_USB_HOST is not set # CONFIG_RT_USING_USB_DEVICE is not set -# end of Using USB -# end of Device Drivers # # POSIX layer and C standard library # -# CONFIG_RT_USING_LIBC is not set -CONFIG_RT_LIBC_USING_TIME=y +# CONFIG_RT_USING_MODULE is not set CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # # POSIX (Portable Operating System Interface) layer # -# CONFIG_RT_USING_POSIX_FS is not set +CONFIG_RT_USING_POSIX_FS=y +# CONFIG_RT_USING_POSIX_DEVIO is not set +# CONFIG_RT_USING_POSIX_POLL is not set +# CONFIG_RT_USING_POSIX_SELECT is not set +# CONFIG_RT_USING_POSIX_TERMIOS is not set +# CONFIG_RT_USING_POSIX_AIO is not set +# CONFIG_RT_USING_POSIX_MMAN is not set # CONFIG_RT_USING_POSIX_DELAY is not set # CONFIG_RT_USING_POSIX_CLOCK is not set -# CONFIG_RT_USING_POSIX_GETLINE is not set # CONFIG_RT_USING_PTHREADS is not set # @@ -226,9 +223,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # # Socket is in the 'Network' category # -# end of Interprocess Communication (IPC) -# end of POSIX (Portable Operating System Interface) layer -# end of POSIX layer and C standard library # # Network @@ -238,32 +232,26 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # Socket abstraction layer # # CONFIG_RT_USING_SAL is not set -# end of Socket abstraction layer # # Network interface device # # CONFIG_RT_USING_NETDEV is not set -# end of Network interface device # # light weight TCP/IP stack # # CONFIG_RT_USING_LWIP is not set -# end of light weight TCP/IP stack # # AT commands # # CONFIG_RT_USING_AT is not set -# end of AT commands -# end of Network # # VBUS(Virtual Software BUS) # # CONFIG_RT_USING_VBUS is not set -# end of VBUS(Virtual Software BUS) # # Utilities @@ -273,14 +261,11 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_RT_USING_UTEST is not set # CONFIG_RT_USING_VAR_EXPORT is not set # CONFIG_RT_USING_RT_LINK is not set -# end of Utilities -# end of RT-Thread Components # # RT-Thread Utestcases # # CONFIG_RT_USING_UTESTCASES is not set -# end of RT-Thread Utestcases # # RT-Thread online packages @@ -315,17 +300,12 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # Marvell WiFi # # CONFIG_PKG_USING_WLANMARVELL is not set -# end of Marvell WiFi # # Wiced WiFi # # CONFIG_PKG_USING_WLAN_WICED is not set -# end of Wiced WiFi - # CONFIG_PKG_USING_RW007 is not set -# end of Wi-Fi - # CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NETUTILS is not set @@ -347,8 +327,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_JIOT-C-SDK is not set # CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set # CONFIG_PKG_USING_JOYLINK is not set -# end of IoT Cloud - +# CONFIG_PKG_USING_EZ_IOT_OS is not set # CONFIG_PKG_USING_NIMBLE is not set # CONFIG_PKG_USING_OTA_DOWNLOADER is not set # CONFIG_PKG_USING_IPMSG is not set @@ -383,7 +362,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set # CONFIG_PKG_USING_HM is not set # CONFIG_PKG_USING_SMALL_MODBUS is not set -# end of IoT - internet of things +# CONFIG_PKG_USING_NET_SERVER is not set # # security packages @@ -393,7 +372,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_TINYCRYPT is not set # CONFIG_PKG_USING_TFM is not set # CONFIG_PKG_USING_YD_CRYPTO is not set -# end of security packages # # language packages @@ -402,7 +380,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_JERRYSCRIPT is not set # CONFIG_PKG_USING_MICROPYTHON is not set # CONFIG_PKG_USING_PIKASCRIPT is not set -# end of language packages # # multimedia packages @@ -414,15 +391,12 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_LVGL is not set # CONFIG_PKG_USING_LITTLEVGL2RTT is not set # CONFIG_PKG_USING_LV_MUSIC_DEMO is not set -# end of LVGL: powerful and easy-to-use embedded GUI library # # u8g2: a monochrome graphic library # # CONFIG_PKG_USING_U8G2_OFFICIAL is not set # CONFIG_PKG_USING_U8G2 is not set -# end of u8g2: a monochrome graphic library - # CONFIG_PKG_USING_OPENMV is not set # CONFIG_PKG_USING_MUPDF is not set # CONFIG_PKG_USING_STEMWIN is not set @@ -442,8 +416,9 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # # CONFIG_PKG_USING_PAINTERENGINE is not set # CONFIG_PKG_USING_PAINTERENGINE_AUX is not set -# end of PainterEngine: A cross-platform graphics application framework written in C language -# end of multimedia packages +# CONFIG_PKG_USING_MCURSES is not set +# CONFIG_PKG_USING_TERMBOX is not set +# CONFIG_PKG_USING_VT100 is not set # # tools packages @@ -487,7 +462,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_SOLAR_TERMS is not set # CONFIG_PKG_USING_GAN_ZHI is not set # CONFIG_PKG_USING_FDT is not set -# end of tools packages # # system packages @@ -499,7 +473,12 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_RT_MEMCPY_CM is not set # CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set # CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set -# end of enhanced kernel services + +# +# POSIX extension functions +# +# CONFIG_PKG_USING_POSIX_GETLINE is not set +# CONFIG_PKG_USING_POSIX_WCWIDTH is not set # # acceleration: Assembly language or algorithmic acceleration packages @@ -507,14 +486,12 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_QFPLIB_M0_FULL is not set # CONFIG_PKG_USING_QFPLIB_M0_TINY is not set # CONFIG_PKG_USING_QFPLIB_M3 is not set -# end of acceleration: Assembly language or algorithmic acceleration packages # # CMSIS: ARM Cortex-M Microcontroller Software Interface Standard # # CONFIG_PKG_USING_CMSIS_5 is not set # CONFIG_PKG_USING_CMSIS_RTOS2 is not set -# end of CMSIS: ARM Cortex-M Microcontroller Software Interface Standard # # Micrium: Micrium software products porting for RT-Thread @@ -525,8 +502,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_UC_CLK is not set # CONFIG_PKG_USING_UC_COMMON is not set # CONFIG_PKG_USING_UC_MODBUS is not set -# end of Micrium: Micrium software products porting for RT-Thread - # CONFIG_RT_USING_ARDUINO is not set # CONFIG_PKG_USING_GUIENGINE is not set # CONFIG_PKG_USING_CAIRO is not set @@ -556,11 +531,10 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_TLSF is not set # CONFIG_PKG_USING_EVENT_RECORDER is not set # CONFIG_PKG_USING_ARM_2D is not set -# CONFIG_PKG_USING_WCWIDTH is not set # CONFIG_PKG_USING_MCUBOOT is not set # CONFIG_PKG_USING_TINYUSB is not set # CONFIG_PKG_USING_USB_STACK is not set -# end of system packages +# CONFIG_PKG_USING_LUATOS_SOC is not set # # peripheral libraries and drivers @@ -634,10 +608,10 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_BLUETRUM_SDK is not set # CONFIG_PKG_USING_MISAKA_AT24CXX is not set # CONFIG_PKG_USING_MISAKA_RGB_BLING is not set +# CONFIG_PKG_USING_LORA_MODEM_DRIVER is not set # CONFIG_PKG_USING_BL_MCU_SDK is not set # CONFIG_PKG_USING_SOFT_SERIAL is not set # CONFIG_PKG_USING_MB85RS16 is not set -# end of peripheral libraries and drivers # # AI packages @@ -651,7 +625,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_ULAPACK is not set # CONFIG_PKG_USING_QUEST is not set # CONFIG_PKG_USING_NAXOS is not set -# end of AI packages # # miscellaneous packages @@ -664,7 +637,6 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set # CONFIG_PKG_USING_NETWORK_SAMPLES is not set # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set -# end of samples: kernel and components samples # # entertainment: terminal games and other interesting software packages @@ -678,8 +650,7 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_SNAKE is not set # CONFIG_PKG_USING_TETRIS is not set # CONFIG_PKG_USING_DONUT is not set -# end of entertainment: terminal games and other interesting software packages - +# CONFIG_PKG_USING_COWSAY is not set # CONFIG_PKG_USING_LIBCSV is not set # CONFIG_PKG_USING_OPTPARSE is not set # CONFIG_PKG_USING_FASTLZ is not set @@ -701,17 +672,11 @@ CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 # CONFIG_PKG_USING_VI is not set # CONFIG_PKG_USING_KI is not set # CONFIG_PKG_USING_ARMv7M_DWT is not set -# CONFIG_PKG_USING_VT100 is not set # CONFIG_PKG_USING_UKAL is not set # CONFIG_PKG_USING_CRCLIB is not set # CONFIG_PKG_USING_LWGPS is not set # CONFIG_PKG_USING_STATE_MACHINE is not set -# CONFIG_PKG_USING_MCURSES is not set -# CONFIG_PKG_USING_COWSAY is not set -# CONFIG_PKG_USING_TERMBOX is not set -# end of miscellaneous packages -# end of RT-Thread online packages - +# CONFIG_PKG_USING_DESIGN_PATTERN is not set CONFIG_SOC_SIMULATOR=y CONFIG_RT_USING_DFS_WINSHAREDIR=y # CONFIG_BSP_USING_LVGL is not set diff --git a/bsp/simulator/Kconfig b/bsp/simulator/Kconfig index 2222df6c93..63832e878f 100644 --- a/bsp/simulator/Kconfig +++ b/bsp/simulator/Kconfig @@ -24,11 +24,10 @@ config SOC_SIMULATOR select RT_USING_USER_MAIN default y -if RT_USING_DFS - config RT_USING_DFS_WINSHAREDIR - bool "Enable shared file system between windows" - default n -endif +config RT_USING_DFS_WINSHAREDIR + bool "Enable shared file system between windows" + select RT_USING_POSIX_FS + default n config BSP_USING_LVGL bool "Enable LVGL for LCD" @@ -44,5 +43,4 @@ if BSP_USING_LVGL config BSP_LCD_HEIGHT int "LCD height" default 480 - endif diff --git a/bsp/simulator/drivers/SConscript b/bsp/simulator/drivers/SConscript index d5a82f93b7..8f0c9275ff 100644 --- a/bsp/simulator/drivers/SConscript +++ b/bsp/simulator/drivers/SConscript @@ -8,8 +8,6 @@ LIBS = [] LIBPATH = [] CPPPATH = [cwd] -CPPDEFINES = ['_CRT_DECLARE_NONSTDC_NAMES=0'] # avoid to conflict with the inherent STDC in VS - # remove no need file. if GetDepend('PKG_USING_GUIENGINE') == False: SrcRemove(src, 'sdl_fb.c') @@ -32,8 +30,7 @@ if GetDepend('RT_USING_DFS') == False or GetDepend('RT_USING_MODULE') == False: if sys.platform[0:5]=="linux": #check whether under linux SrcRemove(src, ['module_win32.c', 'dfs_win32.c']) -group = DefineGroup('Drivers', src, depend = [''], - CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH, CPPDEFINES = CPPDEFINES) +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, LIBS=LIBS, LIBPATH=LIBPATH) list = os.listdir(cwd) for item in list: diff --git a/bsp/simulator/drivers/dfs_win32.c b/bsp/simulator/drivers/dfs_win32.c index 230425f3e4..95bfba030f 100644 --- a/bsp/simulator/drivers/dfs_win32.c +++ b/bsp/simulator/drivers/dfs_win32.c @@ -194,7 +194,7 @@ static int dfs_win32_open(struct dfs_fd *file) wdirp->start = malloc(len); //not rt_malloc! wdirp->end = wdirp->curr = wdirp->start; wdirp->end += len; - strncpy(wdirp->curr, wdirp->finddata.name, len); + rt_strncpy(wdirp->curr, wdirp->finddata.name, len); file->data = (void *)wdirp; rt_free(file_path); @@ -361,7 +361,7 @@ static int dfs_win32_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint3 wdirp->start = realloc(wdirp->start, wdirp->end - wdirp->start + name_len); wdirp->curr = wdirp->start + (wdirp->curr - old_start); wdirp->end = wdirp->curr + name_len; - strcpy(wdirp->curr, wdirp->finddata.name); + rt_strcpy(wdirp->curr, wdirp->finddata.name); } else { diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index ffb8bed62e..889457dce4 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -1,7 +1,8 @@ #ifndef RT_CONFIG_H__ #define RT_CONFIG_H__ -/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */ +/* Automatically generated file; DO NOT EDIT. */ +/* RT-Thread Configuration */ /* RT-Thread Kernel */ @@ -18,7 +19,6 @@ /* kservice optimization */ -/* end of kservice optimization */ #define RT_DEBUG #define RT_DEBUG_COLOR @@ -29,7 +29,6 @@ #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE -/* end of Inter-Thread communication */ /* Memory Management */ @@ -37,7 +36,6 @@ #define RT_USING_SMALL_MEM #define RT_USING_SMALL_MEM_AS_HEAP #define RT_USING_HEAP -/* end of Memory Management */ /* Kernel Device Object */ @@ -45,9 +43,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "console" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40100 -/* end of RT-Thread Kernel */ /* RT-Thread Components */ @@ -58,7 +54,6 @@ /* C++ features */ -/* end of C++ features */ /* Command shell */ @@ -75,7 +70,6 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ @@ -100,9 +94,7 @@ #define RT_DFS_ELM_MAX_SECTOR_SIZE 512 #define RT_DFS_ELM_REENTRANT #define RT_DFS_ELM_MUTEX_TIMEOUT 3000 -/* end of elm-chan's FatFs, Generic FAT Filesystem Module */ #define RT_USING_DFS_DEVFS -/* end of Device virtual file system */ /* Device Drivers */ @@ -114,57 +106,42 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ -#define RT_LIBC_USING_TIME #define RT_LIBC_DEFAULT_TIMEZONE 8 /* POSIX (Portable Operating System Interface) layer */ +#define RT_USING_POSIX_FS /* Interprocess Communication (IPC) */ /* Socket is in the 'Network' category */ -/* end of Interprocess Communication (IPC) */ -/* end of POSIX (Portable Operating System Interface) layer */ -/* end of POSIX layer and C standard library */ - /* Network */ /* Socket abstraction layer */ -/* end of Socket abstraction layer */ /* Network interface device */ -/* end of Network interface device */ /* light weight TCP/IP stack */ -/* end of light weight TCP/IP stack */ /* AT commands */ -/* end of AT commands */ -/* end of Network */ /* VBUS(Virtual Software BUS) */ -/* end of VBUS(Virtual Software BUS) */ /* Utilities */ -/* end of Utilities */ -/* end of RT-Thread Components */ /* RT-Thread Utestcases */ -/* end of RT-Thread Utestcases */ /* RT-Thread online packages */ @@ -175,83 +152,63 @@ /* Marvell WiFi */ -/* end of Marvell WiFi */ /* Wiced WiFi */ -/* end of Wiced WiFi */ -/* end of Wi-Fi */ /* IoT Cloud */ -/* end of IoT Cloud */ -/* end of IoT - internet of things */ /* security packages */ -/* end of security packages */ /* language packages */ -/* end of language packages */ /* multimedia packages */ /* LVGL: powerful and easy-to-use embedded GUI library */ -/* end of LVGL: powerful and easy-to-use embedded GUI library */ /* u8g2: a monochrome graphic library */ -/* end of u8g2: a monochrome graphic library */ /* PainterEngine: A cross-platform graphics application framework written in C language */ -/* end of PainterEngine: A cross-platform graphics application framework written in C language */ -/* end of multimedia packages */ /* tools packages */ -/* end of tools packages */ /* system packages */ /* enhanced kernel services */ -/* end of enhanced kernel services */ + +/* POSIX extension functions */ + /* acceleration: Assembly language or algorithmic acceleration packages */ -/* end of acceleration: Assembly language or algorithmic acceleration packages */ /* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */ -/* end of CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */ /* Micrium: Micrium software products porting for RT-Thread */ -/* end of Micrium: Micrium software products porting for RT-Thread */ -/* end of system packages */ /* peripheral libraries and drivers */ -/* end of peripheral libraries and drivers */ /* AI packages */ -/* end of AI packages */ /* miscellaneous packages */ /* samples: kernel and components samples */ -/* end of samples: kernel and components samples */ /* entertainment: terminal games and other interesting software packages */ -/* end of entertainment: terminal games and other interesting software packages */ -/* end of miscellaneous packages */ -/* end of RT-Thread online packages */ #define SOC_SIMULATOR #define RT_USING_DFS_WINSHAREDIR #include "rtconfig_project.h" diff --git a/bsp/simulator/rtconfig_project.h b/bsp/simulator/rtconfig_project.h index 098255741e..12892e9a98 100644 --- a/bsp/simulator/rtconfig_project.h +++ b/bsp/simulator/rtconfig_project.h @@ -13,10 +13,11 @@ #define RT_HEAP_SIZE (1024*1024*8) #if defined(_MSC_VER) -#define NORESOURCE //RT_VESRION in winuser.h -#define _CRT_ERRNO_DEFINED //errno macro redefinition -#define _INC_WTIME_INL//dfs_elm.c time.h conflicts with wtime.inl -#define _INC_TIME_INL //dfs_elm.c time.h conflicts with wtime.inl +#define NORESOURCE /* RT_VESRION in winuser.h */ +#define _CRT_ERRNO_DEFINED /* errno macro redefinition */ +#define _INC_WTIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */ +#define _INC_TIME_INL /* dfs_elm.c time.h conflicts with wtime.inl */ +#define _CRT_DECLARE_NONSTDC_NAMES 0 /* avoid to conflict with the inherent STDC in VS */ /* disable some warning in MSC */ #pragma warning(disable:4273) /* to ignore: warning C4273: inconsistent dll linkage */ diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index 55c60d716e..ce3f3a3c08 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -42,20 +42,14 @@ struct timezone int tz_dsttime; /* type of dst correction */ }; -/* - * Structure returned by gettimeofday(2) system call, - * and used in other calls. - */ -#ifndef _TIMEVAL_DEFINED +#if !defined(_TIMEVAL_DEFINED) && !defined(_WIN32) #define _TIMEVAL_DEFINED -#if !defined(_WIN32) struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* and microseconds */ }; #endif -#endif /* _TIMEVAL_DEFINED */ #if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \ !(defined(__ICCARM__) && (__VER__ >= 8010001)) && \ @@ -73,6 +67,16 @@ int gettimeofday(struct timeval *tv, struct timezone *tz); int settimeofday(const struct timeval *tv, const struct timezone *tz); #if defined(__ARMCC_VERSION) || defined (__ICCARM__) struct tm *gmtime_r(const time_t *timep, struct tm *r); +#elif defined(_WIN32) +struct tm* gmtime_r(const time_t* timep, struct tm* r); +struct tm* gmtime(const time_t* t); +struct tm* localtime_r(const time_t* t, struct tm* r); +struct tm* localtime(const time_t* t); +time_t mktime(struct tm* const t); +char* asctime_r(const struct tm* t, char* buf); +char* ctime_r(const time_t* tim_p, char* result); +char* ctime(const time_t* tim_p); +time_t time(time_t* t); #endif #ifdef RT_USING_POSIX_CLOCK diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 256268a3fc..d5442738a8 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -217,7 +217,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - local_tz = *t + tz_get() * 3600; + local_tz = *t + (time_t)tz_get() * 3600; return gmtime_r(&local_tz, r); } RTM_EXPORT(localtime_r); @@ -234,7 +234,7 @@ time_t mktime(struct tm * const t) time_t timestamp; timestamp = timegm(t); - timestamp = timestamp - 3600 * tz_get(); + timestamp = timestamp - 3600 * (time_t)tz_get(); return timestamp; } RTM_EXPORT(mktime); @@ -367,7 +367,7 @@ time_t timegm(struct tm * const t) { register time_t day; register time_t i; - register time_t years = t->tm_year - 70; + register time_t years = (time_t)t->tm_year - 70; if (t->tm_sec > 60) { -- cgit v1.3.1