File Coverage

blib/lib/Device/Chip/DAC7571.pm
Criterion Covered Total %
statement 29 29 100.0
branch 1 2 50.0
condition 1 2 50.0
subroutine 8 8 100.0
pod 0 1 0.0
total 39 42 92.8


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