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, 2017-2021 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
228548
|
use v5.26; |
|
2
|
|
|
|
|
21
|
|
7
|
2
|
|
|
2
|
|
10
|
use Object::Pad 0.57; |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::PCF8575 0.05; |
10
|
|
|
|
|
|
|
class Device::Chip::PCF8575 |
11
|
2
|
|
|
2
|
|
1040
|
:isa(Device::Chip::PCF857x); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=encoding UTF-8 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
C - chip driver for a F or F |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
This L subclass provides specific communication to a |
22
|
|
|
|
|
|
|
F or F F attached to a computer via an I²C |
23
|
|
|
|
|
|
|
adapter. Due to hardware similarity this can also drive a F. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
The reader is presumed to be familiar with the general operation of this chip; |
26
|
|
|
|
|
|
|
the documentation here will not attempt to explain or define chip-specific |
27
|
|
|
|
|
|
|
concepts or features, only the use of this module to access them. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 MOUNT PARAMETERS |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head2 addr |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
The I²C address of the device. Can be specified in decimal, octal or hex with |
36
|
|
|
|
|
|
|
leading C<0> or C<0x> prefixes. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 METHODS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The following methods documented in an C expression return L |
43
|
|
|
|
|
|
|
instances. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 write |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
await $chip->write( $val ); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Sets the value of the GPIO pins, as a 16-bit integer. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Pins set low will sink current suitable for signalling or driving an LED. Pins |
54
|
|
|
|
|
|
|
set high will source current via a weak current-source to act as a pull-up for |
55
|
|
|
|
|
|
|
an active-low input signal, such as a button. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 read |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$val = await $chip->read; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Reads the current logic levels on the GPIO pins, returned as a 16-bit |
64
|
|
|
|
|
|
|
integer. Pins of interest as inputs should have previously been set to high |
65
|
|
|
|
|
|
|
level using the L method. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
2
|
|
318
|
use constant PACKFMT => "S<"; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
107
|
|
70
|
2
|
|
|
2
|
|
11
|
use constant READLEN => 2; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
95
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 as_adapter |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
$adapter = $chip->as_adapter |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Returns a new object implementing the L interface which |
77
|
|
|
|
|
|
|
allows access to the GPIO pins of the chip as if it was a GPIO protocol |
78
|
|
|
|
|
|
|
adapter. The returned instance supports the following methods: |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$protocol = await $adapter->make_protocol( 'GPIO' ) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$protocol->list_gpios |
83
|
|
|
|
|
|
|
await $protocol->write_gpios |
84
|
|
|
|
|
|
|
await $protocol->read_gpios |
85
|
|
|
|
|
|
|
await $protocol->tris_gpios |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
2
|
|
10
|
use constant DEFMASK => 0xFFFF; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
264
|
|
90
|
|
|
|
|
|
|
use constant GPIOBITS => { |
91
|
16
|
|
|
|
|
36
|
( map { +"P0$_", ( 1 << $_ ) } 0 .. 7 ), |
92
|
2
|
|
|
|
|
5
|
( map { +"P1$_", ( 0x100 << $_ ) } 0 .. 7 ) |
|
16
|
|
|
|
|
242
|
|
93
|
2
|
|
|
2
|
|
11
|
}; |
|
2
|
|
|
|
|
4
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Paul Evans |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
0x55AA; |