LTC2400.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 50.0% 1 / 2 totaltotal 89.1% 41 / 46 CC 3 SCAR 5.3
CC
3
Cov
89%
read_adc
3.1
BEGIN
1.0
BEGIN
1.0
CRAP 1.7
« AD5691R.pm ↑ Summary DAC7571.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, 2017-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::LTC2400 0.16;
11 class Device::Chip::LTC2400
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::LTC2400> - chip driver for F<LTC2400>
21  
22 =head1 DESCRIPTION
23  
24 This L<Device::Chip> subclass provides specific communications to a
25 F<Linear Technologies> F<LTC2400> chip attached to a computer via an SPI
26 adapter.
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 sub SPI_options
35 1 ▶{
Subroutine SPI_options: called CC=1 SCAR=0.0
Pod undocumented
36 return (
37 1 mode => 0,
38 max_bitrate => 2E6,
39 );
40 }
41  
42 =head1 METHODS
43  
44 The following methods documented in an C<await> expression return L<Future>
45 instances.
46  
47 =cut
48  
49 =head2 read_adc
50  
51 $reading = await $chip->read_adc;
52  
53 Returns a C<HASH> reference containing the fields obtained after a successful
54 conversion.
55  
56 The following values will be stored in the hash:
57  
58 EOC => 0 | 1
59 EXR => 0 | 1
60 SIG => 0 | 1
61 VALUE => (a 24bit integer)
62  
63 If the C<EOC> value is false, then a conversion is still in progress and no
64 other fields will be provided.
65  
66 =cut
67  
68 1 ▶async method read_adc ()
Subroutine read_adc: called CC=3 SCAR=11.3
Pod documented
69 1 {
70 1 my $bytes = await $self->protocol->readwrite( "\x00" x 4 );
71  
72 1 my $value = unpack "L>", $bytes;
73  
74 1 ▶ if( $value & 1<<30 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value & 1073741824) 0 1 1
75 0 return Future->fail( "Expected dummy bit LOW" );
76 }
77 1 ▶ if( $value & 1<<31 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value & 2147483648) 0 1 1
78 0 return Future->done( { EOC => 0 } );
79 }
80  
81 1 my $sig = ( $value & 1<<29 ) > 0;
82 1 my $exr = ( $value & 1<<28 ) > 0;
83  
84 1 $value &= ( 1<<28 )-1;
85 1 $value >>= 4;
86  
87 return {
88 1 EOC => 1,
89 SIG => $sig,
90 EXR => $exr,
91 VALUE => $value,
92 };
93 2 }
94  
95 =head1 AUTHOR
96  
97 Paul Evans <leonerd@leonerd.org.uk>
98  
99 =cut
100  
101 2 0x55AA;
« AD5691R.pm ↑ Summary DAC7571.pm »