diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-06-12 17:54:40 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-06-12 17:54:40 +1000 |
| commit | 64bd9053a25297f7a442ca831c7da5b44bd33f84 (patch) | |
| tree | a90c6cad25a12028302ab1a5334510fba0229bae /lib/lvgl/tests/src/test_libs | |
| parent | 611176ed667c4ed7ee9f609e958f9404f4aee91d (diff) | |
| download | tangara-fw-64bd9053a25297f7a442ca831c7da5b44bd33f84.tar.gz | |
Update LVGL to v9.1.0
Diffstat (limited to 'lib/lvgl/tests/src/test_libs')
8 files changed, 406 insertions, 0 deletions
diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.c b/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.c new file mode 100644 index 00000000..9375a74c --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.c @@ -0,0 +1,65 @@ +/** +* @file lv_rnd_unicodes.c +* +*/ + +/********************* + * INCLUDES + *********************/ +#include "lv_rnd_unicodes.h" + + +#include "rnd_unicodes/src/library.h" + +#define UNICODE_MAX_VALUE 0x10FFFF + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * STATIC PROTOTYPES + **********************/ + +const uint32_t LV_RND_UNICODE_ALPHANUM_AND_CJK_TABLE[] = { + 0x4e00, 0x9fa5, // CJK Unified Ideographs + 'A', 'Z', + 'a', 'z', + '0', '9', +}; +const uint32_t LV_RND_UNICODE_ALPHANUM_AND_CJK_TABLE_LEN = sizeof(LV_RND_UNICODE_ALPHANUM_AND_CJK_TABLE) / sizeof( + unicode_t) / 2; + +/********************** + * GLOBAL VARIABLES + **********************/ + +/********************** + * STATIC VARIABLES + **********************/ + +/********************** + * MACROS + **********************/ + +/********************** + * GLOBAL FUNCTIONS + **********************/ + +uint32_t RANDOM_CALL_PROCESS(void) +{ + return lv_rand(0, UNICODE_MAX_VALUE); +} + +int lv_random_utf8_chars(uint8_t * buf, int buf_len, const uint32_t * ranges, uint32_t range_num, int char_num) +{ + return random_utf8_chars(buf, buf_len, ranges, range_num, char_num); +} + +/********************** + * STATIC FUNCTIONS + **********************/ diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.h b/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.h new file mode 100644 index 00000000..be9a5244 --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/lv_rnd_unicodes.h @@ -0,0 +1,56 @@ +/** +* @file lv_rnd_unicodes.h +* +*/ + +#ifndef LV_RND_UNICODES_H +#define LV_RND_UNICODES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lvgl.h" + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +extern const uint32_t LV_RND_UNICODE_ALPHANUM_AND_CJK_TABLE[]; +extern const uint32_t LV_RND_UNICODE_ALPHANUM_AND_CJK_TABLE_LEN; + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/** + * Generate random UTF-8 characters in the given ranges. + * @param buf buffer to store the generated characters + * @param buf_len length of the buffer + * @param ranges array of ranges to choose from + * @param range_num number of ranges + * @param char_num number of characters to generate + * @return number of generated characters in bytes + */ +int lv_random_utf8_chars(uint8_t * buf, int buf_len, const uint32_t * ranges, uint32_t range_num, int char_num); + +/************************* + * GLOBAL VARIABLES + *************************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /*extern "C"*/ +#endif + +#endif /*LV_RND_UNICODES_H*/ diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/.gitignore b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/.gitignore new file mode 100644 index 00000000..64e52d20 --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/.gitignore @@ -0,0 +1,5 @@ +cmake-build-* +build/* +.idea +*.o +.DS_Store diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/CMakeLists.txt b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/CMakeLists.txt new file mode 100644 index 00000000..bcfaf42b --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.10) +project(rnd_unicodes C) + +set(CMAKE_C_STANDARD 11) + +add_library(rnd_unicodes SHARED src/library.c) + +add_executable(rnd_unicodes_test examples/main.c) +target_link_libraries(rnd_unicodes_test rnd_unicodes) diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/LICENSE b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/LICENSE new file mode 100644 index 00000000..50cfd6dd --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Benign X + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/README.md b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/README.md new file mode 100644 index 00000000..09dbcca9 --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/README.md @@ -0,0 +1,41 @@ +# rnd_unicodes + +## Description + +This is a simple c lib that generates a random unicode string of a given length. + +## Usage + +```c +#include "library.h" +#include "stdio.h" +#include "stdlib.h" +#include "time.h" + +#define BUF_LEN 1024 + +utf8_t chars[BUF_LEN]; + +// override the random function to use the system's random number generator +uint32_t RANDOM_CALL_PROCESS(void) { + return rand(); +} + +int main() { + srand(time(NULL)); + int len = random_utf8_chars(chars, BUF_LEN, ALPHANUM_AND_CJK_TABLE, ALPHANUM_AND_CJK_TABLE_LEN, 256); + + printf("LEN: %d\n%s\n", len, chars); + return 0; +} + +``` + +```bash +LEN: 398 +9Ky鰒9奷鱈39澂9R鴥8覗E祫f912QR梑dX啀凐覎liGPC俟j3S6V4ZBU8藉W舖旫iR8EFcHV8b尜橃o8Wsle121nb駆侓6璸9hQQ6Cy桪oc8姌f7X賣5孛0幬5Sb2埉w砏3XRSh钳D869b盓儊a95B菩62濆Z机郹9145UHaLT擎馇貤m臨v夛砃xPD7CWQq堾j稄3YmFw7Z欠P8PCcu7鶚68韾7KGgTN2P793L雙hy壒TGb螿虊C6m弩呚YBt0骇fAtn恔雸餙営n共1MeH嘿刑步焒簡RejV援21q77rT蛸4N橷4ZFa恲m詘焣悷b61瘥Z绢v +``` + +## License + +MIT diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.c b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.c new file mode 100644 index 00000000..6ebcded6 --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.c @@ -0,0 +1,162 @@ +/* + * MIT License + * + * Copyright (c) 2023 Benign X + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#include "library.h" + +__attribute__((weak)) uint32_t RANDOM_CALL_PROCESS(void) +{ + /*Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs"*/ + static uint32_t x = 0x114514; + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + + return x; +} + +const uint32_t ALPHANUM_AND_CJK_TABLE[] = { + 0x4e00, 0x9fa5, // CJK Unified Ideographs + 'A', 'Z', + 'a', 'z', + '0', '9', +}; +const uint32_t ALPHANUM_AND_CJK_TABLE_LEN = sizeof(ALPHANUM_AND_CJK_TABLE) / sizeof(unicode_t) / 2; + +const uint32_t ONLY_CJK_TABLE[] = { + 0x4e00, 0x9fa5, // CJK Unified Ideographs +}; +const uint32_t ONLY_CJK_TABLE_LEN = sizeof(ALPHANUM_AND_CJK_TABLE) / sizeof(unicode_t) / 2; + +const uint32_t ALPHANUM_TABLE[] = { + 'A', 'Z', + 'a', 'z', + '0', '9', +}; +const uint32_t ALPHANUM_TABLE_LEN = sizeof(ALPHANUM_TABLE) / sizeof(unicode_t) / 2; + +static int unicode_to_utf8_bytes_len(unicode_t unicode) +{ + if(unicode < 0x80) { + return 1; + } + else if(unicode < 0x800) { + return 2; + } + else if(unicode < 0x10000) { + return 3; + } + else if(unicode < 0x200000) { + return 4; + } + else if(unicode < 0x4000000) { + return 5; + } + else { + return 6; + } +} + +static int unicode_to_uft8(utf8_t * buf, uint32_t buf_len, unicode_t unicode) +{ + uint32_t unicode_len = unicode_to_utf8_bytes_len(unicode); + if(buf_len < unicode_len) { + return -1; + } + + int buf_index = 0; + + switch(unicode_len) { + case 1: + buf[buf_index++] = (uint8_t) unicode; + break; + case 2: + buf[buf_index++] = (uint8_t)(0xc0 | (unicode >> 6)); + buf[buf_index++] = (uint8_t)(0x80 | (unicode & 0x3f)); + break; + case 3: + buf[buf_index++] = (uint8_t)(0xe0 | (unicode >> 12)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 6) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | (unicode & 0x3f)); + break; + case 4: + buf[buf_index++] = (uint8_t)(0xf0 | (unicode >> 18)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 12) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 6) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | (unicode & 0x3f)); + break; + case 5: + buf[buf_index++] = (uint8_t)(0xf8 | (unicode >> 24)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 18) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 12) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 6) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | (unicode & 0x3f)); + break; + case 6: + buf[buf_index++] = (uint8_t)(0xfc | (unicode >> 30)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 24) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 18) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 12) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | ((unicode >> 6) & 0x3f)); + buf[buf_index++] = (uint8_t)(0x80 | (unicode & 0x3f)); + break; + default: + return -1; + } + return buf_index; +} + +static int random_one_utf8_char(utf8_t * buf, int buf_len, unicode_t char_range_min, unicode_t char_range_max) +{ + if(buf_len < 1) { + return -1; + } + + uint32_t r = RANDOM_CALL_PROCESS() % (char_range_max - char_range_min + 1) + char_range_min; + + return unicode_to_uft8(buf, buf_len, r); +} + +int random_utf8_chars(utf8_t * buf, int buf_len, const unicode_t * ranges, uint32_t range_num, int char_num) +{ + if(buf_len < char_num) { + return -1; + } + + int buf_index = 0; + for(int i = 0; i < char_num && buf_index < buf_len; i++) { + int range_index = RANDOM_CALL_PROCESS() % range_num; + int ret = random_one_utf8_char(buf + buf_index, + buf_len - buf_index, + ranges[2 * range_index], + ranges[2 * range_index + 1]); + if(ret < 0) { + return -1; + } + buf_index += ret; + } + + buf[buf_index] = '\0'; + return buf_index; +} diff --git a/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.h b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.h new file mode 100644 index 00000000..ee70a94d --- /dev/null +++ b/lib/lvgl/tests/src/test_libs/rnd_unicodes/rnd_unicodes/src/library.h @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2023 Benign X + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#ifndef RND_UNICODES_LIBRARY_H +#define RND_UNICODES_LIBRARY_H + +#include <stdint.h> + +typedef uint32_t unicode_t; +typedef uint8_t utf8_t; + +extern const uint32_t ALPHANUM_AND_CJK_TABLE[]; +extern const uint32_t ALPHANUM_AND_CJK_TABLE_LEN; + +extern const uint32_t ONLY_CJK_TABLE[]; +extern const uint32_t ONLY_CJK_TABLE_LEN; + +extern const uint32_t ALPHANUM_TABLE[]; +extern const uint32_t ALPHANUM_TABLE_LEN; + +uint32_t RANDOM_CALL_PROCESS(void); + +int random_utf8_chars(utf8_t * buf, int buf_len, const unicode_t * ranges, uint32_t range_num, int char_num); + +#endif //RND_UNICODES_LIBRARY_H |
