Stap 3: Test de bestuurder
We gonna het testprogramma van linux-sunxi/documentatie/usb gebruiken.De code wordt hieronder weergegeven (het kan ook worden gedownload vanaf hier):
statische LIST_HEAD(hidg_func_list);
/ * verborg descriptor voor een toetsenbord * /
statische struct hidg_func_descriptor pcduino_keyboard_date = {}
.subclass = 0, / * geen subklasse * /
.Protocol = 1, / * toetsenbord * /
.report_length = 8,
.report_desc_length = 63,
.report_desc = {}
0 × 05, 0 × 01, / * USAGE_PAGE (generieke Desktop) * /
0 × 09, 0 × 06, / * gebruik (toetsenbord) * /
0xa1, 0 × 01, / * collectie (toepassing) * /
0 × 05, 0 × 07, / * USAGE_PAGE (toetsenbord) * /
0 × 19, 0xe0, / * USAGE_MINIMUM (LeftControl toetsenbord) * /
0 × 29, 0xe7, / * USAGE_MAXIMUM (toetsenbord recht GUI) * /
0 × 15, 0 × 00, / * LOGICAL_MINIMUM (0) * /
0 × 25, 0 × 01, / * LOGICAL_MAXIMUM (1) * /
0 × 75, 0 × 01, / * REPORT_SIZE (1) * /
0 × 95, 0 × 08, / * REPORT_COUNT (8) * /
0 × 81, 0 × 02, / * INPUT (Data, Var, Abs) * /
0 × 95, 0 × 01, / * REPORT_COUNT (1) * /
0 × 75, 0 × 08, / * REPORT_SIZE (8) * /
0 × 81, 0 × 03, / * INPUT (Cnst, Var, Abs) * /
0 × 95, 0 × 05, / * REPORT_COUNT (5) * /
0 × 75, 0 × 01, / * REPORT_SIZE (1) * /
0 × 05, 0 × 08, / * USAGE_PAGE (LED's) * /
0 × 19, 0 × 01, / * USAGE_MINIMUM (Num Lock) * /
0 × 29, 0 × 05, / * USAGE_MAXIMUM (Kana) * /
0 × 91, 0 × 02, / * OUTPUT (Data, Var, Abs) * /
0 × 95, 0 × 01, / * REPORT_COUNT (1) * /
0 × 75, 0 × 03, / * REPORT_SIZE (3) * /
0 × 91, 0 × 03, / * OUTPUT (Cnst, Var, Abs) * /
0 × 95, 0 × 06, / * REPORT_COUNT (6) * /
0 × 75, 0 × 08, / * REPORT_SIZE (8) * /
0 × 15, 0 × 00, / * LOGICAL_MINIMUM (0) * /
0 × 25, 0 × 65, / * LOGICAL_MAXIMUM (101) * /
0 × 05, 0 × 07, / * USAGE_PAGE (toetsenbord) * /
0 × 19, 0 × 00, / * USAGE_MINIMUM (gereserveerd) * /
0 × 29, 0 × 65, / * USAGE_MAXIMUM (de toepassing van het toetsenbord) * /
0 × 81, 0 × 00, / * INPUT (Data, Aire, Abs) * /
0XC0 / * END_COLLECTION * /
}
};
statische struct platform_device pcduino_hid_keyboard = {}
.name = "hidg",
.id = 0,
.num_resources = 0,
.resource = 0,
. dev.platform_data = & amp; amp; pcduino_keyboard_date,
};
/ * verborg descriptor voor een muis * /
statische struct hidg_func_descriptor pcduino_mouse_data = {}
.subclass = 0, //No subklasse
.Protocol = 2, //Mouse
.report_length = 4,
.report_desc_length = 52,
.report_desc = {}
0 × 05, 0 × 01, //Usage Page (generieke Desktop Controls)
0 × 09, 0 × 02, //Usage (muis)
0xa1, 0 × 01, //Collction (toepassing)
0 × 09, 0 × 01, //Usage (pointer)
0xa1, 0 × 00, //Collction (fysiek)
0 × 05, 0 × 09 //Usage pagina (knop)
0 × 19, 0 × 01, //Usage Minimum(1)
0 × 29, 0 × 05, //Usage Maximum(5)
0 × 15, 0 × 00, //Logical Minimum(1)
0 × 25, 0 × 01, //Logical Maximum(1)
0 × 95, 0 × 05, //Report Count(5)
0 × 75, 0 × 01, //Report Size(1)
0 × 81, 0 × 02, //Input(Data,Variable,Absolute,BitField)
0 × 95, 0 × 01, //Report Count(1)
0 × 75, 0 × 03, //Report Size(3)
0 × 81, 0 × 01, //Input(Constant,Array,Absolute,BitField)
0 × 05, 0 × 01, //Usage Page (generieke Desktop Controls)
0 × 09, 0 × 30, //Usage(x)
0 × 09, 0 × 31, //Usage(y)
0 × 09, 0 × 38, //Usage(Wheel)
0 × 15, 0 × 81, //Logical Minimum(-127)
0 × 25, 0x7F, //Logical Maximum(127)
0 × 75, 0 × 08, //Report Size(8)
0 × 95, 0 × 03, //Report Count(3)
0 × 81, 0 × 06, //Input(Data,Variable,Relative,BitField)
0xc0, //End-collectie
0xc0 //End collectie
}
};
statische struct platform_device pcduino_hid_mouse = {}
.name = "hidg",
.id = 1,
.num_resources = 0,
.resource = 0,
. dev.platform_data = & amp; amp; pcduino_mouse_data,
};
statische int __init hidg_init(void)
{
int status;
status = platform_device_register (& amp; amp; pcduino_hid_keyboard);
Als (status & amp; lt; 0) {}
printk ("hid toetsenbord reg failed\n");
platform_device_unregister (& amp; amp; pcduino_hid_keyboard);
status; retourneren
}
status = platform_device_register (& amp; amp; pcduino_hid_mouse);
Als (status & amp; lt; 0) {}
printk ("hid muis reg failed\n");
platform_device_unregister (& amp; amp; pcduino_hid_mouse);
status; retourneren
}
status = platform_driver_probe (& amp; amp; hidg_plat_driver,
hidg_plat_driver_probe);
Als (status & amp; lt; 0)
status; retourneren
status = usb_composite_probe (& amp; amp; hidg_driver, hid_bind);
Als (status & amp; lt; 0)
platform_driver_unregister (& amp; amp; hidg_plat_driver);
status; retourneren
}
module_init(hidg_init);
statische ongeldig __exit hidg_cleanup(void)
{
platform_driver_unregister (& amp; amp; hidg_plat_driver);
platform_device_unregister (& amp; amp; pcduino_hid_keyboard);
platform_device_unregister (& amp; amp; pcduino_hid_mouse);
usb_composite_unregister (& amp; amp; hidg_driver);
}
Compileren:
$gcc gadget_hid.c
Door pcDuino sluit aan op een PC via USB OTG en voert u de volgende opdracht op pcDuino:
root. /a.out/dev/hidg0 k #keyboard
keyboard opties:
– Houd
– linker-ctrl
– juiste-ctrl
– linker-shift
– juiste-shift
– Linker-alt
– rechter-alt
-links-meta
– juiste-meta
toetsenbord waarden:
[a-z] of
– – esc terugkeren
– bckspc – tabblad
– SPATIEBALK-caps-lock
–f1 –f2
–f3 –f4
–f5 –f6
–f7 –f8
– f9-f10
– f11-f12
– invoegen-home
– pageup-del
– – pagedown beëindigen
-rechts-links
– down-kp-Voer
– – num-lock up
Voer: een b c d e f
U ziet nu iets verschijnen op het scherm van PC.
Wanneer de volgende opdrachten uitvoeren op pcDunio:
root. /a.out/dev/hidg1 m #keyboard
muis opties:
– Houd
– b1
– b2
– b3
muis waarden:
Twee ondertekende getallen
– stoppen om te sluiten
Hier is een kleine uitleg:
– b1 10 10
Wanneer u dit uitvoert, fungeert het als de linkerknop van de muis.
– b2 1
Wanneer u dit uitvoert, fungeert het als rechterknop van muis.
– b3-10 100
Wanneer u dit uitvoert, fungeert het als de muis bewegen.