From 67e906bb19dd62ce37ed76b0be64e26f3c23bcb8 Mon Sep 17 00:00:00 2001 From: Luxferre Date: Tue, 23 Dec 2025 22:02:44 +0200 Subject: [PATCH] added cpu_f --- README.md | 1 + deck/hwinfo.py | 9 ++++++++- tdeckboot.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1db5ad9..e0315a9 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ Exports the following functions: - `board_id()`: get the board ID (e.g. `lilygo_tdeck` for T-Deck/T-Deck Plus), or `emulated` if it's not run on a CircuitPython device - `battery_v()`: (T-Deck-specific) get the current battery voltage (or 0 if running in an emulated environment) +- `cpu_f()`: CPU frequency in Hertz Also, this module exposes the `REAL_HW` variable to detect whether the code is running on a real hardware in the CircuitPython environment. diff --git a/deck/hwinfo.py b/deck/hwinfo.py index 1eec80d..87072f9 100644 --- a/deck/hwinfo.py +++ b/deck/hwinfo.py @@ -2,7 +2,7 @@ REAL_HW = False try: - import board, analogio + import board, analogio, microcontroller vbat_analog = analogio.AnalogIn(board.BAT_ADC) REAL_HW = True except: @@ -19,5 +19,12 @@ def board_id(): def battery_v(): if REAL_HW: return (vbat_analog.value * 3.3) / 65535 * 2 + else: + return 0.0 + +# get CPU frequency +def cpu_f(): + if REAL_HW: + return microcontroller.cpu.frequency else: return 0 diff --git a/tdeckboot.py b/tdeckboot.py index d690894..4376ada 100644 --- a/tdeckboot.py +++ b/tdeckboot.py @@ -8,7 +8,7 @@ from deck.fs import du, df, sep, pwd, ls, md, cd, rd, rm, mv, cp, sync from deck.input import input, input_multi from deck.pager import print_paged, term_size from deck.time import * -from deck.hwinfo import board_id, battery_v, REAL_HW +from deck.hwinfo import board_id, battery_v, cpu_f, REAL_HW from deck.http import wget, http_fetch, http_set_ua from app.ed import edit, view try: