diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fadd402..c457943 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -16,6 +16,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 # fetch tags for versioning - name: Cache toolchain id: cache-toolchain diff --git a/Makefile b/Makefile index 326477e..7e4b902 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,15 @@ TARGET = badgemagic-ch582 OPT = -Os +####################################### +# Get current version +####################################### +VERSION = $(shell git describe --tags --dirty) +VERSION_ABBR = $(shell git describe --abbrev=0 --tags 2>/dev/null || echo "unknown") +ifeq ($(VERSION_ABBR),unknown) + $(warning Unable to determine version from git tags) +endif + ####################################### # paths ####################################### @@ -127,6 +136,7 @@ ifeq ($(USBC_VERSION), 1) CFLAGS += -DUSBC_VERSION=$(USBC_VERSION) endif +CFLAGS += -DVERSION='"$(VERSION)"' -DVERSION_ABBR='"$(VERSION_ABBR)"' # Generate dependency information CFLAGS += -MMD -MP diff --git a/src/ble/profile/devinfo.c b/src/ble/profile/devinfo.c index f29526d..f508b3d 100644 --- a/src/ble/profile/devinfo.c +++ b/src/ble/profile/devinfo.c @@ -5,17 +5,25 @@ static const uint8_t systemId_val[] = {0, 0, 0, 0, 0, 0, 0, 0}; static const uint16_t systemId_UUID = SYSTEM_ID_UUID; -static const uint8_t modelNumber_val[] = "B1144"; +#ifdef USBC_VERSION +#define USBC_VER_PREFIX "(C) " +#define USBC_VER_SUFIX "-C" +#else +#define USBC_VER_PREFIX "" +#define USBC_VER_SUFIX "" +#endif + +static const uint8_t modelNumber_val[] = "BM1144" USBC_VER_SUFIX; static const uint16_t modelNumber_UUID = MODEL_NUMBER_UUID; const uint16_t serialNumber_UUID = SERIAL_NUMBER_UUID; static const uint8_t serialNumber_val[] = "N/A"; const uint16_t firmwareRev_UUID = FIRMWARE_REV_UUID; -static const uint8_t firmwareRev_val[] = "v0.0.1"; +static const uint8_t firmwareRev_val[] = USBC_VER_PREFIX VERSION; const uint16_t hardwareRev_UUID = HARDWARE_REV_UUID; -static const uint8_t hardwareRev_val[] = "221028"; +static const uint8_t hardwareRev_val[] = "20240908"; const uint16_t softwareRev_UUID = SOFTWARE_REV_UUID; static const uint8_t softwareRev_val[] = "N/A"; diff --git a/src/main.c b/src/main.c index 7d7d48c..b531f7e 100644 --- a/src/main.c +++ b/src/main.c @@ -425,7 +425,7 @@ static void disp_charging() if (is_charging()) { disp_bat_stt(blink ? percent : 0, 2, 2); if (ani_xbm_next_frame(&fabm_xbm, fb, 16, 0) == 0) { - fb_puts("v0.1", 4, 16, 2); // TODO: get version from git tag + fb_puts(VERSION_ABBR, sizeof(VERSION_ABBR), 16, 2); fb_putchar(' ', 40, 2); } blink = !blink; diff --git a/src/usb/dev.c b/src/usb/dev.c index fb28e43..569dd25 100644 --- a/src/usb/dev.c +++ b/src/usb/dev.c @@ -53,16 +53,30 @@ static uint16_t product_info[] = { 'M', 'a', 'g', 'i', 'c' }; -// TODO: auto update firmware version by CI here static uint16_t serial_number[] = { - 47 * 2 | /* bLength */ +#ifdef USBC_VERSION + 4 + +#endif + (12 + sizeof(VERSION_ABBR) - 1) * 2 | /* bLength */ 0x03 << 8, /* bDescriptorType */ /* bString */ - 'N', 'o', 't', ' ', 'y', 'e', 't', ' ', - 'i', 'm', 'p', 'l', 'e', 'm', 'e', 'n', 't', 'e', 'd', '\n', - 'P', 'R', 'E', 'S', 'S', ' ', 'A', 'L', 'T', '+', 'F', '4', ' ', - 'T', 'O', ' ', 'C', 'O', 'N', 'T', 'I', 'N', 'U', 'E', '.' + 'B', 'M', '1', '1', '4', '4', +#ifdef USBC_VERSION + '-', 'C', +#endif + ' ', + 'f', 'w', ':',' ', + /* vX.Y */ + VERSION[0], + VERSION[1], + VERSION[2], + VERSION[3], + VERSION[4], + VERSION[5], + VERSION[6], + VERSION[7], + VERSION[8] }; static void desc_dev(USB_SETUP_REQ *request)