lvgl-micropython / lvgl_micropython

LVGL module for MicroPython
MIT License
73 stars 24 forks source link

ESP32 Core 1 Threading #144

Open dcmcshan opened 4 hours ago

dcmcshan commented 4 hours ago

I would like to run a thread on core 1 of ESP32S3. Here is an example for us to work with. Ideally, I'd like to be able to run the thread on core1 at 1000Hz. It will collect some high rate data, and core0 will display it.

How do I use your cleverness to get thread_core1 actually on core1?


import _thread
import time

# Shared counter variable
counter = 0

def thread_core1():
    print("Starting thread_core1")
    global counter
    while True:
        counter += 1
        time.sleep_ms(10)

def thread_core0():
    print("Starting thread_core0")
    while True:
        print(f"Counter value: {counter}")
        time.sleep(1)

# Start thread on Core 1
_thread.start_new_thread(thread_core1, ())

# Start thread on Core 0 (main core)
_thread.start_new_thread(thread_core0, ())
kdschlosser commented 2 hours ago

Well..... already built into the binding is the ability to turn on multi core threading. However you will not get to decide what gets run on what core. All threads run on core 1 and the main loop runs on core 0. It has not been tested and the GIL gets disabled in order for it to work. There is more development I need to do to expose being able to send notifications and adding different lock types and waits that don't have a spinning wheels. Things like that. I will mess about with it this evening to see what I can do with it.