File Coverage

blib/lib/Device/Chip/LTC2400.pm
Criterion Covered Total %
statement 28 30 93.3
branch 2 4 50.0
condition n/a
subroutine 7 7 100.0
pod 1 2 50.0
total 38 43 88.3


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, 2017-2023 -- leonerd@leonerd.org.uk
5              
6 2     2   344086 use v5.26;
  2         8  
7 2     2   11 use warnings;
  2         5  
  2         122  
8 2     2   27 use Object::Pad 0.800;
  2         16  
  2         84  
9              
10             package Device::Chip::LTC2400 0.16;
11             class Device::Chip::LTC2400
12             :isa(Device::Chip);
13              
14 2     2   800 use Future::AsyncAwait;
  2         7  
  2         26  
15              
16 2     2   185 use constant PROTOCOL => "SPI";
  2         5  
  2         1866  
17              
18             =head1 NAME
19              
20             C - chip driver for F
21              
22             =head1 DESCRIPTION
23              
24             This L subclass provides specific communications to a
25             F F 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             {
36             return (
37 1     1 0 592 mode => 0,
38             max_bitrate => 2E6,
39             );
40             }
41              
42             =head1 METHODS
43              
44             The following methods documented in an C expression return L
45             instances.
46              
47             =cut
48              
49             =head2 read_adc
50              
51             $reading = await $chip->read_adc;
52              
53             Returns a C 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 value is false, then a conversion is still in progress and no
64             other fields will be provided.
65              
66             =cut
67              
68 1     1 1 1933 async method read_adc ()
  1         5  
  1         8  
69 1         3 {
70 1         8 my $bytes = await $self->protocol->readwrite( "\x00" x 4 );
71              
72 1         8927 my $value = unpack "L>", $bytes;
73              
74 1 50       7 if( $value & 1<<30 ) {
75 0         0 return Future->fail( "Expected dummy bit LOW" );
76             }
77 1 50       5 if( $value & 1<<31 ) {
78 0         0 return Future->done( { EOC => 0 } );
79             }
80              
81 1         4 my $sig = ( $value & 1<<29 ) > 0;
82 1         3 my $exr = ( $value & 1<<28 ) > 0;
83              
84 1         4 $value &= ( 1<<28 )-1;
85 1         4 $value >>= 4;
86              
87             return {
88 1         13 EOC => 1,
89             SIG => $sig,
90             EXR => $exr,
91             VALUE => $value,
92             };
93             }
94              
95             =head1 AUTHOR
96              
97             Paul Evans
98              
99             =cut
100              
101             0x55AA;