martinberlin / cale-idf

CalEPD is an Epaper component driver for the ESP-IDF framework with GFX and font support, optional touch interface, compatible with ESP32 / S2 / S3 / C3
https://fasani.de
Apache License 2.0
270 stars 24 forks source link

Mirrored text #91

Closed Johboh closed 1 year ago

Johboh commented 1 year ago

Hi! I have a issue where the text I'm printing is mirrored, and I have a bit of a struggle trying to find out why. This is the code (from small-display.cpp)

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <stdio.h>
#include "color/gdeh0154z90.h"

EpdSpi io;
Gdeh0154z90 display(io);

#include <Fonts/FreeMono18pt7b.h>

extern "C" {
void app_main();
}

void app_main(void) {
  display.init(false);
  vTaskDelay(1000 / portTICK_RATE_MS);

  display.setRotation(2); // without this, text is upside down (but still mirrored)
  display.fillScreen(EPD_WHITE);
  display.setTextColor(EPD_BLACK);
  display.setFont(&FreeMono18pt7b);
  display.setCursor(10, 20);
  display.print("Hello!");
  display.update();
}

This is for when using this component (@master branch) together with Adafruit GFX IDF@master in an ESP-IDF (v.4.4.4) + Visual Studio Code project. PXL_20230517_135538700

However, If I setup a platform I/O Arduino project and uses zinggjm/GxEPD with the same code (and same device and display), the text is correct. Note that in this case I don't need to set the rotation.

  display.fillScreen(GxEPD_WHITE);
  display.setTextColor(GxEPD_BLACK);
  display.setFont(&FreeMono18pt7b);
  display.setCursor(10, 20);
  display.print("Hello!");
  display.update();

PXL_20230517_140250597

I'm most probably missing something here. What could cause this?

martinberlin commented 1 year ago

Maybe I didn't test rotation right. Will take a look but I don't have one of this with 2 colors. What you can try and fix it yourself since this was a external contribution that I approved but never had a display to test.

Just try to invert the update loop (check it also for red since it has 2 buffers) https://github.com/martinberlin/cale-idf/blob/master/components/CalEPD/models/color/gdeh0154z90.cpp#L100

       // REVERSE either x or y but start with Y:

        for (uint16_t y = GDEH0154Z90_HEIGHT; y > 0; y--)
      {
        for (uint16_t x = 0; x < xLineBytes; x++)
        {
          uint16_t idx = y * xLineBytes + x;  
          x1buf[x] = (idx < sizeof(_mono_buffer)) ? ~ _mono_buffer[idx] : 0xFF;
        }
        // Flush the X line buffer to SPI
        IO.data(x1buf, sizeof(x1buf));
      }

As a reference check gdey0154d67 If that works please test all rotation modes to see it works as expected (Write 2 lines one in each color) And then please make a Merge Request so you contribute to fix the issue.

If you manage to solve it then I will try it with a similar display but only black and merge it.

- - - - If this works you don't have to do anything: FIX proposed in develop branch Please switch to that branch and test it, also with red, and different rotations. Thanks for your time

Johboh commented 1 year ago

@martinberlin I cherry picked your commit and now the text is correct, thanks! I also verified black and red colors as well as that all rotations where correct.

martinberlin commented 1 year ago

Thanks for the test. Will merge it into master soon! Mind that to use this as a component you need to use CalEPD that is in a different repository. Is easier and lighter. Moving this update there also quite soon

Johboh commented 1 year ago

Yes I'm using CalEPD and Adafruit GFX IDF as components in the project.

martinberlin commented 1 year ago

Latest this weekend develop is merged in master here and then I copy the contents to CalEPD and make a new release