Skip to content

Commit

Permalink
Merge pull request esp8266#1930 from WereCatf/master
Browse files Browse the repository at this point in the history
Speed up writePattern() a bit more
igrr committed Apr 18, 2016

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
2 parents 7450dd3 + 8ffe1aa commit 7e4e1a4
Showing 1 changed file with 51 additions and 25 deletions.
76 changes: 51 additions & 25 deletions libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
@@ -364,36 +364,62 @@ void SPIClass::writePattern(uint8_t * data, uint8_t size, uint32_t repeat) {
uint8_t *bufferPtr=(uint8_t *)&buffer;
uint8_t *dataPtr = data;
volatile uint32_t * fifoPtr = &SPI1W0;
uint8_t r = 64 / size;
uint32_t repeatRem = repeat % r;
repeat = repeat / r;

while(r--){
dataPtr = data;
for(uint8_t i=0; i<size; i++){
*bufferPtr = *dataPtr;
bufferPtr++;
dataPtr++;
uint8_t r;
uint32_t repeatRem;
uint8_t i;

if((repeat * size) <= 64){
repeatRem = repeat * size;
r = repeat;
while(r--){
dataPtr = data;
for(i=0; i<size; i++){
*bufferPtr = *dataPtr;
bufferPtr++;
dataPtr++;
}
}
}

fifoPtr = &SPI1W0;
for(uint8_t i=0; i<16; i++){
*fifoPtr = buffer[i];
fifoPtr++;
}
r = repeatRem;
if(r & 3) r = r / 4 + 1;
else r = r / 4;
for(i=0; i<r; i++){
*fifoPtr = buffer[i];
fifoPtr++;
}
SPI1U = SPIUMOSI | SPIUSSE;
} else {
//Orig
r = 64 / size;
repeatRem = repeat % r * size;
repeat = repeat / r;

while(r--){
dataPtr = data;
for(i=0; i<size; i++){
*bufferPtr = *dataPtr;
bufferPtr++;
dataPtr++;
}
}

//Fill fifo with data
for(i=0; i<16; i++){
*fifoPtr = buffer[i];
fifoPtr++;
}

r = 64 / size;
r = 64 / size;

SPI1U = SPIUMOSI | SPIUSSE;
//Fill fifo with data
setDataBits(r * size * 8);
while(repeat--){
SPI1CMD |= SPIBUSY;
while(SPI1CMD & SPIBUSY) {}
SPI1U = SPIUMOSI | SPIUSSE;
setDataBits(r * size * 8);
while(repeat--){
SPI1CMD |= SPIBUSY;
while(SPI1CMD & SPIBUSY) {}
}
}

setDataBits(repeatRem * size * 8);
//End orig
setDataBits(repeatRem * 8);
SPI1CMD |= SPIBUSY;
while(SPI1CMD & SPIBUSY) {}

0 comments on commit 7e4e1a4

Please sign in to comment.