PaulStoffregen / ILI9341_t3

Optimized ILI9341 TFT Library
http://pjrc.com/store/display_ili9341.html
241 stars 93 forks source link

Off-by-one bug in readRect #29

Open pepijndevos opened 7 years ago

pepijndevos commented 7 years ago

I found that readRect will never read the last pixel.

The below sketch reproduces the problem using the Teensy 3.1, the Adafruit shield and the latest stable Teensyduino.

I fixed it by just incrementing c in readRect, but that's probably not the correct solution. It seems on the last byte you clear the SR register, which makes the check if there are 3 bytes in the FIFO fail, but not knowing the meaning of all the SPI registers I was unable to quickly see the correct solution.

#include <ILI9341_t3.h> // Hardware-specific library
#include <SPI.h>

#define TFT_DC  9
#define TFT_CS 10
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

void setup(void) {

  tft.begin();
  tft.fillScreen(ILI9341_BLUE);

  Serial.begin(9600);
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.println(F("Waiting for Arduino Serial Monitor..."));
  while (!Serial) {
    if (millis() > 8000) break;
  }

  tft.fillScreen(ILI9341_BLUE);

  uint16_t buf[32*32];
  tft.readRect(0, 0, 32, 32, buf);

  for(int i=0; i<32*32;i++) {
    if(buf[i] != ILI9341_BLUE) {
      Serial.print("Error ");
      Serial.print(i);
      Serial.print(" ");
      Serial.print(buf[i], HEX);
    }
  }

}

void loop() {
}