Usb Hid Library

5
USB HID Library Universal Serial Bus (USB) provides a serial bus standard for connecting a wide variety of devices, including computers, cell phones, game consoles, PDA’s, etc. mikroC includes a library for working with human interface devices via Universal Serial Bus. A human interface device or HID is a type of computer device that interacts directly with and takes input from humans, such as the keyboard, mouse, graphics tablet, and the like. Descriptor File Each project based on the USB HID library should include a descriptor source file which contains vendor id and name, product id and name, report length, and other relevant information. To create a descriptor file, use the integrated USB HID terminal of mikroC (Tools › USB HID Terminal). The default name for descriptor file is USBdsc.c, but you may rename it. The provided code in the “Examples” folder works at 48MHz, and the flags should not be modified without consulting the appropriate datasheet first. Library Routines Hid_Enable Hid_Read Hid_Write Hid_Disable Hid_Enable Prototyp e void Hid_Enable(unsigned *readbuff, unsigned *writebuff); Returns Nothing.

description

Usb Hid Library

Transcript of Usb Hid Library

USB HID LibraryUniversal Serial Bus (USB) provides a serial bus standard for connecting a wide variety of devices, including computers, cell phones, game consoles, PDAs, etc!mi"ro# includes a library for wor"ing with human interface devices via Universal Serial Bus! A human interface device or $%D is a type of computer device that interacts directly with and ta"es input from humans, such as the "eyboard, mouse, graphics tablet, and the li"e!Descriptor File&ach pro'ect based on the USB $%D library should include a descriptor source file which contains vendor id and name, product id and name, report length, and other relevant information! (o create a descriptor file, use the integrated USB $%D terminal of mi"ro# (Tools USB HID Terminal)! (he default name for descriptor file is USBdsc.c, but you may rename it!(he provided code in the )&*amples+ folder wor"s at ,-.$/, and the flags should not bemodified without consulting the appropriate datasheet first!Library Routines $id0&nable $id01ead $id02rite $id0Disable Hid_EnablePrototypeoid $id0&nable(unsi!ned 3readbuff, unsi!ned 3writebuff)4Returns5othing!Description &nables USB $%D communication! Parameters readbuff and writebuff arethe 1ead Buffer and the 2rite Buffer, respectively, which are used for $%D communication!(his function needs to be called before using other routines of USB $%D 6ibrary!Re"uires5othing!E#ampleHid_Enable(&rd, &wr);Hid_ReadPrototypeunsi!ned s$ort $id01ead(oid)4Returns5umber of characters in the 1ead Buffer received from the host!Description1eceives message from host and stores it in the 1ead Buffer! 7unction returns the number of characters received in the 1ead Buffer!Re"uiresUSB $%D needs to be enabled before using this function! See $id0&nable!E#ampleget = Hid_Read();Hid_%ritePrototypeunsi!ned s$ort $id02rite(unsi!ned 3writebuff, unsi!ned s$ort len)4Returns& if data was successfully sent, ' if not!Description 7unction sends data from 2rite Buffer writebuff to host! 2rite Buffer is the same parameter as used in initiali/ation4 see $id0&nable! Parameter len should specify a length of the data to be transmitted!7unction call needs to be repeated as long as data is not successfully sent!Re"uiresUSB $%D needs to be enabled before using this function! See $id0&nable!E#ample// retry until success.while(Hid_!rite(&"#_Usb_Buff, $));Hid_DisablePrototypeoid $id0Disable(oid)4Returns5othing!DescriptionDisables USB $%D communication!Re"uiresUSB $%D needs to be enabled before using this function! See $id0&nable!E#ampleHid_%isable();Library E#ample(he following e*ample continually sends se8uence of numbers 9!!:;; to the P# via Universal Serial Bus! usbdsc.c must be included in the pro'ect (via mi"ro# %D& tool or via &include mechanism in source code)!unsigned short ", ';unsigned short userR%_buffer()*+;unsigned short user!R_buffer()*+;void interru,t() -asm ./00 _Hid_1nterru,t2r3casm n3,4//~void 1nit_5ain() -// Disable all interrupts// Disable GIE, PEIE, TMR0IE, INT0IE,RBIE167.86 = 9;167.86: = 9; = 9;.9;// Disable Priority Leels on interruptsR.86.12E6 = 9;21E$ = 9;21E: = 9;21R$ = 9;21R: = 9;// !on"i#ure all ports $it% analo# "unction as &i#ital/%.86$ ?= 9;9