Last active
January 23, 2017 00:44
-
-
Save C47D/d8c54041abcf29b5f1911c481bea3e93 to your computer and use it in GitHub Desktop.
Basic python scripts to send USB Vendor Commands to PSoC5LP, based on Cypress AN56377
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
#!/usr/bin/env python3 | |
''' | |
Basic script to send USB Vendor Commands to PSoC5LP | |
Based on Cypress AN56377 | |
VID = 0x04B4 | |
PID = 0xE176 | |
Direction = OUT | |
ReqType = Vendor | |
Target = Device | |
Request Codes: | |
0xA1 = Turn onboard LED on | |
0xB1 = Turn onboard LED off | |
0xA2 = TODO, read data | |
0xB2 = TODO, send data | |
''' | |
import usb | |
import sys | |
from sys import platform as _platform | |
import time | |
VID = 0x04B4 | |
PID = 0xE176 | |
dev = usb.core.find(idVendor = VID, idProduct = PID) | |
if not dev: | |
print("No se encontro el PSoC") | |
exit(1) | |
print("PSoC encontrado") | |
if _platform == "linux" or _platform == "linux2": | |
if dev.is_kernel_driver_active(0): | |
dev.detach_kernel_driver(0) | |
for i in range(10): | |
# dev.ctrl_transfer(bmRequestType, bmRequest, wValue, wIndex, data) | |
# Prendemos el LED | |
dev.ctrl_transfer(0x40 , 0xA1, 0, 0, []) | |
# Esperamos | |
time.sleep(0.5) | |
# Apagamos el LED | |
dev.ctrl_transfer(0x40 , 0xB1, 0, 0, []) | |
time.sleep(0.5) | |
print("Adios!") | |
exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment