File Coverage

blib/lib/Device/Chip/DAC75xx.pm
Criterion Covered Total %
statement 30 39 76.9
branch 2 2 100.0
condition 1 3 33.3
subroutine 7 9 77.7
pod 2 4 50.0
total 42 57 73.6


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, 2018-2023 -- leonerd@leonerd.org.uk
5              
6 3     3   34 use v5.26;
  3         10  
7 3     3   15 use warnings;
  3         6  
  3         177  
8 3     3   14 use Object::Pad 0.800;
  3         19  
  3         109  
9              
10             package Device::Chip::DAC75xx 0.16;
11             class Device::Chip::DAC75xx
12             :isa(Device::Chip);
13              
14 3     3   1109 use Carp;
  3         6  
  3         4117  
15 3     3   20 use Future::AsyncAwait;
  3         10  
  3         20  
16              
17             =encoding UTF-8
18              
19             =head1 NAME
20              
21             C - common chip driver for F-family DACs
22              
23             =head1 DESCRIPTION
24              
25             This L subclass provides a base class for specific chip drivers
26             for chips in the F 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 expression return L
37             instances.
38              
39             =cut
40              
41             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     0 0 0 async method read_config () { return {} }
  0         0  
  0         0  
  0         0  
  0         0  
50 0     0 0 0 async method change_config (%) { }
  0         0  
  0         0  
  0         0  
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 if not provided. Must
59             be one of the following four values
60              
61             normal 1k 100k hiZ
62              
63             =cut
64              
65 6     6 1 37649 async method write_dac ( $dac, $powerdown = undef )
  6         28  
  6         12  
  6         15  
  6         12  
66 6         17 {
67 6         12 $dac &= 0x0FFF;
68              
69 6         12 my $pd = 0;
70 6 100 33     32 $pd = $NAME_TO_POWERDOWN{$powerdown} // croak "Unrecognised powerdown state '$powerdown'"
71             if defined $powerdown;
72              
73 6         34 await $self->_write( $pd << 12 | $dac );
74             }
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     2 1 11545 async method write_dac_ratio ( $ratio )
  2         10  
  2         4  
  2         3  
85 2         5 {
86 2         13 await $self->write_dac( $ratio * 2**12 );
87             }
88              
89             =head1 AUTHOR
90              
91             Paul Evans
92              
93             =cut
94              
95             0x55AA;