line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2016-2022 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
66
|
use v5.26; |
|
5
|
|
|
|
|
17
|
|
7
|
5
|
|
|
5
|
|
25
|
use Object::Pad 0.66; |
|
5
|
|
|
|
|
68
|
|
|
5
|
|
|
|
|
24
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::PCF857x 0.05; |
10
|
|
|
|
|
|
|
class Device::Chip::PCF857x |
11
|
1
|
|
|
1
|
|
491
|
:isa(Device::Chip); |
|
1
|
|
|
|
|
15256
|
|
|
1
|
|
|
|
|
30
|
|
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
1394
|
use constant PROTOCOL => "I2C"; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
348
|
|
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
32
|
use Future::AsyncAwait; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
27
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
method I2C_options |
18
|
4
|
|
|
4
|
0
|
1623
|
{ |
19
|
4
|
|
|
|
|
13
|
my %opts = @_; |
20
|
|
|
|
|
|
|
|
21
|
4
|
|
50
|
|
|
28
|
my $addr = $opts{addr} // 0x20; |
22
|
4
|
50
|
|
|
|
18
|
$addr = oct $addr if $addr =~ m/^0/; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
return ( |
25
|
4
|
|
|
|
|
27
|
addr => $addr, |
26
|
|
|
|
|
|
|
max_bitrate => 100E3, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
4
|
|
|
|
|
7
|
async method write ( $v ) |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
6
|
|
31
|
4
|
|
|
|
|
13
|
{ |
32
|
4
|
|
|
|
|
28
|
await $self->protocol->write( pack( $self->PACKFMT, $v ) ); |
33
|
4
|
|
|
4
|
0
|
617
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
async method read |
36
|
4
|
|
|
|
|
13
|
{ |
37
|
4
|
|
|
|
|
33
|
return unpack $self->PACKFMT, await $self->protocol->read( $self->READLEN ); |
38
|
4
|
|
|
4
|
0
|
23954
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
method as_adapter |
41
|
2
|
|
|
2
|
0
|
437
|
{ |
42
|
2
|
|
|
|
|
19
|
return Device::Chip::PCF857x::_Adapter->new( chip => $self ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
class # hide from indexer |
46
|
|
|
|
|
|
|
Device::Chip::PCF857x::_Adapter; |
47
|
|
|
|
|
|
|
# Can't 'extend' yet because D:C:A itself has no sub new |
48
|
5
|
|
|
5
|
|
3340
|
use base qw( Device::Chip::Adapter ); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
834
|
|
49
|
|
|
|
|
|
|
|
50
|
5
|
|
|
5
|
|
4650
|
use Carp; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
311
|
|
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
5
|
|
30
|
use Future; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
5453
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
field $_chip :param; |
55
|
|
|
|
|
|
|
field $_mask; |
56
|
|
|
|
|
|
|
field $_gpiobits; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
ADJUST |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
$_mask = $_chip->DEFMASK; |
61
|
|
|
|
|
|
|
$_gpiobits = $_chip->GPIOBITS; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
async method power ( $on ) |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
65
|
0
|
|
|
|
|
0
|
{ |
66
|
0
|
|
|
|
|
0
|
await $_chip->protocol->power( $on ); |
67
|
0
|
|
|
0
|
|
0
|
} |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
2
|
|
26
|
async method make_protocol_GPIO { return $self } |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
20
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
method list_gpios |
72
|
2
|
|
|
2
|
|
103
|
{ |
73
|
2
|
|
|
|
|
4
|
return sort keys %{ $_gpiobits }; |
|
2
|
|
|
|
|
44
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
5
|
async method write_gpios ( $gpios ) |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
77
|
2
|
|
|
|
|
7
|
{ |
78
|
2
|
|
|
|
|
3
|
my $newmask = $_mask; |
79
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
8
|
foreach my $pin ( keys %$gpios ) { |
81
|
2
|
50
|
|
|
|
18
|
my $bit = $_gpiobits->{$pin} or |
82
|
|
|
|
|
|
|
croak "Unrecognised GPIO pin name $pin"; |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
6
|
$newmask &= ~$bit; |
85
|
2
|
50
|
|
|
|
8
|
$newmask |= $bit if $gpios->{$pin}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
2
|
50
|
|
|
|
8
|
return if $newmask == $_mask; |
89
|
|
|
|
|
|
|
|
90
|
2
|
|
|
|
|
16
|
await $_chip->write( $_mask = $newmask ); |
91
|
2
|
|
|
2
|
|
6909
|
} |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
4
|
async method read_gpios ( $gpios ) |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
4
|
|
94
|
2
|
|
|
|
|
7
|
{ |
95
|
2
|
|
|
|
|
10
|
my $mask = await $_chip->read; |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
|
|
16077
|
my %ret; |
98
|
2
|
|
|
|
|
15
|
foreach my $pin ( @$gpios ) { |
99
|
2
|
50
|
|
|
|
10
|
my $bit = $_gpiobits->{$pin} or |
100
|
|
|
|
|
|
|
croak "Unrecognised GPIO pin name $pin"; |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
8
|
$ret{$pin} = !!( $mask & $bit ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
|
|
20
|
return \%ret; |
106
|
2
|
|
|
2
|
|
2199
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
async method tris_gpios ( $gpios ) |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
{ |
110
|
0
|
|
|
|
|
|
await $self->write_gpios( { map { $_ => 1 } @$gpios } ); |
111
|
0
|
|
|
0
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
0x55AA; |