diff --git a/scripts/lv_conf_internal_gen.py b/scripts/lv_conf_internal_gen.py index 5cad053d63..b208764854 100755 --- a/scripts/lv_conf_internal_gen.py +++ b/scripts/lv_conf_internal_gen.py @@ -163,7 +163,7 @@ for line in fin.read().splitlines(): fout.write(f'{line}\n') fout.write( -''' +r''' /*---------------------------------- * End of parsing lv_conf_template.h @@ -214,6 +214,9 @@ LV_EXPORT_CONST_INT(LV_DRAW_BUF_ALIGN); #endif #endif +/*Allow only upper case letters and '/' ('/' is a special case for backward compatibility)*/ +#define LV_FS_IS_VALID_LETTER(l) ((l) == '/' || ((l) >= 'A' && (l) <= 'Z')) + /* If running without lv_conf.h, add typedefs with default value. */ #ifdef LV_CONF_SKIP #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/ diff --git a/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp b/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp index cd8df4cf7b..820aa57356 100644 --- a/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp +++ b/src/libs/fsdrv/lv_fs_arduino_esp_littlefs.cpp @@ -4,17 +4,8 @@ #include "../../core/lv_global.h" #include "LittleFS.h" -#if LV_FS_ARDUINO_ESP_LITTLEFS_LETTER == '\0' - #error "LV_FS_ARDUINO_ESP_LITTLEFS_LETTER must be set to a valid value" -#else - #if (LV_FS_ARDUINO_ESP_LITTLEFS_LETTER < 'A') || (LV_FS_ARDUINO_ESP_LITTLEFS_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_ARDUINO_ESP_LITTLEFS_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_ARDUINO_ESP_LITTLEFS_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif +#if !LV_FS_IS_VALID_LETTER(LV_FS_ARDUINO_ESP_LITTLEFS_LETTER) + #error "Invalid drive letter" #endif typedef struct ArduinoEspLittleFile { @@ -198,4 +189,3 @@ static lv_fs_res_t fs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) #endif #endif /*LV_USE_FS_ARDUINO_ESP_LITTLEFS*/ - diff --git a/src/libs/fsdrv/lv_fs_arduino_sd.cpp b/src/libs/fsdrv/lv_fs_arduino_sd.cpp index 14941aca02..db68226a13 100644 --- a/src/libs/fsdrv/lv_fs_arduino_sd.cpp +++ b/src/libs/fsdrv/lv_fs_arduino_sd.cpp @@ -5,17 +5,8 @@ #include #include "SD.h" -#if LV_FS_ARDUINO_SD_LETTER == '\0' - #error "LV_FS_ARDUINO_SD_LETTER must be set to a valid value" -#else - #if (LV_FS_ARDUINO_SD_LETTER < 'A') || (LV_FS_ARDUINO_SD_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_ARDUINO_SD_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_ARDUINO_SD_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif +#if !LV_FS_IS_VALID_LETTER(LV_FS_ARDUINO_SD_LETTER) + #error "Invalid drive letter" #endif typedef struct SdFile { diff --git a/src/libs/fsdrv/lv_fs_fatfs.c b/src/libs/fsdrv/lv_fs_fatfs.c index 79c62a3678..dff3c5951c 100644 --- a/src/libs/fsdrv/lv_fs_fatfs.c +++ b/src/libs/fsdrv/lv_fs_fatfs.c @@ -20,17 +20,8 @@ #define DIR FF_DIR /* ESP IDF typedefs `DIR` as `FF_DIR` in its version of ff.h. Use `FF_DIR` in LVGL too */ #endif -#if LV_FS_FATFS_LETTER == '\0' - #error "LV_FS_FATFS_LETTER must be set to a valid value" -#else - #if (LV_FS_FATFS_LETTER < 'A') || (LV_FS_FATFS_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_FATFS_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_FATFS_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif +#if !LV_FS_IS_VALID_LETTER(LV_FS_FATFS_LETTER) + #error "Invalid drive letter" #endif /********************** diff --git a/src/libs/fsdrv/lv_fs_littlefs.c b/src/libs/fsdrv/lv_fs_littlefs.c index 490c6feeb2..d9ee9f61ee 100644 --- a/src/libs/fsdrv/lv_fs_littlefs.c +++ b/src/libs/fsdrv/lv_fs_littlefs.c @@ -4,17 +4,8 @@ #include "lfs.h" #include "../../core/lv_global.h" -#if LV_FS_LITTLEFS_LETTER == '\0' - #error "LV_FS_LITTLEFS_LETTER must be set to a valid value" -#else - #if (LV_FS_LITTLEFS_LETTER < 'A') || (LV_FS_LITTLEFS_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_LITTLEFS_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_LITTLEFS_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif +#if !LV_FS_IS_VALID_LETTER(LV_FS_LITTLEFS_LETTER) + #error "Invalid drive letter" #endif typedef struct LittleFile { diff --git a/src/libs/fsdrv/lv_fs_memfs.c b/src/libs/fsdrv/lv_fs_memfs.c index c207c76fd2..4e1b18a39f 100644 --- a/src/libs/fsdrv/lv_fs_memfs.c +++ b/src/libs/fsdrv/lv_fs_memfs.c @@ -47,17 +47,9 @@ /********************* * DEFINES *********************/ -#if LV_FS_MEMFS_LETTER == '\0' - #error "LV_FS_MEMFS_LETTER must be set to a valid value" -#else - #if (LV_FS_MEMFS_LETTER < 'A') || (LV_FS_MEMFS_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_MEMFS_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_MEMFS_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif + +#if !LV_FS_IS_VALID_LETTER(LV_FS_MEMFS_LETTER) + #error "Invalid drive letter" #endif /********************** diff --git a/src/libs/fsdrv/lv_fs_posix.c b/src/libs/fsdrv/lv_fs_posix.c index f1e66fd233..5e593d71ab 100644 --- a/src/libs/fsdrv/lv_fs_posix.c +++ b/src/libs/fsdrv/lv_fs_posix.c @@ -22,17 +22,8 @@ * DEFINES *********************/ -#if LV_FS_POSIX_LETTER == '\0' - #error "LV_FS_POSIX_LETTER must be set to a valid value" -#else - #if (LV_FS_POSIX_LETTER < 'A') || (LV_FS_POSIX_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_POSIX_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_POSIX_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif +#if !LV_FS_IS_VALID_LETTER(LV_FS_POSIX_LETTER) + #error "Invalid drive letter" #endif /** The reason for 'fd + 1' is because open() may return a legal fd with a value of 0, diff --git a/src/libs/fsdrv/lv_fs_stdio.c b/src/libs/fsdrv/lv_fs_stdio.c index a6c901e153..5a4e91c07c 100644 --- a/src/libs/fsdrv/lv_fs_stdio.c +++ b/src/libs/fsdrv/lv_fs_stdio.c @@ -21,17 +21,9 @@ /********************* * DEFINES *********************/ -#if LV_FS_STDIO_LETTER == '\0' - #error "LV_FS_STDIO_LETTER must be set to a valid value" -#else - #if (LV_FS_STDIO_LETTER < 'A') || (LV_FS_STDIO_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_STDIO_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_STDIO_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif + +#if !LV_FS_IS_VALID_LETTER(LV_FS_STDIO_LETTER) + #error "Invalid drive letter" #endif #define MAX_PATH_LEN 256 diff --git a/src/libs/fsdrv/lv_fs_win32.c b/src/libs/fsdrv/lv_fs_win32.c index d5fb36487a..764953e128 100644 --- a/src/libs/fsdrv/lv_fs_win32.c +++ b/src/libs/fsdrv/lv_fs_win32.c @@ -17,17 +17,9 @@ /********************* * DEFINES *********************/ -#if LV_FS_WIN32_LETTER == '\0' - #error "LV_FS_WIN32_LETTER must be set to a valid value" -#else - #if (LV_FS_WIN32_LETTER < 'A') || (LV_FS_WIN32_LETTER > 'Z') - #if LV_FS_DEFAULT_DRIVE_LETTER != '\0' /*When using default drive letter, strict format (X:) is mandatory*/ - #error "LV_FS_WIN32_LETTER must be an upper case ASCII letter" - #else /*Lean rules for backward compatibility*/ - #warning LV_FS_WIN32_LETTER should be an upper case ASCII letter. \ - Using a slash symbol as drive letter should be replaced with LV_FS_DEFAULT_DRIVE_LETTER mechanism - #endif - #endif + +#if !LV_FS_IS_VALID_LETTER(LV_FS_WIN32_LETTER) + #error "Invalid drive letter" #endif #define MAX_PATH_LEN 256 diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index 47f535c8fe..1b22549c12 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -4078,6 +4078,9 @@ LV_EXPORT_CONST_INT(LV_DRAW_BUF_ALIGN); #endif #endif +/*Allow only upper case letters and '/' ('/' is a special case for backward compatibility)*/ +#define LV_FS_IS_VALID_LETTER(l) ((l) == '/' || ((l) >= 'A' && (l) <= 'Z')) + /* If running without lv_conf.h, add typedefs with default value. */ #ifdef LV_CONF_SKIP #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) /*Disable warnings for Visual Studio*/