File Coverage

blib/lib/Device/Chip/PCF8574.pm
Criterion Covered Total %
statement 21 21 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod n/a
total 28 28 100.0


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 3     3   251056 use v5.26;
  3         28  
7 3     3   485 use Object::Pad 0.57;
  3         8627  
  3         12  
8              
9             package Device::Chip::PCF8574 0.05;
10             class Device::Chip::PCF8574
11 3     3   1504 :isa(Device::Chip::PCF857x);
  3         7  
  3         91  
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 an 8-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 an 8-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 3     3   477 use constant PACKFMT => "C";
  3         7  
  3         165  
70 3     3   18 use constant READLEN => 1;
  3         6  
  3         152  
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 3     3   17 use constant DEFMASK => 0xFF;
  3         5  
  3         283  
90             use constant GPIOBITS => {
91 3         8 map { +"P$_", ( 1 << $_ ) } 0 .. 7
  24         339  
92 3     3   17 };
  3         6  
93              
94             =head1 AUTHOR
95              
96             Paul Evans
97              
98             =cut
99              
100             0x55AA;