next up previous
Next: Interrupt (IRQ) Handling Up: PARAPIN: A Parallel Port Previous: Setting Output Pin States

Subsections


Polling Input Pins

C library version and Kernel version

Once Parapin has been initialized (Section 5), and pins have been configured as input pins (Section 6), the value being asserted by the ``far end'' can be queried using the following function:

        int pin_is_set(int pins);

Any number of pins can be queried simultaneously. The pins argument accepts the LP_PINnn constants described in Section 3. The return value is an integer in the same format. Any pins that are set (electrically high) will be set in the return value; pins that are clear (electrically low) will be clear in the return value.

Pins may only be queried if:

Any query to an output pin will always return a value indicating that the pin is clear. In other words, this function can not be used to determine what value was previously asserted to an output pin.

Examples:

        pin_input_mode(LP_PIN01 | LP_DATA_PINS | LP_PIN17);
        /* Pins 1, 2-9, and 17 are now in input mode, along with
           Pins 10, 11, 12, 13, and 15, which are always inputs */

        /* check the state of pin 1 */
        printf("Pin 1 is %s!\n", pin_is_set(LP_PIN01) ? "on" : "off");

        /* check pins 2, 5, 10, and 17 - demonstrating a multiple query */
        int result = pin_is_set(LP_PIN02 | LP_PIN05 | LP_PIN10 | LP_PIN17);

        if (!result)
                printf("Pins 2, 5, 10 and 17 are all off\n");
        else {
                if (result & LP_PIN02)
                        printf("Pin 2 is high!\n");
                if (result & LP_PIN05)
                        printf("Pin 5 is high!\n");
                if (result & LP_PIN10)
                        printf("Pin 10 is high!\n");
                if (result & LP_PIN17)
                        printf("Pin 17 is high!\n");
        }

Device driver interface

Querying pin state through the device driver interface follows all the same rules as described above. The ioctl command used is ``PPDRV_IOC_PINGET''.

Examples:

        int value;
        value = ioctl(device, PPDRV_IOC_PINGET, DATA);

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: Interrupt (IRQ) Handling Up: PARAPIN: A Parallel Port Previous: Setting Output Pin States
Al Hooton 2004-11-16