DAC75xx.pm

filter: Statementstmt 80.4% 37 / 46 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod 50.0% 2 / 4 totaltotal 76.5% 49 / 64 CC 4 SCAR 7.4
CC
4
Cov
80%
write_dac
4.0
read_config
1.6
change_config
1.5
CRAP 2.1
« MAX11200.pm ↑ Summary AnalogConverters.pm »
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, 2018-2023 -- leonerd@leonerd.org.uk
5  
6 3 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Object::Pad 0.800;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package Device::Chip::DAC75xx 0.16;
11 class Device::Chip::DAC75xx
12 :isa(Device::Chip);
13  
14 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =encoding UTF-8
18  
19 =head1 NAME
20  
21 C<Device::Chip::DAC75xx> - common chip driver for F<DAC75xx>-family DACs
22  
23 =head1 DESCRIPTION
24  
25 This L<Device::Chip> subclass provides a base class for specific chip drivers
26 for chips in the F<Texas Instruments> DAC 75xx family.
27  
28 The reader is presumed to be familiar with the general operation of this chip;
29 the documentation here will not attempt to explain or define chip-specific
30 concepts or features, only the use of this module to access them.
31  
32 =cut
33  
34 =head1 METHODS
35  
36 The following methods documented in an C<await> expression return L<Future>
37 instances.
38  
39 =cut
40  
41 3 my %NAME_TO_POWERDOWN = (
42 normal => 0,
43 "1k" => 1,
44 "100k" => 2,
45 "hiZ" => 3,
46 );
47  
48 # Chip has no config registers
49 0 ▶async method read_config () { return {} }
Subroutine read_config: not called CC=1 SCAR=4.6
Pod undocumented
50 0 ▶async method change_config (%) { }
Subroutine change_config: not called CC=1 SCAR=4.1
Pod undocumented
51  
52 =head2 write_dac
53  
54 await $chip->write_dac( $dac, $powerdown );
55  
56 Writes a new value for the DAC output and powerdown state.
57  
58 C<$powerdown> is optional and will default to C<normal> if not provided. Must
59 be one of the following four values
60  
61 normal 1k 100k hiZ
62  
63 =cut
64  
65 6 ▶async method write_dac ( $dac, $powerdown = undef )
Subroutine write_dac: called CC=4 SCAR=13.9
Pod documented
66 6 {
67 6 $dac &= 0x0FFF;
68  
69 6 my $pd = 0;
70 6 ▶ $pd = $NAME_TO_POWERDOWN{$powerdown} // croak "Unrecognised powerdown state '$powerdown'"
Branch: 1 branch
BranchTrueFalseTotal
if defined $powerdown 2 4 6
Condition50%1/2
$NAME_TO_POWERDOWN{$powerdown} // croak("Unrecognised powerdown state '${powerdown}'")
l!l
20
MC/DC0%0/1
$NAME_TO_POWERDOWN{$powerdown} // croak("Unrecognised powerdown state '${powerdown}'")
$NAME_TO_POWERDOWN{$powerdown}
Truth table50%1/2
A
A= $NAME_TO_POWERDOWN{$powerdown}
Aresult
11
00
71 if defined $powerdown;
72  
73 6 await $self->_write( $pd << 12 | $dac );
74 3 }
75  
76 =head2 write_dac_ratio
77  
78 await $chip->write_dac_ratio( $ratio );
79  
80 Writes a new value for the DAC output as a scaled ratio between 0.0 and 1.0.
81  
82 =cut
83  
84 2 ▶async method write_dac_ratio ( $ratio )
Subroutine write_dac_ratio: called CC=1 SCAR=0.0
Pod documented
85 2 {
86 2 await $self->write_dac( $ratio * 2**12 );
87 3 }
88  
89 =head1 AUTHOR
90  
91 Paul Evans <leonerd@leonerd.org.uk>
92  
93 =cut
94  
95 3 0x55AA;
« MAX11200.pm ↑ Summary AnalogConverters.pm »