Skip to content

Instantly share code, notes, and snippets.

@ArcaneNibble
Created July 18, 2022 03:42
Show Gist options
  • Save ArcaneNibble/d3cb6270345f5c6fd135c40b800141ea to your computer and use it in GitHub Desktop.
Save ArcaneNibble/d3cb6270345f5c6fd135c40b800141ea to your computer and use it in GitHub Desktop.
import struct
import time
import usb
dev = usb.core.find(idVendor=0x32f8, idProduct=0x424c)
# print(dev)
dev.set_configuration()
serno = usb.util.get_string(dev, dev.iSerialNumber)
print(f"Found T5 device {serno}")
with open('t5-firmware.bin', 'rb') as f:
firmware = f.read()
def get_thing_1():
return bytes(dev.ctrl_transfer(0xa1, 1, 0, 0, 8))
def get_thing_2():
return bytes(dev.ctrl_transfer(0xa1, 2, 0, 0, 16))
assert get_thing_1() == b'\x06\x00\x03\x00\x00\x00\x00\x00'
assert get_thing_2() == b'\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
fwlen = struct.pack("<II", len(firmware), 0)
# print(fwlen)
dev.ctrl_transfer(0x21, 2, 0, 0, fwlen)
assert get_thing_1() == b'\x06\x00\x03\x00\x00\x00\x00\x00'
assert get_thing_2() == b'\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00'
bytes_sent = dev.write(1, firmware)
print(f"Sent {bytes_sent} bytes")
assert bytes_sent == len(firmware)
while True:
assert get_thing_1() == b'\x06\x00\x03\x00\x00\x00\x00\x00'
thing2 = get_thing_2()
print(thing2)
assert thing2 == b'\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' or thing2 == b'\x00\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00'
if thing2 == b'\x00\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00':
break
time.sleep(1)
dev.ctrl_transfer(0x21, 3, 0, 0, b'')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment