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