File Coverage

blib/lib/Device/Chip/DAC75xx.pm
Criterion Covered Total %
statement 27 36 75.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 6 8 75.0
pod 2 4 50.0
total 38 53 71.7


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-2022 -- leonerd@leonerd.org.uk
5              
6 3     3   30 use v5.26;
  3         8  
7 3     3   14 use Object::Pad 0.57;
  3         29  
  3         13  
8              
9             package Device::Chip::DAC75xx 0.13;
10             class Device::Chip::DAC75xx
11             :isa(Device::Chip);
12              
13 3     3   822 use Carp;
  3         13  
  3         176  
14 3     3   17 use Future::AsyncAwait;
  3         5  
  3         26  
15              
16             =encoding UTF-8
17              
18             =head1 NAME
19              
20             C - common chip driver for F-family DACs
21              
22             =head1 DESCRIPTION
23              
24             This L subclass provides a base class for specific chip drivers
25             for chips in the F DAC 75xx family.
26              
27             The reader is presumed to be familiar with the general operation of this chip;
28             the documentation here will not attempt to explain or define chip-specific
29             concepts or features, only the use of this module to access them.
30              
31             =cut
32              
33             =head1 METHODS
34              
35             The following methods documented in an C expression return L
36             instances.
37              
38             =cut
39              
40             my %NAME_TO_POWERDOWN = (
41             normal => 0,
42             "1k" => 1,
43             "100k" => 2,
44             "hiZ" => 3,
45             );
46              
47             # Chip has no config registers
48 0     0 0 0 async method read_config () { return {} }
  0         0  
  0         0  
  0         0  
  0         0  
49 0     0 0 0 async method change_config (%) { }
  0         0  
  0         0  
  0         0  
50              
51             =head2 write_dac
52              
53             await $chip->write_dac( $dac, $powerdown );
54              
55             Writes a new value for the DAC output and powerdown state.
56              
57             C<$powerdown> is optional and will default to C if not provided. Must
58             be one of the following four values
59              
60             normal 1k 100k hiZ
61              
62             =cut
63              
64 6         12 async method write_dac ( $dac, $powerdown = undef )
  6         9  
  6         10  
  6         6  
65 6         38 {
66 6         10 $dac &= 0x0FFF;
67              
68 6         8 my $pd = 0;
69 6 100 33     21 $pd = $NAME_TO_POWERDOWN{$powerdown} // croak "Unrecognised powerdown state '$powerdown'"
70             if defined $powerdown;
71              
72 6         22 await $self->_write( $pd << 12 | $dac );
73 6     6 1 20457 }
74              
75             =head2 write_dac_ratio
76              
77             await $chip->write_dac_ratio( $ratio );
78              
79             Writes a new value for the DAC output as a scaled ratio between 0.0 and 1.0.
80              
81             =cut
82              
83 2         4 async method write_dac_ratio ( $ratio )
  2         4  
  2         3  
84 2         5 {
85 2         8 await $self->write_dac( $ratio * 2**12 );
86 2     2 1 6137 }
87              
88             =head1 AUTHOR
89              
90             Paul Evans
91              
92             =cut
93              
94             0x55AA;