Created
November 2, 2026 12:56
-
-
Save EmbeddedAndroid/b661004e8def1f33a80d0848bf035817 to your computer and use it in GitHub Desktop.
narrow-alpaca-edl.sh: find which Alpaca TTL bits must be high alongside bit 5 low for EDL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Bit 5 low alone did not give EDL, but bit 5 low with bits 0,3,4,6,7 high did. | |
| # Find which of those must be high: drop one at a time (bit 5 stays low). | |
| # Usage: narrow-alpaca-edl.sh <alpaca tty> <edl serial> | |
| set -u | |
| tty=${1:?alpaca tty}; want=${2:?edl serial}; wait_s=${WAIT_S:-5} | |
| others="0 3 4 6 7" | |
| stty -F "$tty" 115200 raw -echo cs8 clocal cread || exit 1 | |
| cmd() { printf '%s\r' "$*" > "$tty"; sleep 0.3; } | |
| edl() { for d in /sys/bus/usb/devices/*; do [ -r "$d/idVendor" ] || continue | |
| [ "$(cat $d/idVendor)" = 05c6 ] && [ "$(cat $d/idProduct)" = 9008 ] || continue | |
| grep -qi "$want" "$d/serial" "$d/product" 2>/dev/null && return 0; done; return 1; } | |
| run() { # $1 = bits to set high (bit 5 always low) | |
| cmd devicePower 0; sleep 2 | |
| for b in $others 5; do cmd ttl outputBit $b 0; done | |
| for b in $1; do cmd ttl outputBit $b 1; done | |
| cmd devicePower 1; sleep "$wait_s" | |
| if edl; then r=EDL; else r=no; fi | |
| cmd devicePower 0; sleep 1 | |
| echo "$r" | |
| } | |
| cmd usbDevicePower 1 | |
| echo "all of [$others] high, 5 low: $(run "$others")" | |
| need= | |
| for o in $others; do | |
| set_=$(echo $others | tr ' ' '\n' | grep -vx "$o" | tr '\n' ' ') | |
| r=$(run "$set_"); echo "without $o high: $r" | |
| [ "$r" = no ] && need="$need $o" | |
| done | |
| echo "only [${need# }] high, 5 low: $(run "$need")" | |
| for b in $others 5; do cmd ttl outputBit $b 0; done | |
| cmd devicePower 0 | |
| echo "RESULT: EDL needs bit(s) [${need# }] high and bit 5 low" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment