MAX1166x.pm

filter: Statementstmt 78.0% 32 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 40.0% 2 / 5 totaltotal 75.0% 42 / 56 CC 1 SCAR 1.0
CC
1
Cov
78%
read_config
1.6
change_config
1.5
BEGIN
1.0
CRAP 1.1
« ADC121Sx.pm ↑ Summary DAC7513.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, 2020-2023 -- leonerd@leonerd.org.uk
5  
6 2 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Object::Pad 0.800;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 package Device::Chip::MAX1166x 0.16;
11 class Device::Chip::MAX1166x
12 :isa(Device::Chip);
13  
14 2 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use constant PROTOCOL => "SPI";
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 =head1 NAME
19  
20 C<Device::Chip::MAX1166x> - chip driver for F<MAX1166x> family
21  
22 =head1 SYNOPSIS
23  
24 use Device::Chip::MAX1166x;
25 use Future::AsyncAwait;
26  
27 my $chip = Device::Chip::MAX1166x->new;
28 await $chip->mount( Device::Chip::Adapter::...->new );
29  
30 printf "The reading is %d\n", await $chip->read_adc;
31  
32 =head1 DESCRIPTION
33  
34 This L<Device::Chip> subclass provides specific communications to a chip in
35 the F<Maxim> F<MAX1166x> family, such as F<MAX11661>, F<MAX11663> or
36 F<MAX11665>.
37  
38 The reader is presumed to be familiar with the general operation of this chip;
39 the documentation here will not attempt to explain or define chip-specific
40 concepts or features, only the use of this module to access them.
41  
42 =cut
43  
44 1 ▶sub SPI_options ( $, %params )
Subroutine SPI_options: called CC=1 SCAR=0.0
Pod undocumented
45 {
46 return (
47 1 mode => 2,
48 max_bitrate => 8E6,
49 );
50 }
51  
52 =head1 METHODS
53  
54 The following methods documented in an C<await> expression return L<Future>
55 instances.
56  
57 =cut
58  
59 # Chip has no config registers
60 0 ▶async method read_config () { return {} }
Subroutine read_config: not called CC=1 SCAR=4.6
Pod undocumented
61 0 ▶async method change_config (%) { }
Subroutine change_config: not called CC=1 SCAR=4.1
Pod undocumented
62  
63 =head2 read_adc
64  
65 $value = await $chip->read_adc;
66  
67 Performs a conversion and returns the result as a plain unsigned 12-bit
68 integer.
69  
70 =cut
71  
72 2 ▶async method read_adc ()
Subroutine read_adc: called CC=1 SCAR=0.0
Pod documented
73 2 {
74 2 my $buf = await $self->protocol->read( 2 );
75  
76 2 return unpack "S>", $buf;
77 2 }
78  
79 =head2 read_adc_ratio
80  
81 $ratio = await $chip->read_adc_ratio;
82  
83 Performs a conversion and returns the result as a floating-point number
84 between 0 and 1.
85  
86 =cut
87  
88 1 ▶async method read_adc_ratio ()
Subroutine read_adc_ratio: called CC=1 SCAR=0.0
Pod documented
89 1 {
90 # MAX1166x reads as 14-bit with some trailing zeroes
91 # First bit is invalid so must mask it off
92 1 return ( ( await $self->read_adc ) & 0x7FFF ) / 2**14;
93 2 }
94  
95 =head1 AUTHOR
96  
97 Paul Evans <leonerd@leonerd.org.uk>
98  
99 =cut
100  
101 2 0x55AA;
« ADC121Sx.pm ↑ Summary DAC7513.pm »