next up previous
Next: Setting Output Pin States Up: PARAPIN: A Parallel Port Previous: Initialization and Shutdown

Subsections


Configuring Pins as Inputs or Outputs

As shown in the table in Section 2, most of the pins on modern parallel ports can be configured as either inputs or outputs. When Parapin is initialized, it is safest to assume that the state of all these switchable pins is undefined. That is, they must be explicitly configured as outputs before values are asserted, or configured as inputs before they are queried.

As mentioned earlier, Pins 2-9 can not be configured independently. They are always in the same mode: either all input or all output. Configuring any pin in that range has the effect of configuring all of them. The constant LP_DATA_PINS is an alias that refers to all the pins in this range (2-9).

The other switchable pins (Pins 1, 14, 16, and 17) may be independently configured. Pins 10, 11, 12, 13, and 15 are always inputs and can not be configured.

It is also worth reiterating that having two devices both try to assert (output) a value on the same pin at the same time can be dangerous. The results are undefined and are often dependent on the exact hardware implementation of your particular parallel port. This situation should be avoided. The protocol spoken between the PC and the external device you're controlling to should always agree who is asserting a value on a pin and who is reading that pin as an input.

C library version and Kernel version

In both the userspace C library version, and the kernel version, pins are configured using one of the following three functions:

        void pin_input_mode(int pins);
        void pin_output_mode(int pins);
        void pin_mode(int pins, int mode);

The pins argument of all three functions accepts the LP_PINnn constants described in Section 3. The pin_mode function is just provided for convenience; it does the same thing as the pin_input and pin_output functions. Its mode argument takes one of the two constants LP_INPUT or LP_OUTPUT. Calling pin_mode(pins, LP_INPUT) is exactly the same as calling pin_input(pins).

Examples:

        pin_input_mode(LP_PIN01);
        /* Pin 1 is now an input */

        pin_output_mode(LP_PIN14 | LP_PIN16);
        /* Pins 14 and 16 are now outputs */

        pin_mode(LP_PIN02, LP_INPUT);
        /* Pins 2 through 9 are now ALL inputs */

        pin_mode(LP_PIN01 | LP_PIN02, LP_OUTPUT);
        /* Pin 1, and Pins 2-9 are ALL outputs */

        pin_input_mode(LP_DATA_PINS);
        /* The constant LP_DATA_PINS is an alias for Pins 2-9 */

Device driver interface

When using the parapindriver device interface, all functionality related to pins on the parallel port is invoked via the ioctl(2) system call. The ioctl commands for parapindriver are defined in the parapindriver.h header file. The two used to set pins to be either output pins or input pins are ``PPDRV_IOC_PINMODE_OUT'' and ``PPDRV_IOC_PINMODE_IN'', respectively.

Examples:

        ioctl(device, PPDRV_IOC_PINMODE_OUT, LP_PIN01 | LP_PIN02);
        ioctl(device, PPDRV_IOC_PINMODE_IN, LP_PIN11);

Note that the arguments to these ioctl calls use exactly the same constants as are used by the userspace and kernel versions of parapin itself. The rules for combining constants using bitwise 'or' are allowed as well. These constants are made available to your program because the parapindriver.h header file also includes the parapin.h header file to define the constant values.

Return values from these ioctl calls are the same as those defined for the corresponding functions in kparapin. There is one additional return value from an ioctl call in to parapindriver, the value -ENOTTY. This indicates that an invalid ioctl command value was passed down.


next up previous
Next: Setting Output Pin States Up: PARAPIN: A Parallel Port Previous: Initialization and Shutdown
Al Hooton 2004-11-16