// Steuersoftware für (eine!) chinesische RGB-Leuchtdiode WS2812
// am ATtiny10 (oder ATtiny9) mit der auf < 1 KByte geschrumpften
// V-USB-Firmware von Tim Böschke.
// Henrik Haftmann, 171214, Freeware.
// Dies ist für libusb-0.1! Nicht libusb-1.0!
// libusb-0.1 und libusb-1.0 sind nicht kompatibel,
// ungefähr so kompatibel wie Blaubeeren und Braunbären.
// Dieser Quelltext ist für MSVC6 und meine msvcrt-light.lib erstellt.
// Die Bindung der ATtiny10-Schaltung an libusb-0.1 erfolgt
// am sichersten mit "inf-wizard.exe" aus dem Download-Paket
// "libusb-win32-bin-1.2.6.0.zip".
// Die dort enthaltenen Treiber sind zertifiziert.
// Mit libusb-1.0 habe ich's partout nie zum Laufen bekommen,
// für diese Erkenntnis 3 Tage benötigt;
// mit "libusb-win32-xx" war's hingegen ganz einfach,
// allerdings ohne gefundene Dokumentation.
// Dass es bei 0.1 eine naheliegende Funktion
// usb_open_by_hid_vid() nicht gibt, ist verschmerzbar.
// HID ist in die 1 KByte Flash des ATtiny10 nur schwer hineinzubekommen,
// ich werde mich mal damit beschäftigen …
#include "lusb0_usb.h"
#include <stdio.h>
#include <shlwapi.h>
// Find and open the first ATtiny10 with WS2812 firmware
static usb_dev_handle *my_open() {
struct usb_bus *bus;
struct usb_device *dev;
for (bus = usb_get_busses(); bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
if (dev->descriptor.idVendor == 0x1781
&& dev->descriptor.idProduct == 0x0C9F) return usb_open(dev);
}
}
return NULL;
}
// Main program avoiding run-time library code inclusion
EXTERN_C void mainCRTStartup() {
usb_init(); // initialize the library
usb_find_busses(); // find all busses
usb_find_devices(); // find all connected devices
int color; // RGB value from command line
TCHAR s[10];
s[0]='0'; // StrToIntEx() needs this prefix
s[1]='x';
TCHAR*p=PathGetArgs(GetCommandLine());
if (!*p) {
printf("Usage: Hexadecimal RGB value as single argument\n");
ExitProcess(0);
}
if (*p=='#') p++; // Ignore HTML-style '#' prefix (for ease typing)
lstrcpyn(s+2,p,8);
StrToIntEx(s,STIF_SUPPORT_HEX,&color);
usb_dev_handle*dev=my_open();
if (!dev) {
printf("error opening device: \n%s\n", usb_strerror());
}else{
#if 0
if (usb_set_configuration(dev,1) < 0)
{
printf("error setting config: %s\n", usb_strerror());
goto done;
}
else
{
printf("success: set configuration\n");
}
if (usb_claim_interface(dev,0) < 0)
{
printf("error claiming interface:\n%s\n", usb_strerror());
goto done;
}
else
{
printf("success: claim_interface\n");
}
#endif
usb_control_msg(dev,USB_TYPE_VENDOR,42,
color&0xFF00, // wValue: High byte = green
color>>16&0xFF|color<<8&0xFF00, // wIndex: Low byte = red, High byte = blue
NULL,0,1000); // = WS2812 order GRB, see ~heha/Mikrocontroller/LEDs#4.
usb_release_interface(dev, 0);
}
//done:
usb_close(dev);
ExitProcess(0);
}
| Detected encoding: ANSI (CP1252) | 4
|
|
|