Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adafruit BusIO and LVGL compatibility #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eringerli
Copy link
Contributor

@eringerli eringerli commented Jun 5, 2022

To increase the performance in the range of factor 10, I used Adafruit BusIO. This is also a stresstest for PR adafruit/Adafruit_BusIO#97, as it uses the chunked transfer for big buffers.

Other changes include:

  • replaced the #defines with constexpr constants. This allows for taking the address of it as a prefix in Adafruit_SPIDevice.cpp::write() and makes the code more type safe
  • some small formatting changes/corrections
  • added Adafruit_RA8875::setWindow() for using this lib together with LVGL
  • added Adafruit BusIO as a dependency

The only method which really profits of the chunked transfer is Adafruit_RA8875::drawPixels(). All other methods use either small, interupted or even worse bytewise transfers.

This also solves #15

@ladyada ladyada requested a review from makermelissa June 5, 2022 19:47
@ladyada
Copy link
Member

ladyada commented Jun 5, 2022

woohoo thank you for busio'ification! this is the goal of busio library - we had so many iffy spi implementations :)

@eringerli
Copy link
Contributor Author

No problem. When you have this optimised code, it would be a pitty to not use it. The refresh rate was really laggy, now it is quite usable, even as this display is not built for LVGL. I hope I can use a higher rate than 12MHz on the finished PCB, but now it is connected via these long wires, so it crashes relyably even with 14MHz.

@eringerli
Copy link
Contributor Author

eringerli commented Jun 5, 2022

Without this PR, I have about 1.5fps with 20% of a 800x480px screen refreshed. The whole screen takes about 5s to load. With it, I get about >10fps (fluid) with 20% refreshed, the whole screen takes under a second.

@eringerli
Copy link
Contributor Author

eringerli commented Jun 5, 2022

@viniciusmiguel / #39: I managed to get LVGL working with this PR, but with a custom callback:

void
ra8875Flush( lv_disp_drv_t* drv, const lv_area_t* area, lv_color_t* color_map ) {
  static lv_coord_t x1 = LV_COORD_MIN;
  static lv_coord_t x2 = LV_COORD_MIN;
  static lv_coord_t x  = LV_COORD_MIN;
  static lv_coord_t y  = LV_COORD_MIN;

  uint32_t w      = ( area->x2 - area->x1 + 1 );
  uint32_t h      = ( area->y2 - area->y1 + 1 );
  uint8_t* buffer = ( uint8_t* )color_map;

  if( ( x1 != area->x1 ) || ( x2 != area->x2 ) ) {
    tft.setWindow( area->x1, area->x2, area->y1, area->y2 );
    x1 = area->x1;
    x2 = area->x2;
  }

  // Set cursor if needed
  if( ( x != area->x1 ) || ( y != area->y1 ) ) {
    tft.setXY( area->x1, area->y1 );
    x = area->x1;
  }

  // Update to future cursor location
  y = area->y2 + 1;
  if( y >= LV_VER_RES_MAX ) {
    y = 0;
  }

  // Write data
  tft.drawPixels(
    ( uint16_t* )buffer, w * h, uint16_t( area->x1 ), uint16_t( area->y1 ) );

  lv_disp_flush_ready( drv );
}

The code is from https://github.com/lvgl/lvgl_esp32_drivers/blob/master/lvgl_tft/ra8875.c#L198 with some changes. It needs LV_COLOR_16_SWAP defined for accounting of little/big endianess.

@ladyada
Copy link
Member

ladyada commented Jun 5, 2022

oki @makermelissa will review when time allows :)

@makermelissa
Copy link
Contributor

Very exciting. I'll probably take a look at this after I get back in a few weeks. I forgot to grab the hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants