### PointerDriver Usage Example Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Example demonstrating the setup of a touch driver (FT6x36) using I2C, including calibration and rotation. This code shows the typical initialization flow for a touch input device. ```python import pointer_framework import ft6x36 import i2c import lvgl as lv # Create I2C bus i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=100000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) # Create touch driver touch = ft6x36.FT6x36(touch_dev) # Calibrate if needed if not touch.is_calibrated: display.set_backlight(100) touch.calibrate() # Set rotation AFTER calibration display.set_rotation(lv.DISPLAY_ROTATION._90) # Use touch input normally - no additional calls needed ``` -------------------------------- ### start() Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/I2CBus.md Generates an I2C START condition on the bus. ```APIDOC ## start() ### Description Generate I2C START condition. ### Example ```python i2c_bus.start() ``` ``` -------------------------------- ### MatrixKeypad Implementation Example Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Example of a custom KeypadDriver subclass for a matrix keypad. Implements `_get_key()` to scan the keypad matrix and return key press events. Requires hardware-specific pin configuration. ```python import keypad_framework import lvgl as lv class MatrixKeypad(keypad_framework.KeypadDriver): def __init__(self, row_pins, col_pins): self.row_pins = row_pins self.col_pins = col_pins self.key_map = [ ['1', '2', '3', 'A'], ['4', '5', '6', 'B'], ['7', '8', '9', 'C'], ['*', '0', '#', 'D'] ] super().__init__() def _get_key(self): # Scan keypad matrix for pressed key for row in range(len(self.row_pins)): self.row_pins[row].value(0) # Pull row low for col in range(len(self.col_pins)): if self.col_pins[col].value() == 0: # Column reads low self.row_pins[row].value(1) # Release row char = self.key_map[row][col] return (self.PRESSED, ord(char)) # Return (state, keycode) self.row_pins[row].value(1) # Release row return None # No key pressed # Create driver import machine rows = [machine.Pin(i, machine.Pin.OUT) for i in range(32, 36)] cols = [machine.Pin(i, machine.Pin.IN) for i in range(36, 40)] keypad = MatrixKeypad(rows, cols) # Keys are now received by LVGL as keypad events ``` -------------------------------- ### Initialize SDLPointer and Display Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md This example demonstrates how to initialize both the SDLDisplay and SDLPointer drivers. Ensure these are set up before creating interactive UI elements. ```python import lvgl as lv import lcd_bus import sdl_display import sdl_pointer import task_handler # Create SDL display bus = lcd_bus.SDLBus(flags=0) buf = bus.allocate_framebuffer(480 * 320 * 3, 0) display = sdl_display.SDLDisplay( data_bus=bus, display_width=480, display_height=320, frame_buffer1=buf, color_space=lv.COLOR_FORMAT.RGB888 ) display.init() # Create mouse input mouse = sdl_pointer.SDLPointer() # Start event loop th = task_handler.TaskHandler(duration=5) # Create interactive UI screen = lv.screen_active() button = lv.button(screen) label = lv.label(button) label.set_text("Click me!") button.center() # Mouse clicks and movement now work in SDL window ``` -------------------------------- ### Example board.json Configuration Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/custom_board_and_toml_examples/README.md Defines the microcontroller for the custom board. Ensure the 'mcu' value is one of the supported options. ```json { "mcu": "{MCU}" } ``` -------------------------------- ### active Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Gets the currently active keypad driver instance. ```APIDOC ## active ### Description Get currently active keypad driver. ### Method ```python @classmethod active() -> KeypadDriver ``` ### Returns Active KeypadDriver or None. ### Example ```python current = KeypadDriver.active() ``` ``` -------------------------------- ### Initialize Display and Touch with LVGL Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/00-START-HERE.md This snippet shows the necessary imports and setup for a display and touch controller. Ensure the correct pins and bus configurations are used for your hardware. ```python # Display setup import lcd_bus import st7796 import task_handler import lvgl as lv # Create display bus = lcd_bus.SPIBus(spi_bus, freq=80000000, dc=0, cs=10) display = st7796.ST7796( data_bus=bus, display_width=320, display_height=480, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_BGR, backlight_pin=45 ) display.init() display.set_power(True) display.set_backlight(100) # Add touch import ft6x36 import i2c i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=400000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) touch = ft6x36.FT6x36(touch_dev) if not touch.is_calibrated: touch.calibrate() # Start event loop th = task_handler.TaskHandler(duration=33) # Use LVGL normally screen = lv.screen_active() button = lv.button(screen) button.center() ``` -------------------------------- ### I2C.Device Usage Example Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/I2CBus.md Demonstrates creating an I2C.Bus instance and then an I2C.Device instance. Shows basic register read and write operations using the device object. ```python import i2c # Create device on I2C bus i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=100000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) # Read register data = touch_dev.read_mem(0x02, num_bytes=10) # Write register touch_dev.write_mem(0x00, b'\x80') ``` -------------------------------- ### I2C Bus Initialization and Device Scan Example Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/I2CBus.md Demonstrates how to create an I2C bus instance, initialize an I2C device, and scan for connected I2C devices. Ensure the 'i2c' and 'ft6x36' modules are available. ```python import i2c import ft6x36 # Create I2C bus on host 0 with standard frequency i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=100000, use_locks=False) # Create touch device on same bus touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) # Create touch driver using the device touch = ft6x36.FT6x36(touch_dev) # Access bus directly if needed devices = i2c_bus.scan() print(f"I2C devices found: {[hex(addr) for addr in devices]}") ``` -------------------------------- ### Example mpconfigboard.cmake Build Script Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/custom_board_and_toml_examples/README.md Configures the build target and includes necessary configuration files for the custom board. Replace placeholders with actual values. ```cmake set(IDF_TARGET {MCU}) set(SDKCONFIG_DEFAULTS boards/sdkconfig.base ${SDKCONFIG_IDF_VERSION_SPECIFIC} boards/{BOARD_CONATINING_FOLDER}/sdkconfig.board ) ``` -------------------------------- ### Get Parameters (No-op) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md This method is a no-operation for the SDL display. ```python display.get_params(0x04, buf) # No effect ``` -------------------------------- ### Generate I2C START Condition Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/I2CBus.md Generates an I2C START condition. This is typically used before initiating a read or write operation. ```python i2c_bus.start() ``` -------------------------------- ### Initialize ST7796 Display Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDriver.md Example demonstrating how to create and initialize an ST7796 display driver, including setting up the SPI bus, allocating framebuffers, and configuring display-specific parameters like color format and byte order. ```python import lcd_bus import st7796 import lvgl as lv # Create display bus (SPI example) display_bus = lcd_bus.SPIBus( spi_bus=spi_bus, freq=80000000, dc=0, cs=10 ) # Allocate framebuffers (optional - auto-allocated if None) fb1 = display_bus.allocate_framebuffer(30720, lcd_bus.MEMORY_DMA) fb2 = display_bus.allocate_framebuffer(30720, lcd_bus.MEMORY_DMA) # Create ST7796 display driver (subclass of DisplayDriver) display = st7796.ST7796( data_bus=display_bus, display_width=320, display_height=480, frame_buffer1=fb1, frame_buffer2=fb2, backlight_pin=45, backlight_on_state=display_driver_framework.STATE_HIGH, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_BGR, rgb565_byte_swap=True ) display.init() display.set_power(True) display.set_backlight(100) ``` -------------------------------- ### Usage Example: Custom Button Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/ButtonDriver.md Demonstrates how to create a custom ButtonDriver subclass to read physical button states. Ensure the display driver is initialized before the button driver. ```python import button_framework import lvgl as lv class MyButtonDriver(button_framework.ButtonDriver): def __init__(self, button_pins): self.button_pins = button_pins super().__init__() def _get_button(self): # Return button ID if pressed, None if no button pressed for pin_id, pin in enumerate(self.button_pins): if pin.value() == 0: # Active low return pin_id return None # Create buttons import machine button1 = machine.Pin(32, machine.Pin.IN) button2 = machine.Pin(33, machine.Pin.IN) # Create driver buttons = MyButtonDriver([button1, button2]) # Set button point locations for coordinate-based buttons buttons.set_button_points( lv.point_t({'x': 100, 'y': 100}), # Button 0 position lv.point_t({'x': 200, 'y': 100}) # Button 1 position ) ``` -------------------------------- ### PointerDriver Subclass Implementation Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Example of how to subclass PointerDriver and implement the _get_coords method to read hardware touch input. ```APIDOC ## PointerDriver Subclass Implementation Template Subclasses must override `_get_coords()` to read hardware: ```python class MyTouchDriver(pointer_framework.PointerDriver): def __init__(self, device): self._device = device super().__init__() def _get_coords(self): # Read touch from hardware # Return None if no touch, else (state, x, y) # state: PRESSED (lv.INDEV_STATE.PRESSED) or RELEASED # x, y: raw sensor coordinates state, x, y = self._device.read() if state == self.RELEASED: return None return (state, x, y) ``` ``` -------------------------------- ### Persistent Touch Calibration (ESP32 NVRAM) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TouchDrivers.md On ESP32 with NVRAM support, calibration data is automatically saved and restored. This example shows the first boot calibration and subsequent automatic loading. ```python import ft6x36 # First boot: calibrate touch = ft6x36.FT6x36(device) if not touch.is_calibrated: touch.calibrate() # Saves to NVRAM # Subsequent boots: calibration automatically loaded touch2 = ft6x36.FT6x36(device) assert touch2.is_calibrated # True from NVRAM ``` -------------------------------- ### Get Backlight Status Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md Always returns 100.0 for the SDL display, representing full backlight brightness in the simulation. ```python assert display.get_backlight() == 100.0 ``` -------------------------------- ### ILI9341 SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the ILI9341 display driver. This is an industry-standard controller supporting I80 parallel and SPI interfaces. ```python import ili9341 display = ili9341.ILI9341( data_bus=display_bus, display_width=240, display_height=320, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=ili9341.BYTE_ORDER_BGR ) ``` -------------------------------- ### Mandatory Touch Calibration (Resistive) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TouchDrivers.md Resistive touch drivers require calibration on every boot. This example shows how to perform mandatory calibration and assert its success. ```python import xpt2046 touch = xpt2046.XPT2046(device) # Calibration is required every boot display.set_backlight(100) success = touch.calibrate() assert success, "Must calibrate resistive touch" # Now ready to use ``` -------------------------------- ### ST7789 SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the ST7789 display driver. This driver offers improved performance and is popular for mid-size displays. ```python import st7789 display = st7789.ST7789( data_bus=display_bus, display_width=240, display_height=320, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### Initialize I8080 Display and I2C Touch for MCU Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Python code for initializing an I8080-based display and an I2C touch input device (FT6x36) for MCUs. Includes display rotation and touch calibration setup. ```python import lcd_bus from micropython import const # display settings _WIDTH = const(320) _HEIGHT = const(480) _BL = const(45) _RST = const(4) _DC = const(0) _WR = const(47) _FREQ = const(20000000) _DATA0 = const(9) _DATA1 = const(46) _DATA2 = const(3) _DATA3 = const(8) _DATA4 = const(18) _DATA5 = const(17) _DATA6 = const(16) _DATA7 = const(15) _BUFFER_SIZE = const(30720) _SCL = const(5) _SDA = const(6) _TP_FREQ = const(100000) display_bus = lcd_bus.I80Bus( dc=_DC, wr=_WR, freq=_FREQ, data0=_DATA0, data1=_DATA1, data2=_DATA2, data3=_DATA3, data4=_DATA4, data5=_DATA5, data6=_DATA6, data7=_DATA7 ) fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA) fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA) import st7796 # NOQA import lvgl as lv # NOQA lv.init() display = st7796.ST7796( data_bus=display_bus, frame_buffer1=fb1, frame_buffer2=fb2, display_width=_WIDTH, display_height=_HEIGHT, backlight_pin=_BL, # reset=_RST, # reset_state=st7796.STATE_LOW, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_BGR, rgb565_byte_swap=True, ) import i2c # NOQA import task_handler # NOQA import ft6x36 # NOQA display.init() i2c_bus = i2c.I2C.Bus(host=0, scl=_SCL, sda=_SDA, freq=_TP_FREQ, use_locks=False) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=ft6x36.I2C_ADDR, reg_bits=ft6x36.BITS) indev = ft6x36.FT6x36(touch_dev) display.invert_colors() if not indev.is_calibrated: display.set_backlight(100) indev.calibrate() # you want to rotate the display after the calibration has been done in order # to keep the corners oriented properly. display.set_rotation(lv.DISPLAY_ROTATION._90) display.set_backlight(100) th = task_handler.TaskHandler() scrn = lv.screen_active() scrn.set_style_bg_color(lv.color_hex(0x000000), 0) slider = lv.slider(scrn) slider.set_size(300, 50) slider.center() label = lv.label(scrn) label.set_text('HELLO WORLD!') label.align(lv.ALIGN.CENTER, 0, -50) ``` -------------------------------- ### ST7789 Display with FT6x36 Capacitive Touch (I2C) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing an ST7789 display and an FT6x36 capacitive touch controller using SPI for the display and I2C for the touch controller. Calibration is performed if the touch controller is not already calibrated. ```python import st7789 import ft6x36 import i2c # Display display = st7789.ST7789( data_bus=display_bus, display_width=240, display_height=320 ) display.init() # Touch i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=400000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) touch = ft6x36.FT6x36(touch_dev) if not touch.is_calibrated: touch.calibrate() ``` -------------------------------- ### ILI9488 SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the ILI9488 display driver. This driver is suitable for high-resolution, larger TFT displays. ```python import ili9488 display = ili9488.ILI9488( data_bus=display_bus, display_width=320, display_height=480, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### Common Key Codes - ASCII Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Examples of obtaining ASCII key codes for printable characters. These are used for text input. ```python # ASCII printable characters (32-126) ord('A') # 65 ord('1') # 49 ``` -------------------------------- ### GC9A01 SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the GC9A01 display driver. This driver is specialized for round displays with a 240x240 resolution. ```python import gc9a01 display = gc9a01.GC9A01( data_bus=display_bus, display_width=240, display_height=240, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### ST7735R SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the ST7735R display driver. This driver is suitable for small TFT displays and supports 8-bit SPI. ```python import st7735r_red display = st7735r_red.ST7735R( data_bus=display_bus, display_width=128, display_height=160, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### PointerDriver.get_gesture_dir Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Gets the direction of a swipe gesture. ```APIDOC ## PointerDriver.get_gesture_dir ### Description Gets the direction of a swipe gesture. ### Method `get_gesture_dir() -> int` ### Returns Direction flags for the swipe gesture. ### Usage Example ```python gesture = touch.get_gesture_dir() ``` ``` -------------------------------- ### get_point Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Gets the current position of the mouse cursor. ```APIDOC ## get_point ### Description Gets the current mouse position. ### Method ```python get_point(point: lv.point_t) ``` ### Parameters #### Parameters - **point** (lv.point_t) - Required - Point to fill with current mouse coordinates ### Request Example ```python pos = lv.point_t() mouse.get_point(pos) print(f"Mouse: x={pos.x}, y={pos.y}") ``` ``` -------------------------------- ### HX8357D SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the HX8357D display driver. This driver is designed for high-resolution, larger TFT displays. ```python import hx8357d display = hx8357d.HX8357D( data_bus=display_bus, display_width=480, display_height=320, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### ST7796 SPI Display Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing the ST7796 display driver using an SPI bus. This driver supports parallel and SPI interfaces and various resolutions. ```python import lcd_bus import st7796 import lvgl as lv # Create SPI bus display_bus = lcd_bus.SPIBus( spi_bus=spi_bus, freq=80000000, dc=0, cs=10 ) # Create display display = st7796.ST7796( data_bus=display_bus, display_width=320, display_height=480, backlight_pin=45, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_BGR, rgb565_byte_swap=True ) display.init() display.set_power(True) display.set_backlight(100) ``` -------------------------------- ### ST7796 Display with GT911 Capacitive Touch Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing an ST7796 display and a GT911 capacitive touch controller using SPI and I2C respectively. Calibration is performed if the touch controller is not already calibrated. The display rotation is set to 90 degrees. ```python import st7796 import gt911 import i2c # Display display_bus = lcd_bus.SPIBus(spi_bus, freq=80000000, dc=0, cs=10) display = st7796.ST7796( data_bus=display_bus, display_width=320, display_height=480, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_BGR ) display.init() # Touch i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=400000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x5D, reg_bits=16) touch = gt911.GT911(touch_dev) if not touch.is_calibrated: touch.calibrate() display.set_rotation(lv.DISPLAY_ROTATION._90) ``` -------------------------------- ### Get Scroll Direction Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the direction in which the encoder is currently scrolling. ```python scroll_dir = encoder.get_scroll_dir() ``` -------------------------------- ### Get Backlight Level Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDriver.md Retrieves the current backlight brightness level. ```python level = display.get_backlight() print(f"Backlight: {level}%") ``` -------------------------------- ### init Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md Initializes the SDL2 display and prepares it for rendering. This method must be called after creating an SDLDisplay instance and before any rendering operations. ```APIDOC ## init ### Description Initializes the SDL2 display and prepares it for rendering. This method must be called after creating an SDLDisplay instance and before any rendering operations. ### Method ```python init() ``` ### Usage Example ```python display.init() ``` ``` -------------------------------- ### Get Object with Focus Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Returns the LVGL object that currently has input focus. ```python mouse.get_active_obj() ``` -------------------------------- ### Get All DisplayDriver Instances Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDriver.md Returns a list of all currently active DisplayDriver instances. ```python all_displays = DisplayDriver.get_displays() ``` -------------------------------- ### Configuration Options Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/MANIFEST.txt Details on the constructor parameters and configuration options available for various components of the LVGL MicroPython binding, including display drivers, input devices, and the task handler. ```APIDOC ## Configuration - **DisplayDriver Constructor**: Over 20 parameters available for detailed display configuration. - **SDLDisplay Constructor**: 15 parameters for SDL display setup. - **TaskHandler Constructor**: 4 parameters for task scheduling and event loop management. - **Touch Driver Constructors**: Configuration options for various touch input drivers. - **I2C Bus and Device Creation**: Parameters for setting up I2C communication. - **Memory Allocation Flags**: Flags to control memory allocation behavior. - **Touch Calibration Options**: Parameters for touch screen calibration. ``` -------------------------------- ### Combined Memory Allocation Flags Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/configuration.md Example of allocating framebuffer memory using a combination of DMA and SPIRAM flags. Ensure 'bus' is an initialized display bus object and 'size' is the desired buffer size. ```python fb = bus.allocate_framebuffer(size, lcd_bus.MEMORY_DMA | lcd_bus.MEMORY_SPIRAM) ``` -------------------------------- ### ILI9341 Display with XPT2046 Resistive Touch (SPI) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Example of initializing an ILI9341 display and an XPT2046 resistive touch controller using separate SPI Chip Select (CS) pins. Calibration is mandatory for resistive touchscreens. ```python import ili9341 import xpt2046 # Display display = ili9341.ILI9341( data_bus=display_bus, # SPI at 40 MHz display_width=240, display_height=320 ) display.init() # Touch (separate SPI CS) touch_dev = machine.SPI.Device( spi_bus=spi_bus, freq=2000000, # 2 MHz for touch cs=18 # Different CS than display ) touch = xpt2046.XPT2046(touch_dev) touch.calibrate() # Mandatory for resistive ``` -------------------------------- ### Get Gesture Direction Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Determines the direction of a gesture based on mouse drag input. ```python mouse.get_gesture_dir() ``` -------------------------------- ### Initialize SDLDisplay Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md Instantiates and initializes the SDLDisplay driver. This involves creating an SDL bus, allocating a framebuffer, and setting up the display with specified dimensions and color format. It's essential to call `display.init()` after instantiation. ```python import lvgl as lv import lcd_bus import sdl_display import sdl_pointer import task_handler # Create SDL bus bus = lcd_bus.SDLBus(flags=0) # Allocate framebuffer buf = bus.allocate_framebuffer(480 * 320 * 3, 0) # Create display display = sdl_display.SDLDisplay( data_bus=bus, display_width=480, display_height=320, frame_buffer1=buf, color_space=lv.COLOR_FORMAT.RGB888 ) display.init() # Create touch pointer mouse = sdl_pointer.SDLPointer() # Start event loop th = task_handler.TaskHandler(duration=5) # Create UI screen = lv.screen_active() button = lv.button(screen) label = lv.label(button) label.set_text("Hello SDL2!") button.center() # SDL window runs until closed ``` -------------------------------- ### Get Associated Display Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the display driver object that this encoder is associated with. ```python display = encoder.get_disp() ``` -------------------------------- ### Initialize PointerDriver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Instantiate a PointerDriver with optional calibration data, startup rotation, and debug mode. If no calibration data is provided, it will be auto-created. ```python PointerDriver( touch_cal=None, startup_rotation=lv.DISPLAY_ROTATION._0, debug=False ) ``` -------------------------------- ### Get Default DisplayDriver Instance Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDriver.md Retrieves the currently active default DisplayDriver instance. ```python default_display = DisplayDriver.get_default() ``` -------------------------------- ### Get Associated Display Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Retrieves the display driver object associated with this input device. ```python mouse.get_disp() ``` -------------------------------- ### Build for Unix with SDL Display Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Command to build for Unix systems using the SDL display and pointer input drivers. Ensure all Unix compilation requirements are met. ```bash python3 make.py unix DISPLAY=sdl_display INDEV=sdl_pointer ``` -------------------------------- ### Get Input Device Type Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Returns the type of the input device, which for SDLPointer is always `lv.INDEV_TYPE.POINTER`. ```python mouse.get_type() ``` -------------------------------- ### Build for ESP32-S3 with Octal SPIRAM Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Use this command to build for an ESP32-S3 processor with Octal SPIRAM and specified display/input drivers. Add 'clean' to resolve build issues from previous attempts. ```bash python3 make.py esp32 BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT DISPLAY=st7796 INDEV=gt911 ``` -------------------------------- ### Initialize SDL Display and Input for Unix/macOS Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Python code to initialize the LVGL display and input system for Unix-like systems using SDL. Requires `lvgl`, `sdl_display`, `sdl_pointer`, and `task_handler`. ```python from micropython import const # NOQA import lcd_bus # NOQA _WIDTH = const(480) _HEIGHT = const(320) bus = lcd_bus.SDLBus(flags=0) buf1 = bus.allocate_framebuffer(_WIDTH * _HEIGHT * 3, 0) import lvgl as lv # NOQA import sdl_display # NOQA display = sdl_display.SDLDisplay( data_bus=bus, display_width=_WIDTH, display_height=_HEIGHT, frame_buffer1=buf1, color_space=lv.COLOR_FORMAT.RGB888 ) display.init() import sdl_pointer import task_handler mouse = sdl_pointer.SDLPointer() # the duration needs to be set to 5 to have a good response from the mouse. # There is a thread that runs that facilitates double buffering. th = task_handler.TaskHandler(duration=5) scrn = lv.screen_active() scrn.set_style_bg_color(lv.color_hex(0x000000), 0) slider = lv.slider(scrn) slider.set_size(300, 25) slider.center() ``` -------------------------------- ### Get Encoder Read Timer Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the timer object used for automatic encoder reads. ```python timer = encoder.get_read_timer() ``` -------------------------------- ### Clone and Build LVGL MicroPython Binding Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Follow these steps to clone the repository and build the binding. Ensure you do not initialize submodules. ```bash git clone https://github.com/lvgl-micropython/lvgl_micropython cd lvgl_micropython python3 make.py esp32 ...... ``` -------------------------------- ### Get Automatic Read Timer Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Retrieves the timer object used for automatic input read cycles. ```python mouse.get_read_timer() ``` -------------------------------- ### SDLPointer Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Initializes the SDLPointer driver, registering it as an LVGL input device. It allows configuration of startup rotation and debug output. ```APIDOC ## Class: SDLPointer Touch/pointer driver using SDL2 mouse events. Integrates with SDLDisplay for desktop LVGL development and testing. ### Constructor ```python SDLPointer( *_, startup_rotation=lv.DISPLAY_ROTATION._0, debug=False, **__ ) ``` | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | startup_rotation | int | lv.DISPLAY_ROTATION._0 | Display rotation at initialization | | debug | bool | False | Enable debug output for mouse coordinates | ### Returns SDLPointer instance with LVGL mouse input device registered. ### Usage Example ```python import lvgl as lv import lcd_bus import sdl_display import sdl_pointer import task_handler # Create SDL display bus = lcd_bus.SDLBus(flags=0) buf = bus.allocate_framebuffer(480 * 320 * 3, 0) display = sdl_display.SDLDisplay( data_bus=bus, display_width=480, display_height=320, frame_buffer1=buf, color_space=lv.COLOR_FORMAT.RGB888 ) display.init() # Create mouse input mouse = sdl_pointer.SDLPointer() # Start event loop th = task_handler.TaskHandler(duration=5) # Create interactive UI screen = lv.screen_active() button = lv.button(screen) label = lv.label(button) label.set_text("Click me!") button.center() # Mouse clicks and movement now work in SDL window ``` ``` -------------------------------- ### Get Number of Queued Events Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Returns the total count of events currently waiting in the event queue. ```python mouse.get_event_count() ``` -------------------------------- ### Get Associated Object Group Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the LVGL group object currently associated with this encoder input. ```python group = encoder.get_group() ``` -------------------------------- ### Include Multiple Input Devices Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/configuration.md Compile with support for multiple input devices by setting the INDEV environment variable multiple times. ```bash INDEV=gt911 INDEV=xpt2046 ``` -------------------------------- ### Get Encoder Button State Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the current state of the encoder's button (pressed or released). ```python state = encoder.get_state() ``` -------------------------------- ### Configure SPI Bus for Display and Touch Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/README.md Initializes an SPI bus for both the display and touch controller. Ensure the correct SPI host is used, as SPI host 0 is reserved on ESP32 for SPIRAM and flash. ```python import lcd_bus from micropython import const import machine # display settings _WIDTH = const(320) _HEIGHT = const(480) _BL = const(45) _RST = const(4) _DC = const(0) _MOSI = const(11) _MISO = const(13) _SCK = const(12) _HOST = const(1) # SPI2 _LCD_CS = const(10) _LCD_FREQ = const(80000000) _TOUCH_CS = const(18) _TOUCH_FREQ = const(10000000) spi_bus = machine.SPI.Bus( host=_HOST, mosi=_MOSI, miso=_MISO, sck=_SCK ) display_bus = lcd_bus.SPIBus( spi_bus=spi_bus, freq=_LCD_FREQ, dc=_DC, cs=_LCD_CS, ) # we are going to let the display driver sort out the best freame buffer size and where to allocate it to. # fb1 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA) # fb2 = display_bus.allocate_framebuffer(_BUFFER_SIZE, lcd_bus.MEMORY_INTERNAL | lcd_bus.MEMORY_DMA) import st7796 # NOQA import lvgl as lv # NOQA display = st7796.ST7796( data_bus=display_bus, display_width=_WIDTH, display_height=_HEIGHT, backlight_pin=_BL, color_space=lv.COLOR_FORMAT.RGB565, color_byte_order=st7796.BYTE_ORDER_RGB, rgb565_byte_swap=True, ) import task_handler # NOQA import xpt2046 # NOQA display.set_power(True) display.init() display.set_backlight(100) touch_dev = machine.SPI.Device( spi_bus=spi_bus, freq=_TOUCH_FREQ, cs=_TOUCH_CS ) indev = xpt2046.XPT2046(touch_dev) th = task_handler.TaskHandler() scrn = lv.screen_active() scrn.set_style_bg_color(lv.color_hex(0x000000), 0) slider = lv.slider(scrn) slider.set_size(300, 50) slider.center() label = lv.label(scrn) label.set_text('HELLO WORLD!') label.align(lv.ALIGN.CENTER, 0, -50) ``` -------------------------------- ### Get Currently Focused Object Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Returns the LVGL object that currently has focus via the encoder input. ```python active_obj = encoder.get_active_obj() ``` -------------------------------- ### KeypadDriver Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Initializes the keypad driver and registers it with LVGL. No parameters are required. ```python KeypadDriver() ``` -------------------------------- ### Get Encoder Input Type Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the type of the input device. Use this to confirm it's an encoder. ```python assert encoder.get_type() == lv.INDEV_TYPE.ENCODER ``` -------------------------------- ### Initialize RGB Display Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md Instantiate an RGBDisplayDriver for RGB-capable displays. Requires an RGBBus instance, display dimensions, and color format. ```python from rgb_display_framework import RGBDisplayDriver display = RGBDisplayDriver( data_bus=rgb_bus, # RGBBus instance display_width=480, display_height=320, color_space=lv.COLOR_FORMAT.RGB565 ) ``` -------------------------------- ### Get Event Count Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Returns the total number of events currently present in the input device queue. ```python count = keypad.get_event_count() ``` -------------------------------- ### Common Touch Driver Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TouchDrivers.md Most touch drivers follow this pattern for initialization. The `device` parameter specifies the I2C or SPI bus, `touch_cal` is for calibration data, `startup_rotation` sets the initial display orientation, and `debug` enables verbose output. ```python TouchDriver( device, touch_cal=None, startup_rotation=lv.DISPLAY_ROTATION._0, debug=False ) ``` -------------------------------- ### Correct Touch and Display Initialization Sequence Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TouchDrivers.md Initialize the display driver first, then the touch driver, calibrate the touch, and finally set the display rotation. This ensures accurate touch input mapping. ```python import st7796 import ft6x36 import display_driver_framework # 1. Create and initialize display display = st7796.ST7796(data_bus=bus, ...) display.init() # 2. Create touch driver touch = ft6x36.FT6x36(device) # 3. Calibrate if needed if not touch.is_calibrated: touch.calibrate() # 4. Set rotation AFTER calibration display.set_rotation(lv.DISPLAY_ROTATION._90) # 5. Create task handler th = task_handler.TaskHandler() # Now UI and touch work together ``` -------------------------------- ### Get Event Descriptor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Retrieves the event descriptor object for an event at a given index in the input queue. ```python event = keypad.get_event_dsc(0) ``` -------------------------------- ### Initialize TaskHandler Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TaskHandler.md Instantiate the TaskHandler to manage LVGL rendering. Configure the duration for the desired frame rate. The event loop runs automatically via timer interrupts. ```python import lvgl as lv import task_handler # Initialize LVGL lv.init() # Create display and input devices... display = ... # Start the task handler with 33ms period (30 FPS) th = task_handler.TaskHandler(duration=33) # Event loop runs automatically via timer interrupt # Application code continues to run normally ``` -------------------------------- ### Get Input Device Type Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Retrieves the type of the input device. For KeypadDriver, this will always return `lv.INDEV_TYPE.KEYPAD`. ```python assert keypad.get_type() == lv.INDEV_TYPE.KEYPAD ``` -------------------------------- ### Set Display Offset Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDriver.md Sets the offset for partial screen rendering. Useful for displays with non-standard starting points. ```python display.set_offset(0, 0) # Default: no offset ``` -------------------------------- ### Build Command for LilyGo-TDeck Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/display_configs/LilyGo-TDeck/README.md Use this command to build the lvgl-micropython firmware with the LilyGo-TDeck custom board path. Ensure you have python3 and make.py available. ```bash python3 make.py --custom-board-path=display_configs/LilyGo-TDeck ``` -------------------------------- ### KeypadDriver Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Initializes the KeypadDriver and registers it with LVGL. Subclasses should override the _get_key() method to implement hardware-specific key reading. ```APIDOC ## KeypadDriver() ### Description Initializes keypad driver and registers with LVGL. ### Parameters None. ### Returns KeypadDriver instance with LVGL input device registered and enabled. ``` -------------------------------- ### ButtonDriver Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/ButtonDriver.md Initializes the ButtonDriver and registers it with the LVGL input device system. No parameters are required. ```APIDOC ## ButtonDriver() ### Description Initializes the button driver and registers it with LVGL. ### Constructor ```python ButtonDriver() ``` ### Returns ButtonDriver instance with LVGL input device registered and configured. ``` -------------------------------- ### enable Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/KeypadDriver.md Enables or disables the keypad input functionality. ```APIDOC ## enable ### Description Enable or disable keypad input. ### Method ```python enable(enabled: bool) ``` ### Parameters #### Path Parameters - **enabled** (bool) - True to enable, False to disable ### Example ```python keypad.enable(False) # Disable keypad ``` ``` -------------------------------- ### Get Current Mouse Button State Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Returns the current state of the mouse buttons, either `lv.INDEV_STATE.PRESSED` or `lv.INDEV_STATE.RELEASED`. ```python mouse.get_state() ``` -------------------------------- ### Get Object Being Scrolled Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Returns the LVGL object that is currently being scrolled by the mouse wheel, or `None` if no object is being scrolled. ```python mouse.get_scroll_obj() ``` -------------------------------- ### FT6x36 I2C Touch Driver Initialization Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TouchDrivers.md Initializes the FT6x36 touch controller via I2C. It includes steps for checking and performing calibration if needed. Debug output can be enabled by passing `debug=True` to the constructor. ```python import i2c import ft6x36 i2c_bus = i2c.I2C.Bus(host=0, scl=5, sda=6, freq=100000) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=0x38, reg_bits=8) touch = ft6x36.FT6x36(touch_dev) # Read calibration status if not touch.is_calibrated: touch.calibrate() # Enable debug output touch = ft6x36.FT6x36(touch_dev, debug=True) ``` -------------------------------- ### Include Multiple Display Drivers Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/configuration.md Compile with support for multiple display drivers by setting the DISPLAY environment variable multiple times. ```bash DISPLAY=st7796 DISPLAY=st7735 ``` -------------------------------- ### Get Drag Velocity Vector Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLPointer.md Retrieves the drag velocity vector. The `point` object will be populated with the velocity components. ```python mouse.get_vect(point) ``` -------------------------------- ### Common Display Driver Constructor Pattern Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/DisplayDrivers.md This pattern is followed by most display drivers. Parameters are documented in `DisplayDriver.md`, with IC-specific variations noted. ```python DisplayIC( data_bus, display_width, display_height, frame_buffer1=None, frame_buffer2=None, reset_pin=None, reset_state=display_driver_framework.STATE_HIGH, power_pin=None, power_on_state=display_driver_framework.STATE_HIGH, backlight_pin=None, backlight_on_state=display_driver_framework.STATE_HIGH, offset_x=0, offset_y=0, color_byte_order=BYTE_ORDER_RGB, color_space=lv.COLOR_FORMAT.RGB565, rgb565_byte_swap=False ) ``` -------------------------------- ### Get Active Encoder Driver Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the currently active EncoderDriver instance. Returns None if no encoder is active. ```python current = EncoderDriver.active() ``` -------------------------------- ### SDLDisplay Constructor Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md Initializes the SDLDisplay driver, creating a desktop window for LVGL applications. It configures the display dimensions, framebuffers, and color settings. ```APIDOC ## SDLDisplay Constructor ### Description Initializes the SDLDisplay driver, creating a desktop window for LVGL applications. It configures the display dimensions, framebuffers, and color settings. ### Parameters #### Path Parameters - **data_bus** (lcd_bus.SDLBus) - Required - SDL2 bus object for window management - **display_width** (int) - Required - Window width in pixels - **display_height** (int) - Required - Window height in pixels - **frame_buffer1** (bytearray) - Optional - Primary framebuffer. Auto-allocated if None. - **frame_buffer2** (bytearray) - Optional - Secondary framebuffer. Auto-allocated if None. - **reset_pin** (int/Pin) - Optional - Ignored for SDL (no hardware reset) - **reset_state** (int) - Optional - Ignored for SDL - **power_pin** (int/Pin) - Optional - Ignored for SDL - **power_on_state** (int) - Optional - Ignored for SDL - **backlight_pin** (int/Pin) - Optional - Ignored for SDL - **backlight_on_state** (int) - Optional - Ignored for SDL - **offset_x** (int) - Optional - Horizontal pixel offset - **offset_y** (int) - Optional - Vertical pixel offset - **color_byte_order** (int) - Optional - RGB (0x00) or BGR (0x08) byte order - **color_space** (int) - Optional - Color format: RGB565, RGB888, ARGB8888, etc. - **rgb565_byte_swap** (bool) - Optional - Swap red/blue bytes for RGB565 (typically False) ### Returns SDLDisplay instance with SDL2 window created and LVGL display driver registered. ``` -------------------------------- ### Get Number of Queued Encoder Events Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/EncoderDriver.md Retrieves the current count of events waiting in the encoder's queue. ```python event_count = encoder.get_event_count() ``` -------------------------------- ### Get Scrolling Object Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Returns the LVGL object that is currently being scrolled by the user. Returns None if no object is being scrolled. ```python scrolling_obj = touch.get_scroll_obj() ``` -------------------------------- ### Set Parameters (No-op) Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/SDLDisplay.md This method is a no-operation for the SDL display as it is not applicable to the simulation environment. ```python display.set_params(0x36, None) # No effect ``` -------------------------------- ### Get Drag Vector Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/PointerDriver.md Retrieves the velocity vector of a drag gesture. The vector is filled into the provided lv.point_t structure. ```python vect = lv.point_t() touch.get_vect(vect) print(f"Drag velocity: x={vect.x}, y={vect.y}") ``` -------------------------------- ### add_event_cb Source: https://github.com/lvgl-micropython/lvgl_micropython/blob/main/_autodocs/api-reference/TaskHandler.md Registers a callback function to be executed when specific task handler events occur (task start or task finish). ```APIDOC ## add_event_cb Registers a callback function to be executed when specific task handler events occur (task start or task finish). ### Signature ```python add_event_cb(callback, event, user_data=None) ``` ### Parameters #### Parameters - **callback** (callable) - Required - Function called with (event_type, user_data) signature. - **event** (int) - Required - Event mask: TASK_HANDLER_STARTED (0x01) or TASK_HANDLER_FINISHED (0x02). - **user_data** (any) - Optional - Data passed to the callback. If omitted, callback receives None. ### Behavior If the callback is already registered, only the event mask and user_data are updated. ### Example ```python def on_started(event_type, data): print("Task cycle started") th.add_event_cb(on_started, task_handler.TASK_HANDLER_STARTED, None) ``` ```