frak / php_spi

An OO PHP interface to SPI devices developed for use on the Raspberry Pi
Other
17 stars 7 forks source link

PHP 7 support #7

Open dneykov opened 6 years ago

dneykov commented 6 years ago

Is there a chance to add PHP 7 support for this library?

Thanks

marius-meissner commented 6 years ago

I created a fork/branch and tried to fix the PHP7 errors: https://github.com/SkydiveMarius/php_spi/tree/php7_support (For the moment the branch is not backward compatible with PHP < 7.0)

The positive news is, that my branch compiles now fine with PHP 7.0.16. The bad news: Some of the tests are failing.

So I compiled the master with PHP 5.6, which compiled also fine, but the same tests are failing with exactly the same reason as on PHP 7.0.

For example the following test is failing:

$spi = new Spi(0, 0);
$data = array(array(1, 2), array(3, 4), array(5, 6), array(7, 8));
$sent = $spi->blockTransfer($data);
if($sent == $data) {
    echo "Passed";
}

Expected $sent:

[
    [1, 2],
    [3, 4],
    [5, 6],
    [7, 8]
]

Actual $sent:

[
    [0, 0],
    [0, 0],
    [0, 0],
    [0, 0]
]

As I never used the extension before, I'm not sure if the test results have been caused by bad environment (testing with Raspberry 3) or real problem in the extension.

Do you have a working extension running? If yes, which result do you receiving executing the mentioned test?

frak commented 6 years ago

I don't have the extension running, but do you have anything connected to your MOSI/O pins?

Data is sent full-duplex, so if you connect your MOSI and MISO pins to each other (GPIO pins 9 and 10) the data received will exactly match the data sent.

marius-meissner commented 6 years ago

@frak Thanks for the big hint, now almost all tests are running fine with PHP 7.0:

=====================================================================
PHP         : /usr/bin/php7.0 
PHP_SAPI    : cli
PHP_VERSION : 7.0.16-4+0~20170306095027.1+jessie~1.gbp278b8e
ZEND_VERSION: 3.0.0
PHP_OS      : Linux - Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l
INI actual  : /home/pi/php_spi/tmp-php.ini
More .INIs  :  
CWD         : /home/pi/php_spi
Extra dirs  : 
VALGRIND    : Not used
=====================================================================
TIME START 2017-12-07 21:15:27
=====================================================================
PASS Spi::__construct() member function [tests/Spi____construct.phpt] 
PASS Spi::blockTransfer() member function [tests/Spi__blockTransfer.phpt] 
PASS Spi::getInfo() member function [tests/Spi__getInfo.phpt] 
PASS Spi::setupTimer() member function [tests/Spi__setupTimer.phpt] 
PASS Spi::transfer() member function [tests/Spi__transfer.phpt] 
FAIL Spi::usecDelay() member function [tests/Spi__usecDelay.phpt] 
=====================================================================
TIME END 2017-12-07 21:16:28

Seems that the timer is hanging forever. Any clue about the cause?

Just for curiosity, how accurate needs the timer functionality have to be for regular SPI applications?

marius-meissner commented 6 years ago

Sorry, was a little lazy :) Just realized that my Raspberry3 has BCM2837 instead of BCM2835, which is using different peri address. After updating it, access to free running counter is working again.

Somehow the frequency seems to be wrong, resulting in wrong timings with exactly the same factor (~0,62). Example: 1000ms results in 620ms 2000ms results in 1240ms

Somehow the frequency is controlled by using the control address:

*(timer + (0x408 >> 2)) = 0xF90200;

Honestly I´m not really sure, how this frequency control works. Could you help?

marius-meissner commented 6 years ago

As the maintenance of this extension seems to a bit unattended, we started building our own native extension build on top of pigpio and PHP-CPP: https://github.com/Volantus/berry-spi

Testers are highly welcome :+1: