line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
######################################################################################### |
2
|
|
|
|
|
|
|
# Package HiPi::Device::GPIO::Pin |
3
|
|
|
|
|
|
|
# Description: Pin |
4
|
|
|
|
|
|
|
# Created Wed Feb 20 04:37:38 2013 |
5
|
|
|
|
|
|
|
# Copyright : Copyright (c) 2013-2017 Mark Dootson |
6
|
|
|
|
|
|
|
# License : This is free software; you can redistribute it and/or modify it under |
7
|
|
|
|
|
|
|
# the same terms as the Perl 5 programming language system itself. |
8
|
|
|
|
|
|
|
######################################################################################### |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package HiPi::Device::GPIO::Pin; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
######################################################################################### |
13
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
14
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
15
|
1
|
|
|
1
|
|
5
|
use parent qw( HiPi::Pin ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
16
|
1
|
|
|
1
|
|
99
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
17
|
1
|
|
|
1
|
|
6
|
use Fcntl; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
325
|
|
18
|
1
|
|
|
1
|
|
7
|
use HiPi qw( :rpi ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
919
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION ='0.81'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->create_accessors(); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _open { |
25
|
0
|
|
|
0
|
|
|
my ($class, %params) = @_; |
26
|
0
|
0
|
|
|
|
|
defined($params{pinid}) or croak q(pinid not defined in parameters); |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $pinroot = qq(/sys/class/gpio/gpio$params{pinid}); |
29
|
0
|
0
|
|
|
|
|
croak qq(pin $params{pinid} is not exported) if !-d $pinroot; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $self = $class->SUPER::_open(%params); |
32
|
0
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _do_getvalue { |
36
|
0
|
|
|
0
|
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->pin_read( $self->pinid ); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _do_setvalue { |
41
|
0
|
|
|
0
|
|
|
my( $self, $newval) = @_; |
42
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->pin_write($self->pinid, $newval ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _do_getmode { |
46
|
0
|
|
|
0
|
|
|
my $self = shift; |
47
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->get_pin_mode($self->pinid ); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _do_setmode { |
51
|
0
|
|
|
0
|
|
|
my ($self, $newmode) = @_; |
52
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->set_pin_mode($self->pinid, $newmode ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _do_getinterrupt { |
56
|
0
|
|
|
0
|
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->get_pin_interrupt( $self->pinid ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _do_setinterrupt { |
61
|
0
|
|
|
0
|
|
|
my ($self, $newedge) = @_; |
62
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->set_pin_interrupt( $self->pinid, $newedge ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _do_get_interrupt_filepath { |
66
|
0
|
|
|
0
|
|
|
my($self) = @_; |
67
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->get_pin_interrupt_filepath( $self->pinid ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _do_get_function_name { |
71
|
0
|
|
|
0
|
|
|
my($self) = @_; |
72
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->get_pin_function( $self->pinid ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _do_setpud { |
76
|
0
|
|
|
0
|
|
|
my($self, $pudval) = @_; |
77
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->set_pin_pud($self->pinid, $pudval); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _do_getpud { |
81
|
0
|
|
|
0
|
|
|
my($self) = @_; |
82
|
0
|
|
|
|
|
|
return HiPi::Device::GPIO->get_pin_pud($self->pinid); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _do_activelow { |
86
|
0
|
|
|
0
|
|
|
my($self, $newval) = @_; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $result = undef; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if( defined( $newval ) ) { |
91
|
0
|
|
|
|
|
|
$result = HiPi::Device::GPIO->set_pin_activelow($self->pinid, $newval); |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
|
$result = HiPi::Device::GPIO->get_pin_activelow($self->pinid); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $result; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |