3 Replies Latest reply on Oct 20, 2014 4:18 AM by mhahn

    MRAA - Maybe add a transfer function that you pass in rx and tx for speed

    KurtE

      Not sure if this is the best place to ask things like this, or if it would be better to instead or in addition to add a issue up on the MRAA github project.

       

      I have been playing around with Adafruit 2.8" tft display which uses SPI with an ILI9341 Controller chip.  I have now my own versions of the Adafruit_ILI9341 library ported over to run on the Intel Edison.  I have an Arduino version, and I have the version I am playing with now that runs under Linux and I am using MRAA to talk to hardware, which I have posted about.  Code for my both are up on github, the current one is in my Raspberry Pi project (KurtE/Raspberry_Pi · GitHub) Bad name, but first linux box...

       

      The current version up on github uses the standard mraa_spi functions.  One thing I noticed was the mraa_spi_write_buf function always does a malloc for return data, which I have to free, so I wondered about a transfer function that you can pass in you own RX buffer.  Also while I am not good yet at looking at device driver code, I got the impression that the rx buffer was optional to pass to it, so wondered what would happen if did not ask for the data to be returned.  So I hacked up my own transfer function...  I extracted some definitions from MRAA project

       

      #ifdef MRAA_SPI_TRANSFER_BUF

      // from internals of SPI

      struct _spi {

          /*@{*/

          int devfd; /**< File descriptor to SPI Device */

          int mode; /**< Spi mode see spidev.h */

          int clock; /**< clock to run transactions at */

          mraa_boolean_t lsb; /**< least significant bit mode */

          unsigned int bpw; /**< Bits per word */

          /*@}*/

      };

       

       

      mraa_result_t mraa_spi_transfer_buf(mraa_spi_context dev, uint8_t* abOut, uint8_t* abIn, int length)

      {

          struct spi_ioc_transfer msg;

          memset(&msg, 0, sizeof(msg));

       

          msg.tx_buf = (unsigned long) abOut;

          msg.rx_buf = (unsigned long) abIn;

          msg.speed_hz = dev->clock;

          msg.bits_per_word = dev->bpw;

          msg.delay_usecs = 0;

          msg.len = length;

          if (ioctl(dev->devfd, SPI_IOC_MESSAGE(1), &msg) < 0) {

              //syslog(LOG_ERR, "Failed to perform dev transfer");

              return MRAA_ERROR_INVALID_RESOURCE;

          }

          return MRAA_SUCCESS;

      }

       

      #endif

       

      I then changed my ported version of the Adafruit graphic test program to see if it changed in the timings.  Before my change my last run showed:

      ILI9341 Test!

      Display Power Mode: 0x9C

      MADCTL Mode: 0x48

      Pixel Format: 0x5

      Image Format: 0x9C

      Self Diagnostic: 0xC0

      Benchmark                Time (microseconds)

      Screen fill              2969897

      Text                     2833053

      Lines                    27616144

      Horiz/Vert Lines         342621

      Rectangles (outline)     488944

      Rectangles (filled)      6204091

      Circles (filled)         15837252

      Circles (outline)        12089819

      Triangles (outline)      8772333

      Triangles (filled)       10038844

      Rounded rects (outline)  3949121

      Rounded rects (filled)   9064036

      Done!

       

      After I changed my code in the driver to use the function above the timings are:

      root@Edison:~/Raspberry_Pi/testAdafruit_ILI9341C# ./graphictest

      ILI9341 Test!

      Display Power Mode: 0x9C

      MADCTL Mode: 0x48

      Pixel Format: 0x5

      Image Format: 0x9C

      Self Diagnostic: 0x0

      Benchmark                Time (microseconds)

      Screen fill              2909710

      Text                     2780826

      Lines                    27218499

      Horiz/Vert Lines         338233

      Rectangles (outline)     476022

      Rectangles (filled)      6057534

      Circles (filled)         15288228

      Circles (outline)        11925822

      Triangles (outline)      8634251

      Triangles (filled)       9750937

      Rounded rects (outline)  3882691

      Rounded rects (filled)   8900734

      Done!

      Also wondering what will happen if I pass NULL for tx and non NULL for rx, which may also speed up some of my readPixel/readRect type functions

       

      Again not sure if this is the appropriate place to ask, but personally I think adding a function like this to the main MRAA?

       

      Thanks