Where to put hardware-related code so I don't interfere with the GUI code

Description

General Information Question: Where do I put my hardware code? I am working on a project where I need to have the GUI respond to hardware changes in a circuit. Do I simply put it in sleepWithLvHandler() or do I need a separate thread to manage the hardware?

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

STM32F407VET6 “black” board and the gnu compiler.

What do you want to achieve?

I want the GUI to be responsive but I need it to respond to hardware signals (e.g. a button, or a rising edge on a pin).

What have you tried so far?

Nothing yet, because I felt this was a simple question that someone who as done this before could tell me rather than me putting the code in the wrong place and then not being able to debug the GUI code.

I’m still learning my way around LittlevGL, so I was hoping a simple answer would allow me to continue rather than putting the code in the wrong place and then causing problems with the GUI code. I’m new to running a GUI on a microcontroller. Eventually, I will be building a custom board and porting both LittlevGL and MBedOS over to it, but for now I’m using a “black” board for prototyping.

Code to reproduce

None yet.

Screenshot and/or video

None yet.

With Mbed, you have threads and preemptive multitasking. There you can do IO stuff and access the data from the GUI thread or use inter process communication like queues. You must not call lv functions from other threads, or at least you have to put mutex guards to protect from interrupting.
For slower polling functions you can use also the lv tasks, but that is cooperative multitasking and functions must not block for a responsive GUI.

OK. That should be simple enough. I was hoping that would be the answer. Thanks!