diff --git a/scripts/gdb/lvglgdb/__init__.py b/scripts/gdb/lvglgdb/__init__.py index a2fc81bbf6..c961be86b7 100644 --- a/scripts/gdb/lvglgdb/__init__.py +++ b/scripts/gdb/lvglgdb/__init__.py @@ -35,6 +35,7 @@ from .lvgl import ( event_code_name, EVENT_CODE_NAMES, LVAnim, + LVTimer, ) from . import cmds as cmds @@ -73,4 +74,5 @@ __all__ = [ "event_code_name", "EVENT_CODE_NAMES", "LVAnim", + "LVTimer", ] diff --git a/scripts/gdb/lvglgdb/cmds/__init__.py b/scripts/gdb/lvglgdb/cmds/__init__.py index 9fbc41bbd5..c569257ec7 100644 --- a/scripts/gdb/lvglgdb/cmds/__init__.py +++ b/scripts/gdb/lvglgdb/cmds/__init__.py @@ -9,6 +9,7 @@ from .misc import ( CheckPrefix, CheckCache, DumpAnim, + DumpTimer, ) from .debugger import Debugger from .drivers import Lvglobal @@ -32,6 +33,7 @@ DumpCache() CheckPrefix() CheckCache() DumpAnim() +DumpTimer() DumpDrawTask() # Infos diff --git a/scripts/gdb/lvglgdb/cmds/misc/__init__.py b/scripts/gdb/lvglgdb/cmds/misc/__init__.py index cf0c5441b3..1ba9fb86c8 100644 --- a/scripts/gdb/lvglgdb/cmds/misc/__init__.py +++ b/scripts/gdb/lvglgdb/cmds/misc/__init__.py @@ -1,6 +1,7 @@ from .lv_style import InfoStyle from .lv_cache import DumpCache, CheckPrefix, CheckCache from .lv_anim import DumpAnim +from .lv_timer import DumpTimer __all__ = [ "InfoStyle", @@ -8,4 +9,5 @@ __all__ = [ "CheckPrefix", "CheckCache", "DumpAnim", + "DumpTimer", ] diff --git a/scripts/gdb/lvglgdb/cmds/misc/lv_timer.py b/scripts/gdb/lvglgdb/cmds/misc/lv_timer.py new file mode 100644 index 0000000000..df7e632ea2 --- /dev/null +++ b/scripts/gdb/lvglgdb/cmds/misc/lv_timer.py @@ -0,0 +1,16 @@ +import gdb + +from lvglgdb.lvgl import curr_inst +from lvglgdb.lvgl.misc.lv_timer import LVTimer + + +class DumpTimer(gdb.Command): + """dump all active timers""" + + def __init__(self): + super(DumpTimer, self).__init__( + "dump timers", gdb.COMMAND_USER, gdb.COMPLETE_EXPRESSION + ) + + def invoke(self, args, from_tty): + LVTimer.print_entries(curr_inst().timers()) diff --git a/scripts/gdb/lvglgdb/lvgl/__init__.py b/scripts/gdb/lvglgdb/lvgl/__init__.py index abd2eaf347..5c07ec2f07 100644 --- a/scripts/gdb/lvglgdb/lvgl/__init__.py +++ b/scripts/gdb/lvglgdb/lvgl/__init__.py @@ -36,6 +36,7 @@ from .misc import ( event_code_name, EVENT_CODE_NAMES, LVAnim, + LVTimer, ) __all__ = [ @@ -78,4 +79,5 @@ __all__ = [ "event_code_name", "EVENT_CODE_NAMES", "LVAnim", + "LVTimer", ] diff --git a/scripts/gdb/lvglgdb/lvgl/core/lv_global.py b/scripts/gdb/lvglgdb/lvgl/core/lv_global.py index fe733fbe69..edf22885f7 100644 --- a/scripts/gdb/lvglgdb/lvgl/core/lv_global.py +++ b/scripts/gdb/lvglgdb/lvgl/core/lv_global.py @@ -67,6 +67,14 @@ class LVGL: for anim in LVList(self.lv_global.anim_state.anim_ll, "lv_anim_t"): yield LVAnim(anim) + def timers(self): + from ..misc.lv_timer import LVTimer + + for timer in LVList(self.lv_global.timer_state.timer_ll, "lv_timer_t"): + yield LVTimer(timer) + + + def image_header_cache(self): from ..misc.lv_image_header_cache import LVImageHeaderCache diff --git a/scripts/gdb/lvglgdb/lvgl/misc/__init__.py b/scripts/gdb/lvglgdb/lvgl/misc/__init__.py index 209f7eb744..10e2f8fd4e 100644 --- a/scripts/gdb/lvglgdb/lvgl/misc/__init__.py +++ b/scripts/gdb/lvglgdb/lvgl/misc/__init__.py @@ -24,6 +24,7 @@ from .lv_event import ( EVENT_CODE_NAMES, ) from .lv_anim import LVAnim +from .lv_timer import LVTimer __all__ = [ "LVList", @@ -53,4 +54,5 @@ __all__ = [ "event_code_name", "EVENT_CODE_NAMES", "LVAnim", + "LVTimer", ] diff --git a/scripts/gdb/lvglgdb/lvgl/misc/lv_timer.py b/scripts/gdb/lvglgdb/lvgl/misc/lv_timer.py new file mode 100644 index 0000000000..dcf7e70580 --- /dev/null +++ b/scripts/gdb/lvglgdb/lvgl/misc/lv_timer.py @@ -0,0 +1,66 @@ +from prettytable import PrettyTable + +from lvglgdb.value import Value, ValueInput + + +class LVTimer(Value): + """LVGL timer wrapper""" + + def __init__(self, timer: ValueInput): + super().__init__(Value.normalize(timer, "lv_timer_t")) + + @property + def period(self) -> int: + return int(self.super_value("period")) + + @property + def last_run(self) -> int: + return int(self.super_value("last_run")) + + @property + def timer_cb(self) -> Value: + return self.super_value("timer_cb") + + @property + def repeat_count(self) -> int: + return int(self.super_value("repeat_count")) + + @property + def paused(self) -> bool: + return bool(int(self.super_value("paused"))) + + @property + def user_data(self) -> Value: + return self.super_value("user_data") + + @property + def auto_delete(self) -> bool: + return bool(int(self.super_value("auto_delete"))) + + @staticmethod + def print_entries(timers): + """Print timers as a PrettyTable.""" + table = PrettyTable() + table.field_names = ["#", "callback", "period", "freq", "last_run", "repeat", "paused"] + table.align = "l" + + for i, timer in enumerate(timers): + cb_str = timer.timer_cb.format_string(symbols=True, address=True) + repeat = "inf" if timer.repeat_count == -1 else str(timer.repeat_count) + freq = f"{1000 / timer.period:.1f}Hz" if timer.period > 0 else "-" + table.add_row( + [ + i, + cb_str, + timer.period, + freq, + timer.last_run, + repeat, + timer.paused, + ] + ) + + if not table.rows: + print("No active timers.") + else: + print(table)