File Coverage

blib/lib/Device/Chip/DAC7571.pm
Criterion Covered Total %
statement 26 26 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 7 7 100.0
pod 0 1 0.0
total 35 38 92.1


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, 2020-2022 -- leonerd@leonerd.org.uk
5              
6 2     2   130618 use v5.26;
  2         18  
7 2     2   11 use Object::Pad 0.57;
  2         40  
  2         10  
8              
9             package Device::Chip::DAC7571 0.14;
10             class Device::Chip::DAC7571
11 1     1   572 :isa(Device::Chip::DAC75xx);
  1         2  
  1         29  
12              
13 2     2   474 use Future::AsyncAwait;
  2         4  
  2         9  
14              
15 2     2   104 use constant PROTOCOL => "I2C";
  2         4  
  2         769  
16              
17             =encoding UTF-8
18              
19             =head1 NAME
20              
21             C - chip driver for F
22              
23             =head1 SYNOPSIS
24              
25             use Device::Chip::DAC7571;
26             use Future::AsyncAwait;
27              
28             my $chip = Device::Chip::DAC7571->new;
29             await $chip->mount( Device::Chip::Adapter::...->new );
30              
31             # Presuming Vcc = 5V
32             await $chip->write_dac_ratio( 1.23 / 5 );
33             print "Output is now set to 1.23V\n";
34              
35             =head1 DESCRIPTION
36              
37             This L subclass provides specific communication to a
38             F F attached to a computer via an I²C adapter.
39              
40             The reader is presumed to be familiar with the general operation of this chip;
41             the documentation here will not attempt to explain or define chip-specific
42             concepts or features, only the use of this module to access them.
43              
44             This class is derived from L, and inherits the methods
45             defined there.
46              
47             =cut
48              
49             =head1 MOUNT PARAMETERS
50              
51             =head2 addr
52              
53             The I²C address of the device. Can be specified in decimal, octal or hex with
54             leading C<0> or C<0x> prefixes.
55              
56             =cut
57              
58             sub I2C_options ( $, %params )
59 1     1 0 458 {
  1         2  
  1         4  
60 1   50     7 my $addr = delete $params{addr} // 0x4C;
61 1 50       5 $addr = oct $addr if $addr =~ m/^0/;
62              
63             return (
64 1         5 addr => $addr,
65             max_bitrate => 400E3,
66             );
67             }
68              
69 3         4 async method _write ( $code )
  3         6  
  3         4  
70 3         7 {
71 3         9 await $self->protocol->write( pack "S>", $code );
72 3     3   5 }
73              
74             =head1 AUTHOR
75              
76             Paul Evans
77              
78             =cut
79              
80             0x55AA;