in reply to ST7789V2 LCD Controller

Not wanting to delve into C programming just yet (I had to do some C++ at uni and didn't get very far!), I have been trying to approach the problem with just Perl. This is what I have got.

use strict; use warnings; use RPi::SPI; # Initialize SPI: bus 0, 8 MHz my $spi = RPi::SPI->new(0, 8000000); # Reset display (if necessary) sub reset_display { # Handle reset } # Send command to the display sub send_command { my ($cmd) = @_; my $data = \[ $cmd ]; # Create an array reference for a single co +mmand byte print "Sending command\n"; $spi->rw($data, 1); # Send command via SPI } # Send data to the display (ensure data is an array reference) sub send_data { my ($data_ref) = @_; print "Sending data\n"; $spi->rw($data_ref); # Send data via SPI } # Initialize the display (according to the display's datasheet) sub init_display { send_command(0x01); # Command: software reset } reset_display(); init_display();

I'm getting an error from $spi->rw($data, 1); that doesn't seem to make sense. The error is data param must be an array reference but the RPi::SPI documentation says that rw takes buf (arrayref) and len (integer). It doesn't mention a data parameter and I am giving it an arrayref and an integer!

I've searched the source code and the error text is not there.

Some help debugging this would be appreciated please

Replies are listed 'Best First'.
Re^2: ST7789V2 LCD Controller
by tybalt89 (Monsignor) on Sep 28, 2024 at 23:36 UTC
    my $data = \[ $cmd ]; # Create an array reference for a single comman +d byte

    should be

    my $data = [ $cmd ]; # Create an array reference for a single command + byte

    You were sending a reference to a reference to an array :(