diff --git a/apps/shared/post_and_hardware_tests.cpp b/apps/shared/post_and_hardware_tests.cpp index 944568fdc..4eaea2323 100644 --- a/apps/shared/post_and_hardware_tests.cpp +++ b/apps/shared/post_and_hardware_tests.cpp @@ -17,7 +17,46 @@ bool POSTAndHardwareTests::VBlankOK() { return result; } +void ColorPixelBuffer(KDColor * pixels, int numberOfPixels, KDColor c) { + for (int i = 0; i < numberOfPixels; i++) { + pixels[i] = c; + } +} + +bool POSTAndHardwareTests::WhiteTilingLCDTestOK() { + constexpr int numberOfPixels = k_stampSize * k_stampSize; + KDColor whiteStamp[numberOfPixels]; + KDColor pullStamp[numberOfPixels]; + + ColorPixelBuffer(whiteStamp, numberOfPixels, KDColorWhite); + + // Tiling test with pushRect + KDColor wantedColor = KDColorWhite; + int numberOfInvalidPixels = 0; + for (int i = 0; i < Ion::Display::Width / k_stampSize; i++) { + for (int j = 0; j < Ion::Display::Height / k_stampSize; j++) { + // Push the color + Ion::Display::pushRect(KDRect(i * k_stampSize, j * k_stampSize, k_stampSize, k_stampSize), whiteStamp); + // Pull the display + ColorPixelBuffer(pullStamp, numberOfPixels, KDColorRed); + Ion::Display::pullRect(KDRect(i * k_stampSize, j * k_stampSize, k_stampSize, k_stampSize), pullStamp); + for (int k = 0; k < numberOfPixels; k++) { + if (pullStamp[k] != wantedColor) { + numberOfInvalidPixels++; + if (numberOfInvalidPixels > k_invalidPixelsLimit) { + return false; + } + } + } + } + } + return true; +} + bool POSTAndHardwareTests::LCDDataOK(int numberOfIterations) { + if (!WhiteTilingLCDTestOK()) { + return false; + } for (int iteration = 0; iteration < numberOfIterations; iteration++) { Ion::Display::POSTPushMulticolor(iteration, k_stampSize); KDColor stamp[k_stampSize*k_stampSize]; diff --git a/apps/shared/post_and_hardware_tests.h b/apps/shared/post_and_hardware_tests.h index 37875b601..b9059a94d 100644 --- a/apps/shared/post_and_hardware_tests.h +++ b/apps/shared/post_and_hardware_tests.h @@ -14,6 +14,7 @@ public: private: constexpr static int k_stampSize = 8; constexpr static int k_invalidPixelsLimit = 2; + static bool WhiteTilingLCDTestOK(); static_assert(Ion::Display::Width % k_stampSize == 0, "Stamps must tesselate the display"); static_assert(Ion::Display::Height % k_stampSize == 0, "Stamps must tesselate the display"); static_assert(k_stampSize % 2 == 0, "Even number of XOR needed.");