Last active
August 4, 2022 17:33
-
-
Save agners/299639de3c5cfd97ba01db409c03b5b6 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# Author: Stefan Agner | |
import os | |
import sys | |
import time | |
import usb | |
BITMODE_CBUS = 0x20 | |
SIO_SET_BITMODE_REQUEST = 0x0b | |
# FTDIs CBUS bitmode expect the following value: | |
# CBUS Bits | |
# 3210 3210 | |
# |------ Output Control 0->LO, 1->HI | |
# |----------- Input/Output 0->Input, 1->Output | |
# PyUSB control endpoint communication, see also: | |
# https://github.com/pyusb/pyusb/blob/master/docs/tutorial.rst | |
def ftdi_set_bitmode(dev, bitmask): | |
bmRequestType = usb.util.build_request_type(usb.util.CTRL_OUT, | |
usb.util.CTRL_TYPE_VENDOR, | |
usb.util.CTRL_RECIPIENT_DEVICE) | |
wValue = bitmask | (BITMODE_CBUS << 8) | |
dev.ctrl_transfer(bmRequestType, SIO_SET_BITMODE_REQUEST, wValue) | |
def main(): | |
"""Main program""" | |
dev = usb.core.find(custom_match = \ | |
lambda d: \ | |
d.idVendor==0x0403 and | |
d.idProduct==0x6001 and | |
d.serial_number=="A10XXXXX") | |
# Set CBUS2/3 high... | |
ftdi_set_bitmode(dev, 0xCC) | |
time.sleep(1) | |
# Set CBUS2/3 low... | |
ftdi_set_bitmode(dev, 0xC0) | |
# Set CBUS2/3 back to tristate | |
ftdi_set_bitmode(dev, 0x00) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, oh well 🤷♂️ Thanks for posting it here.