next up previous contents
Next: 6.3 Developing Your Driver Up: 6. Developing a Driver Previous: 6.1 Using the DriverWizard   Contents

Subsections


6.2 Writing the Device Driver Without the DriverWizard

There may be times when you choose to write your driver directly, without using DriverWizard. In such cases, either follow the steps outlined in this section to create a new driver project, or use one of the WinDriver samples, which most closely resembles your target driver, and modify the sample to suit your specific requirements.


6.2.1 Include the Required WinDriver Files

  1. Include the relevant WinDriver header files in your driver project (all header files are found under the WinDriver/include/ directory).
    All WinDriver projects require the windrvr.h header file.
    When using the WDU_xxx WinDriver USB API [B.2], include the wdu_lib.h header file (this file already includes windrvr.h).
    Include any other header file that provides APIs that you wish to use from your code (e.g. files from the WinDriver/samples/shared/ directory, which provide convenient diagnostics functions.)

  2. Include the relevant header files from your source code: For example, to use the USB API from the wdu_lib.h header file, add the following line to the code:

          #include "wdu_lib.h"
    

  3. Link your code with the wdapi920 library/shared object:

    You can also include the library's source files in your project instead of linking the project with the library. The C source files are located under the WinDriver/src/wdapi directory.

    NOTE: When linking your project with the wdapi920 library/shared object, you will need to distribute the wdapi920 DLL/shared object with your driver. For Windows, get wdapi920.dll / wdapi920_32.dll (for 32-bit applications targeted at 64-bit platforms) from the WinDriver$\backslash$redist or WinDriver$\backslash$redist_win98_compat directory. For Linux, distribute WinDriver/lib/libwdapi920.so. For details, refer to the driver distribution instructions in Chapter 11.

  4. Add any other WinDriver source files that implement API that you which to use in your code (e.g. files from the WinDriver/samples/shared directory.)


6.2.2 Write Your Code

  1. Call WDU_Init() [B.4.1] at the beginning of your program to initialize WinDriver for your USB device and wait for the device-attach callback. The relevant device information will be provided in the attach callback.

  2. Once the attach callback is received, you can start using one of the WDU_Transfer() [B.4.8.1] functions family to send and receive data.

  3. To finish, call WDU_Uninit() [B.4.7] to un-register from the device.