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
|
|
129225
|
use v5.26; |
|
2
|
|
|
|
|
16
|
|
7
|
2
|
|
|
2
|
|
12
|
use Object::Pad 0.57; |
|
2
|
|
|
|
|
23
|
|
|
2
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::MAX1166x 0.14; |
10
|
|
|
|
|
|
|
class Device::Chip::MAX1166x |
11
|
|
|
|
|
|
|
:isa(Device::Chip); |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
695
|
use Future::AsyncAwait; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
113
|
use constant PROTOCOL => "SPI"; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1179
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
C - chip driver for F family |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Device::Chip::MAX1166x; |
24
|
|
|
|
|
|
|
use Future::AsyncAwait; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $chip = Device::Chip::MAX1166x->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, F or |
35
|
|
|
|
|
|
|
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
|
413
|
{ |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
45
|
|
|
|
|
|
|
return ( |
46
|
1
|
|
|
|
|
5
|
mode => 2, |
47
|
|
|
|
|
|
|
max_bitrate => 8E6, |
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
|
|
|
|
|
3
|
|
72
|
2
|
|
|
|
|
6
|
{ |
73
|
2
|
|
|
|
|
8
|
my $buf = await $self->protocol->read( 2 ); |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
10830
|
return unpack "S>", $buf; |
76
|
2
|
|
|
2
|
1
|
312
|
} |
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
|
|
|
|
|
4
|
{ |
89
|
|
|
|
|
|
|
# MAX1166x reads as 14-bit with some trailing zeroes |
90
|
|
|
|
|
|
|
# First bit is invalid so must mask it off |
91
|
1
|
|
|
|
|
6
|
return ( ( await $self->read_adc ) & 0x7FFF ) / 2**14; |
92
|
1
|
|
|
1
|
1
|
3961
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Paul Evans |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
0x55AA; |