| 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
|
|
1206
|
use v5.26; |
|
|
2
|
|
|
|
|
5
|
|
|
7
|
2
|
|
|
2
|
|
18
|
use Object::Pad 0.35; # role :compat(invokable) |
|
|
2
|
|
|
|
|
20
|
|
|
|
2
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Device::Chip::ProtocolBase::SPI 0.23; |
|
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
|
|
|
|
|
2
|
method write ( $words ) |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
2
|
|
|
38
|
1
|
|
|
1
|
1
|
21
|
{ |
|
39
|
1
|
|
|
|
|
8
|
$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
|
|
|
|
|
2
|
method read ( $len ) |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2
|
|
|
54
|
1
|
|
|
1
|
1
|
20
|
{ |
|
55
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
3
|
method write_no_ss ( $words ) |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1
|
|
|
65
|
1
|
|
|
2
|
1
|
2
|
{ |
|
66
|
1
|
|
|
|
|
3
|
$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
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
2
|
|
|
79
|
1
|
|
|
2
|
1
|
4
|
{ |
|
80
|
1
|
|
|
|
|
4
|
$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
|
|
|
|
|
4
|
method readwrite ( $words_out ) |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
4
|
|
|
93
|
3
|
|
|
4
|
1
|
26
|
{ |
|
94
|
|
|
|
|
|
|
$self->assert_ss |
|
95
|
3
|
|
|
6
|
|
9563
|
->then( sub { $self->readwrite_no_ss( $words_out ) } ) |
|
96
|
|
|
|
|
|
|
->followed_by( sub { |
|
97
|
3
|
|
|
3
|
|
3055
|
my ( $f ) = @_; |
|
98
|
3
|
|
|
|
|
10
|
$self->release_ss->then( sub { $f } ); |
|
|
3
|
|
|
|
|
2905
|
|
|
99
|
3
|
|
|
|
|
8
|
}); |
|
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
|
|
|
|
|
17
|
method write_then_read ( $words_out, $len_in ) |
|
|
1
|
|
|
|
|
19
|
|
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
1
|
|
|
112
|
1
|
|
|
1
|
1
|
19
|
{ |
|
113
|
|
|
|
|
|
|
$self->assert_ss |
|
114
|
1
|
|
|
2
|
|
1080
|
->then( sub { $self->write_no_ss( $words_out ) } ) |
|
115
|
1
|
|
|
1
|
|
1110
|
->then( sub { $self->read_no_ss( $len_in ) } ) |
|
116
|
|
|
|
|
|
|
->followed_by( sub { |
|
117
|
1
|
|
|
1
|
|
957
|
my ( $f ) = @_; |
|
118
|
1
|
|
|
|
|
4
|
$self->release_ss->then( sub { $f } ); |
|
|
1
|
|
|
|
|
963
|
|
|
119
|
1
|
|
|
|
|
4
|
}); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Paul Evans |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
0x55AA; |