A new unit has been added: the USB_HID_library.
See section "Units" on the website http://www.rosseeld.be/DRO/PIC/index.htm. The interface is somewhat different than the one of mE.
The "Descriptor" part of the "HID Terminal" tool is not used any more. In stead the descriptors are embedded in the library and adapted according the values set in the file "USB_HID_ProjectItems.ppas" (see further).
The main part of the unit's interface is:
Code: Select all
{ ---------------------------- USB_HID Library Interface -----------------------
procedure InitUsb;
// Initializes USB HID and starts the uSB enumeration process.
function ConfiguredUsb: boolean;
// Returns true if the USB enumeration process was completed and successful.
function USB_HID_Read(DstPtr: ^byte; MaxLen: byte): boolean;
// Returns true if some data has arrived, false means: no data arrived.
// The arguments are:
// DstPtr: the address of the user defined receive buffer.
// MaxLen: the actual number of received bytes to be copied into the user defined receive buffer
// (can be less than or equal to the size of the user defined receive buffer).
function USB_HID_Write(SrcPtr: ^byte; ByteCount: byte): boolean;
// Returns success as true, false means: try later again (USB sendbuffer was still busy).
// The arguments are:
// SrcPtr: the address of the user defined send buffer.
// ByteCount: the actual number of bytes to be sent
// (can be less than or equal to the size of the user defined send buffer).
procedure DeInitUsb;
// Stops and disables USB HID.
procedure SoftDetachUsb;
// Disconnects USB from the "host" and connects it again,
// restarting the USB enumeration process.
As also mentioned on the web the following holds:
An example of usage:Intended for the PIC18F2455/2550/4455 and 4550 PIC's or PICs with the same USB SIE.
Derived from the "TB054" publication of Microchip. No knowledge of USB "descriptors" required.
Warning: before usage one should delete "USBGenHID" from both the files "P18Fxxxx.mlk" and "P18Fxxxxdef.ppas"
in "C:\Program Files\MikroElektronika\mikroPascal\defs". Once deleted, a restart of mikroPascal is needed.
Example project: http://www.rosseeld.be/DRO/PIC/USB_Demo.ppas: the main (demo) project, and http://www.rosseeld.be/DRO/PIC/USB_Demo.ppp, the ppp file (8 Mhz crystal used).
Important: For each project using the library, a separate version of "USB_HID_ProjectItems.ppas" should be available (it is "used" by the library), residing the the project's directory itself. The libary itself ("USB_HID_Library.ppas") can reside in a common directory.
Code: Select all
program xxx;
uses USB_HID_Library;
var I: byte;
ReceiveBuffer: array[5] of byte;
SendBuffer: array[5] of byte;
...
procedure InitMain;
...
end;
procedure interrupt;
begin
USB_Interrupt; // <--- necessary call to the library
end;
begin // main
InitMain;
InitUsb; // Init Usb and start enumeration process
repeat until ConfiguredUsb; // wait for the completion of the USB enumeration
while true do // main loop
begin
// read data from the USB-HID interface and echo it
if USB_HID_Read(@ReceiveBuffer, SizeOf(ReceiveBuffer)) then // USB data came in
begin
for I := 0 to SizeOf(SendBuffer) - 1
do SendBuffer[i] := ReceiveBuffer[i]; // simply echo
repeat until USB_HID_Write(@SendBuffer, SizeOf(SendBuffer)); // send
end;
end;
end.
Have fun.