Skip to content

Commit

Permalink
Fix wrong opening of SPI transaction which caused freezing
Browse files Browse the repository at this point in the history
  • Loading branch information
squix78 committed Mar 9, 2019
1 parent e1c5256 commit 3298a4a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/EPD_WaveShare_29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ void EPD_WaveShare29::writeBuffer(BufferInfo *bufferInfo) {
break;
}

Serial.printf("Rotation: %d, XPos: %d, YPos: %d, Source width: %d, height: %d, target width: %d, height: %d\n", rotation, xPos, yPos, sourceWidth, sourceHeight, targetWidth, targetHeight);

uint8_t data;
uint8_t bufferUpdates = this->isFastRefreshEnabled ? 1 : 1;

SetMemoryArea(xPos, yPos, xPos + targetWidth - 1, yPos + targetHeight - 1);
SetMemoryPointer(xPos, yPos);
Expand Down Expand Up @@ -155,11 +152,13 @@ uint8_t EPD_WaveShare29::getPixel(uint8_t *buffer, uint16_t x, uint16_t y, uint1
}

int EPD_WaveShare29::IfInit(void) {
digitalWrite(this->cs_pin, OUTPUT);
pinMode(this->cs_pin, OUTPUT);
pinMode(this->reset_pin, OUTPUT);
pinMode(this->dc_pin, OUTPUT);
pinMode(this->busy_pin, INPUT);
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setFrequency(4000000);
SPI.begin();
return 0;
}
Expand Down Expand Up @@ -188,6 +187,7 @@ int EPD_WaveShare29::Init(const unsigned char* lut) {
if (IfInit() != 0) {
return -1;
}

/* EPD hardware init start */
this->lut = lut;
Reset();
Expand Down Expand Up @@ -232,9 +232,19 @@ void EPD_WaveShare29::SendData(unsigned char data) {
* @brief: Wait until the busy_pin goes LOW
*/
void EPD_WaveShare29::WaitUntilIdle(void) {
while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
DelayMs(100);
Serial.println(F("Waiting for display idle"));
unsigned long start = micros();
while (1) {
if (digitalRead(this->busy_pin) == LOW) {
break;
}
delay(1);
if (micros() - start > 10000000) {
Serial.println(F("Busy Timeout!"));
break;
}
}
Serial.println(F("Display ready"));
}

/**
Expand Down

0 comments on commit 3298a4a

Please sign in to comment.