
Management of a home-made USB-HID LED using the GUI shell on .NET

A similar thing, assembled from a small number of parts, can be useful for modding or just for lighting the keyboard.
Atmel uses Atmel's AtTiny45 microcontroller to connect to USB. This microcontroller does not have a hardware USB interface, so it is implemented programmatically using the V-USB library from Objective Development. Also, this eight-legged cockroach has a built-in PLL (PLL), which allows you to get rid of quartz and strapping, and so free not numerous legs, but the most important thing is to tune to the desired clock frequency for USB ~ 16.5 MHz. Also, the PLL allows you to adjust this frequency if necessary, using the same USB ticks. Which, in fact, is done the first time you connect the device. After that, the adjustment value 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 there are not many resources left in the microcontroller. Tiny45 is easily flashed by any in-circuit programmer,

Since I’m a lazy creature, I didn’t want to breed the handkerchief itself, so it was purchased on the microsin.ru/content/view/655/44 website , there is also a connection diagram, as well as a V-USB library translated into Russian and a description of how work with her microsin.ru/content/view/613/44 .
Using the V-USB library example from the \ examples \ hid-custom-rq \ folder, screwing the PLL \ libs-device \, compiled it with AtTiny45. I requested it. 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 that calls it. But it didn’t work for me.
The command line is certainly good, but not practical. I decided to fix and rebuild the example from \ examples \ hid-custom-rq \ commandline \ in the DLL and fasten the GUI shell to it.
First, I assembled the DLL using the MinGW compiler and the manual from here www.adp-gmbh.ch/win/misc/mingw/dll.html , I had to sweat so that everything compiles with the libusb-win32 library. Inside the DLL, two functions turned out: Then I wrote a small program in C # that calls this DLL from under the command line, using the manual www.adp-gmbh.ch/csharp/call_dll.html . On XP, it worked almost immediately, the only thing that .NET under win7'64 does not want to communicate with my DLL, I did not check the rest of the OS. The resulting command-line program code:
void led_set( int isOn ){
...
}
int led_get( void ){
...
}
* 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.
Delivered Microsoft Visual C # 2008 Express Edition and based on the simplest project WindowsFormsApplication created a small program with one single ChekBox, which turns the LED on and off. It also checks every 300ms whether the device is connected and in what condition it is.



This is my first C # program, so I didn’t implement any classes, and I called functions from the dll directly. Actually the video of the resulting device:
Actually the circuit + hex + sources + studio project:
led_t45.rar