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, 2018-2020 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
3
|
|
1473
|
use v5.26; |
|
2
|
|
|
|
|
7
|
|
7
|
2
|
|
|
2
|
|
26
|
use Object::Pad 0.35; # role :compat(invokable) |
|
2
|
|
|
|
|
25
|
|
|
2
|
|
|
|
|
12
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::ProtocolBase::SPI 0.25; |
10
|
|
|
|
|
|
|
role Device::Chip::ProtocolBase::SPI :compat(invokable); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
C - a role for implementing SPI protocols |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This role (or abstract base class) provides some convenient wrapper methods |
19
|
|
|
|
|
|
|
for providing higher-level SPI protocol implementations, by using simpler |
20
|
|
|
|
|
|
|
lower-level ones. It can be used by implementation classes to help provide |
21
|
|
|
|
|
|
|
parts of the API. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 WRAPPER METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 write |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
await $protocol->write( $words ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
A wrapper for L that ignores the result. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
4
|
method write ( $words ) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
38
|
1
|
|
|
1
|
1
|
33
|
{ |
39
|
1
|
|
|
|
|
3
|
$self->readwrite( $words )->then_done(); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 read |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$words = await $protocol->read( $len ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
A wrapper for L that sends unspecified data which the chip will |
47
|
|
|
|
|
|
|
ignore, returning the result. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
This implementation currently sends all-bits-low. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
3
|
method read ( $len ) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
54
|
1
|
|
|
1
|
1
|
33
|
{ |
55
|
1
|
|
|
|
|
5
|
$self->readwrite( "\x00" x $len ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 write_no_ss |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A wrapper for L that ignores the result. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
2
|
method write_no_ss ( $words ) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
65
|
1
|
|
|
2
|
1
|
4
|
{ |
66
|
1
|
|
|
|
|
5
|
$self->readwrite_no_ss( $words )->then_done(); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 read_no_ss |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
A wrapper for L that sends unspecified data which the chip |
72
|
|
|
|
|
|
|
will ignore, returning the result. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This implemention currenetly sends all-bits-low. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
2
|
method read_no_ss ( $len ) |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
3
|
|
79
|
1
|
|
|
2
|
1
|
3
|
{ |
80
|
1
|
|
|
|
|
5
|
$self->readwrite_no_ss( "\x00" x $len ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 readwrite |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$words_in = await $protocol->readwrite( $words_out ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
A wrapper for performing a complete SPI transfer, using L, |
88
|
|
|
|
|
|
|
L, L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
3
|
|
|
|
|
6
|
method readwrite ( $words_out ) |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
4
|
|
93
|
3
|
|
|
4
|
1
|
38
|
{ |
94
|
|
|
|
|
|
|
$self->assert_ss |
95
|
3
|
|
|
6
|
|
11391
|
->then( sub { $self->readwrite_no_ss( $words_out ) } ) |
96
|
|
|
|
|
|
|
->followed_by( sub { |
97
|
3
|
|
|
3
|
|
3645
|
my ( $f ) = @_; |
98
|
3
|
|
|
|
|
61
|
$self->release_ss->then( sub { $f } ); |
|
3
|
|
|
|
|
3896
|
|
99
|
3
|
|
|
|
|
10
|
}); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 write_then_read |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$words_in = await $protocol->write_then_read( $words_out, $len_in ) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
A wrapper for performing a complete SPI transfer in two phases, using |
107
|
|
|
|
|
|
|
L, L, L and L. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
4
|
method write_then_read ( $words_out, $len_in ) |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
112
|
1
|
|
|
1
|
1
|
32
|
{ |
113
|
|
|
|
|
|
|
$self->assert_ss |
114
|
1
|
|
|
2
|
|
1415
|
->then( sub { $self->write_no_ss( $words_out ) } ) |
115
|
1
|
|
|
1
|
|
1312
|
->then( sub { $self->read_no_ss( $len_in ) } ) |
116
|
|
|
|
|
|
|
->followed_by( sub { |
117
|
1
|
|
|
1
|
|
1281
|
my ( $f ) = @_; |
118
|
1
|
|
|
|
|
5
|
$self->release_ss->then( sub { $f } ); |
|
1
|
|
|
|
|
1220
|
|
119
|
1
|
|
|
|
|
4
|
}); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Paul Evans |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
0x55AA; |