How to show a file list from SDcard folder with Unicode

Description

How to use the list to display the file name of the folder in the SD card and the file name encoded in Unicode,The name of the list can only display English characters, not Chinese characters.

What MCU/Processor/Board and compiler are you using?

STM32F407

What LVGL version are you using?

7.0.2

What do you want to achieve?

What have you tried so far?

no

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

image

The screen can display the Chinese written in the program, but the Chinese file name in the SD card folder cannot be displayed

Maybe you’re not using the correct font on the list buttons?

/* Optionally declare your custom fonts here.

  • You can use these fonts as default font too
  • and they will be available globally. E.g.
  • #define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(my_font_1) \
  •                            LV_FONT_DECLARE(my_font_2)
    

*/
#define LV_FONT_CUSTOM_DECLARE LV_FONT_DECLARE(myFont12)
LV_FONT_DECLARE(myFont18)
LV_FONT_DECLARE(myFont24)

/* Enable it if you have fonts with a lot of characters.

  • The limit depends on the font size, font face and bpp
  • but with > 10,000 characters if you see issues probably you need to enable it.*/
    #define LV_FONT_FMT_TXT_LARGE 0

/* Set the pixel order of the display.

  • Important only if “subpx fonts” are used.
  • With “normal” font it doesn’t matter.
    */
    #define LV_FONT_SUBPX_BGR 0

/Declare the type of the user data of fonts (can be e.g. void *, int, struct)/
typedef void * lv_font_user_data_t;

/*================

  • THEME USAGE
    ================/

/Always enable at least on theme/

/* No theme, you can apply your styles as you need

  • No flags. Set LV_THEME_DEFAULT_FLAG 0 */
    #define LV_USE_THEME_EMPTY 1

/*Simple to the create your theme based on it

  • No flags. Set LV_THEME_DEFAULT_FLAG 0 */
    #define LV_USE_THEME_TEMPLATE 1

/* A fast and impressive theme.

  • Flags:
  • LV_THEME_MATERIAL_FLAG_LIGHT: light theme
  • LV_THEME_MATERIAL_FLAG_DARK: dark theme*/
    #define LV_USE_THEME_MATERIAL 1

/* Mono-color theme for monochrome displays.

  • If LV_THEME_DEFAULT_COLOR_PRIMARY is LV_COLOR_BLACK the
  • texts and borders will be black and the background will be
  • white. Else the colors are inverted.
  • No flags. Set LV_THEME_DEFAULT_FLAG 0 */
    #define LV_USE_THEME_MONO 1

#define LV_THEME_DEFAULT_INCLUDE <stdint.h> /Include a header for the init. function/
#define LV_THEME_DEFAULT_INIT lv_theme_material_init
#define LV_THEME_DEFAULT_COLOR_PRIMARY LV_COLOR_RED
#define LV_THEME_DEFAULT_COLOR_SECONDARY LV_COLOR_BLUE
#define LV_THEME_DEFAULT_FLAG LV_THEME_MATERIAL_FLAG_LIGHT
#define LV_THEME_DEFAULT_FONT_SMALL &myFont12
#define LV_THEME_DEFAULT_FONT_NORMAL &myFont12
#define LV_THEME_DEFAULT_FONT_SUBTITLE &myFont18
#define LV_THEME_DEFAULT_FONT_TITLE &myFont24

I have declared the font and changed the default font,it should not be a problem that fonts are not applied to the list,only Chinese is not displayed in the list.

It could be filesystem issue as well. Can you verify with debugger (or printing to serial port, etc) if the read filenames are correct before sending them to LVGL?

BTW, the files should be UTF-8 encoded and not Unicode. Unicode describes the mapping of values to characters and UTF-8 tells how to store the Unicode values in a compact form.

An algorithm for converting Unicode to utf8 encoding may be needed

“Unicode” is not a character encoding; it’s a character set. Are you referring to UTF-16?

I don’t understand this. I just can’t display the folder with Chinese name

Have you tested what I suggested here?