<commit_before>#!/usr/bin/env bash

TARGET_DEF_FILE=$1
SW_VERSION_MAJOR=$2
SW_VERSION_MINOR=$3
SW_VERSION_REVISION=$4
YAML_PARSER="dasel -n -p yaml --plain -f"
TARGET_NAME=$(basename "$TARGET_DEF_FILE" .yml)
GEN_DIR=board/gen/"$(basename "$TARGET_DEF_FILE" .yml)"

rm -rf "$GEN_DIR"
mkdir -p "$GEN_DIR"

OUT_FILE_HEADER_USB="$GEN_DIR"/USBnames.h
OUT_FILE_HEADER_PINS="$GEN_DIR"/Pins.h
OUT_FILE_SOURCE_PINS="$GEN_DIR"/Pins.cpp
OUT_FILE_MAKEFILE_DEFINES="$GEN_DIR"/Defines.mk

#################################################### CORE ####################################################

arch=$($YAML_PARSER "$TARGET_DEF_FILE" arch)
mcu_family=$($YAML_PARSER "$TARGET_DEF_FILE" mcuFamily)
mcu=$($YAML_PARSER "$TARGET_DEF_FILE" mcu)

{
    printf "%s\n" "MCU_FAMILY := $mcu_family"
    #base mcu without the variant-specific letters at the end
    printf "%s\n" "MCU_BASE := $(echo "$mcu" | rev | cut -c3- | rev)"
    printf "%s\n" "MCU_DIR := board/$arch/variants/$mcu_family/$mcu"
    printf "%s\n" "DEFINES += FW_UID=$(../scripts/fw_uid_gen.sh "$TARGET_NAME")"
} >> "$OUT_FILE_MAKEFILE_DEFINES"

if [[ -f board/$arch/variants/$mcu_family/$mcu/fuses.txt ]]
then
    {
        printf "%s\n" "FUSE_UNLOCK := $(grep ^unlock= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_EXT := $(grep ^ext= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_HIGH := $(grep ^high= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_LOW := $(grep ^low= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_LOCK := $(grep ^lock= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
    } >> "$OUT_FILE_MAKEFILE_DEFINES"
fi

hse_val=$($YAML_PARSER "$TARGET_DEF_FILE" extClockMhz)

if [[ $hse_val != "null" ]]
then
    printf "%s%s\n" "DEFINES += HSE_VALUE=$hse_val" "000000" >> "$OUT_FILE_MAKEFILE_DEFINES"
fi

printf "%s\n" "DEFINES += OD_BOARD=\\\"$TARGET_NAME\\\"" >> "$OUT_FILE_MAKEFILE_DEFINES"

########################################################################################################

{
    printf "%s\n\n" "#include \"core/src/general/IO.h\""
} >> "$OUT_FILE_HEADER_PINS"

#################################################### PERIPHERALS ####################################################

if [[ $($YAML_PARSER "$TARGET_DEF_FILE" usb) == "true" ]]
then
    printf "%s\n" "DEFINES += USB_MIDI_SUPPORTED" >> "$OUT_FILE_MAKEFILE_DEFINES"

    {
        printf "%s\n" "#if defined(FW_APP)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck | $TARGET_NAME\")"
        printf "%s\n" "#elif defined(FW_BOOT)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck DFU v$SW_VERSION_MAJOR.$SW_VERSION_MINOR.$SW_VERSION_REVISION | $TARGET_NAME\")"
        printf "%s\n" "#elif defined(FW_CDC)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck CDC | $TARGET_NAME\")"<commit_msg>build: remove firmware version from dfu usb name<commit_after>#!/usr/bin/env bash

TARGET_DEF_FILE=$1
SW_VERSION_MAJOR=$2
SW_VERSION_MINOR=$3
SW_VERSION_REVISION=$4
YAML_PARSER="dasel -n -p yaml --plain -f"
TARGET_NAME=$(basename "$TARGET_DEF_FILE" .yml)
GEN_DIR=board/gen/"$(basename "$TARGET_DEF_FILE" .yml)"

rm -rf "$GEN_DIR"
mkdir -p "$GEN_DIR"

OUT_FILE_HEADER_USB="$GEN_DIR"/USBnames.h
OUT_FILE_HEADER_PINS="$GEN_DIR"/Pins.h
OUT_FILE_SOURCE_PINS="$GEN_DIR"/Pins.cpp
OUT_FILE_MAKEFILE_DEFINES="$GEN_DIR"/Defines.mk

#################################################### CORE ####################################################

arch=$($YAML_PARSER "$TARGET_DEF_FILE" arch)
mcu_family=$($YAML_PARSER "$TARGET_DEF_FILE" mcuFamily)
mcu=$($YAML_PARSER "$TARGET_DEF_FILE" mcu)

{
    printf "%s\n" "MCU_FAMILY := $mcu_family"
    #base mcu without the variant-specific letters at the end
    printf "%s\n" "MCU_BASE := $(echo "$mcu" | rev | cut -c3- | rev)"
    printf "%s\n" "MCU_DIR := board/$arch/variants/$mcu_family/$mcu"
    printf "%s\n" "DEFINES += FW_UID=$(../scripts/fw_uid_gen.sh "$TARGET_NAME")"
} >> "$OUT_FILE_MAKEFILE_DEFINES"

if [[ -f board/$arch/variants/$mcu_family/$mcu/fuses.txt ]]
then
    {
        printf "%s\n" "FUSE_UNLOCK := $(grep ^unlock= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_EXT := $(grep ^ext= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_HIGH := $(grep ^high= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_LOW := $(grep ^low= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
        printf "%s\n" "FUSE_LOCK := $(grep ^lock= < board/"$arch"/variants/"$mcu_family"/"$mcu"/fuses.txt | cut -d= -f2)"
    } >> "$OUT_FILE_MAKEFILE_DEFINES"
fi

hse_val=$($YAML_PARSER "$TARGET_DEF_FILE" extClockMhz)

if [[ $hse_val != "null" ]]
then
    printf "%s%s\n" "DEFINES += HSE_VALUE=$hse_val" "000000" >> "$OUT_FILE_MAKEFILE_DEFINES"
fi

printf "%s\n" "DEFINES += OD_BOARD=\\\"$TARGET_NAME\\\"" >> "$OUT_FILE_MAKEFILE_DEFINES"

########################################################################################################

{
    printf "%s\n\n" "#include \"core/src/general/IO.h\""
} >> "$OUT_FILE_HEADER_PINS"

#################################################### PERIPHERALS ####################################################

if [[ $($YAML_PARSER "$TARGET_DEF_FILE" usb) == "true" ]]
then
    printf "%s\n" "DEFINES += USB_MIDI_SUPPORTED" >> "$OUT_FILE_MAKEFILE_DEFINES"

    {
        printf "%s\n" "#if defined(FW_APP)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck | $TARGET_NAME\")"
        printf "%s\n" "#elif defined(FW_BOOT)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck DFU | $TARGET_NAME\")"
        printf "%s\n" "#elif defined(FW_CDC)"
        printf "%s\n" "#define USB_PRODUCT UNICODE_STRING(\"OpenDeck CDC | $TARGET_NAME\")"
{'fraction_non_alphanumeric': 0.2823179791976226, 'fraction_numerical': 0.005283143470364867, 'mean_word_length': 4.89873417721519, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7109363', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2307, 'n_words': 385}