Manage a homemade USB-HID LED using a .NET GUI shell
Such a thing, assembled from a small number of parts, can be useful for modding or just for backlighting the keyboard.
To connect to a USB, use Atmel's AtTiny45 microcontroller. This microcontroller does not have a hardware USB interface, so it is implemented programmatically using the V-USB library from Objective Development. Also, this octopus cockroach has a built-in PLL (PLL), which allows you to get rid of quartz and strapping, and free so many legs, and most importantly tune the clock frequency of ~ 16.5 MHz required for USB. Also, the PLL allows you to tune this frequency, if necessary, using the same USB cycles. What, in fact, is done when you first connect the device. After that, the value of the adjustment is stored in the EEPROM memory, and the next time it is connected, it is unloaded from it. Next comes the USB software stack, so the microcontroller doesn’t have much resources left. Tiny45 is easily flashed with any in-circuit programmer, I used USBasp.
')
Since I am a lazy creature, I didn’t want to plant the scarf myself, so it was acquired on the website microsin.ru/content/view/655/44 , there is also a connection scheme, as well as the V-USB library translated into Russian and a description of how to work with it microsin.ru/content/view/613/44 .
Using the example of the V-USB library from the \ examples \ hid-custom-rq \ folder, screwing the PLL \ libs-device \, compiled it under AtTiny45. I asked. Checked using the command line. Works. To work, you need to install the libusb library sourceforge.net/projects/libusb-win32/files , in theory, you can not install it, but simply put the libusb0.dll file in the directory next to the program of its calling function. But it did not work for me.
The command line is nice, but not practical. I decided to correct and rebuild the example from \ examples \ hid-custom-rq \ commandline \ into the DLL and tie the GUI shell to it.
At first I built a DLL using the MinGW compiler and the manual from here www.adp-gmbh.ch/win/misc/mingw/dll.html , I had to sweat that everything would compile with the library libusb-win32. Inside the DLLs, there are two functions: void led_set( int isOn ){ ... } int led_get( void ){ ... } * This source code was highlighted with Source Code Highlighter .
void led_set( int isOn ){ ... } int led_get( void ){ ... } * This source code was highlighted with Source Code Highlighter .
Then I wrote a small C # program that calls this DLL from under the command line using the www.adp-gmbh.ch/csharp/call_dll.html manual. On XP, everything worked almost immediately, the only thing that .NET under win7'64 does not want to communicate with my DLL, did not check the rest of the OS. The resulting command line program code is: using System.Runtime.InteropServices; using System;
class call_led { [DllImport( "led.dll" )] private static extern int led_get(); [DllImport( "led.dll" )] private static extern void led_set( int isOn );
public static void Main() { led_set(0); Console .WriteLine( "led is {0}" , led_get()); } } * This source code was highlighted with Source Code Highlighter .
using System.Runtime.InteropServices; using System;
class call_led { [DllImport( "led.dll" )] private static extern int led_get(); [DllImport( "led.dll" )] private static extern void led_set( int isOn );
public static void Main() { led_set(0); Console .WriteLine( "led is {0}" , led_get()); } } * This source code was highlighted with Source Code Highlighter .
I put Microsoft Visual C # 2008 Express Edition and, on the basis of the simplest project, Windows FormsApplication created a small program with only one ChekBox, which turns the LED on and off. It also checks whether the device is connected every 300ms and in what condition.
This is my first C # program, so I didn’t implement any classes, and in the forehead I called functions from dll's. Actually the video of the resulting device:
Actually scheme + hex + source + studio project: led_t45.rar