line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPi::SPI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16211
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
239
|
use WiringPi::API qw(:wiringPi); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.3607'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my ($class, $channel, $speed) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $self = bless {}, $class; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$self->_channel($channel); |
16
|
|
|
|
|
|
|
$self->_channel($speed); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# check if we're in bit-banging mode |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
if ($self->_cs){ |
21
|
|
|
|
|
|
|
pin_mode($self->_cs, 1); |
22
|
|
|
|
|
|
|
write_pin($self->_cs, 1); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if (wiringPiSPISetup($self->_channel, $self->_speed) < 0){ |
26
|
|
|
|
|
|
|
die "couldn't establish communication on the SPI bus\n"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
sub rw { |
32
|
|
|
|
|
|
|
my ($self, $buf, $len) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if ($self->_cs){ |
35
|
|
|
|
|
|
|
pin_mode($self->_cs, 0); |
36
|
|
|
|
|
|
|
@$buf = spiDataRW($self->_channel, $buf, $len); |
37
|
|
|
|
|
|
|
pin_mode($self->_cs, 1); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
|
|
|
|
|
|
@$buf = spiDataRW($self->_channel, $buf, $len); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return @$buf; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
sub _channel { |
46
|
|
|
|
|
|
|
my ($self, $chan) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if (defined $chan){ |
49
|
|
|
|
|
|
|
if ($chan > 1){ |
50
|
|
|
|
|
|
|
$self->_cs($chan); |
51
|
|
|
|
|
|
|
$self->{channel} = 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
|
|
|
|
|
|
$self->{channel} = $chan; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
return $self->{channel}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
sub _cs { |
61
|
|
|
|
|
|
|
my ($self, $cs) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->{cs} = $cs if defined $cs; |
64
|
|
|
|
|
|
|
return $self->{cs}; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
sub _speed { |
67
|
|
|
|
|
|
|
my ($self, $speed) = @_; |
68
|
|
|
|
|
|
|
$self->{speed} = $speed if defined $speed; |
69
|
|
|
|
|
|
|
return $self->{speed} || 1000000; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
sub _vim{}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
74
|
|
|
|
|
|
|
__END__ |