LVGL MicroPython

repository·main·Indexed 43 days ago

https://github.com/lvgl-micropython/lvgl_micropython

A mechanism to build MicroPython with LVGL support on custom ESP32 hardware. It features board-specific configuration files and TOML-based hardware abstraction for defining MCU settings, bus configurations (I80, I2C), and display/input device drivers for targets including esp32, esp32s2, esp32s3, esp32c3, and esp32c6.

Tokens
1.3K
Snippets
3
Records
3
Agent score
5%

What's inside LVGL MicroPython

  1. Use a TOML file to configure custom boards

    main

    While not strictly required, using a .toml file is strongly recommended to tie together display and input device (indev) configurations. The TOML file allows you to define MCU settings, bus configurations (I80, I2C), devices, and drivers in a structured way.

    TOML Structure Rules

    • [MCU.{target}]: Defines MCU-specific build parameters. {target} is your build target (e.g., esp32).

      • Convert CLI flags: Remove leading -- and replace all - with _ (e.g., --octal-flash becomes octal_flash).
      • Case sensitivity: Options are case-sensitive.
      • Strings: Wrap string values in double quotes ("value").
      • Booleans: Options that take no value must be set to true.
      • Limitation: DISPLAY and INDEV sections cannot be repeated; only one display and one indev can be supplied.
    • [{bus_type}.{variable_name}]: Defines a bus (e.g., [I80Bus.display_bus]). This is converted into a constructor call like display_bus = lcd_bus.I80Bus(...). The options listed under this heading must match the parameter names of the class being used.

    • [I2C.Bus.{variable_name}] and [I2C.Device.{variable_name}]: Used to configure I2C buses and the devices attached to them.

    [MCU.esp32]
    BOARD = "ESP32_GENERIC_S3"
    BOARD_VARIANT = "SPIRAM_OCT"
    octal_flash = true
    flash_size = 16
    enable_jtag_repl = 'n'
    enable_cdc_repl = 'n'
    enable_uart_repl = 'y'
    uart_repl_bitrate = 115200
    
    [I80Bus.display_bus]
    data0 = 9
    data1 = 46
    data2 = 3
    data3 = 8
    data4 = 18
    data5 = 17
    data6 = 16
    data7 = 15
    dc = 0
    wr = 47
    cs = -1
    freq = 20000000
    
    [I2C.Bus.i2c_bus]
    host = 0
    scl = 5
    sda = 6
    freq = 100000
    
    [I2C.Device.indev_device]
    bus = "i2c_bus"
    dev_id = "ft6x36.I2C_ADDR"
    reg_bits = "ft6x36.BITS"
    
    [ST7796.display]
    data_bus = "display_bus"
    display_width = 320
    display_height = 480
    backlight_pin = 45
    color_byte_order = "st7789.BYTE_ORDER_BGR"
    color_space = "lv.COLOR_FORMAT.RGB565"
    rgb565_byte_swap = true
    
    [ST7796.display.init]
    params = []
    
    [FT6x36.indev]
    device = "indev_device"
    
    [display.set_color_inversion]
    params = [true]
    
    [display.set_rotation]
    params = ["lv.DISPLAY_ROTATION._90"]
    
    [display.set_backlight]
    params = [100]
    
    [task_handler.TaskHandler]
    params=[]
  2. Define a custom board for building

    main

    To build with a custom board, you must provide a path to a folder containing specific board specification files. When building, you must use the --custom-board-path command and specify the build target. Other build options are ignored because configuration is handled within the board files themselves.

    Required Files

    1. board.json: Defines the MCU. At minimum, it must contain:

      {
          "mcu": "{MCU}"
      }

      Supported {MCU} values: esp32, esp32s2, esp32s3, esp32c3, esp32c6.

    2. sdkconfig.board: Contains ESP-IDF specific configuration settings.

    3. mpconfigboard.h: Contains MicroPython configuration settings.

    4. mpconfigboard.cmake: The build script. It must include the following logic (replacing {MCU} with your target and {BOARD_CONATINING_FOLDER} with the name of the folder containing these files):

      set(IDF_TARGET {MCU})
      
      set(SDKCONFIG_DEFAULTS
          boards/sdkconfig.base
          ${SDKCONFIG_IDF_VERSION_SPECIFIC}
          boards/{BOARD_CONATINING_FOLDER}/sdkconfig.board
      )
    5. partition.csv: Defines the ESP32 partition table.

    # Example usage (conceptual)
    # Use the build target and the --custom-board-path flag
    python build.py --target esp32s3 --custom-board-path /path/to/your/custom_board_folder