Contents Up Previous Next

HiPi::Device::GPIO

The HiPi::Device::GPIO module provides access to the kernel driver for the GPIO.

See : GPIO Device Driver

Many of the methods expect a GPIO Pin Id as a parameter. You can use the pin id constants exported by HiPi::Constant module if you wish.

use HiPi::Constant qw( :raspberry );

# this will export, amongst other things, the following 
# pin constants that you can pass to the HiPi::BCM2835 
# methods and functions

    RPI_PAD1_PIN_3 
    RPI_PAD1_PIN_5 
    RPI_PAD1_PIN_7 
    RPI_PAD1_PIN_8 
    RPI_PAD1_PIN_10 
    RPI_PAD1_PIN_11 
    RPI_PAD1_PIN_12 
    RPI_PAD1_PIN_13
    RPI_PAD1_PIN_15 
    RPI_PAD1_PIN_16 
    RPI_PAD1_PIN_18 
    RPI_PAD1_PIN_19
    RPI_PAD1_PIN_21 
    RPI_PAD1_PIN_22 
    RPI_PAD1_PIN_23 
    RPI_PAD1_PIN_24 
    RPI_PAD1_PIN_26
 
# on Model B Revision 2 or a Model A boards
# then constants for Pad 5 are also exported

    RPI_PAD5_PIN_3 
    RPI_PAD5_PIN_4 
    RPI_PAD5_PIN_5 
    RPI_PAD5_PIN_6

# the constant RPI_BOARD_REVISION is also exported
# under the :raspberry tag and will be defined as 
# 1 or 2 depending on your board revision

Object Constructor and Methods

my $dev = HiPi::Device::GPIO->new();
    Creates a new object instance of class HiPi::Device::GPIO;
my $status = $dev->pin_status( $pinid );
    $pindid   GPIO Pin Number

    Returns the current status of the pin which indicates
    whether it is currently exported by the kernel driver.
    Return value is one of 

          DEV_GPIO_PIN_STATUS_NONE 
          DEV_GPIO_PIN_STATUS_EXPORTED

    You may import these constants into your namespace with

    use HiPi::Device::GPIO qw( :pinstatus );
$dev->export_pin( $pinid );
    $pindid   GPIO Pin Number

    Will export the specified pin id so that it may be accessed
    using the kernel device driver. The script user must have 
    permissions to export device driver pins ( probably 
    conferred by membership of gpio group).
    
    The method returns a HiPi::Device::GPIO::Pin object for the 
    specified pin number. (see also $dev->get_pin( $pinid ) ).
    
    see : GPIO Device Driver
$dev->unexport_pin( $pinid );
    $pindid   GPIO Pin Number

    Will unexport the specified pin id so that it may mo loner 
    be accessed using the kernel device driver. The script user 
    must have permissions to unexport device driver pins.
    
    see : GPIO Device Driver
my $pinobj = $dev->get_pin( $pinid );
    $pinid  GPIO Pin Number

    returns an object instance of HiPi::Device::GPIO::Pin





Contents Up Previous Next


HiPi Modules Copyright © 2013 Mark Dootson