diff options
author | zhiayang <[email protected]> | 2024-03-30 19:12:37 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2024-03-30 19:12:37 -0400 |
commit | 4bef4e98f52c3ea57630a3cd1e0e2d078d67758b (patch) | |
tree | d40bd0af55ed6c9b959c87e3e38353a4e35a03d2 | |
parent | fff1cbecdcc75302b6280a469ed31687cfc79776 (diff) | |
download | zmk-4bef4e98f52c3ea57630a3cd1e0e2d078d67758b.tar.gz zmk-4bef4e98f52c3ea57630a3cd1e0e2d078d67758b.zip |
feat(boards): Support board revisions in setup scripts.
* Make setup.sh/ps1 prompt for board revision for boards that have revisions
-rw-r--r-- | docs/src/templates/setup.ps1.mustache | 29 | ||||
-rw-r--r-- | docs/src/templates/setup.sh.mustache | 35 | ||||
-rw-r--r-- | schema/hardware-metadata.schema.json | 15 |
3 files changed, 78 insertions, 1 deletions
diff --git a/docs/src/templates/setup.ps1.mustache b/docs/src/templates/setup.ps1.mustache index 90f9cdcfae..b8ecc2937f 100644 --- a/docs/src/templates/setup.ps1.mustache +++ b/docs/src/templates/setup.ps1.mustache @@ -131,6 +131,19 @@ if ($keyboard_type -eq "shield") { {{/boards}} } + $boards_revisions = [ordered]@{ + {{#boards}} + {{id}} = @({{#revisions}} + "{{.}}"{{/revisions}}); + {{/boards}} + } + + $boards_default_revision=[ordered]@{ + {{#boards}} + {{id}} = "{{{default_revision}}}"; + {{/boards}} + } + Write-Host "$title" Write-Host "" Write-Host "MCU Board Selection:" @@ -145,6 +158,22 @@ if ($keyboard_type -eq "shield") { $shields = $keyboard_siblings $board = $($($boards.keys)[$choice]) $boards = ( $board ) + + if ($($($boards_revisions.values)[$choice]).count -gt 0) { + $valid_revisions = $($($boards_revisions.values)[$choice]) + $revision_choices = @() + $valid_revisions + + for ($i = 0; $i -lt $valid_revisions.count; $i += 1) { + if ($valid_revisions[$i] -eq $($($boards_default_revision.values)[$choice])) { + $revision_choices[$i] += " (default)" + } + } + + $revision_choice = Get-Choice-From-Options -Options $revision_choices -Prompt $prompt + $board = $board + "@" + $valid_revisions[$revision_choice] + $boards = ( $board ) + } + } else { $boards = ( $keyboard_siblings ) $shields = @( ) diff --git a/docs/src/templates/setup.sh.mustache b/docs/src/templates/setup.sh.mustache index c711dbc5b1..dd7a7a2d2f 100644 --- a/docs/src/templates/setup.sh.mustache +++ b/docs/src/templates/setup.sh.mustache @@ -122,6 +122,9 @@ if [ "$keyboard_shield" == "y" ]; then board_ids=({{#boards}}"{{id}}" {{/boards}}) boards_usb_only=({{#boards}}"{{#usb_only}}y{{/usb_only}}{{^usb_only}}n{{/usb_only}}" {{/boards}}) + boards_revisions=({{#boards}}"{{#revisions}}{{.}} {{/revisions}}" {{/boards}}) + boards_default_revision=({{#boards}}"{{{default_revision}}}" {{/boards}}) + echo "" echo "MCU Board Selection:" PS3="$prompt " @@ -151,6 +154,38 @@ if [ "$keyboard_shield" == "y" ]; then esac done + + if [ -n "${boards_revisions[$board_index]}" ]; then + read -a _valid_revisions <<< "${boards_revisions[$board_index]}" + + _rev_choices=("${_valid_revisions[@]}") + for (( _i=0; _i<${#_valid_revisions}; _i++ )); do + if [ "${boards_default_revision[board_index]}" = "${_valid_revisions[_i]}" ]; then + _rev_choices[_i]+=" (default)" + fi + done + + echo "" + echo "MCU Board Revision:" + select opt in "${_rev_choices[@]}" "Quit"; do + case "$REPLY" in + ''|*[!0-9]*) echo "Invalid option. Try another one."; continue;; + + $(( ${#_valid_revisions[@]}+1 )) ) echo "Goodbye!"; exit 1;; + *) + if [ $REPLY -gt $(( ${#_valid_revisions[@]}+1 )) ] || [ $REPLY -lt 0 ]; then + echo "Invalid option. Try another one." + continue + fi + + _rev_index=$(( $REPLY-1 )) + board="${board_ids[$board_index]}@${_valid_revisions[_rev_index]}" + boards=( "${board}" ) + break + ;; + esac + done + fi else board=${keyboard} boards=$keyboard_siblings diff --git a/schema/hardware-metadata.schema.json b/schema/hardware-metadata.schema.json index 4c2bdf3b73..9710c79239 100644 --- a/schema/hardware-metadata.schema.json +++ b/schema/hardware-metadata.schema.json @@ -16,7 +16,11 @@ "$defs": { "id": { "type": "string", - "pattern": "^[a-z0-9_]+$" + "pattern": "^[a-z0-9_]+(@([A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})))?$" + }, + "revision": { + "type": "string", + "pattern": "[A-Z]|[0-9]+|([0-9]+(\\.[0-9]+){1,2})" }, "keyboard_siblings": { "type": "array", @@ -202,6 +206,15 @@ }, "exposes": { "$ref": "#/$defs/interconnects" + }, + "revisions": { + "type": "array", + "items": { + "$ref": "#/$defs/revision" + } + }, + "default_revision": { + "$ref": "#/$defs/revision" } } }, |