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   312512 use v5.26;
  2         19  
7 2     2   12 use warnings;
  2         4  
  2         66  
8 2     2   11 use Object::Pad 0.800;
  2         15  
  2         92  
9              
10             package Device::Chip::LTC2400 0.15;
11             class Device::Chip::LTC2400
12             :isa(Device::Chip);
13              
14 2     2   669 use Future::AsyncAwait;
  2         4  
  2         12  
15              
16 2     2   131 use constant PROTOCOL => "SPI";
  2         5  
  2         1288  
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 447 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         3 async method read_adc ()
  1         2  
69 1         3 {
70 1         6 my $bytes = await $self->protocol->readwrite( "\x00" x 4 );
71              
72 1         9283 my $value = unpack "L>", $bytes;
73              
74 1 50       6 if( $value & 1<<30 ) {
75 0         0 return Future->fail( "Expected dummy bit LOW" );
76             }
77 1 50       4 if( $value & 1<<31 ) {
78 0         0 return Future->done( { EOC => 0 } );
79             }
80              
81 1         2 my $sig = ( $value & 1<<29 ) > 0;
82 1         3 my $exr = ( $value & 1<<28 ) > 0;
83              
84 1         2 $value &= ( 1<<28 )-1;
85 1         2 $value >>= 4;
86              
87             return {
88 1         9 EOC => 1,
89             SIG => $sig,
90             EXR => $exr,
91             VALUE => $value,
92             };
93 1     1 1 344 }
94              
95             =head1 AUTHOR
96              
97             Paul Evans
98              
99             =cut
100              
101             0x55AA;