Skip to content

Instantly share code, notes, and snippets.

@a-type
Last active May 20, 2016 16:31
Show Gist options
  • Save a-type/1f4675e3a0e848aabc8e5a9d73ea6364 to your computer and use it in GitHub Desktop.
Save a-type/1f4675e3a0e848aabc8e5a9d73ea6364 to your computer and use it in GitHub Desktop.
Recover AR1100 Resistive Touchscreen Controller
#!/usr/bin/python
import usb.core
import usb.util
# TURN_INTO = "GENERIC"
TURN_INTO = "MOUSE"
USB_MODE_GENERIC = [0x55, 0x01, 0x70]
USB_MODE_MOUSE = [0x55, 0x01, 0x71]
MCP_VID = 0x04D8
GENERIC_PID = 0x0C01
MOUSE_PID = 0x0C02
DIGITIZER_PID = 0x0C03
# Try to locate it as each type:
print "Searching for digitizer..."
dev = usb.core.find(idVendor=MCP_VID, idProduct=DIGITIZER_PID)
if dev:
print "Found Digitizer"
if not dev:
print "Searching for mouse..."
dev = usb.core.find(idVendor=MCP_VID, idProduct=MOUSE_PID)
if dev:
print "Found Mouse"
if TURN_INTO == "MOUSE":
print "Verified!"
exit(0)
if not dev:
print "Searching for generic..."
dev = usb.core.find(idVendor=MCP_VID, idProduct=GENERIC_PID)
if dev:
print "Found Generic"
if TURN_INTO == "GENERIC":
print "Verified!"
exit(0)
if dev:
# first endpoint
interface = 0
endpoint = dev[0][(0,0)][0]
# if the OS kernel already claimed the device, which is most likely true
# thanks to http://stackoverflow.com/questions/8218683/pyusb-cannot-set-configuration
if dev.is_kernel_driver_active(interface) is True:
print "Detaching from kernel"
# tell the kernel to detach
dev.detach_kernel_driver(interface)
# claim the device
usb.util.claim_interface(dev, interface)
# try to send it command to swap to generic HID
try:
print "Turning into " + TURN_INTO
if TURN_INTO == "GENERIC":
# turn into HID
# bReq, wVal, wIndex, data
ret = dev.ctrl_transfer(0x21, 0x09, 0x0003, 0x0000, USB_MODE_GENERIC)
if (ret == 3):
print "Turned into HID!"
else:
print "Failed!"
print ret
elif TURN_INTO == "MOUSE":
# turn into mouse
# bReq, wVal, wIndex, data
ret = dev.ctrl_transfer(0x21, 0x09, 0x0003, 0x0000, USB_MODE_MOUSE)
if (ret == 3):
print "Turned into Mouse!"
else:
print "Failed!"
print ret
except:
# failed to get data for this request
print "Failed to turn into " + TURN_INTO
exit(-1)
# Try to locate it as the desired device mode
if TURN_INTO == "GENERIC":
dev = usb.core.find(idVendor=MCP_VID, idProduct=GENERIC_PID)
elif TURN_INTO == "MOUSE":
dev = usb.core.find(idVendor=MCP_VID, idProduct=MOUSE_PID)
if (not dev):
print "Couldn't find the device as expected... something went wrong"
else:
print "Verified!"
# release the device
usb.util.release_interface(dev, interface)
# reattach the device to the OS kernel
dev.attach_kernel_driver(interface)
@a-type
Copy link
Author

a-type commented May 9, 2016

The Adafruit AR1100 touchscreen controller can be put into a bad state by configuring it as a digitizer on Windows. Here's a script which may be able to recover it by reconfiguring it as a mouse or generic HID controller on a Linux machine. After recovering the device, hopefully you can reconnect it to the configuration software in Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment