| 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 | ▶ | use v5.26; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Object::Pad 0.800; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | package Device::Chip::SSD1306::SPI4 0.16; | ||||||||||
| 11 | class Device::Chip::SSD1306::SPI4 | ||||||||||
| 12 | 1 | ▶ | :isa(Device::Chip::SSD1306); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 2 | ▶ | use Future::AsyncAwait; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | =head1 NAME | ||||||||||
| 17 | |||||||||||
| 18 | C<Device::Chip::SSD1306::SPI4> - use a F<SSD1306> OLED driver in 4-wire SPI mode | ||||||||||
| 19 | |||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||
| 21 | |||||||||||
| 22 | This L<Device::Chip::SSD1306> subclass provides specific communication to an | ||||||||||
| 23 | F<SSD1306> chip attached via SPI in 4-wire mode; using the C<D/C#> pin. | ||||||||||
| 24 | |||||||||||
| 25 | For actually interacting with the attached module, see the main | ||||||||||
| 26 | L<Device::Chip::SSD1306> documentation. | ||||||||||
| 27 | |||||||||||
| 28 | =cut | ||||||||||
| 29 | |||||||||||
| 30 | 2 | ▶ | use constant PROTOCOL => "SPI"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | |||||||||||
| 32 | method SPI_options | ||||||||||
| 33 | 1 | ▶ | { | ||||||||
|
Subroutine
SPI_options: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | return ( | ||||||||||
| 35 | 1 | mode => 0, | |||||||||
| 36 | max_bitrate => 1E6, | ||||||||||
| 37 | ); | ||||||||||
| 38 | 2 | } | |||||||||
| 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<D/C#> pin | ||||||||||
| 45 | of the chip. | ||||||||||
| 46 | |||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | 2 | field $dc; | |||||||||
| 50 | |||||||||||
| 51 | 1 | ▶ | method mount ( $adapter, %params ) | ||||||||
|
Subroutine
mount: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 52 | { | ||||||||||
| 53 | $dc = delete $params{dc} or | ||||||||||
| 54 | 1 | ▶ | die "Require a 'dc' parameter"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 1 | return $self->SUPER::mount( $adapter, %params ); | |||||||||
| 57 | 2 | } | |||||||||
| 58 | |||||||||||
| 59 | # passthrough | ||||||||||
| 60 | 0 | ▶ | method power ( $on ) { $self->protocol->power( $on ) } | ||||||||
|
Subroutine
power: not called CC=1 SCAR=4.6
Pod
undocumented
| |||||||||||
| 61 | |||||||||||
| 62 | 2 | ▶ | method set_dc ( $on ) | ||||||||
|
Subroutine
set_dc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 63 | { | ||||||||||
| 64 | 2 | $self->protocol->write_gpios( { $dc => $on } ); | |||||||||
| 65 | 2 | } | |||||||||
| 66 | |||||||||||
| 67 | 1 | ▶ | async method send_cmd ( @vals ) | ||||||||
|
Subroutine
send_cmd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 68 | 1 | { | |||||||||
| 69 | 1 | await $self->set_dc( 0 ); | |||||||||
| 70 | 1 | await $self->protocol->readwrite( join "", map { chr } @vals ); | |||||||||
| 71 | 2 | } | |||||||||
| 72 | |||||||||||
| 73 | 1 | ▶ | async method send_data ( $bytes ) | ||||||||
|
Subroutine
send_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 74 | 1 | { | |||||||||
| 75 | 1 | await $self->set_dc( 1 ); | |||||||||
| 76 | 1 | await $self->protocol->readwrite( $bytes ); | |||||||||
| 77 | 2 | } | |||||||||
| 78 | |||||||||||
| 79 | =head1 AUTHOR | ||||||||||
| 80 | |||||||||||
| 81 | Paul Evans <leonerd@leonerd.org.uk> | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||
| 85 | 2 | 0x55AA; | |||||||||