File Coverage

blib/lib/Device/Chip/SSD1306/SPI4.pm
Criterion Covered Total %
statement 43 48 89.5
branch 1 2 50.0
condition n/a
subroutine 10 11 90.9
pod 1 5 20.0
total 55 66 83.3


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