File Coverage

blib/lib/Device/Chip/LTC2400.pm
Criterion Covered Total %
statement 25 27 92.5
branch 2 4 50.0
condition n/a
subroutine 6 6 100.0
pod 1 2 50.0
total 34 39 87.1


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-2022 -- leonerd@leonerd.org.uk
5              
6 2     2   131329 use v5.26;
  2         18  
7 2     2   12 use Object::Pad 0.57;
  2         41  
  2         13  
8              
9             package Device::Chip::LTC2400 0.14;
10             class Device::Chip::LTC2400
11             :isa(Device::Chip);
12              
13 2     2   692 use Future::AsyncAwait;
  2         5  
  2         12  
14              
15 2     2   93 use constant PROTOCOL => "SPI";
  2         5  
  2         1096  
16              
17             =head1 NAME
18              
19             C - chip driver for F
20              
21             =head1 SYNOPSIS
22              
23             This L subclass provides specific communications to a
24             F F chip attached to a computer via an SPI
25             adapter.
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             sub SPI_options
34             {
35             return (
36 1     1 0 481 mode => 0,
37             max_bitrate => 2E6,
38             );
39             }
40              
41             =head1 METHODS
42              
43             The following methods documented in an C expression return L
44             instances.
45              
46             =cut
47              
48             =head2 read_adc
49              
50             $reading = await $chip->read_adc;
51              
52             Returns a C reference containing the fields obtained after a successful
53             conversion.
54              
55             The following values will be stored in the hash:
56              
57             EOC => 0 | 1
58             EXR => 0 | 1
59             SIG => 0 | 1
60             VALUE => (a 24bit integer)
61              
62             If the C value is false, then a conversion is still in progress and no
63             other fields will be provided.
64              
65             =cut
66              
67 1         2 async method read_adc ()
  1         2  
68 1         4 {
69 1         5 my $bytes = await $self->protocol->readwrite( "\x00" x 4 );
70              
71 1         9226 my $value = unpack "L>", $bytes;
72              
73 1 50       7 if( $value & 1<<30 ) {
74 0         0 return Future->fail( "Expected dummy bit LOW" );
75             }
76 1 50       4 if( $value & 1<<31 ) {
77 0         0 return Future->done( { EOC => 0 } );
78             }
79              
80 1         5 my $sig = ( $value & 1<<29 ) > 0;
81 1         2 my $exr = ( $value & 1<<28 ) > 0;
82              
83 1         2 $value &= ( 1<<28 )-1;
84 1         3 $value >>= 4;
85              
86             return {
87 1         10 EOC => 1,
88             SIG => $sig,
89             EXR => $exr,
90             VALUE => $value,
91             };
92 1     1 1 380 }
93              
94             =head1 AUTHOR
95              
96             Paul Evans
97              
98             =cut
99              
100             0x55AA;