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, 2020-2022 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
133672
|
use v5.26; |
|
2
|
|
|
|
|
39
|
|
7
|
2
|
|
|
2
|
|
17
|
use Object::Pad 0.57; |
|
2
|
|
|
|
|
27
|
|
|
2
|
|
|
|
|
11
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::ADC121Sx 0.14; |
10
|
|
|
|
|
|
|
class Device::Chip::ADC121Sx |
11
|
|
|
|
|
|
|
:isa(Device::Chip); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
664
|
use Future::AsyncAwait; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
111
|
use constant PROTOCOL => "SPI"; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1231
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - chip driver for F family |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Device::Chip::ADC121Sx; |
24
|
|
|
|
|
|
|
use Future::AsyncAwait; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $chip = Device::Chip::ADC121Sx->new; |
27
|
|
|
|
|
|
|
await $chip->mount( Device::Chip::Adapter::...->new ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
printf "The reading is %d\n", await $chip->read_adc; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This L subclass provides specific communications to a chip in |
34
|
|
|
|
|
|
|
the F F family, such as F, |
35
|
|
|
|
|
|
|
F or F. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
The reader is presumed to be familiar with the general operation of this chip; |
38
|
|
|
|
|
|
|
the documentation here will not attempt to explain or define chip-specific |
39
|
|
|
|
|
|
|
concepts or features, only the use of this module to access them. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub SPI_options ( $, %params ) |
44
|
1
|
|
|
1
|
0
|
436
|
{ |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
45
|
|
|
|
|
|
|
return ( |
46
|
1
|
|
|
|
|
6
|
mode => 2, |
47
|
|
|
|
|
|
|
max_bitrate => 20E6, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 METHODS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
The following methods documented in an C expression return L |
54
|
|
|
|
|
|
|
instances. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Chip has no config registers |
59
|
0
|
|
|
0
|
0
|
0
|
async method read_config () { return {} } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
60
|
0
|
|
|
0
|
0
|
0
|
async method change_config (%) { } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 read_adc |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$value = await $chip->read_adc; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Performs a conversion and returns the result as a plain unsigned 12-bit |
67
|
|
|
|
|
|
|
integer. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
4
|
async method read_adc () |
|
2
|
|
|
|
|
13
|
|
72
|
2
|
|
|
|
|
6
|
{ |
73
|
2
|
|
|
|
|
10
|
my $buf = await $self->protocol->read( 2 ); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
11085
|
return unpack "S>", $buf; |
76
|
2
|
|
|
2
|
1
|
832
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 read_adc_ratio |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$ratio = await $chip->read_adc_ratio; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Performs a conversion and returns the result as a floating-point number |
83
|
|
|
|
|
|
|
between 0 and 1. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
2
|
async method read_adc_ratio () |
|
1
|
|
|
|
|
2
|
|
88
|
1
|
|
|
|
|
5
|
{ |
89
|
|
|
|
|
|
|
# ADC121Sx is 12-bit |
90
|
1
|
|
|
|
|
7
|
return ( await $self->read_adc ) / 2**12; |
91
|
1
|
|
|
1
|
1
|
4429
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AUTHOR |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Paul Evans |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
0x55AA; |