File Coverage

blib/lib/Device/Chip/SSD1306/SPI4.pm
Criterion Covered Total %
statement 42 47 89.3
branch 1 2 50.0
condition n/a
subroutine 10 11 90.9
pod 1 6 16.6
total 54 66 81.8


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, 2015-2022 -- leonerd@leonerd.org.uk
5              
6 2     2   104747 use v5.26;
  2         16  
7 2     2   9 use Object::Pad 0.57;
  2         21  
  2         10  
8              
9             package Device::Chip::SSD1306::SPI4 0.12;
10             class Device::Chip::SSD1306::SPI4
11 1     1   491 :isa(Device::Chip::SSD1306);
  1         2  
  1         30  
12              
13 2     2   402 use Future::AsyncAwait;
  2         4  
  2         9  
14              
15             =head1 NAME
16              
17             C - use a F OLED driver in 4-wire SPI mode
18              
19             =head1 DESCRIPTION
20              
21             This L subclass provides specific communication to an
22             F chip attached via SPI in 4-wire mode; using the C pin.
23              
24             For actually interacting with the attached module, see the main
25             L documentation.
26              
27             =cut
28              
29 2     2   94 use constant PROTOCOL => "SPI";
  2         4  
  2         1216  
30              
31             method SPI_options
32 1     1 0 288 {
33             return (
34 1         5 mode => 0,
35             max_bitrate => 1E6,
36             );
37             }
38              
39             =head1 MOUNT PARAMETERS
40              
41             =head2 dc
42              
43             The name of the GPIO line on the adapter that is connected to the C pin
44             of the chip.
45              
46             =cut
47              
48 1         1 method mount ( $adapter, %params )
  1         2  
  1         3  
  1         1  
49 1     1 1 83 {
50             $self->{dc} = delete $params{dc} or
51 1 50       7 die "Require a 'dc' parameter";
52              
53 1         8 return $self->SUPER::mount( $adapter, %params );
54             }
55              
56             # passthrough
57 0     0 0 0 method power ( $on ) { $self->protocol->power( $on ) }
  0         0  
  0         0  
  0         0  
  0         0  
58              
59 2         4 method set_dc ( $dc )
  2         3  
  2         3  
60 2     2 0 3 {
61 2         13 $self->protocol->write_gpios( { $self->{dc} => $dc } );
62             }
63              
64 1         2 async method send_cmd ( @vals )
  1         2  
  1         1  
65 1         2 {
66 1         4 await $self->set_dc( 0 );
67 1         7523 await $self->protocol->readwrite( join "", map { chr } @vals );
68 1     1 0 305 }
69              
70 1         2 async method send_data ( $bytes )
  1         2  
  1         1  
71 1         3 {
72 1         3 await $self->set_dc( 1 );
73 1         1038 await $self->protocol->readwrite( $bytes );
74 1     1 0 4102 }
75              
76             =head1 AUTHOR
77              
78             Paul Evans
79              
80             =cut
81              
82             0x55AA;