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   128835 use v5.26;
  2         16  
7 2     2   12 use Object::Pad 0.66;
  2         23  
  2         12  
8              
9             package Device::Chip::SSD1306::SPI4 0.13;
10             class Device::Chip::SSD1306::SPI4
11 1     1   606 :isa(Device::Chip::SSD1306);
  1         2  
  1         36  
12              
13 2     2   478 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   96 use constant PROTOCOL => "SPI";
  2         4  
  2         1499  
30              
31             method SPI_options
32 1     1 0 335 {
33             return (
34 1         7 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             field $dc;
49              
50 1         2 method mount ( $adapter, %params )
  1         6  
  1         4  
  1         1  
51 1     1 1 74 {
52             $dc = delete $params{dc} or
53 1 50       6 die "Require a 'dc' parameter";
54              
55 1         10 return $self->SUPER::mount( $adapter, %params );
56             }
57              
58             # passthrough
59 0     0 0 0 method power ( $on ) { $self->protocol->power( $on ) }
  0         0  
  0         0  
  0         0  
  0         0  
60              
61 2         6 method set_dc ( $on )
  2         5  
  2         4  
62 2     2 0 6 {
63 2         8 $self->protocol->write_gpios( { $dc => $on } );
64             }
65              
66 1         2 async method send_cmd ( @vals )
  1         5  
  1         2  
67 1         3 {
68 1         6 await $self->set_dc( 0 );
69 1         9224 await $self->protocol->readwrite( join "", map { chr } @vals );
70 1     1 0 405 }
71              
72 1         3 async method send_data ( $bytes )
  1         5  
  1         2  
73 1         6 {
74 1         5 await $self->set_dc( 1 );
75 1         1262 await $self->protocol->readwrite( $bytes );
76 1     1 0 5031 }
77              
78             =head1 AUTHOR
79              
80             Paul Evans
81              
82             =cut
83              
84             0x55AA;