diff --git a/_audioif.c b/_audioif.c index cca98b2..f131c08 100644 --- a/_audioif.c +++ b/_audioif.c @@ -37,6 +37,7 @@ #include "py/mperrno.h" #include "py/mphal.h" #include "py/obj.h" +#include "py/objstr.h" #include "py/runtime.h" #include "audiocore/__init__.h" @@ -1760,8 +1761,18 @@ static MP_DEFINE_CONST_FUN_OBJ_0(audiopump_lock_probe_obj, #endif + +// _audioif.__revision__: which audioif this firmware was built from. The build +// passes AUDIOIF_REVISION (git describe) as a compile definition; a build with no +// git says "unknown" rather than guessing. +#ifndef AUDIOIF_REVISION +#define AUDIOIF_REVISION "unknown" +#endif +static const MP_DEFINE_STR_OBJ(_audioif_revision_obj, AUDIOIF_REVISION); + static const mp_rom_map_elem_t audioif_driver_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__audioif) }, + { MP_ROM_QSTR(MP_QSTR___revision__), MP_ROM_PTR(&_audioif_revision_obj) }, // What this driver says it is. audiopump.driver() asks the ENGINE the same // question, through the binding; the two agreeing is the proof the // binding took. diff --git a/micropython.cmake b/micropython.cmake index 49676ad..dd267a7 100644 --- a/micropython.cmake +++ b/micropython.cmake @@ -56,3 +56,16 @@ target_include_directories(usermod_audiopump INTERFACE target_compile_definitions(usermod_audiopump INTERFACE AUDIOIF_DRIVER_ESP32=1) target_link_libraries(usermod INTERFACE usermod_audiopump) + +# --- which audioif this firmware was built from ---------------------- +# Computed at build time from this repo's own git, never stored; "unknown" when +# there is no git (a tarball). Read on a target as .__revision__. +execute_process( + COMMAND git -C ${AUDIOPUMP_MOD_DIR} describe --always --dirty --abbrev=7 + OUTPUT_VARIABLE AUDIOIF_REVISION + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET) +if(NOT AUDIOIF_REVISION) + set(AUDIOIF_REVISION "unknown") +endif() +target_compile_definitions(usermod_audiopump INTERFACE AUDIOIF_REVISION=\"${AUDIOIF_REVISION}\") diff --git a/micropython.mk b/micropython.mk index c36230d..7d14d88 100644 --- a/micropython.mk +++ b/micropython.mk @@ -13,3 +13,9 @@ AUDIODSP_DIR ?= $(abspath $(AUDIOPUMP_MOD_DIR)/../audiodsp) CFLAGS_USERMOD += -I$(AUDIODSP_DIR)/src SRC_USERMOD_C += $(AUDIOPUMP_MOD_DIR)/_audioif.c SRC_USERMOD_C += $(AUDIOPUMP_MOD_DIR)/audiobusio.c + +# --- which audioif this firmware was built from ---------------------- +# Computed at build time from this repo's own git, never stored; "unknown" when +# there is no git (a tarball). Read on a target as .__revision__. +AUDIOIF_REVISION := $(shell git -C $(AUDIOPUMP_MOD_DIR) describe --always --dirty --abbrev=7 2>/dev/null || echo unknown) +CFLAGS_USERMOD += -DAUDIOIF_REVISION='"$(AUDIOIF_REVISION)"'